collapsed all view seeks down to one function so the seek struct can be passed straight through. fixed a bug with the seek bounds checking.
parent
ab207cf8f0
commit
5be1cd9588
5
4ed.cpp
5
4ed.cpp
|
@ -391,11 +391,10 @@ COMMAND_DECL(reopen){
|
|||
view_set_file(vptrs[i], file, models);
|
||||
|
||||
int32_t line = line_number[i];
|
||||
int32_t column = column_number[i];
|
||||
int32_t character = column_number[i];
|
||||
|
||||
*vptrs[i]->edit_pos = edit_poss[i];
|
||||
Full_Cursor cursor =
|
||||
view_compute_cursor_from_line_char(vptrs[i], line, column);
|
||||
Full_Cursor cursor = view_compute_cursor(vptrs[i], seek_line_char(line, character));
|
||||
|
||||
view_set_cursor(vptrs[i], cursor, true,
|
||||
file->settings.unwrapped_lines);
|
||||
|
|
|
@ -81,7 +81,7 @@ fill_view_summary(View_Summary *view, View *vptr, Live_Views *live_set, Working_
|
|||
|
||||
view->buffer_id = buffer_id;
|
||||
|
||||
view->mark = view_compute_cursor_from_pos(vptr, vptr->edit_pos->mark);
|
||||
view->mark = view_compute_cursor(vptr, seek_pos(vptr->edit_pos->mark));
|
||||
view->cursor = vptr->edit_pos->cursor;
|
||||
view->preferred_x = vptr->edit_pos->preferred_x;
|
||||
|
||||
|
|
|
@ -384,6 +384,7 @@ view_cursor_limits(View *view){
|
|||
return(limits);
|
||||
}
|
||||
|
||||
#if 0
|
||||
inline Full_Cursor
|
||||
view_compute_cursor_from_pos(View *view, i32 pos){
|
||||
Editing_File *file = view->file_data.file;
|
||||
|
@ -459,41 +460,37 @@ view_compute_cursor_from_line_char(View *view, i32 line, i32 character){
|
|||
|
||||
return(result);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline Full_Cursor
|
||||
view_compute_cursor(View *view, Buffer_Seek seek){
|
||||
Full_Cursor result = {};
|
||||
Editing_File *file = view->file_data.file;
|
||||
Models *models = view->persistent.models;
|
||||
Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font;
|
||||
|
||||
switch(seek.type){
|
||||
case buffer_seek_pos:
|
||||
result = view_compute_cursor_from_pos(view, seek.pos);
|
||||
break;
|
||||
|
||||
case buffer_seek_wrapped_xy:
|
||||
result = view_compute_cursor_from_wrapped_xy(view, seek.x, seek.y, seek.round_down);
|
||||
break;
|
||||
|
||||
case buffer_seek_unwrapped_xy:
|
||||
result = view_compute_cursor_from_unwrapped_xy(view, seek.x, seek.y, seek.round_down);
|
||||
break;
|
||||
|
||||
case buffer_seek_line_char:
|
||||
result = view_compute_cursor_from_line_char(view, seek.line, seek.character);
|
||||
break;
|
||||
}
|
||||
Buffer_Cursor_Seek_Params params;
|
||||
params.buffer = &file->state.buffer;
|
||||
params.seek = seek;
|
||||
params.max_width = view_file_display_width(view);
|
||||
params.font_height = (f32)font->height;
|
||||
params.adv = font->advance_data;
|
||||
params.wraps = file->state.wraps;
|
||||
|
||||
Full_Cursor result = buffer_cursor_seek(params);
|
||||
return (result);
|
||||
}
|
||||
|
||||
inline Full_Cursor
|
||||
view_compute_cursor_from_xy(View *view, f32 seek_x, f32 seek_y){
|
||||
Full_Cursor result;
|
||||
Buffer_Seek seek;
|
||||
if (view->file_data.file->settings.unwrapped_lines){
|
||||
result = view_compute_cursor_from_unwrapped_xy(view, seek_x, seek_y);
|
||||
seek = seek_unwrapped_xy(seek_x, seek_y, 0);
|
||||
}
|
||||
else{
|
||||
result = view_compute_cursor_from_wrapped_xy(view, seek_x, seek_y);
|
||||
seek = seek_wrapped_xy(seek_x, seek_y, 0);
|
||||
}
|
||||
|
||||
Full_Cursor result = view_compute_cursor(view, seek);
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
@ -647,7 +644,7 @@ view_set_cursor_and_scroll(View *view,
|
|||
|
||||
inline void
|
||||
view_set_temp_highlight(View *view, i32 pos, i32 end_pos){
|
||||
view->file_data.temp_highlight = view_compute_cursor_from_pos(view, pos);
|
||||
view->file_data.temp_highlight = view_compute_cursor(view, seek_pos(pos));
|
||||
view->file_data.temp_highlight_end_pos = end_pos;
|
||||
view->file_data.show_temp_highlight = 1;
|
||||
|
||||
|
@ -895,7 +892,7 @@ file_update_cursor_positions(Models *models, Editing_File *file){
|
|||
i32 pos = view_get_cursor_pos(iter.view);
|
||||
|
||||
if (!iter.view->file_data.show_temp_highlight){
|
||||
Full_Cursor cursor = view_compute_cursor_from_pos(iter.view, pos);
|
||||
Full_Cursor cursor = view_compute_cursor(iter.view, seek_pos(pos));
|
||||
view_set_cursor(iter.view, cursor, 1, iter.view->file_data.file->settings.unwrapped_lines);
|
||||
}
|
||||
else{
|
||||
|
@ -1679,25 +1676,27 @@ view_cursor_move(View *view, Full_Cursor cursor){
|
|||
|
||||
inline void
|
||||
view_cursor_move(View *view, i32 pos){
|
||||
Full_Cursor cursor = view_compute_cursor_from_pos(view, pos);
|
||||
Full_Cursor cursor = view_compute_cursor(view, seek_pos(pos));
|
||||
view_cursor_move(view, cursor);
|
||||
}
|
||||
|
||||
inline void
|
||||
view_cursor_move(View *view, f32 x, f32 y, b32 round_down = 0){
|
||||
Full_Cursor cursor;
|
||||
Buffer_Seek seek;
|
||||
if (view->file_data.file->settings.unwrapped_lines){
|
||||
cursor = view_compute_cursor_from_unwrapped_xy(view, x, y, round_down);
|
||||
seek = seek_unwrapped_xy(x, y, round_down);
|
||||
}
|
||||
else{
|
||||
cursor = view_compute_cursor_from_wrapped_xy(view, x, y, round_down);
|
||||
seek = seek_wrapped_xy(x, y, round_down);
|
||||
}
|
||||
|
||||
Full_Cursor cursor = view_compute_cursor(view, seek);
|
||||
view_cursor_move(view, cursor);
|
||||
}
|
||||
|
||||
inline void
|
||||
view_cursor_move(View *view, i32 line, i32 pos){
|
||||
Full_Cursor cursor = view_compute_cursor_from_line_char(view, line, pos);
|
||||
view_cursor_move(View *view, i32 line, i32 character){
|
||||
Full_Cursor cursor = view_compute_cursor(view, seek_line_char(line, character));
|
||||
view_cursor_move(view, cursor);
|
||||
}
|
||||
|
||||
|
@ -1955,8 +1954,7 @@ file_edit_cursor_fix(System_Functions *system, Models *models,
|
|||
Assert(view->edit_pos);
|
||||
|
||||
i32 cursor_pos = cursors[cursor_count++].pos;
|
||||
Full_Cursor new_cursor =
|
||||
view_compute_cursor_from_pos(view, cursor_pos);
|
||||
Full_Cursor new_cursor = view_compute_cursor(view, seek_pos(cursor_pos));
|
||||
|
||||
GUI_Scroll_Vars scroll = view->edit_pos->scroll;
|
||||
|
||||
|
@ -1965,8 +1963,7 @@ file_edit_cursor_fix(System_Functions *system, Models *models,
|
|||
if (view->edit_pos->scroll_i != new_scroll_i){
|
||||
view->edit_pos->scroll_i = new_scroll_i;
|
||||
|
||||
Full_Cursor temp_cursor =
|
||||
view_compute_cursor_from_pos(view, view->edit_pos->scroll_i);
|
||||
Full_Cursor temp_cursor = view_compute_cursor(view, seek_pos(view->edit_pos->scroll_i));
|
||||
|
||||
f32 y_offset = MOD(view->edit_pos->scroll.scroll_y, view->line_height);
|
||||
f32 y_position = temp_cursor.wrapped_y;
|
||||
|
|
|
@ -461,7 +461,6 @@ buffer_cursor_seek(Buffer_Cursor_Seek_Params params){
|
|||
|
||||
i32 line_index = buffer_get_line_index_range(params.buffer, params.seek.pos, 0, params.buffer->line_count);
|
||||
cursor = make_cursor_hint(line_index, params.buffer->line_starts, params.wraps, params.font_height);
|
||||
|
||||
if (cursor.pos >= params.seek.pos){
|
||||
goto buffer_cursor_seek_end;
|
||||
}
|
||||
|
@ -470,7 +469,6 @@ buffer_cursor_seek(Buffer_Cursor_Seek_Params params){
|
|||
case buffer_seek_line_char:
|
||||
{
|
||||
i32 line_index = params.seek.line - 1;
|
||||
|
||||
if (line_index >= params.buffer->line_count){
|
||||
line_index = params.buffer->line_count - 1;
|
||||
}
|
||||
|
@ -479,8 +477,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_Params params){
|
|||
}
|
||||
|
||||
cursor = make_cursor_hint(line_index, params.buffer->line_starts, params.wraps, params.font_height);
|
||||
|
||||
if (params.seek.x == 0 && cursor.wrapped_y >= params.seek.y){
|
||||
if (cursor.line >= params.seek.line && cursor.character >= params.seek.character){
|
||||
goto buffer_cursor_seek_end;
|
||||
}
|
||||
}break;
|
||||
|
@ -488,7 +485,6 @@ buffer_cursor_seek(Buffer_Cursor_Seek_Params params){
|
|||
case buffer_seek_unwrapped_xy:
|
||||
{
|
||||
i32 line_index = (i32)(params.seek.y / params.font_height);
|
||||
|
||||
if (line_index >= params.buffer->line_count){
|
||||
line_index = params.buffer->line_count - 1;
|
||||
}
|
||||
|
@ -497,7 +493,6 @@ buffer_cursor_seek(Buffer_Cursor_Seek_Params params){
|
|||
}
|
||||
|
||||
cursor = make_cursor_hint(line_index, params.buffer->line_starts, params.wraps, params.font_height);
|
||||
|
||||
if (params.seek.x == 0 && cursor.unwrapped_y >= params.seek.y){
|
||||
goto buffer_cursor_seek_end;
|
||||
}
|
||||
|
@ -509,8 +504,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_Params params){
|
|||
params.font_height, 0, params.buffer->line_count);
|
||||
|
||||
cursor = make_cursor_hint(line_index, params.buffer->line_starts, params.wraps, params.font_height);
|
||||
|
||||
if (cursor.line >= params.seek.line && cursor.character >= params.seek.character){
|
||||
if (params.seek.x == 0 && cursor.wrapped_y >= params.seek.y){
|
||||
goto buffer_cursor_seek_end;
|
||||
}
|
||||
}break;
|
||||
|
@ -702,7 +696,7 @@ typedef struct Render_Item_Write{
|
|||
|
||||
inline_4tech Render_Item_Write
|
||||
write_render_item(Render_Item_Write write, i32 index, u16 glyphid, u16 flags){
|
||||
f32 ch_width = measure_character(write.adv, (char)glyphid);
|
||||
f32 ch_width = write.adv[(u8)glyphid];
|
||||
|
||||
if (write.x <= write.x_max && write.x + ch_width >= write.x_min){
|
||||
write.item->index = index;
|
||||
|
@ -753,6 +747,7 @@ struct Buffer_Render_State{
|
|||
|
||||
i32 line;
|
||||
b32 skipping_whitespace;
|
||||
b32 first_whitespace_skip;
|
||||
|
||||
i32 __pc__;
|
||||
};
|
||||
|
@ -820,7 +815,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32
|
|||
do{
|
||||
for (; S.i < S.stream.end; ++S.i){
|
||||
S.ch = (u8)S.stream.data[S.i];
|
||||
S.ch_width = measure_character(params.adv, S.ch);
|
||||
S.ch_width = params.adv[S.ch];
|
||||
|
||||
if (S.ch_width + S.write.x > params.width + shift_x && S.ch != '\n' && params.wrapped){
|
||||
if (params.virtual_white){
|
||||
|
@ -842,6 +837,12 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32
|
|||
S.skipping_whitespace = 0;
|
||||
}
|
||||
|
||||
if (S.skipping_whitespace && S.first_whitespace_skip){
|
||||
S.write = write_render_item(S.write, S.i, ' ', 0);
|
||||
S.write.x = shift_x + line_shift;
|
||||
S.first_whitespace_skip = 0;
|
||||
}
|
||||
|
||||
if (!S.skipping_whitespace){
|
||||
switch (S.ch){
|
||||
case '\n':
|
||||
|
@ -855,11 +856,20 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32
|
|||
DrYield(3, S_stop);
|
||||
|
||||
S.skipping_whitespace = 1;
|
||||
|
||||
if (line_shift >= params.adv[' ']){
|
||||
S.first_whitespace_skip = 1;
|
||||
}
|
||||
}
|
||||
|
||||
++S.line;
|
||||
|
||||
S.write.x = shift_x + line_shift;
|
||||
if (S.first_whitespace_skip){
|
||||
S.write.x = shift_x;
|
||||
}
|
||||
else{
|
||||
S.write.x = shift_x + line_shift;
|
||||
}
|
||||
S.write.y += params.font_height;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -77,8 +77,6 @@ lroundup_(i32 x, i32 granularity){
|
|||
#define round_pot_4tech ROUNDPOT32
|
||||
#endif
|
||||
|
||||
#define measure_character(a,c) ((a)[c])
|
||||
|
||||
typedef struct Buffer_Batch_State{
|
||||
i32 i;
|
||||
i32 shift_total;
|
||||
|
|
Loading…
Reference in New Issue