Переглянути джерело

support mouse wheel events

David Rose 22 роки тому
батько
коміт
04304b1e20

+ 29 - 4
panda/src/putil/mouseButton.cxx

@@ -18,13 +18,13 @@
 
 
 #include "mouseButton.h"
 #include "mouseButton.h"
 #include "buttonRegistry.h"
 #include "buttonRegistry.h"
-
-#include <stdio.h>
 #include "notify.h"
 #include "notify.h"
 
 
-static const int num_mouse_buttons = 3;
+#include <stdio.h>
 
 
-static ButtonHandle _buttons[num_mouse_buttons];
+ButtonHandle MouseButton::_buttons[num_mouse_buttons];
+ButtonHandle MouseButton::_wheel_up;
+ButtonHandle MouseButton::_wheel_down;
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: MouseButton::button
 //     Function: MouseButton::button
@@ -75,6 +75,28 @@ three() {
   return _buttons[2];
   return _buttons[2];
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: MouseButton::wheel_up
+//       Access: Public, Static
+//  Description: Returns the ButtonHandle generated when the mouse
+//               wheel is rolled one notch upwards.
+////////////////////////////////////////////////////////////////////
+ButtonHandle MouseButton::
+wheel_up() {
+  return _wheel_up;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MouseButton::wheel_down
+//       Access: Public, Static
+//  Description: Returns the ButtonHandle generated when the mouse
+//               wheel is rolled one notch downwards.
+////////////////////////////////////////////////////////////////////
+ButtonHandle MouseButton::
+wheel_down() {
+  return _wheel_down;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: MouseButton::is_mouse_button
 //     Function: MouseButton::is_mouse_button
 //       Access: Public, Static
 //       Access: Public, Static
@@ -108,4 +130,7 @@ init_mouse_buttons() {
 
 
     ButtonRegistry::ptr()->register_button(_buttons[i], numstr);
     ButtonRegistry::ptr()->register_button(_buttons[i], numstr);
   }
   }
+
+  ButtonRegistry::ptr()->register_button(_wheel_up, "wheel_up");
+  ButtonRegistry::ptr()->register_button(_wheel_down, "wheel_down");
 }
 }

+ 7 - 0
panda/src/putil/mouseButton.h

@@ -35,11 +35,18 @@ PUBLISHED:
   static ButtonHandle one();
   static ButtonHandle one();
   static ButtonHandle two();
   static ButtonHandle two();
   static ButtonHandle three();
   static ButtonHandle three();
+  static ButtonHandle wheel_up();
+  static ButtonHandle wheel_down();
 
 
   static bool is_mouse_button(ButtonHandle button);
   static bool is_mouse_button(ButtonHandle button);
 
 
 public:
 public:
   static void init_mouse_buttons();
   static void init_mouse_buttons();
+
+  enum { num_mouse_buttons = 3 };
+  static ButtonHandle _buttons[num_mouse_buttons];
+  static ButtonHandle _wheel_up;
+  static ButtonHandle _wheel_down;
 };
 };
 
 
 #endif
 #endif

+ 21 - 0
panda/src/windisplay/winGraphicsWindow.cxx

@@ -874,6 +874,27 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
         ReleaseCapture();
         ReleaseCapture();
         handle_keyrelease(MouseButton::button(button), get_message_time());
         handle_keyrelease(MouseButton::button(button), get_message_time());
         break;
         break;
+
+      case WM_MOUSEWHEEL:
+        {
+          int delta = GET_WHEEL_DELTA_WPARAM(wparam);
+          int x = translate_mouse(LOWORD(lparam));
+          int y = translate_mouse(HIWORD(lparam));
+          double time = get_message_time();
+
+          if (delta >= 0) {
+            while (delta > 0) {
+              handle_keypress(MouseButton::wheel_up(), x, y, time);
+              delta -= WHEEL_DELTA;
+            }
+          } else {
+            while (delta < 0) {
+              handle_keypress(MouseButton::wheel_down(), x, y, time);
+              delta += WHEEL_DELTA;
+            }
+          }
+          return 0;
+        }
     
     
       case WM_IME_NOTIFY:
       case WM_IME_NOTIFY:
         if (wparam == IMN_SETOPENSTATUS) {
         if (wparam == IMN_SETOPENSTATUS) {