added a wrap_line index to the cursors, switch the dialogical wrap APIs to using wrap_line instead of pos, for identifying wrap positions

master
Allen Webster 2016-09-27 15:33:44 -04:00
parent ab4bdaf535
commit 8f8806f86d
3 changed files with 39 additions and 27 deletions

View File

@ -178,10 +178,11 @@ for concisely creating Buffer_Seek structs. They can be found in 4coder_buffer_
user's expected behavior. Not rounding down means that the right hand portion of
the character's box, which is closer to the next character, will land on that next
character. The unrounded behavior is the expected behavior when moving vertically
and keeping the preferred x.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>x</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>The x coordinate for xy type seeks.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>y</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>The y coordinate for xy type seeks.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>line</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>The line number of a line-character type seek.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>character</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>The character number of a line-character type seek.<br><br></div></div></div><div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>See Also</i></b></div><div style='margin-left: 5mm; margin-right: 5mm;'><a href='#Buffer_Seek_Type_doc'>Buffer_Seek_Type</a></div><div style='margin-left: 5mm; margin-right: 5mm;'><a href='#4coder_Buffer_Positioning_System_doc'>4coder_Buffer_Positioning_System</a></div></div><hr><div id='Full_Cursor_doc' style='margin-bottom: 1cm;'><h4>&sect;3.4.35: Full_Cursor</h4><div style='font-family: "Courier New", Courier, monospace; text-align: left; margin-top: 3mm; margin-bottom: 3mm; font-size: .95em; background: #DFDFDF; padding: 0.25em;'>struct Full_Cursor {<br><div style='margin-left: 8mm;'>int32_t pos;<br>int32_t character_pos;<br>int32_t line;<br>int32_t character;<br>float unwrapped_x;<br>float unwrapped_y;<br>float wrapped_x;<br>float wrapped_y;<br></div>};<br></div><div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>Description</i></b></div><div style='margin-left: 5mm; margin-right: 5mm;'>Full_Cursor describes the position of a cursor in every buffer
and keeping the preferred x.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>x</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>The x coordinate for xy type seeks.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>y</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>The y coordinate for xy type seeks.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>line</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>The line number of a line-character type seek.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>character</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>The character number of a line-character type seek.<br><br></div></div></div><div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>See Also</i></b></div><div style='margin-left: 5mm; margin-right: 5mm;'><a href='#Buffer_Seek_Type_doc'>Buffer_Seek_Type</a></div><div style='margin-left: 5mm; margin-right: 5mm;'><a href='#4coder_Buffer_Positioning_System_doc'>4coder_Buffer_Positioning_System</a></div></div><hr><div id='Full_Cursor_doc' style='margin-bottom: 1cm;'><h4>&sect;3.4.35: Full_Cursor</h4><div style='font-family: "Courier New", Courier, monospace; text-align: left; margin-top: 3mm; margin-bottom: 3mm; font-size: .95em; background: #DFDFDF; padding: 0.25em;'>struct Full_Cursor {<br><div style='margin-left: 8mm;'>int32_t pos;<br>int32_t character_pos;<br>int32_t line;<br>int32_t character;<br>int32_t wrap_line;<br>float unwrapped_x;<br>float unwrapped_y;<br>float wrapped_x;<br>float wrapped_y;<br></div>};<br></div><div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>Description</i></b></div><div style='margin-left: 5mm; margin-right: 5mm;'>Full_Cursor describes the position of a cursor in every buffer
coordinate system supported by 4coder. This cursor type requires that
the buffer is associated with a view to give the x/y values meaning.<br><br></div><div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>Fields</i></b></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>pos</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>This field contains the cursor's position in absolute byte index positioning.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>character_pos</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>This field contains the cursor's position in apparent character index positioning.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>line</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>This field contains the number of the line where the cursor is located. This field is one based.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>character</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>This field contains the number of the character from the beginninf of the line
where the cursor is located. This field is one based.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>unwrapped_x</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>This field contains the x position measured with unwrapped lines.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>unwrapped_y</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>This field contains the y position measured with unwrapped lines.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>wrapped_x</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>This field contains the x position measured with wrapped lines.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>wrapped_y</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>This field contains the y position measured with wrapped lines.<br><br></div></div></div><div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>See Also</i></b></div><div style='margin-left: 5mm; margin-right: 5mm;'><a href='#4coder_Buffer_Positioning_System_doc'>4coder_Buffer_Positioning_System</a></div></div><hr><div id='Partial_Cursor_doc' style='margin-bottom: 1cm;'><h4>&sect;3.4.36: Partial_Cursor</h4><div style='font-family: "Courier New", Courier, monospace; text-align: left; margin-top: 3mm; margin-bottom: 3mm; font-size: .95em; background: #DFDFDF; padding: 0.25em;'>struct Partial_Cursor {<br><div style='margin-left: 8mm;'>int32_t pos;<br>int32_t line;<br>int32_t character;<br></div>};<br></div><div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>Description</i></b></div><div style='margin-left: 5mm; margin-right: 5mm;'>Partial_Cursor describes the position of a cursor in all of
where the cursor is located. This field is one based.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>wrap_line</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>This field contains the number of the line where the cursor is located, taking the line wrapping
into account. This field is one based.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>unwrapped_x</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>This field contains the x position measured with unwrapped lines.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>unwrapped_y</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>This field contains the y position measured with unwrapped lines.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>wrapped_x</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>This field contains the x position measured with wrapped lines.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>wrapped_y</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>This field contains the y position measured with wrapped lines.<br><br></div></div></div><div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>See Also</i></b></div><div style='margin-left: 5mm; margin-right: 5mm;'><a href='#4coder_Buffer_Positioning_System_doc'>4coder_Buffer_Positioning_System</a></div></div><hr><div id='Partial_Cursor_doc' style='margin-bottom: 1cm;'><h4>&sect;3.4.36: Partial_Cursor</h4><div style='font-family: "Courier New", Courier, monospace; text-align: left; margin-top: 3mm; margin-bottom: 3mm; font-size: .95em; background: #DFDFDF; padding: 0.25em;'>struct Partial_Cursor {<br><div style='margin-left: 8mm;'>int32_t pos;<br>int32_t line;<br>int32_t character;<br></div>};<br></div><div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>Description</i></b></div><div style='margin-left: 5mm; margin-right: 5mm;'>Partial_Cursor describes the position of a cursor in all of
the coordinate systems that a invariant to the View. In other words
the coordinate systems available here can be used on a buffer that is
not currently associated with a View.<br><br></div><div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>Fields</i></b></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>pos</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>This field contains the cursor's position in absolute byte index positioning.<br><br></div></div></div><div><div style='font-family: "Courier New", Courier, monospace; text-align: left;'><span style='font-weight: 600;'>line</span></div><div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>This field contains the number of the character from the beginninf of the line

View File

@ -557,6 +557,9 @@ struct Full_Cursor{
/* DOC(This field contains the number of the character from the beginninf of the line
where the cursor is located. This field is one based.) */
int32_t character;
/* DOC(This field contains the number of the line where the cursor is located, taking the line wrapping
into account. This field is one based.) */
int32_t wrap_line;
/* DOC(This field contains the x position measured with unwrapped lines.) */
float unwrapped_x;
/* DOC(This field contains the y position measured with unwrapped lines.) */

View File

@ -220,7 +220,7 @@ enum{
struct Buffer_Layout_Stop{
u32 status;
i32 line_index;
i32 pos;
i32 wrap_line_index;
};
internal_4tech Buffer_Layout_Stop
@ -239,7 +239,7 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para
if (params.virtual_white){
S_stop.status = BLStatus_NeedLineShift;
S_stop.line_index = S.line_index;
S_stop.pos = S.i;
S_stop.wrap_line_index = S.current_wrap_index;
DrYield(1, S_stop);
}
@ -262,7 +262,7 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para
if (params.virtual_white){
S_stop.status = BLStatus_NeedLineShift;
S_stop.line_index = S.line_index - 1;
S_stop.pos = S.i+1;
S_stop.wrap_line_index = S.current_wrap_index;
DrYield(2, S_stop);
}
@ -285,7 +285,7 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para
if (params.virtual_white){
S_stop.status = BLStatus_NeedWrapLineShift;
S_stop.line_index = S.line_index - 1;
S_stop.pos = S.i;
S_stop.wrap_line_index = S.current_wrap_index;
DrYield(3, S_stop);
}
@ -582,16 +582,16 @@ buffer_get_line_index_range(Buffer_Type *buffer, i32 pos, i32 l_bound, i32 u_bou
end = i;
}
else{
start = i;
break;
}
assert_4tech(start < end);
if (start == end - 1){
i = start;
break;
}
}
return(start);
return(i);
}
inline_4tech i32
@ -600,7 +600,7 @@ buffer_get_line_index(Buffer_Type *buffer, i32 pos){
return(result);
}
// TODO(allen): Try to merge this with the other line start binary search.
// TODO(allen): Merge all these binary searches.
internal_4tech i32
buffer_get_line_index_from_character_pos(i32 *character_starts, i32 pos, i32 l_bound, i32 u_bound){
i32 start = l_bound, end = u_bound;
@ -815,6 +815,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
S.cursor.character_pos = params.character_starts[line_index];
S.cursor.line = line_index + 1;
S.cursor.character = 1;
S.cursor.wrap_line = params.wrap_line_index[line_index] + 1;
S.cursor.unwrapped_y = (f32)(line_index * params.font_height);
S.cursor.unwrapped_x = 0;
S.cursor.wrapped_y = (f32)(params.wrap_line_index[line_index] * params.font_height);
@ -825,9 +826,9 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
// Adjust the non-screen based coordinates to point to the first
// non-virtual character of the line.
if (params.virtual_white){
S_stop.status = BLStatus_NeedLineShift;
S_stop.line_index = S.cursor.line-1;
S_stop.pos = S.cursor.pos;
S_stop.status = BLStatus_NeedLineShift;
S_stop.line_index = S.cursor.line-1;
S_stop.wrap_line_index = S.cursor.wrap_line-1;
DrYield(1, S_stop);
S.cursor.unwrapped_x += line_shift;
@ -913,15 +914,16 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
{
++S.cursor.character_pos;
++S.cursor.line;
++S.cursor.wrap_line;
S.cursor.unwrapped_y += params.font_height;
S.cursor.wrapped_y += params.font_height;
S.cursor.character = 1;
S.cursor.unwrapped_x = 0;
if (params.virtual_white){
S_stop.status = BLStatus_NeedLineShift;
S_stop.line_index = S.cursor.line-1;
S_stop.pos = S.cursor.pos+1;
S_stop.status = BLStatus_NeedLineShift;
S_stop.line_index = S.cursor.line-1;
S_stop.wrap_line_index = S.cursor.wrap_line-1;
DrYield(2, S_stop);
}
@ -935,10 +937,11 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
if (S.cursor.wrapped_x + S.ch_width > params.width){
S.cursor.wrapped_y += params.font_height;
++S.cursor.wrap_line;
if (params.virtual_white){
S_stop.status = BLStatus_NeedWrapLineShift;
S_stop.line_index = S.cursor.line-1;
S_stop.pos = S.cursor.pos;
S_stop.status = BLStatus_NeedWrapLineShift;
S_stop.line_index = S.cursor.line-1;
S_stop.wrap_line_index = S.cursor.wrap_line-1;
DrYield(3, S_stop);
}
@ -1162,6 +1165,7 @@ struct Buffer_Render_State{
Render_Item_Write write;
i32 line;
i32 wrap_line;
b32 skipping_whitespace;
i32 __pc__;
@ -1197,11 +1201,12 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32
}
S.line = params.start_cursor.line - 1;
S.wrap_line = params.start_cursor.wrap_line - 1;
if (params.virtual_white){
S_stop.status = BLStatus_NeedLineShift;
S_stop.line_index = S.line;
S_stop.pos = params.start_cursor.pos;
S_stop.status = BLStatus_NeedLineShift;
S_stop.line_index = S.line;
S_stop.wrap_line_index = S.wrap_line;
DrYield(1, S_stop);
}
@ -1226,12 +1231,14 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32
if (S.ch_width + S.write.x > params.width + shift_x && S.ch != '\n' && params.wrapped){
if (params.virtual_white){
S_stop.status = BLStatus_NeedWrapLineShift;
S_stop.line_index = S.line;
S_stop.pos = S.i+1;
S_stop.status = BLStatus_NeedWrapLineShift;
S_stop.line_index = S.line;
S_stop.wrap_line_index = S.wrap_line + 1;
DrYield(2, S_stop);
}
++S.wrap_line;
S.write.x = shift_x + line_shift;
S.write.y += params.font_height;
}
@ -1251,15 +1258,16 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32
S.write = write_render_item(S.write, S.i, ' ', 0);
if (params.virtual_white){
S_stop.status = BLStatus_NeedLineShift;
S_stop.line_index = S.line+1;
S_stop.pos = S.i+1;
S_stop.status = BLStatus_NeedLineShift;
S_stop.line_index = S.line+1;
S_stop.wrap_line_index = S.wrap_line+1;
DrYield(3, S_stop);
S.skipping_whitespace = 1;
}
++S.line;
++S.wrap_line;
S.write.x = shift_x + line_shift;
S.write.y += params.font_height;