From 1ade2e32279890d5706b1616ff60d9f8ca43f3de Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 6 Jul 2007 09:15:43 +0000 Subject: [PATCH] Fixed bug #382 Added horizontal scrolling support: SDL_BUTTON_WHEELLEFT (6) and SDL_BUTTON_WHEELRIGHT (7) --- WhatsNew | 2 ++ docs.html | 3 +++ include/SDL_mouse.h | 4 ++++ src/video/bwindow/SDL_sysevents.cc | 23 +++++++++++++++++------ src/video/quartz/SDL_QuartzEvents.m | 25 ++++++++++++++++++------- 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/WhatsNew b/WhatsNew index 8538e93ac..02cdc8bd5 100644 --- a/WhatsNew +++ b/WhatsNew @@ -7,6 +7,8 @@ Version 1.0: Added SDL_VIDEO_ALLOW_SCREENSAVER to override SDL's disabling of the screensaver on Mac OS X and X11. + Added SDL_BUTTON_WHEELLEFT (6) and SDL_BUTTON_WHEELRIGHT (7) + 1.2.10: If SDL_OpenAudio() is passed zero for the desired format fields, the following environment variables will be used diff --git a/docs.html b/docs.html index 25cb6fd9f..95df93587 100644 --- a/docs.html +++ b/docs.html @@ -28,6 +28,9 @@

General Notes

Added SDL_VIDEO_ALLOW_SCREENSAVER to override SDL's disabling of the screensaver on Mac OS X, Windows, and X11.

+

+ Added SDL_BUTTON_WHEELLEFT (6) and SDL_BUTTON_WHEELRIGHT (7) +

Fixed buffer overrun crash when resampling audio rates.

diff --git a/include/SDL_mouse.h b/include/SDL_mouse.h index c2364d859..cc01e50e1 100644 --- a/include/SDL_mouse.h +++ b/include/SDL_mouse.h @@ -115,6 +115,8 @@ extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle); Button 3: Right mouse button Button 4: Mouse wheel up (may also be a real button) Button 5: Mouse wheel down (may also be a real button) + Button 6: Mouse wheel left (may also be a real button) + Button 7: Mouse wheel right (may also be a real button) */ #define SDL_BUTTON(X) (1 << ((X)-1)) #define SDL_BUTTON_LEFT 1 @@ -122,6 +124,8 @@ extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle); #define SDL_BUTTON_RIGHT 3 #define SDL_BUTTON_WHEELUP 4 #define SDL_BUTTON_WHEELDOWN 5 +#define SDL_BUTTON_WHEELLEFT 6 +#define SDL_BUTTON_WHEELRIGHT 7 #define SDL_BUTTON_LMASK SDL_BUTTON(SDL_BUTTON_LEFT) #define SDL_BUTTON_MMASK SDL_BUTTON(SDL_BUTTON_MIDDLE) #define SDL_BUTTON_RMASK SDL_BUTTON(SDL_BUTTON_RIGHT) diff --git a/src/video/bwindow/SDL_sysevents.cc b/src/video/bwindow/SDL_sysevents.cc index 2a084682b..0746897fa 100644 --- a/src/video/bwindow/SDL_sysevents.cc +++ b/src/video/bwindow/SDL_sysevents.cc @@ -294,12 +294,23 @@ SDL_WarpMouse((int)center.x*2-1,(int)center.y*2-1); float x, y; x = y = 0; if (msg->FindFloat("be:wheel_delta_x", &x) == B_OK && msg->FindFloat("be:wheel_delta_y", &y) == B_OK) { - if (x < 0 || y < 0) { - SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELDOWN, 0, 0); - SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELDOWN, 0, 0); - } else if (x > 0 || y > 0) { - SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELUP, 0, 0); - SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELUP, 0, 0); + if ( y ) { + if (y < 0) { + SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELDOWN, 0, 0); + SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELDOWN, 0, 0); + } else { + SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELUP, 0, 0); + SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELUP, 0, 0); + } + } + if ( x ) { + if (x < 0) { + SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELRIGHT, 0, 0); + SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELRIGHT, 0, 0); + } else { + SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELLEFT, 0, 0); + SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELLEFT, 0, 0); + } } } break; diff --git a/src/video/quartz/SDL_QuartzEvents.m b/src/video/quartz/SDL_QuartzEvents.m index 1647570b5..f531ea804 100644 --- a/src/video/quartz/SDL_QuartzEvents.m +++ b/src/video/quartz/SDL_QuartzEvents.m @@ -932,13 +932,24 @@ disassociated from the mouse (and therefore Uint8 button; dy = [ event deltaY ]; dx = [ event deltaX ]; - if ( dy > 0.0 || dx > 0.0 ) /* Scroll up */ - button = SDL_BUTTON_WHEELUP; - else /* Scroll down */ - button = SDL_BUTTON_WHEELDOWN; - /* For now, wheel is sent as a quick down+up */ - SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); - SDL_PrivateMouseButton (SDL_RELEASED, button, 0, 0); + if ( dy ) { + if ( dy > 0.0 ) /* Scroll up */ + button = SDL_BUTTON_WHEELUP; + else /* Scroll down */ + button = SDL_BUTTON_WHEELDOWN; + /* For now, wheel is sent as a quick down+up */ + SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); + SDL_PrivateMouseButton (SDL_RELEASED, button, 0, 0); + } + if ( dx ) { + if ( dx > 0.0 ) /* Scroll left */ + button = SDL_BUTTON_WHEELLEFT; + else /* Scroll right */ + button = SDL_BUTTON_WHEELRIGHT; + /* For now, wheel is sent as a quick down+up */ + SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); + SDL_PrivateMouseButton (SDL_RELEASED, button, 0, 0); + } } break; case NSKeyUp: