From fb3a833cf6fb311f1e46868aced03fb4980adafd Mon Sep 17 00:00:00 2001 From: fs Date: Mon, 13 Jan 2025 20:45:43 +0200 Subject: [PATCH 1/3] Added better support for scrolling on windows --- code/4ed.cpp | 6 +++--- code/4ed_view.cpp | 13 ++++++++++++- code/custom/4coder_base_commands.cpp | 8 ++++---- code/custom/4coder_default_hooks.cpp | 6 ++++-- code/custom/4coder_events.h | 4 ++-- code/custom/4coder_file_moving.h | 0 code/custom/4coder_lister_base.cpp | 2 +- code/custom/4coder_log_parser.cpp | 2 +- code/custom/4coder_types.h | 2 +- code/platform_win32/win32_4ed.cpp | 23 ++++++++++++++--------- 10 files changed, 42 insertions(+), 24 deletions(-) mode change 100644 => 100755 code/4ed.cpp mode change 100644 => 100755 code/4ed_view.cpp mode change 100644 => 100755 code/custom/4coder_base_commands.cpp mode change 100644 => 100755 code/custom/4coder_default_hooks.cpp mode change 100644 => 100755 code/custom/4coder_events.h mode change 100644 => 100755 code/custom/4coder_file_moving.h mode change 100644 => 100755 code/custom/4coder_lister_base.cpp mode change 100644 => 100755 code/custom/4coder_log_parser.cpp mode change 100644 => 100755 code/custom/4coder_types.h mode change 100644 => 100755 code/platform_win32/win32_4ed.cpp diff --git a/code/4ed.cpp b/code/4ed.cpp old mode 100644 new mode 100755 index 91758015d..724306ed4 --- a/code/4ed.cpp +++ b/code/4ed.cpp @@ -444,11 +444,11 @@ App_Step_Sig(app_step){ event.mouse.modifiers = copy_modifier_set(scratch, &modifiers); push_input_event(scratch, &input_list, &event); } - if (input->mouse.wheel != 0){ + if (input->mouse.wheel.y != 0 || input->mouse.wheel.x != 0){ Input_Event event = {}; event.kind = InputEventKind_MouseWheel; - event.mouse_wheel.value = (f32)(input->mouse.wheel); - event.mouse_wheel.p = input->mouse.p; + event.mouse_wheel.x = input->mouse.wheel.x; + event.mouse_wheel.y = input->mouse.wheel.y; event.mouse_wheel.modifiers = copy_modifier_set(scratch, &modifiers); push_input_event(scratch, &input_list, &event); } diff --git a/code/4ed_view.cpp b/code/4ed_view.cpp old mode 100644 new mode 100755 index 96427bd63..4e35a7ff8 --- a/code/4ed_view.cpp +++ b/code/4ed_view.cpp @@ -408,8 +408,19 @@ view_move_cursor_to_view(Thread_Context *tctx, Models *models, View *view, Buffe adjusted_y = false; } + b32 adjusted_x = true; + if (p.x < 0.f){ + p.x = 0.f; + } + else if (p.x > view_dim.x){ + p.x = view_dim.x; + } + else{ + adjusted_x = false; + } + b32 result = false; - if (adjusted_y){ + if (adjusted_y || adjusted_x){ p += scroll.target.pixel_shift; *pos_in_out = file_pos_at_relative_xy(tctx, models, file, layout_func, view_dim.x, face, diff --git a/code/custom/4coder_base_commands.cpp b/code/custom/4coder_base_commands.cpp old mode 100644 new mode 100755 index b86b16c82..8ea41c608 --- a/code/custom/4coder_base_commands.cpp +++ b/code/custom/4coder_base_commands.cpp @@ -270,9 +270,9 @@ CUSTOM_DOC("Reads the scroll wheel value from the mouse state and scrolls accord { View_ID view = get_active_view(app, Access_ReadVisible); Mouse_State mouse = get_mouse_state(app); - if (mouse.wheel != 0){ + if (mouse.wheel.y != 0.f || mouse.wheel.x != 0.f){ Buffer_Scroll scroll = view_get_buffer_scroll(app, view); - scroll.target = view_move_buffer_point(app, view, scroll.target, V2f32(0.f, (f32)mouse.wheel)); + scroll.target = view_move_buffer_point(app, view, scroll.target, mouse.wheel); view_set_buffer_scroll(app, view, scroll, SetBufferScroll_SnapCursorIntoView); } if (mouse.l){ @@ -806,10 +806,10 @@ CUSTOM_DOC("Reads the state of the mouse wheel and uses it to either increase or if (now >= next_resize_time){ next_resize_time = now + 50*1000; Mouse_State mouse = get_mouse_state(app); - if (mouse.wheel > 0){ + if (mouse.wheel.y > 0.f){ decrease_face_size(app); } - else if (mouse.wheel < 0){ + else if (mouse.wheel.y < 0.f){ increase_face_size(app); } } diff --git a/code/custom/4coder_default_hooks.cpp b/code/custom/4coder_default_hooks.cpp old mode 100644 new mode 100755 index 90102e53d..ac89316f4 --- a/code/custom/4coder_default_hooks.cpp +++ b/code/custom/4coder_default_hooks.cpp @@ -442,8 +442,10 @@ default_render_caller(Application_Links *app, Frame_Info frame_info, View_ID vie Buffer_Scroll scroll = view_get_buffer_scroll(app, view_id); - Buffer_Point_Delta_Result delta = delta_apply(app, view_id, - frame_info.animation_dt, scroll); + // NOTE(FS): Scroll animation smoothing with regular dt feels sluggish, + // so I made the animation go fester + f32 dt = frame_info.animation_dt * 3.f; + Buffer_Point_Delta_Result delta = delta_apply(app, view_id, dt, scroll); if (!block_match_struct(&scroll.position, &delta.point)){ block_copy_struct(&scroll.position, &delta.point); view_set_buffer_scroll(app, view_id, scroll, SetBufferScroll_NoCursorChange); diff --git a/code/custom/4coder_events.h b/code/custom/4coder_events.h old mode 100644 new mode 100755 index ba2805030..db911fe8f --- a/code/custom/4coder_events.h +++ b/code/custom/4coder_events.h @@ -72,8 +72,8 @@ struct Input_Event{ Input_Modifier_Set modifiers; } mouse; struct{ - f32 value; - Vec2_i32 p; + f32 x; + f32 y; Input_Modifier_Set modifiers; } mouse_wheel; struct{ diff --git a/code/custom/4coder_file_moving.h b/code/custom/4coder_file_moving.h old mode 100644 new mode 100755 diff --git a/code/custom/4coder_lister_base.cpp b/code/custom/4coder_lister_base.cpp old mode 100644 new mode 100755 index 55310252b..e32882160 --- a/code/custom/4coder_lister_base.cpp +++ b/code/custom/4coder_lister_base.cpp @@ -672,7 +672,7 @@ run_lister(Application_Links *app, Lister *lister){ case InputEventKind_MouseWheel: { Mouse_State mouse = get_mouse_state(app); - lister->scroll.target.y += mouse.wheel; + lister->scroll.target.y += mouse.wheel.y; lister_update_filtered_list(app, lister); }break; diff --git a/code/custom/4coder_log_parser.cpp b/code/custom/4coder_log_parser.cpp old mode 100644 new mode 100755 index ac4331922..06c78bbb6 --- a/code/custom/4coder_log_parser.cpp +++ b/code/custom/4coder_log_parser.cpp @@ -1057,7 +1057,7 @@ CUSTOM_DOC("Parses *log* and displays the 'log graph' UI") case InputEventKind_MouseWheel: { - f32 value = in.event.mouse_wheel.value; + f32 value = in.event.mouse_wheel.y; log_graph.y_scroll += f32_round32(value); }break; diff --git a/code/custom/4coder_types.h b/code/custom/4coder_types.h old mode 100644 new mode 100755 index 64eac916b..6367aea52 --- a/code/custom/4coder_types.h +++ b/code/custom/4coder_types.h @@ -321,7 +321,7 @@ struct Mouse_State{ b8 release_l; b8 release_r; b8 out_of_window; - i32 wheel; + Vec2_f32 wheel; union{ struct{ i32 x; diff --git a/code/platform_win32/win32_4ed.cpp b/code/platform_win32/win32_4ed.cpp old mode 100644 new mode 100755 index 6a1f7b716..441a3f37f --- a/code/platform_win32/win32_4ed.cpp +++ b/code/platform_win32/win32_4ed.cpp @@ -88,7 +88,8 @@ struct Win32_Input_Chunk_Transient{ b8 mouse_r_press; b8 mouse_r_release; b8 out_of_window; - i8 mouse_wheel; + i16 mouse_wheel_y; + i16 mouse_wheel_x; b8 trying_to_kill; }; @@ -1368,13 +1369,15 @@ win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ case WM_MOUSEWHEEL: { win32vars.got_useful_event = true; - i32 rotation = GET_WHEEL_DELTA_WPARAM(wParam); - if (rotation > 0){ - win32vars.input_chunk.trans.mouse_wheel = -100; - } - else{ - win32vars.input_chunk.trans.mouse_wheel = 100; - } + i16 wheel_delta = HIWORD(wParam); + win32vars.input_chunk.trans.mouse_wheel_y = -wheel_delta; + }break; + + case WM_MOUSEHWHEEL: + { + win32vars.got_useful_event = true; + i16 wheel_delta = HIWORD(wParam); + win32vars.input_chunk.trans.mouse_wheel_x = +wheel_delta; }break; case WM_LBUTTONDOWN: @@ -1973,7 +1976,9 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS input.mouse.press_r = input_chunk.trans.mouse_r_press; input.mouse.release_r = input_chunk.trans.mouse_r_release; - input.mouse.wheel = input_chunk.trans.mouse_wheel; + input.mouse.wheel.y = (f32)input_chunk.trans.mouse_wheel_y; + input.mouse.wheel.x = (f32)input_chunk.trans.mouse_wheel_x; + input.mouse.p = input_chunk.pers.mouse; input.trying_to_kill = input_chunk.trans.trying_to_kill; From d29ca9d11630002ac3c508b2d09bfb4e13161da0 Mon Sep 17 00:00:00 2001 From: fs Date: Mon, 13 Jan 2025 21:19:52 +0200 Subject: [PATCH 2/3] Changed the render hook to not correct the cursor position, so it will not lock the view when scrolling around --- code/custom/4coder_default_hooks.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/custom/4coder_default_hooks.cpp b/code/custom/4coder_default_hooks.cpp index ac89316f4..437fb5133 100755 --- a/code/custom/4coder_default_hooks.cpp +++ b/code/custom/4coder_default_hooks.cpp @@ -321,7 +321,7 @@ default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id, paint_text_color_fcolor(app, text_layout_id, visible_range, fcolor_id(defcolor_text_default)); } - i64 cursor_pos = view_correct_cursor(app, view_id); + i64 cursor_pos = view_get_cursor_pos(app, view_id); view_correct_mark(app, view_id); // NOTE(allen): Scope highlight From 3ac5ca33ac8f1824b52367791aec9c0d4982dff2 Mon Sep 17 00:00:00 2001 From: fs Date: Fri, 14 Mar 2025 18:56:22 +0200 Subject: [PATCH 3/3] Added a command to consider the view under the mouse when scrolling, instead of the active one --- code/custom/4coder_base_commands.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) mode change 100755 => 100644 code/custom/4coder_base_commands.cpp diff --git a/code/custom/4coder_base_commands.cpp b/code/custom/4coder_base_commands.cpp old mode 100755 new mode 100644 index 8ea41c608..635a217f4 --- a/code/custom/4coder_base_commands.cpp +++ b/code/custom/4coder_base_commands.cpp @@ -280,6 +280,31 @@ CUSTOM_DOC("Reads the scroll wheel value from the mouse state and scrolls accord } } +CUSTOM_COMMAND_SIG(mouse_wheel_scroll_over_hovered_view) +CUSTOM_DOC("Reads the scroll wheel value from the mouse state and scrolls the view currently under the mouse accordingly.") +{ + Mouse_State mouse = get_mouse_state(app); + View_ID active_view = get_active_view(app, Access_ReadVisible); + if (mouse.wheel.y != 0.f || mouse.wheel.x != 0.f){ + for(View_ID view = get_view_next(app, 0, Access_ReadVisible); + view != 0; + view = get_view_next(app, view, Access_ReadVisible)) { + Rect_f32 view_rect = view_get_screen_rect(app, view); + if(rect_contains_point(view_rect, V2f32(mouse.p))) + { + Buffer_Scroll scroll = view_get_buffer_scroll(app, view); + scroll.target = view_move_buffer_point(app, view, scroll.target, mouse.wheel); + view_set_buffer_scroll(app, view, scroll, SetBufferScroll_NoCursorChange); + active_view = view; + break; + } + } + } + if (mouse.l){ + no_mark_snap_to_cursor(app, active_view); + } +} + //////////////////////////////// internal void