From df5535cc87a4ef9d4cb9a126289401fae135c6fd Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 23 Sep 2016 20:18:27 -0400 Subject: [PATCH] basic navigation kinda works most of the time --- 4ed_file_view.cpp | 39 ++++++++++++++++++++----------- buffer/4coder_buffer_abstract.cpp | 20 ++++++++++------ buffer/4coder_gap_buffer.cpp | 1 + 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index d699f6db..c55caf12 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -393,15 +393,36 @@ view_compute_cursor(View *view, Buffer_Seek seek){ Buffer_Cursor_Seek_Params params; params.buffer = &file->state.buffer; params.seek = seek; - params.max_width = view_file_display_width(view); + params.width = view_file_display_width(view); params.font_height = (f32)font->height; params.adv = font->advance_data; params.wraps = file->state.wraps; - params.virtual_white = 0; + params.virtual_white = 1; Buffer_Cursor_Seek_State state = {0}; Full_Cursor result; - buffer_cursor_seek(&state, params, 0, &result); + Buffer_Layout_Stop stop; + + f32 edge_tolerance = 50.f; + if (edge_tolerance > params.width){ + edge_tolerance = params.width; + } + + f32 line_shift = 0.f; + do{ + f32 this_line_shift = line_shift; + if (this_line_shift > params.width - edge_tolerance){ + this_line_shift = params.width - edge_tolerance; + } + + stop = buffer_cursor_seek(&state, params, this_line_shift, &result); + switch (stop.status){ + case BLStatus_NeedWrapLineShift: + case BLStatus_NeedLineShift: + line_shift = (stop.line_index%4)*9.f; + break; + } + }while(stop.status != BLStatus_Finished); return(result); } @@ -4758,17 +4779,12 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target Buffer_Render_State state = {0}; Buffer_Layout_Stop stop; - f32 line_shift = (render_cursor.line%4)*15.f + 30.f; - while (line_shift >= 60.f){ - line_shift -= 60.f; - } - f32 edge_tolerance = 50.f; - if (edge_tolerance > params.width){ edge_tolerance = params.width; } + f32 line_shift = 0.f; do{ f32 this_line_shift = line_shift; if (this_line_shift > params.width - edge_tolerance){ @@ -4779,10 +4795,7 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target switch (stop.status){ case BLStatus_NeedWrapLineShift: case BLStatus_NeedLineShift: - line_shift += 15.f; - if (line_shift >= 60.f){ - line_shift -= 60.f; - } + line_shift = (stop.line_index%4)*9.f; break; } }while(stop.status != BLStatus_Finished); diff --git a/buffer/4coder_buffer_abstract.cpp b/buffer/4coder_buffer_abstract.cpp index 0e83a2ff..8ccdbbf1 100644 --- a/buffer/4coder_buffer_abstract.cpp +++ b/buffer/4coder_buffer_abstract.cpp @@ -424,8 +424,12 @@ buffer_partial_from_line_character(Buffer_Type *buffer, i32 line, i32 character) max_character = (next_start-this_start); } - if (character <= 0) character = 1; - if (character > max_character) character = max_character; + if (character <= 0){ + character = 1; + } + if (character > max_character){ + character = max_character; + } result.pos = this_start + character - 1; result.line = line_index+1; @@ -437,7 +441,7 @@ buffer_partial_from_line_character(Buffer_Type *buffer, i32 line, i32 character) struct Buffer_Cursor_Seek_Params{ Buffer_Type *buffer; Buffer_Seek seek; - f32 max_width; + f32 width; f32 font_height; f32 *adv; f32 *wraps; @@ -553,10 +557,10 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa S.stream.use_termination_character = 1; S.stream.terminator = '\n'; - if (buffer_stringify_loop(&S.stream, params.buffer, S.i, S.size)){ + if (buffer_stringify_loop(&S.stream, params.buffer, S.cursor.pos, S.size)){ do{ for (; S.cursor.pos < S.stream.end; ++S.cursor.pos){ - S.ch = (u8)S.stream.data[S.i]; + S.ch = (u8)S.stream.data[S.cursor.pos]; if (S.ch != ' ' && S.ch != '\t'){ goto double_break_vwhite; @@ -564,10 +568,12 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa else{ ++S.cursor.character; } + } S.still_looping = buffer_stringify_next(&S.stream); }while(S.still_looping); } + InvalidCodePath; double_break_vwhite:; } @@ -605,9 +611,9 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa // Main seek loop S.i = S.cursor.pos; + S.stream = null_buffer_stream; S.stream.use_termination_character = 1; S.stream.terminator = 0; - if (buffer_stringify_loop(&S.stream, params.buffer, S.i, S.size)){ S.still_looping = 0; do{ @@ -631,7 +637,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa { f32 ch_width = params.adv[S.ch]; - if (S.cursor.wrapped_x + ch_width > params.max_width){ + if (S.cursor.wrapped_x + ch_width > params.width){ S.cursor.wrapped_y += params.font_height; S.cursor.wrapped_x = 0; S.prev_cursor = S.cursor; diff --git a/buffer/4coder_gap_buffer.cpp b/buffer/4coder_gap_buffer.cpp index 803b0e48..bb01fb06 100644 --- a/buffer/4coder_gap_buffer.cpp +++ b/buffer/4coder_gap_buffer.cpp @@ -108,6 +108,7 @@ typedef struct Gap_Buffer_Stream{ b32 use_termination_character; char terminator; } Gap_Buffer_Stream; +static Gap_Buffer_Stream null_buffer_stream = {0}; internal_4tech b32 buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, i32 start, i32 end){