From 161b037d313b7b9d8be260117aa2a3f53bd2659b Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 10 Nov 2017 20:21:50 -0500 Subject: [PATCH] Wheel behavior upgrade --- 4coder_API/types.h | 38 +++++++++++++++++------------------- 4ed.cpp | 2 -- 4ed_file_view.cpp | 2 +- 4ed_gui.cpp | 4 ++-- platform_linux/linux_4ed.cpp | 35 +++++++++++++++++---------------- platform_mac/mac_4ed.cpp | 7 +------ platform_win32/win32_4ed.cpp | 4 ++-- 7 files changed, 42 insertions(+), 50 deletions(-) diff --git a/4coder_API/types.h b/4coder_API/types.h index aa0e3404..b963bc92 100644 --- a/4coder_API/types.h +++ b/4coder_API/types.h @@ -360,27 +360,25 @@ GLOBAL_VAR Key_Event_Data null_key_event_data = {0}; /* DOC(Mouse_State describes an entire mouse state complete with the position, left and right button states, the wheel state, and whether or not the mouse if in the window.) */ STRUCT Mouse_State{ - /* DOC(This field indicates that the left button is held.) */ - char l; - /* DOC(This field indicates that the right button is held.) */ - char r; - /* DOC(This field indicates that the left button was pressed this frame.) */ - char press_l; - /* DOC(This field indicates that the right button was pressed this frame.) */ - char press_r; - /* DOC(This field indicates that the left button was released this frame.) */ - char release_l; - /* DOC(This field indicates that the right button was released this frame.) */ - char release_r; - /* DOC( - This field is 0 when the wheel has not moved, it is 1 for a downward motion and -1 for an upward motion. - ) */ - char wheel; - /* DOC(This field indicates that the mouse is outside of the window.) */ - char out_of_window; - /* DOC(This field contains the x position of the mouse relative to the window where the left side is 0.) */ + /* DOC(Left button is down.) */ + int8_t l; + /* DOC(Right button is down.) */ + int8_t r; + /* DOC(Left button was pressed this frame.) */ + int8_t press_l; + /* DOC(Right button was pressed this frame.) */ + int8_t press_r; + /* DOC(Left button was released this frame.) */ + int8_t release_l; + /* DOC(Right button was released this frame.) */ + int8_t release_r; + /* DOC(Mouse is outside of the window.) */ + int8_t out_of_window; + /* DOC(The motion of the wheel. Zero indicates no motion. Positive indicates downard scrolling. Negative indicates upward scrolling. The magnitude corresponds to the number of pixels of scroll will be applied at standard scroll speeds.) */ + int32_t wheel; + /* DOC(X position of the mouse where the left of the window is x = 0, and x grows to the right.) */ int32_t x; - /* DOC(This field contains the y position of the mouse relative to the window where the top side is 0.) */ + /* DOC(Y position of the mouse where the top of the window is y = 0, and y grows to downward.) */ int32_t y; }; diff --git a/4ed.cpp b/4ed.cpp index cf113e44..6eb8259a 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -1536,8 +1536,6 @@ App_Step_Sig(app_step){ mouse_event.keycode = key_mouse_right_release; input->keys.keys[input->keys.count++] = mouse_event; } - - input->mouse.wheel = -input->mouse.wheel; } // NOTE(allen): detect mouse hover status diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 5998f5be..e4b8578a 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -5580,7 +5580,7 @@ do_step_file_view(System_Functions *system, View *view, Models *models, i32_Rect case guicom_scrollable_invisible: { if (user_input->mouse.wheel != 0){ - result.vars.target_y += user_input->mouse.wheel*target->delta; + result.vars.target_y += user_input->mouse.wheel; result.vars.target_y = clamp(0, result.vars.target_y, max_y); diff --git a/4ed_gui.cpp b/4ed_gui.cpp index 389ceb4c..365c6204 100644 --- a/4ed_gui.cpp +++ b/4ed_gui.cpp @@ -137,6 +137,7 @@ struct GUI_Target{ i32 list_view_max; GUI_id scroll_id; + // TODO(allen): is currently ignored in the wheel code, reevaluate? i32 delta; b32 has_keys; b32 animating; @@ -695,8 +696,7 @@ gui_post_scroll_vars(GUI_Target *target, GUI_Scroll_Vars *vars_in, i32_Rect regi } internal void -gui_begin_scrollable(GUI_Target *target, GUI_id scroll_context_id, - GUI_Scroll_Vars scroll_vars, i32 delta, b32 show_bar){ +gui_begin_scrollable(GUI_Target *target, GUI_id scroll_context_id, GUI_Scroll_Vars scroll_vars, i32 delta, b32 show_bar){ GUI_Header *h; gui_begin_serial_section(target); diff --git a/platform_linux/linux_4ed.cpp b/platform_linux/linux_4ed.cpp index 3bd6d67b..e4f49e3a 100644 --- a/platform_linux/linux_4ed.cpp +++ b/platform_linux/linux_4ed.cpp @@ -1138,7 +1138,7 @@ internal void LinuxHandleX11Events(void) { static XEvent PrevEvent = {}; - b32 should_step = 0; + b32 should_step = false; while (XPending(linuxvars.XDisplay)) { @@ -1151,7 +1151,7 @@ LinuxHandleX11Events(void) switch (Event.type){ case KeyPress: { - should_step = 1; + should_step = true; b32 is_hold = (PrevEvent.type == KeyRelease && PrevEvent.xkey.time == Event.xkey.time && @@ -1219,17 +1219,17 @@ LinuxHandleX11Events(void) }break; case KeyRelease: { - should_step = 1; + should_step = true; }break; case MotionNotify: { - should_step = 1; + should_step = true; linuxvars.input.mouse.x = Event.xmotion.x; linuxvars.input.mouse.y = Event.xmotion.y; }break; case ButtonPress: { - should_step = 1; + should_step = true; switch(Event.xbutton.button){ case Button1: { linuxvars.input.mouse.press_l = 1; @@ -1242,18 +1242,18 @@ LinuxHandleX11Events(void) //NOTE(inso): scroll up case Button4: { - linuxvars.input.mouse.wheel = 1; + linuxvars.input.mouse.wheel = -100; }break; //NOTE(inso): scroll down case Button5: { - linuxvars.input.mouse.wheel = -1; + linuxvars.input.mouse.wheel = 100; }break; } }break; case ButtonRelease: { - should_step = 1; + should_step = true; switch(Event.xbutton.button){ case Button1: { linuxvars.input.mouse.release_l = 1; @@ -1267,24 +1267,24 @@ LinuxHandleX11Events(void) }break; case EnterNotify: { - should_step = 1; + should_step = true; linuxvars.input.mouse.out_of_window = 0; }break; case LeaveNotify: { - should_step = 1; + should_step = true; linuxvars.input.mouse.out_of_window = 1; }break; case FocusIn: case FocusOut: { - should_step = 1; + should_step = true; linuxvars.input.mouse.l = 0; linuxvars.input.mouse.r = 0; }break; case ConfigureNotify: { - should_step = 1; + should_step = true; i32 w = Event.xconfigure.width; i32 h = Event.xconfigure.height; @@ -1302,7 +1302,7 @@ LinuxHandleX11Events(void) case ClientMessage: { if ((Atom)Event.xclient.data.l[0] == linuxvars.atom_WM_DELETE_WINDOW) { - should_step = 1; + should_step = true; linuxvars.keep_running = 0; } else if ((Atom)Event.xclient.data.l[0] == linuxvars.atom__NET_WM_PING) { @@ -1395,15 +1395,16 @@ LinuxHandleX11Events(void) if (e->selection == linuxvars.atom_CLIPBOARD && e->target == linuxvars.atom_UTF8_STRING && e->property != None){ Atom type; int fmt; - unsigned long nitems, bytes_left; + unsigned long nitems; + unsigned long bytes_left; u8 *data; int result = XGetWindowProperty(linuxvars.XDisplay, linuxvars.XWindow, linuxvars.atom_CLIPBOARD, 0L, LINUX_MAX_PASTE_CHARS/4L, False, linuxvars.atom_UTF8_STRING, &type, &fmt, &nitems, &bytes_left, &data); if (result == Success && fmt == 8){ LinuxStringDup(&linuxvars.clipboard_contents, data, nitems); - should_step = 1; - linuxvars.new_clipboard = 1; + should_step = true; + linuxvars.new_clipboard = true; XFree(data); XDeleteProperty(linuxvars.XDisplay, linuxvars.XWindow, linuxvars.atom_CLIPBOARD); } @@ -1412,7 +1413,7 @@ LinuxHandleX11Events(void) case Expose: case VisibilityNotify: { - should_step = 1; + should_step = true; }break; default: { diff --git a/platform_mac/mac_4ed.cpp b/platform_mac/mac_4ed.cpp index 2a05b4f9..864a0e30 100644 --- a/platform_mac/mac_4ed.cpp +++ b/platform_mac/mac_4ed.cpp @@ -462,12 +462,7 @@ osx_mouse(i32 mx, i32 my, u32 type){ external void osx_mouse_wheel(float dx, float dy){ - if (dy > 0){ - osxvars.input.mouse.wheel = 1; - } - else if (dy < 0){ - osxvars.input.mouse.wheel = -1; - } + osxvars.input.mouse.wheel = - (int32_t)(dy); osx_schedule_step(); } diff --git a/platform_win32/win32_4ed.cpp b/platform_win32/win32_4ed.cpp index 9bb197cc..171d3b3b 100644 --- a/platform_win32/win32_4ed.cpp +++ b/platform_win32/win32_4ed.cpp @@ -849,10 +849,10 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ win32vars.got_useful_event = true; i32 rotation = GET_WHEEL_DELTA_WPARAM(wParam); if (rotation > 0){ - win32vars.input_chunk.trans.mouse_wheel = 1; + win32vars.input_chunk.trans.mouse_wheel = -100; } else{ - win32vars.input_chunk.trans.mouse_wheel = -1; + win32vars.input_chunk.trans.mouse_wheel = 100; } }break;