cleaned up view vs cursor issue, fixed casey goto error bug

master
Allen Webster 2016-05-20 09:53:17 -04:00
parent 134e166099
commit a16e77abd4
3 changed files with 150 additions and 61 deletions

30
4ed.cpp
View File

@ -4494,14 +4494,40 @@ App_Step_Sig(app_step){
// NOTE(allen): post scroll vars back to the view's gui targets
{
View *view;
Panel *panel, *used_panels;
View *view = 0;
Panel *panel = 0, *used_panels = 0;
i32 cursor_view_state = 0;
used_panels = &models->layout.used_sentinel;
for (dll_items(panel, used_panels)){
view = panel->view;
cursor_view_state = view_get_cursor_view_change_state(view);
switch (cursor_view_state){
case CursorView_NoChange:break;
case CursorView_Cursor:
case CursorView_Both:
view_move_view_to_cursor(view);
break;
case CursorView_View:
gui_post_scroll_vars(&view->gui_target, view->current_scroll);
break;
}
#if 0
if (view->gui_target.did_file){
if (view->prev_cursor_pos != view->file_data.cursor.pos){
view_move_view_to_cursor(view);
}
}
if (view->current_scroll){
gui_post_scroll_vars(&view->gui_target, view->current_scroll);
}
#endif
}
}

View File

@ -193,6 +193,7 @@ struct View{
Command_Map *map;
File_Viewing_Data file_data;
i32 prev_cursor_pos;
i32_Rect file_region_prev;
i32_Rect file_region;
@ -3118,50 +3119,134 @@ view_reinit_scrolling(View *view){
#define CursorMaxY(m,h) (CursorMaxY_(m,h) > 0)?(CursorMaxY_(m,h)):(0)
#define CursorMinY(m,h) (CursorMinY_(m,h) > 0)?(CursorMinY_(m,h)):(0)
internal void
view_move_cursor_to_view(View *view){
f32 min_target_y = view->recent->scroll.min_y;
i32 line_height = view->font_height;
f32 old_cursor_y = view_get_cursor_y(view);
f32 cursor_y = old_cursor_y;
f32 target_y = view->recent->scroll.target_y;
f32 cursor_max_y = CursorMaxY(view_file_height(view), line_height);
f32 cursor_min_y = CursorMinY(min_target_y, line_height);
if (cursor_y > target_y + cursor_max_y){
cursor_y = target_y + cursor_max_y;
}
if (target_y != 0 && cursor_y < target_y + cursor_min_y){
cursor_y = target_y + cursor_min_y;
}
if (cursor_y != old_cursor_y){
if (cursor_y > old_cursor_y){
cursor_y += line_height;
}
else{
cursor_y -= line_height;
}
view->file_data.cursor =
view_compute_cursor_from_xy(view, view->file_data.preferred_x, cursor_y);
}
}
internal void
view_move_view_to_cursor(View *view){
f32 line_height = (f32)view->font_height;
f32 delta_y = 3.f*line_height;
f32 max_visible_y = view_file_height(view);
f32 max_x = view_file_width(view);
f32 cursor_y = view_get_cursor_y(view);
f32 cursor_x = view_get_cursor_x(view);
GUI_Scroll_Vars scroll_vars = view->gui_target.scroll_updated;
f32 target_y = scroll_vars.target_y;
f32 target_x = scroll_vars.target_x;
f32 cursor_max_y = CursorMaxY(max_visible_y, line_height);
f32 cursor_min_y = CursorMinY(scroll_vars.min_y, line_height);
if (cursor_y > target_y + cursor_max_y){
target_y = cursor_y - cursor_max_y + delta_y;
}
if (cursor_y < target_y + cursor_min_y){
target_y = cursor_y - delta_y - cursor_min_y;
}
if (target_y > scroll_vars.max_y) target_y = scroll_vars.max_y;
if (target_y < scroll_vars.min_y) target_y = view->recent->scroll.min_y;
if (cursor_x < target_x){
target_x = (f32)Max(0, cursor_x - max_x/2);
}
else if (cursor_x >= target_x + max_x){
target_x = (f32)(cursor_x - max_x/2);
}
if (target_x != scroll_vars.target_x || target_y != scroll_vars.target_y){
view->gui_target.scroll_updated.target_x = target_x;
view->gui_target.scroll_updated.target_y = target_y;
}
}
enum CursorView_State{
CursorView_NoChange,
CursorView_Cursor,
CursorView_View,
CursorView_Both
};
internal i32
view_get_cursor_view_change_state(View *view){
i32 result = 0;
b32 cursor_change = 0;
b32 view_change = 0;
if (view->gui_target.did_file){
cursor_change = (view->prev_cursor_pos != view->file_data.cursor.pos);
}
if (!gui_scroll_eq(view->current_scroll, &view->gui_target.scroll_updated)){
view_change = 1;
}
if (cursor_change){
if (view_change){
result = CursorView_Both;
}
else{
result = CursorView_Cursor;
}
}
else{
if (view_change){
result = CursorView_View;
}
else{
result = CursorView_NoChange;
}
}
return(result);
}
internal b32
file_step(View *view, i32_Rect region, Input_Summary *user_input, b32 is_active){
i32 is_animating = 0;
Editing_File *file = view->file_data.file;
if (file && !file->state.is_loading){
f32 line_height = (f32)view->font_height;
f32 delta_y = 3.f*line_height;
f32 max_visible_y = view_file_height(view);
f32 max_x = view_file_width(view);
f32 cursor_y = view_get_cursor_y(view);
f32 cursor_x = view_get_cursor_x(view);
GUI_Scroll_Vars scroll_vars = view->gui_target.scroll_updated;
f32 target_y = scroll_vars.target_y;
f32 target_x = scroll_vars.target_x;
f32 cursor_max_y = CursorMaxY(max_visible_y, line_height);
f32 cursor_min_y = CursorMinY(scroll_vars.min_y, line_height);
view->prev_cursor_pos = view->file_data.cursor.pos;
#if 0
if (!gui_id_eq(view->gui_target.active, gui_id_scrollbar())){
if (cursor_y > target_y + cursor_max_y){
target_y = cursor_y - cursor_max_y + delta_y;
}
if (cursor_y < target_y + cursor_min_y){
target_y = cursor_y - delta_y - cursor_min_y;
}
if (target_y > scroll_vars.max_y) target_y = scroll_vars.max_y;
if (target_y < scroll_vars.min_y) target_y = view->recent->scroll.min_y;
if (cursor_x < target_x){
target_x = (f32)Max(0, cursor_x - max_x/2);
}
else if (cursor_x >= target_x + max_x){
target_x = (f32)(cursor_x - max_x/2);
}
if (target_x != scroll_vars.target_x || target_y != scroll_vars.target_y){
view->gui_target.scroll_updated.target_x = target_x;
view->gui_target.scroll_updated.target_y = target_y;
}
view_move_view_to_cursor(view);
}
#endif
if (file->state.paste_effect.tick_down > 0){
--file->state.paste_effect.tick_down;
@ -3479,8 +3564,6 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
Models *models = view->models;
Key_Summary keys = input.keys;
f32 min_target_y = view->recent->scroll.min_y;
b32 show_scrollbar = !view->hide_scrollbar;
view->current_scroll = 0;
@ -3496,35 +3579,12 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
gui_begin_serial_section(target);
{
i32 line_height = view->font_height;
f32 old_cursor_y = view_get_cursor_y(view);
f32 cursor_y = old_cursor_y;
f32 cursor_max_y = CursorMaxY(view_file_height(view), line_height);
f32 cursor_min_y = CursorMinY(min_target_y, line_height);
f32 delta = 9.f * view->font_height;
f32 target_y = 0;
view->current_scroll = &view->recent->scroll;
if (gui_get_scroll_vars(target, view->showing_ui,
&view->recent->scroll, &view->scroll_region)){
target_y = view->recent->scroll.target_y;
if (cursor_y > target_y + cursor_max_y){
cursor_y = target_y + cursor_max_y;
}
if (target_y != 0 && cursor_y < target_y + cursor_min_y){
cursor_y = target_y + cursor_min_y;
}
if (cursor_y != old_cursor_y){
if (cursor_y > old_cursor_y){
cursor_y += view->font_height;
}
else{
cursor_y -= view->font_height;
}
view->file_data.cursor =
view_compute_cursor_from_xy(view, view->file_data.preferred_x, cursor_y);
}
view_move_cursor_to_view(view);
}
gui_begin_scrollable(target, view->showing_ui, view->recent->scroll,

View File

@ -160,6 +160,7 @@ struct GUI_Target{
u32 scroll_id;
b32 has_keys;
b32 animating;
b32 did_file;
};
struct GUI_Item_Update{
@ -415,6 +416,7 @@ gui_begin_top_level(GUI_Target *target, Input_Summary input){
target->push.pos = 0;
target->has_keys = (input.keys.count > 0);
target->animating = 0;
target->did_file = 0;
}
internal void
@ -431,6 +433,7 @@ gui_do_top_bar(GUI_Target *target){
internal void
gui_do_file(GUI_Target *target){
gui_push_simple_command(target, guicom_file);
target->did_file = 1;
}
internal void