[Bf-blender-cvs] [e4c5a46c129] master: Cleanup: remove NDOF_BUTTON_NONE from the range of usable buttons

Campbell Barton noreply at git.blender.org
Wed Oct 19 05:59:56 CEST 2022


Commit: e4c5a46c1294eefd7464395bca9551b9ca866aea
Author: Campbell Barton
Date:   Wed Oct 19 14:07:36 2022 +1100
Branches: master
https://developer.blender.org/rBe4c5a46c1294eefd7464395bca9551b9ca866aea

Cleanup: remove NDOF_BUTTON_NONE from the range of usable buttons

This is used to represent unknown state, so there is no need to be
able to store it's pressed state.

===================================================================

M	intern/ghost/intern/GHOST_NDOFManager.cpp
M	intern/ghost/intern/GHOST_NDOFManager.h
M	source/blender/blenkernel/BKE_brush.h
M	source/blender/windowmanager/intern/wm_event_system.cc
M	source/blender/windowmanager/wm_event_types.h

===================================================================

diff --git a/intern/ghost/intern/GHOST_NDOFManager.cpp b/intern/ghost/intern/GHOST_NDOFManager.cpp
index 882443ae839..9e9b9f14c43 100644
--- a/intern/ghost/intern/GHOST_NDOFManager.cpp
+++ b/intern/ghost/intern/GHOST_NDOFManager.cpp
@@ -29,8 +29,7 @@ static const char *ndof_progress_string[] = {
 
 /* Printable values for #NDOF_ButtonT enum (keep aligned) */
 static const char *ndof_button_names[] = {
-    "NDOF_BUTTON_NONE",
-    /* Real button values. */
+    /* Exclude `NDOF_BUTTON_NONE` (-1). */
     "NDOF_BUTTON_MENU",
     "NDOF_BUTTON_FIT",
     "NDOF_BUTTON_TOP",
@@ -68,6 +67,7 @@ static const char *ndof_button_names[] = {
     "NDOF_BUTTON_V1",
     "NDOF_BUTTON_V2",
     "NDOF_BUTTON_V3",
+    /* Keyboard emulation. */
     "NDOF_BUTTON_ESC",
     "NDOF_BUTTON_ENTER",
     "NDOF_BUTTON_DELETE",
@@ -270,7 +270,7 @@ bool GHOST_NDOFManager::setDevice(ushort vendor_id, ushort product_id)
         }
         case 0xC62B: {
           device_type_ = NDOF_SpaceMousePro;
-          hid_map_button_num_ = 27; /* Actually has 15 buttons, but HID codes range from 0 to 26. */
+          hid_map_button_num_ = 27; /* 15 physical buttons, but HID codes range from 0 to 26. */
           hid_map_button_mask_ = 0x07C0F137;
           hid_map_ = ndof_HID_map_Modern3Dx;
           break;
@@ -312,7 +312,7 @@ bool GHOST_NDOFManager::setDevice(ushort vendor_id, ushort product_id)
         case 0xC632: /* Wireless. */
         {
           device_type_ = NDOF_SpaceMouseProWireless;
-          hid_map_button_num_ = 27; /* Actually has 15 buttons, but HID codes range from 0 to 26. */
+          hid_map_button_num_ = 27; /* 15 physical buttons, but HID codes range from 0 to 26. */
           hid_map_button_mask_ = 0x07C0F137;
           hid_map_ = ndof_HID_map_Modern3Dx;
           break;
diff --git a/intern/ghost/intern/GHOST_NDOFManager.h b/intern/ghost/intern/GHOST_NDOFManager.h
index 6dadeee1fcc..2d5bba14aa4 100644
--- a/intern/ghost/intern/GHOST_NDOFManager.h
+++ b/intern/ghost/intern/GHOST_NDOFManager.h
@@ -29,8 +29,8 @@ typedef enum {
 
 /* NDOF device button event types */
 typedef enum {
-  /* Used internally, never sent. */
-  NDOF_BUTTON_NONE = 0,
+  /* Used internally, never sent or used as an index. */
+  NDOF_BUTTON_NONE = -1,
   /* These two are available from any 3Dconnexion device. */
   NDOF_BUTTON_MENU,
   NDOF_BUTTON_FIT,
@@ -162,7 +162,7 @@ class GHOST_NDOFManager {
   int rotation_[3];
   int button_depressed_; /* Bit field. */
 
-  uint64_t motion_time_;     /* In milliseconds. */
+  uint64_t motion_time_;      /* In milliseconds. */
   uint64_t motion_time_prev_; /* Time of most recent motion event sent. */
 
   GHOST_TProgress motion_state_;
diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h
index 8f069841fbc..a763b3d12c2 100644
--- a/source/blender/blenkernel/BKE_brush.h
+++ b/source/blender/blenkernel/BKE_brush.h
@@ -126,7 +126,7 @@ float BKE_brush_sample_masktex(const struct Scene *scene,
  * Get the mask texture for this given object mode.
  *
  * This is preferred above using mtex/mask_mtex attributes directly as due to legacy these
- * attributes got switched in sculpt mode. 
+ * attributes got switched in sculpt mode.
  */
 const struct MTex *BKE_brush_mask_texture_get(const struct Brush *brush,
                                               const eObjectMode object_mode);
diff --git a/source/blender/windowmanager/intern/wm_event_system.cc b/source/blender/windowmanager/intern/wm_event_system.cc
index affe0bcf45a..181ec89cabd 100644
--- a/source/blender/windowmanager/intern/wm_event_system.cc
+++ b/source/blender/windowmanager/intern/wm_event_system.cc
@@ -5620,7 +5620,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void
     case GHOST_kEventNDOFButton: {
       GHOST_TEventNDOFButtonData *e = static_cast<GHOST_TEventNDOFButtonData *>(customdata);
 
-      event.type = NDOF_BUTTON_NONE + e->button;
+      event.type = NDOF_BUTTON_INDEX_AS_EVENT(e->button);
 
       switch (e->action) {
         case GHOST_kPress:
diff --git a/source/blender/windowmanager/wm_event_types.h b/source/blender/windowmanager/wm_event_types.h
index 10536a00501..c36c57a12ae 100644
--- a/source/blender/windowmanager/wm_event_types.h
+++ b/source/blender/windowmanager/wm_event_types.h
@@ -252,8 +252,6 @@ enum {
 #define _NDOF_MIN NDOF_MOTION
 #define _NDOF_BUTTON_MIN NDOF_BUTTON_MENU
 
-  /* used internally, never sent */
-  NDOF_BUTTON_NONE = NDOF_MOTION,
   /* these two are available from any 3Dconnexion device */
 
   NDOF_BUTTON_MENU = 0x0191, /* 401 */
@@ -456,6 +454,8 @@ enum eEventType_Mask {
   (EVT_TYPE_MASK_KEYBOARD | EVT_TYPE_MASK_MOUSE | EVT_TYPE_MASK_NDOF)
 #define EVT_TYPE_MASK_HOTKEY_EXCLUDE EVT_TYPE_MASK_KEYBOARD_MODIFIER
 
+#define NDOF_BUTTON_INDEX_AS_EVENT(i) (_NDOF_BUTTON_MIN + (i))
+
 bool WM_event_type_mask_test(int event_type, enum eEventType_Mask mask);
 
 /** \} */



More information about the Bf-blender-cvs mailing list