diff --git a/4coder_default_hooks.cpp b/4coder_default_hooks.cpp index ccbe94cd..e39819fe 100644 --- a/4coder_default_hooks.cpp +++ b/4coder_default_hooks.cpp @@ -321,6 +321,22 @@ struct View_Render_Parameters{ Rect_i32 buffer_rect; }; +struct Buffer_Position{ + i32 line_number; + Vec2 pixel_shift; +}; + +static Buffer_Position +buffer_position_from_scroll_position(Application_Links *app, View_ID view_id, Vec2 scroll){ + Full_Cursor render_cursor = {}; + view_compute_cursor(app, view_id, seek_wrapped_xy(scroll.x, scroll.y, false), &render_cursor); + Buffer_Position result = {}; + result.line_number = render_cursor.line; + result.pixel_shift.x = scroll.x; + result.pixel_shift.y = scroll.y - render_cursor.wrapped_y; + return(result); +} + static void default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View_ID view_id, Rect_i32 view_inner_rect){ Buffer_ID buffer_id = 0; @@ -336,8 +352,14 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View buffer_rect.x0 = clamp_top(buffer_rect.x0, buffer_rect.x1); buffer_rect.y0 = clamp_top(buffer_rect.y0, buffer_rect.y1); + GUI_Scroll_Vars scroll = {}; + view_get_scroll_vars(app, view_id, &scroll); + + Buffer_Position buffer_pos = buffer_position_from_scroll_position(app, view_id, scroll.scroll_p); Range on_screen_range = {}; - compute_render_layout(app, view_id, buffer_id, buffer_rect, &on_screen_range); + compute_render_layout(app, view_id, buffer_id, buffer_rect, + buffer_pos.line_number, buffer_pos.pixel_shift.y, buffer_pos.pixel_shift.x, + &on_screen_range); View_Summary view = get_view(app, view_id, AccessAll); Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessAll); diff --git a/4coder_generated/app_functions.h b/4coder_generated/app_functions.h index 8063e795..7cdd9a20 100644 --- a/4coder_generated/app_functions.h +++ b/4coder_generated/app_functions.h @@ -64,6 +64,7 @@ struct Application_Links; #define VIEW_CLOSE_SIG(n) b32 n(Application_Links *app, View_ID view_id) #define VIEW_GET_REGION_SIG(n) b32 n(Application_Links *app, View_ID view_id, Rect_i32 *region_out) #define VIEW_GET_BUFFER_REGION_SIG(n) b32 n(Application_Links *app, View_ID view_id, Rect_i32 *region_out) +#define VIEW_GET_SCROLL_VARS_SIG(n) b32 n(Application_Links *app, View_ID view_id, GUI_Scroll_Vars *scroll_vars_out) #define VIEW_SET_ACTIVE_SIG(n) b32 n(Application_Links *app, View_ID view_id) #define VIEW_GET_SETTING_SIG(n) b32 n(Application_Links *app, View_ID view_id, View_Setting_ID setting, i32 *value_out) #define VIEW_SET_SETTING_SIG(n) b32 n(Application_Links *app, View_ID view_id, View_Setting_ID setting, i32 value) @@ -165,7 +166,7 @@ struct Application_Links; #define DRAW_COORDINATE_CENTER_PUSH_SIG(n) void n(Application_Links *app, Vec2 point) #define DRAW_COORDINATE_CENTER_POP_SIG(n) Vec2 n(Application_Links *app) #define GET_DEFAULT_FONT_FOR_VIEW_SIG(n) Face_ID n(Application_Links *app, View_ID view_id) -#define COMPUTE_RENDER_LAYOUT_SIG(n) b32 n(Application_Links *app, View_ID view_id, Buffer_ID buffer_id, Rect_i32 rect, Range *on_screen_range_out) +#define COMPUTE_RENDER_LAYOUT_SIG(n) b32 n(Application_Links *app, View_ID view_id, Buffer_ID buffer_id, Rect_i32 screen_rect, i32 buffer_line_number, f32 y_pixel_shift, f32 scroll_x, Range *on_screen_range_out) #define DRAW_RENDER_LAYOUT_SIG(n) void n(Application_Links *app, View_ID view_id) #define OPEN_COLOR_PICKER_SIG(n) void n(Application_Links *app, color_picker *picker) #define ANIMATE_IN_N_MILLISECONDS_SIG(n) void n(Application_Links *app, u32 n) @@ -236,6 +237,7 @@ typedef PANEL_GET_MARGIN_SIG(Panel_Get_Margin_Function); typedef VIEW_CLOSE_SIG(View_Close_Function); typedef VIEW_GET_REGION_SIG(View_Get_Region_Function); typedef VIEW_GET_BUFFER_REGION_SIG(View_Get_Buffer_Region_Function); +typedef VIEW_GET_SCROLL_VARS_SIG(View_Get_Scroll_Vars_Function); typedef VIEW_SET_ACTIVE_SIG(View_Set_Active_Function); typedef VIEW_GET_SETTING_SIG(View_Get_Setting_Function); typedef VIEW_SET_SETTING_SIG(View_Set_Setting_Function); @@ -410,6 +412,7 @@ Panel_Get_Margin_Function *panel_get_margin; View_Close_Function *view_close; View_Get_Region_Function *view_get_region; View_Get_Buffer_Region_Function *view_get_buffer_region; +View_Get_Scroll_Vars_Function *view_get_scroll_vars; View_Set_Active_Function *view_set_active; View_Get_Setting_Function *view_get_setting; View_Set_Setting_Function *view_set_setting; @@ -583,6 +586,7 @@ Panel_Get_Margin_Function *panel_get_margin_; View_Close_Function *view_close_; View_Get_Region_Function *view_get_region_; View_Get_Buffer_Region_Function *view_get_buffer_region_; +View_Get_Scroll_Vars_Function *view_get_scroll_vars_; View_Set_Active_Function *view_set_active_; View_Get_Setting_Function *view_get_setting_; View_Set_Setting_Function *view_set_setting_; @@ -764,6 +768,7 @@ app_links->panel_get_margin_ = Panel_Get_Margin;\ app_links->view_close_ = View_Close;\ app_links->view_get_region_ = View_Get_Region;\ app_links->view_get_buffer_region_ = View_Get_Buffer_Region;\ +app_links->view_get_scroll_vars_ = View_Get_Scroll_Vars;\ app_links->view_set_active_ = View_Set_Active;\ app_links->view_get_setting_ = View_Get_Setting;\ app_links->view_set_setting_ = View_Set_Setting;\ @@ -937,6 +942,7 @@ static b32 panel_get_margin(Application_Links *app, Panel_ID panel_id, i32_Rect static b32 view_close(Application_Links *app, View_ID view_id){return(app->view_close(app, view_id));} static b32 view_get_region(Application_Links *app, View_ID view_id, Rect_i32 *region_out){return(app->view_get_region(app, view_id, region_out));} static b32 view_get_buffer_region(Application_Links *app, View_ID view_id, Rect_i32 *region_out){return(app->view_get_buffer_region(app, view_id, region_out));} +static b32 view_get_scroll_vars(Application_Links *app, View_ID view_id, GUI_Scroll_Vars *scroll_vars_out){return(app->view_get_scroll_vars(app, view_id, scroll_vars_out));} static b32 view_set_active(Application_Links *app, View_ID view_id){return(app->view_set_active(app, view_id));} static b32 view_get_setting(Application_Links *app, View_ID view_id, View_Setting_ID setting, i32 *value_out){return(app->view_get_setting(app, view_id, setting, value_out));} static b32 view_set_setting(Application_Links *app, View_ID view_id, View_Setting_ID setting, i32 value){return(app->view_set_setting(app, view_id, setting, value));} @@ -1038,7 +1044,7 @@ static f32_Rect draw_clip_pop(Application_Links *app){return(app->draw_clip_pop( static void draw_coordinate_center_push(Application_Links *app, Vec2 point){(app->draw_coordinate_center_push(app, point));} static Vec2 draw_coordinate_center_pop(Application_Links *app){return(app->draw_coordinate_center_pop(app));} static Face_ID get_default_font_for_view(Application_Links *app, View_ID view_id){return(app->get_default_font_for_view(app, view_id));} -static b32 compute_render_layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_id, Rect_i32 rect, Range *on_screen_range_out){return(app->compute_render_layout(app, view_id, buffer_id, rect, on_screen_range_out));} +static b32 compute_render_layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_id, Rect_i32 screen_rect, i32 buffer_line_number, f32 y_pixel_shift, f32 scroll_x, Range *on_screen_range_out){return(app->compute_render_layout(app, view_id, buffer_id, screen_rect, buffer_line_number, y_pixel_shift, scroll_x, on_screen_range_out));} static void draw_render_layout(Application_Links *app, View_ID view_id){(app->draw_render_layout(app, view_id));} static void open_color_picker(Application_Links *app, color_picker *picker){(app->open_color_picker(app, picker));} static void animate_in_n_milliseconds(Application_Links *app, u32 n){(app->animate_in_n_milliseconds(app, n));} @@ -1110,6 +1116,7 @@ static b32 panel_get_margin(Application_Links *app, Panel_ID panel_id, i32_Rect static b32 view_close(Application_Links *app, View_ID view_id){return(app->view_close_(app, view_id));} static b32 view_get_region(Application_Links *app, View_ID view_id, Rect_i32 *region_out){return(app->view_get_region_(app, view_id, region_out));} static b32 view_get_buffer_region(Application_Links *app, View_ID view_id, Rect_i32 *region_out){return(app->view_get_buffer_region_(app, view_id, region_out));} +static b32 view_get_scroll_vars(Application_Links *app, View_ID view_id, GUI_Scroll_Vars *scroll_vars_out){return(app->view_get_scroll_vars_(app, view_id, scroll_vars_out));} static b32 view_set_active(Application_Links *app, View_ID view_id){return(app->view_set_active_(app, view_id));} static b32 view_get_setting(Application_Links *app, View_ID view_id, View_Setting_ID setting, i32 *value_out){return(app->view_get_setting_(app, view_id, setting, value_out));} static b32 view_set_setting(Application_Links *app, View_ID view_id, View_Setting_ID setting, i32 value){return(app->view_set_setting_(app, view_id, setting, value));} @@ -1211,7 +1218,7 @@ static f32_Rect draw_clip_pop(Application_Links *app){return(app->draw_clip_pop_ static void draw_coordinate_center_push(Application_Links *app, Vec2 point){(app->draw_coordinate_center_push_(app, point));} static Vec2 draw_coordinate_center_pop(Application_Links *app){return(app->draw_coordinate_center_pop_(app));} static Face_ID get_default_font_for_view(Application_Links *app, View_ID view_id){return(app->get_default_font_for_view_(app, view_id));} -static b32 compute_render_layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_id, Rect_i32 rect, Range *on_screen_range_out){return(app->compute_render_layout_(app, view_id, buffer_id, rect, on_screen_range_out));} +static b32 compute_render_layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_id, Rect_i32 screen_rect, i32 buffer_line_number, f32 y_pixel_shift, f32 scroll_x, Range *on_screen_range_out){return(app->compute_render_layout_(app, view_id, buffer_id, screen_rect, buffer_line_number, y_pixel_shift, scroll_x, on_screen_range_out));} static void draw_render_layout(Application_Links *app, View_ID view_id){(app->draw_render_layout_(app, view_id));} static void open_color_picker(Application_Links *app, color_picker *picker){(app->open_color_picker_(app, picker));} static void animate_in_n_milliseconds(Application_Links *app, u32 n){(app->animate_in_n_milliseconds_(app, n));} diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 3eb82ea9..1c1e20ec 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -670,8 +670,8 @@ DOC_SEE(get_buffer_first) #if 0 // TODO(allen): redocument -API_EXPORT b32 -//Get_Buffer_Summary(Application_Links *app, Buffer_ID buffer_id, Access_Flag access, Buffer_Summary *buffer_summary_out) +//API_EXPORT b32 +Get_Buffer_Summary(Application_Links *app, Buffer_ID buffer_id, Access_Flag access, Buffer_Summary *buffer_summary_out) /* DOC_PARAM(buffer_id, The parameter buffer_id specifies which buffer to try to get.) DOC_PARAM(access, The access parameter determines what levels of protection this call can access.) @@ -2226,6 +2226,24 @@ View_Get_Buffer_Region(Application_Links *app, View_ID view_id, Rect_i32 *region return(result); } +API_EXPORT b32 +View_Get_Scroll_Vars(Application_Links *app, View_ID view_id, GUI_Scroll_Vars *scroll_vars_out){ + Models *models = (Models*)app->cmd_context; + View *view = imp_get_view(models, view_id); + b32 result = false; + if (view_api_check_view(view)){ + if (view->ui_mode){ + *scroll_vars_out = view->ui_scroll; + } + else{ + File_Edit_Positions edit_pos = view_get_edit_pos(view); + *scroll_vars_out = edit_pos.scroll; + } + result = true; + } + return(result); +} + // TODO(allen): redocument API_EXPORT b32 View_Set_Active(Application_Links *app, View_ID view_id) @@ -4592,7 +4610,7 @@ Get_Default_Font_For_View(Application_Links *app, View_ID view_id) } API_EXPORT b32 -Compute_Render_Layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_id, Rect_i32 rect, Range *on_screen_range_out){ +Compute_Render_Layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_id, Rect_i32 screen_rect, i32 buffer_line_number, f32 y_pixel_shift, f32 scroll_x, Range *on_screen_range_out){ Models *models = (Models*)app->cmd_context; System_Functions *system = models->system; View *view = imp_get_view(models, view_id); @@ -4601,14 +4619,13 @@ Compute_Render_Layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_ if (view_api_check_view(view) && buffer_api_check_file(file)){ i32 line_height = view->line_height; f32 max_x = (f32)file->settings.display_width; - i32 max_y = rect.y1 - rect.y0 + line_height; + i32 max_y = screen_rect.y1 - screen_rect.y0 + line_height; f32 left_side_space = 0; - // TODO(allen): Don't force me to over-allocate! Write a looser buffer render thingy, - // or just stop doing that nonsense all together. - f32 screen_width = (f32)rect_width(rect); - f32 screen_height = (f32)rect_height(rect); + // TODO(allen): Don't force me to over-allocate! Write a looser buffer render thingy. + f32 screen_width = (f32)rect_width(screen_rect); + f32 screen_height = (f32)rect_height(screen_rect); f32 smallest_char_width = 6.f; f32 smallest_char_height = 8.f; i32 max = (i32)(screen_width*screen_height/(smallest_char_width*smallest_char_height))*2; @@ -4623,13 +4640,19 @@ Compute_Render_Layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_ b32 wrapped = !file->settings.unwrapped_lines; Face_ID font_id = file->settings.font_id; Font_Pointers font = system->font.get_pointers_by_id(font_id); - + +#if 0 File_Edit_Positions edit_pos = view_get_edit_pos(view); f32 scroll_x = edit_pos.scroll.scroll_x; f32 scroll_y = edit_pos.scroll.scroll_y; Full_Cursor render_cursor = view_get_render_cursor(system, view); - +#else + Full_Cursor intermediate_cursor = file_compute_cursor(system, file, seek_line_char(buffer_line_number, 1)); + f32 scroll_y = intermediate_cursor.unwrapped_y + y_pixel_shift; + Full_Cursor render_cursor = view_get_render_cursor(system, view, scroll_y); +#endif + i32 item_count = 0; i32 end_pos = 0; { @@ -4638,8 +4661,8 @@ Compute_Render_Layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_ params.items = items; params.max = max; params.count = &item_count; - params.port_x = (f32)rect.x0 + left_side_space; - params.port_y = (f32)rect.y0; + params.port_x = (f32)screen_rect.x0 + left_side_space; + params.port_y = (f32)screen_rect.y0; params.clip_w = view_width(models, view) - left_side_space; params.scroll_x = scroll_x; params.scroll_y = scroll_y; @@ -4702,7 +4725,7 @@ Compute_Render_Layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_ Range range = {render_cursor.pos, end_pos}; view->render.view_rect = view->panel->rect_inner; - view->render.buffer_rect = rect; + view->render.buffer_rect = screen_rect; view->render.cursor = render_cursor; view->render.range = range; view->render.items = items;