From 6002e629b244ce31383c2e3252a54de28c0de4b5 Mon Sep 17 00:00:00 2001 From: fs Date: Mon, 13 Jan 2025 20:45:43 +0200 Subject: [PATCH 1/5] 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 1e4163e80..5c2eae6f0 --- 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 984197bae..38fe0b295 --- 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 376867634..b6a94a7e7 --- 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 740cb03b7..15cb16d53 --- a/code/custom/4coder_lister_base.cpp +++ b/code/custom/4coder_lister_base.cpp @@ -642,7 +642,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 54c19ca54..0cd9d51a2 --- 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; }; @@ -1373,13 +1374,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: @@ -1979,7 +1982,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 02cffae562a73eed25fe10f1165ee32b07338575 Mon Sep 17 00:00:00 2001 From: fs Date: Mon, 13 Jan 2025 21:19:52 +0200 Subject: [PATCH 2/5] 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 214b757b34e64f6fcc110572f7c22538d71d5c43 Mon Sep 17 00:00:00 2001 From: fs Date: Fri, 14 Mar 2025 18:56:22 +0200 Subject: [PATCH 3/5] 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 b6a94a7e7..f3c764a56 --- 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 From 7c581bdd15ab8810abd0dd91c8ed92cd029a54bb Mon Sep 17 00:00:00 2001 From: fs Date: Fri, 27 Feb 2026 19:12:46 +0200 Subject: [PATCH 4/5] Added support for horizontal scrolling on linux/x11, it supports only fixed increments --- code/platform_linux/linux_4ed.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/code/platform_linux/linux_4ed.cpp b/code/platform_linux/linux_4ed.cpp index 5cf994812..71fe39ec6 100644 --- a/code/platform_linux/linux_4ed.cpp +++ b/code/platform_linux/linux_4ed.cpp @@ -131,7 +131,8 @@ struct Linux_Input_Chunk_Transient { b8 mouse_l_release; b8 mouse_r_press; b8 mouse_r_release; - i8 mouse_wheel; + i8 mouse_wheel_y; + i8 mouse_wheel_x; b8 trying_to_kill; }; @@ -1580,11 +1581,20 @@ linux_handle_x11_events() { } break; case Button4: { - linuxvars.input.trans.mouse_wheel = -100; + linuxvars.input.trans.mouse_wheel_y = -100; } break; case Button5: { - linuxvars.input.trans.mouse_wheel = +100; + linuxvars.input.trans.mouse_wheel_y = +100; + } break; + + // NOTE(FS): 6 and 7 are undocumented but generally accepted as horizontal scroll buttons. + case 6: { + linuxvars.input.trans.mouse_wheel_x = -100; + } break; + + case 7: { + linuxvars.input.trans.mouse_wheel_x = +100; } break; } } break; @@ -1991,7 +2001,8 @@ main(int argc, char **argv){ input.mouse.release_l = linuxvars.input.trans.mouse_l_release; input.mouse.press_r = linuxvars.input.trans.mouse_r_press; input.mouse.release_r = linuxvars.input.trans.mouse_r_release; - input.mouse.wheel = linuxvars.input.trans.mouse_wheel; + input.mouse.wheel.y = linuxvars.input.trans.mouse_wheel_y; + input.mouse.wheel.x = linuxvars.input.trans.mouse_wheel_x; // NOTE(allen): Application Core Update Application_Step_Result result = {}; From 3b0459365f15596603596ebfb427a8a4a9798e5e Mon Sep 17 00:00:00 2001 From: fs Date: Sat, 28 Feb 2026 16:06:37 +0200 Subject: [PATCH 5/5] Tried to add support for horizontal scrolling on mac (no testing) --- code/platform_mac/mac_4ed.mm | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/code/platform_mac/mac_4ed.mm b/code/platform_mac/mac_4ed.mm index e316dfa7d..bff1fdf02 100644 --- a/code/platform_mac/mac_4ed.mm +++ b/code/platform_mac/mac_4ed.mm @@ -98,7 +98,8 @@ b8 mouse_r_release; b8 out_of_window; b8 trying_to_kill; - i32 mouse_wheel; + i32 mouse_wheel_y; + i32 mouse_wheel_x; }; struct Mac_Input_Chunk_Persistent{ @@ -749,7 +750,8 @@ - (void)updateLayer{ 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 = input_chunk.trans.mouse_wheel_y; + input.mouse.wheel.x = input_chunk.trans.mouse_wheel_x; input.mouse.p = input_chunk.pers.mouse; input.trying_to_kill = input_chunk.trans.trying_to_kill; @@ -1104,15 +1106,23 @@ - (void)mouseDragged:(NSEvent*)event{ - (void)scrollWheel:(NSEvent *)event{ f32 dy = event.scrollingDeltaY; + f32 dx = event.scrollingDeltaX; if ([event hasPreciseScrollingDeltas]){ - mac_vars.input_chunk.trans.mouse_wheel = (i32)(-dy); + mac_vars.input_chunk.trans.mouse_wheel_y = (i32)(-dy); + mac_vars.input_chunk.trans.mouse_wheel_x = (i32)(dx); } else{ if (dy > 0){ - mac_vars.input_chunk.trans.mouse_wheel = -100; + mac_vars.input_chunk.trans.mouse_wheel_y = -100; } - else{ - mac_vars.input_chunk.trans.mouse_wheel = 100; + else if(dy < 0){ + mac_vars.input_chunk.trans.mouse_wheel_y = +100; + } + if (dx > 0){ + mac_vars.input_chunk.trans.mouse_wheel_x = +100; + } + else if(dx < 0){ + mac_vars.input_chunk.trans.mouse_wheel_x = -100; } } system_signal_step(0);