From 8f8806f86dbb25efd4191f8a7add9d9d84b4bc81 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Tue, 27 Sep 2016 15:33:44 -0400 Subject: [PATCH] added a wrap_line index to the cursors, switch the dialogical wrap APIs to using wrap_line instead of pos, for identifying wrap positions --- 4coder_API.html | 5 +-- 4coder_types.h | 3 ++ buffer/4coder_buffer_abstract.cpp | 58 ++++++++++++++++++------------- 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/4coder_API.html b/4coder_API.html index 4276e789..3d1c51f8 100644 --- a/4coder_API.html +++ b/4coder_API.html @@ -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.

x
The x coordinate for xy type seeks.

y
The y coordinate for xy type seeks.

line
The line number of a line-character type seek.

character
The character number of a line-character type seek.

See Also
Buffer_Seek_Type
4coder_Buffer_Positioning_System

§3.4.35: Full_Cursor

struct Full_Cursor {
int32_t pos;
int32_t character_pos;
int32_t line;
int32_t character;
float unwrapped_x;
float unwrapped_y;
float wrapped_x;
float wrapped_y;
};
Description
Full_Cursor describes the position of a cursor in every buffer + and keeping the preferred x.

x
The x coordinate for xy type seeks.

y
The y coordinate for xy type seeks.

line
The line number of a line-character type seek.

character
The character number of a line-character type seek.

See Also
Buffer_Seek_Type
4coder_Buffer_Positioning_System

§3.4.35: Full_Cursor

struct Full_Cursor {
int32_t pos;
int32_t character_pos;
int32_t line;
int32_t character;
int32_t wrap_line;
float unwrapped_x;
float unwrapped_y;
float wrapped_x;
float wrapped_y;
};
Description
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.

Fields
pos
This field contains the cursor's position in absolute byte index positioning.

character_pos
This field contains the cursor's position in apparent character index positioning.

line
This field contains the number of the line where the cursor is located. This field is one based.

character
This field contains the number of the character from the beginninf of the line - where the cursor is located. This field is one based.

unwrapped_x
This field contains the x position measured with unwrapped lines.

unwrapped_y
This field contains the y position measured with unwrapped lines.

wrapped_x
This field contains the x position measured with wrapped lines.

wrapped_y
This field contains the y position measured with wrapped lines.

See Also
4coder_Buffer_Positioning_System

§3.4.36: Partial_Cursor

struct Partial_Cursor {
int32_t pos;
int32_t line;
int32_t character;
};
Description
Partial_Cursor describes the position of a cursor in all of + where the cursor is located. This field is one based.

wrap_line
This field contains the number of the line where the cursor is located, taking the line wrapping + into account. This field is one based.

unwrapped_x
This field contains the x position measured with unwrapped lines.

unwrapped_y
This field contains the y position measured with unwrapped lines.

wrapped_x
This field contains the x position measured with wrapped lines.

wrapped_y
This field contains the y position measured with wrapped lines.

See Also
4coder_Buffer_Positioning_System

§3.4.36: Partial_Cursor

struct Partial_Cursor {
int32_t pos;
int32_t line;
int32_t character;
};
Description
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.

Fields
pos
This field contains the cursor's position in absolute byte index positioning.

line
This field contains the number of the character from the beginninf of the line diff --git a/4coder_types.h b/4coder_types.h index 72e923e3..42203fc8 100644 --- a/4coder_types.h +++ b/4coder_types.h @@ -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.) */ diff --git a/buffer/4coder_buffer_abstract.cpp b/buffer/4coder_buffer_abstract.cpp index 1786cf56..33fd37fa 100644 --- a/buffer/4coder_buffer_abstract.cpp +++ b/buffer/4coder_buffer_abstract.cpp @@ -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;