Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions code/4ed.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
13 changes: 12 additions & 1 deletion code/4ed_view.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
33 changes: 29 additions & 4 deletions code/custom/4coder_base_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,41 @@ 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){
no_mark_snap_to_cursor(app, view);
}
}

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
Expand Down Expand Up @@ -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);
}
}
Expand Down
8 changes: 5 additions & 3 deletions code/custom/4coder_default_hooks.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions code/custom/4coder_events.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Empty file modified code/custom/4coder_file_moving.h
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion code/custom/4coder_lister_base.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion code/custom/4coder_log_parser.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion code/custom/4coder_types.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 14 additions & 9 deletions code/platform_win32/win32_4ed.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down