Wheel behavior upgrade

This commit is contained in:
Allen Webster 2017-11-10 20:21:50 -05:00
parent 023620d378
commit 161b037d31
7 changed files with 42 additions and 50 deletions

View File

@ -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.) */ /* 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{ STRUCT Mouse_State{
/* DOC(This field indicates that the left button is held.) */ /* DOC(Left button is down.) */
char l; int8_t l;
/* DOC(This field indicates that the right button is held.) */ /* DOC(Right button is down.) */
char r; int8_t r;
/* DOC(This field indicates that the left button was pressed this frame.) */ /* DOC(Left button was pressed this frame.) */
char press_l; int8_t press_l;
/* DOC(This field indicates that the right button was pressed this frame.) */ /* DOC(Right button was pressed this frame.) */
char press_r; int8_t press_r;
/* DOC(This field indicates that the left button was released this frame.) */ /* DOC(Left button was released this frame.) */
char release_l; int8_t release_l;
/* DOC(This field indicates that the right button was released this frame.) */ /* DOC(Right button was released this frame.) */
char release_r; int8_t release_r;
/* DOC( /* DOC(Mouse is outside of the window.) */
This field is 0 when the wheel has not moved, it is 1 for a downward motion and -1 for an upward motion. 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.) */
char wheel; int32_t wheel;
/* DOC(This field indicates that the mouse is outside of the window.) */ /* DOC(X position of the mouse where the left of the window is x = 0, and x grows to the right.) */
char out_of_window;
/* DOC(This field contains the x position of the mouse relative to the window where the left side is 0.) */
int32_t x; 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; int32_t y;
}; };

View File

@ -1536,8 +1536,6 @@ App_Step_Sig(app_step){
mouse_event.keycode = key_mouse_right_release; mouse_event.keycode = key_mouse_right_release;
input->keys.keys[input->keys.count++] = mouse_event; input->keys.keys[input->keys.count++] = mouse_event;
} }
input->mouse.wheel = -input->mouse.wheel;
} }
// NOTE(allen): detect mouse hover status // NOTE(allen): detect mouse hover status

View File

@ -5580,7 +5580,7 @@ do_step_file_view(System_Functions *system, View *view, Models *models, i32_Rect
case guicom_scrollable_invisible: case guicom_scrollable_invisible:
{ {
if (user_input->mouse.wheel != 0){ 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 = result.vars.target_y =
clamp(0, result.vars.target_y, max_y); clamp(0, result.vars.target_y, max_y);

View File

@ -137,6 +137,7 @@ struct GUI_Target{
i32 list_view_max; i32 list_view_max;
GUI_id scroll_id; GUI_id scroll_id;
// TODO(allen): is currently ignored in the wheel code, reevaluate?
i32 delta; i32 delta;
b32 has_keys; b32 has_keys;
b32 animating; b32 animating;
@ -695,8 +696,7 @@ gui_post_scroll_vars(GUI_Target *target, GUI_Scroll_Vars *vars_in, i32_Rect regi
} }
internal void internal void
gui_begin_scrollable(GUI_Target *target, GUI_id scroll_context_id, gui_begin_scrollable(GUI_Target *target, GUI_id scroll_context_id, GUI_Scroll_Vars scroll_vars, i32 delta, b32 show_bar){
GUI_Scroll_Vars scroll_vars, i32 delta, b32 show_bar){
GUI_Header *h; GUI_Header *h;
gui_begin_serial_section(target); gui_begin_serial_section(target);

View File

@ -1138,7 +1138,7 @@ internal void
LinuxHandleX11Events(void) LinuxHandleX11Events(void)
{ {
static XEvent PrevEvent = {}; static XEvent PrevEvent = {};
b32 should_step = 0; b32 should_step = false;
while (XPending(linuxvars.XDisplay)) while (XPending(linuxvars.XDisplay))
{ {
@ -1151,7 +1151,7 @@ LinuxHandleX11Events(void)
switch (Event.type){ switch (Event.type){
case KeyPress: { case KeyPress: {
should_step = 1; should_step = true;
b32 is_hold = (PrevEvent.type == KeyRelease && b32 is_hold = (PrevEvent.type == KeyRelease &&
PrevEvent.xkey.time == Event.xkey.time && PrevEvent.xkey.time == Event.xkey.time &&
@ -1219,17 +1219,17 @@ LinuxHandleX11Events(void)
}break; }break;
case KeyRelease: { case KeyRelease: {
should_step = 1; should_step = true;
}break; }break;
case MotionNotify: { case MotionNotify: {
should_step = 1; should_step = true;
linuxvars.input.mouse.x = Event.xmotion.x; linuxvars.input.mouse.x = Event.xmotion.x;
linuxvars.input.mouse.y = Event.xmotion.y; linuxvars.input.mouse.y = Event.xmotion.y;
}break; }break;
case ButtonPress: { case ButtonPress: {
should_step = 1; should_step = true;
switch(Event.xbutton.button){ switch(Event.xbutton.button){
case Button1: { case Button1: {
linuxvars.input.mouse.press_l = 1; linuxvars.input.mouse.press_l = 1;
@ -1242,18 +1242,18 @@ LinuxHandleX11Events(void)
//NOTE(inso): scroll up //NOTE(inso): scroll up
case Button4: { case Button4: {
linuxvars.input.mouse.wheel = 1; linuxvars.input.mouse.wheel = -100;
}break; }break;
//NOTE(inso): scroll down //NOTE(inso): scroll down
case Button5: { case Button5: {
linuxvars.input.mouse.wheel = -1; linuxvars.input.mouse.wheel = 100;
}break; }break;
} }
}break; }break;
case ButtonRelease: { case ButtonRelease: {
should_step = 1; should_step = true;
switch(Event.xbutton.button){ switch(Event.xbutton.button){
case Button1: { case Button1: {
linuxvars.input.mouse.release_l = 1; linuxvars.input.mouse.release_l = 1;
@ -1267,24 +1267,24 @@ LinuxHandleX11Events(void)
}break; }break;
case EnterNotify: { case EnterNotify: {
should_step = 1; should_step = true;
linuxvars.input.mouse.out_of_window = 0; linuxvars.input.mouse.out_of_window = 0;
}break; }break;
case LeaveNotify: { case LeaveNotify: {
should_step = 1; should_step = true;
linuxvars.input.mouse.out_of_window = 1; linuxvars.input.mouse.out_of_window = 1;
}break; }break;
case FocusIn: case FocusIn:
case FocusOut: { case FocusOut: {
should_step = 1; should_step = true;
linuxvars.input.mouse.l = 0; linuxvars.input.mouse.l = 0;
linuxvars.input.mouse.r = 0; linuxvars.input.mouse.r = 0;
}break; }break;
case ConfigureNotify: { case ConfigureNotify: {
should_step = 1; should_step = true;
i32 w = Event.xconfigure.width; i32 w = Event.xconfigure.width;
i32 h = Event.xconfigure.height; i32 h = Event.xconfigure.height;
@ -1302,7 +1302,7 @@ LinuxHandleX11Events(void)
case ClientMessage: { case ClientMessage: {
if ((Atom)Event.xclient.data.l[0] == linuxvars.atom_WM_DELETE_WINDOW) { if ((Atom)Event.xclient.data.l[0] == linuxvars.atom_WM_DELETE_WINDOW) {
should_step = 1; should_step = true;
linuxvars.keep_running = 0; linuxvars.keep_running = 0;
} }
else if ((Atom)Event.xclient.data.l[0] == linuxvars.atom__NET_WM_PING) { 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){ if (e->selection == linuxvars.atom_CLIPBOARD && e->target == linuxvars.atom_UTF8_STRING && e->property != None){
Atom type; Atom type;
int fmt; int fmt;
unsigned long nitems, bytes_left; unsigned long nitems;
unsigned long bytes_left;
u8 *data; 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); 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){ if (result == Success && fmt == 8){
LinuxStringDup(&linuxvars.clipboard_contents, data, nitems); LinuxStringDup(&linuxvars.clipboard_contents, data, nitems);
should_step = 1; should_step = true;
linuxvars.new_clipboard = 1; linuxvars.new_clipboard = true;
XFree(data); XFree(data);
XDeleteProperty(linuxvars.XDisplay, linuxvars.XWindow, linuxvars.atom_CLIPBOARD); XDeleteProperty(linuxvars.XDisplay, linuxvars.XWindow, linuxvars.atom_CLIPBOARD);
} }
@ -1412,7 +1413,7 @@ LinuxHandleX11Events(void)
case Expose: case Expose:
case VisibilityNotify: { case VisibilityNotify: {
should_step = 1; should_step = true;
}break; }break;
default: { default: {

View File

@ -462,12 +462,7 @@ osx_mouse(i32 mx, i32 my, u32 type){
external void external void
osx_mouse_wheel(float dx, float dy){ osx_mouse_wheel(float dx, float dy){
if (dy > 0){ osxvars.input.mouse.wheel = - (int32_t)(dy);
osxvars.input.mouse.wheel = 1;
}
else if (dy < 0){
osxvars.input.mouse.wheel = -1;
}
osx_schedule_step(); osx_schedule_step();
} }

View File

@ -849,10 +849,10 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
win32vars.got_useful_event = true; win32vars.got_useful_event = true;
i32 rotation = GET_WHEEL_DELTA_WPARAM(wParam); i32 rotation = GET_WHEEL_DELTA_WPARAM(wParam);
if (rotation > 0){ if (rotation > 0){
win32vars.input_chunk.trans.mouse_wheel = 1; win32vars.input_chunk.trans.mouse_wheel = -100;
} }
else{ else{
win32vars.input_chunk.trans.mouse_wheel = -1; win32vars.input_chunk.trans.mouse_wheel = 100;
} }
}break; }break;