diff --git a/code/4ed.cpp b/code/4ed.cpp old mode 100644 new mode 100755 index 91758015..724306ed --- 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 96427bd6..4e35a7ff --- 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 index b86b16c8..635a217f 100644 --- 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){ @@ -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 @@ -806,10 +831,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 90102e53..437fb513 --- 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 @@ -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 ba280503..db911fe8 --- 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 55310252..e3288216 --- 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 ac433192..06c78bbb --- 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 64eac916..6367aea5 --- 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 6a1f7b71..441a3f37 --- 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;