浏览代码

added mouse buttons (4 and 5)

Dave Schuyler 20 年之前
父节点
当前提交
1485f8b7ea

+ 3 - 1
panda/src/pgui/pgEntry.cxx

@@ -181,7 +181,9 @@ press(const MouseWatcherParameter &param, bool background) {
       
       
       if (button == MouseButton::one() ||
       if (button == MouseButton::one() ||
           button == MouseButton::two() ||
           button == MouseButton::two() ||
-          button == MouseButton::three()) {
+          button == MouseButton::three() ||
+          button == MouseButton::four() ||
+          button == MouseButton::five()) {
         // Mouse button; set focus.
         // Mouse button; set focus.
         set_focus(true);
         set_focus(true);
         
         

+ 24 - 2
panda/src/putil/mouseButton.cxx

@@ -75,6 +75,28 @@ three() {
   return _buttons[2];
   return _buttons[2];
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: MouseButton::four
+//       Access: Public, Static
+//  Description: Returns the ButtonHandle associated with the
+//               fourth mouse button.
+////////////////////////////////////////////////////////////////////
+ButtonHandle MouseButton::
+four() {
+  return _buttons[3];
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MouseButton::five
+//       Access: Public, Static
+//  Description: Returns the ButtonHandle associated with the
+//               fifth mouse button.
+////////////////////////////////////////////////////////////////////
+ButtonHandle MouseButton::
+five() {
+  return _buttons[4];
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: MouseButton::wheel_up
 //     Function: MouseButton::wheel_up
 //       Access: Public, Static
 //       Access: Public, Static
@@ -105,7 +127,7 @@ wheel_down() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool MouseButton::
 bool MouseButton::
 is_mouse_button(ButtonHandle button) {
 is_mouse_button(ButtonHandle button) {
-  for (int i = 0; i < num_mouse_buttons; i++) {
+  for (int i = 0; i < num_mouse_buttons; ++i) {
     if (button == _buttons[i]) {
     if (button == _buttons[i]) {
       return true;
       return true;
     }
     }
@@ -124,7 +146,7 @@ void MouseButton::
 init_mouse_buttons() {
 init_mouse_buttons() {
   char numstr[20];
   char numstr[20];
 
 
-  for (int i = 0; i < num_mouse_buttons; i++) {
+  for (int i = 0; i < num_mouse_buttons; ++i) {
     sprintf(numstr, "mouse%d", i + 1);
     sprintf(numstr, "mouse%d", i + 1);
     nassertv(strlen(numstr) < 20);
     nassertv(strlen(numstr) < 20);
 
 

+ 3 - 1
panda/src/putil/mouseButton.h

@@ -35,6 +35,8 @@ PUBLISHED:
   static ButtonHandle one();
   static ButtonHandle one();
   static ButtonHandle two();
   static ButtonHandle two();
   static ButtonHandle three();
   static ButtonHandle three();
+  static ButtonHandle four();
+  static ButtonHandle five();
   static ButtonHandle wheel_up();
   static ButtonHandle wheel_up();
   static ButtonHandle wheel_down();
   static ButtonHandle wheel_down();
 
 
@@ -43,7 +45,7 @@ PUBLISHED:
 public:
 public:
   static void init_mouse_buttons();
   static void init_mouse_buttons();
 
 
-  enum { num_mouse_buttons = 3 };
+  enum { num_mouse_buttons = 5 };
   static ButtonHandle _buttons[num_mouse_buttons];
   static ButtonHandle _buttons[num_mouse_buttons];
   static ButtonHandle _wheel_up;
   static ButtonHandle _wheel_up;
   static ButtonHandle _wheel_down;
   static ButtonHandle _wheel_down;

+ 13 - 3
panda/src/tform/trackball.cxx

@@ -27,9 +27,11 @@
 TypeHandle Trackball::_type_handle;
 TypeHandle Trackball::_type_handle;
 
 
 // These are used internally.
 // These are used internally.
-#define B1_MASK 0x1
-#define B2_MASK 0x2
-#define B3_MASK 0x4
+#define B1_MASK 0x01
+#define B2_MASK 0x02
+#define B3_MASK 0x04
+#define B4_MASK 0x08
+#define B5_MASK 0x10
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: Trackball::Constructor
 //     Function: Trackball::Constructor
@@ -62,6 +64,8 @@ Trackball(const string &name) :
   watch_button(MouseButton::one());
   watch_button(MouseButton::one());
   watch_button(MouseButton::two());
   watch_button(MouseButton::two());
   watch_button(MouseButton::three());
   watch_button(MouseButton::three());
+  watch_button(MouseButton::four());
+  watch_button(MouseButton::five());
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -554,6 +558,12 @@ do_transmit_data(const DataNodeTransmit &input, DataNodeTransmit &output) {
     if (is_down(MouseButton::three())) {
     if (is_down(MouseButton::three())) {
       this_button |= B3_MASK;
       this_button |= B3_MASK;
     }
     }
+    if (is_down(MouseButton::four())) {
+      this_button |= B4_MASK;
+    }
+    if (is_down(MouseButton::five())) {
+      this_button |= B5_MASK;
+    }
     
     
     float x = this_x - _lastx;
     float x = this_x - _lastx;
     float y = this_y - _lasty;
     float y = this_y - _lasty;

+ 44 - 1
panda/src/windisplay/winGraphicsWindow.cxx

@@ -1110,6 +1110,22 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
         _input_devices[0].set_pointer_in_window(translate_mouse(LOWORD(lparam)), translate_mouse(HIWORD(lparam)));
         _input_devices[0].set_pointer_in_window(translate_mouse(LOWORD(lparam)), translate_mouse(HIWORD(lparam)));
         _input_devices[0].button_down(MouseButton::button(2), get_message_time());
         _input_devices[0].button_down(MouseButton::button(2), get_message_time());
         break;
         break;
+
+      case WM_XBUTTONDOWN:
+        {
+        if (_lost_keypresses) {
+          resend_lost_keypresses();
+        }
+        SetCapture(hwnd);
+        int whichButton = GET_XBUTTON_WPARAM(wparam);
+        _input_devices[0].set_pointer_in_window(translate_mouse(LOWORD(lparam)), translate_mouse(HIWORD(lparam)));
+        if (whichButton == XBUTTON1) {
+            _input_devices[0].button_down(MouseButton::button(3), get_message_time());
+        } else if (whichButton == XBUTTON2) {
+            _input_devices[0].button_down(MouseButton::button(4), get_message_time());
+        }
+        }
+        break;
     
     
       case WM_LBUTTONUP:
       case WM_LBUTTONUP:
         if (_lost_keypresses) {
         if (_lost_keypresses) {
@@ -1135,6 +1151,21 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
         _input_devices[0].button_up(MouseButton::button(2), get_message_time());
         _input_devices[0].button_up(MouseButton::button(2), get_message_time());
         break;
         break;
 
 
+      case WM_XBUTTONUP:
+        {
+        if (_lost_keypresses) {
+          resend_lost_keypresses();
+        }
+        ReleaseCapture();
+        int whichButton = GET_XBUTTON_WPARAM(wparam);
+        if (whichButton == XBUTTON1) {
+            _input_devices[0].button_up(MouseButton::button(3), get_message_time());
+        } else if (whichButton == XBUTTON2) {
+            _input_devices[0].button_up(MouseButton::button(4), get_message_time());
+        }
+        }
+        break;
+
       case WM_MOUSEWHEEL:
       case WM_MOUSEWHEEL:
         {
         {
           int delta = GET_WHEEL_DELTA_WPARAM(wparam);
           int delta = GET_WHEEL_DELTA_WPARAM(wparam);
@@ -2092,7 +2123,7 @@ handle_raw_input(HRAWINPUT hraw) {
     return;
     return;
   }
   }
   
   
-  for (int i = 1; i < (int)(_input_devices.size()); i++) {
+  for (int i = 1; i < (int)(_input_devices.size()); ++i) {
     if (_input_device_handle[i] == raw->header.hDevice) {
     if (_input_device_handle[i] == raw->header.hDevice) {
       int adjx = raw->data.mouse.lLastX;
       int adjx = raw->data.mouse.lLastX;
       int adjy = raw->data.mouse.lLastY;
       int adjy = raw->data.mouse.lLastY;
@@ -2123,6 +2154,18 @@ handle_raw_input(HRAWINPUT hraw) {
       if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_3_UP) {
       if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_3_UP) {
         _input_devices[i].button_up(MouseButton::button(1), get_message_time());
         _input_devices[i].button_up(MouseButton::button(1), get_message_time());
       }
       }
+      if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_4_DOWN) {
+        _input_devices[i].button_down(MouseButton::button(3), get_message_time());
+      }
+      if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_4_UP) {
+        _input_devices[i].button_up(MouseButton::button(3), get_message_time());
+      }
+      if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_5_DOWN) {
+        _input_devices[i].button_down(MouseButton::button(4), get_message_time());
+      }
+      if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_5_UP) {
+        _input_devices[i].button_up(MouseButton::button(4), get_message_time());
+      }
     }
     }
   }
   }
 }
 }