stricter guards for disabling NDOF code (will test in 3.. 2.. 1..)
authorMike Erwin <significant.bit@gmail.com>
Thu, 4 Aug 2011 03:14:00 +0000 (03:14 +0000)
committerMike Erwin <significant.bit@gmail.com>
Thu, 4 Aug 2011 03:14:00 +0000 (03:14 +0000)
intern/ghost/intern/GHOST_NDOFManagerWin32.cpp
intern/ghost/intern/GHOST_NDOFManagerWin32.h
intern/ghost/intern/GHOST_SystemWin32.cpp

index 57d84ec14d47395bf38eae47a4082dc36453861f..fd62e845f7d954c8edcd827bc1a57e300b2421c6 100644 (file)
@@ -22,7 +22,9 @@
  *
  * ***** END GPL LICENSE BLOCK *****
  */
+
+#ifdef WITH_INPUT_NDOF // use contents of this file
+
 #include "GHOST_NDOFManagerWin32.h"
 
 
@@ -39,3 +41,5 @@ bool GHOST_NDOFManagerWin32::available()
        // always available since RawInput is built into Windows
        return true;
 }
+
+#endif // WITH_INPUT_NDOF
index 31f7e074cd6b1bba8c596924fa972c2430e3faf5..9f3eddeb3c84ddacae395145cb691ec724915d01 100644 (file)
  *
  * ***** END GPL LICENSE BLOCK *****
  */
+
+
 #ifndef _GHOST_NDOFMANAGERWIN32_H_
 #define _GHOST_NDOFMANAGERWIN32_H_
 
+#ifdef WITH_INPUT_NDOF
+
 #include "GHOST_NDOFManager.h"
 
 
@@ -37,4 +40,5 @@ public:
 };
 
 
-#endif
+#endif // WITH_INPUT_NDOF
+#endif // #include guard
index bbf8efeaee399b677013831c4d621c5f01ec3989..38f3985b13931a97e73d2308982f8bb93bb0971d 100644 (file)
@@ -62,7 +62,6 @@
 #endif
 #endif
 
-#include "GHOST_Debug.h"
 #include "GHOST_DisplayManagerWin32.h"
 #include "GHOST_EventButton.h"
 #include "GHOST_EventCursor.h"
 #include "GHOST_TimerManager.h"
 #include "GHOST_WindowManager.h"
 #include "GHOST_WindowWin32.h"
+
+#ifdef WITH_INPUT_NDOF
 #include "GHOST_NDOFManagerWin32.h"
+#endif
 
 // Key code values not found in winuser.h
 #ifndef VK_MINUS
 
 static void initRawInput()
 {
-       RAWINPUTDEVICE devices[2];
-       memset(devices, 0, 2 * sizeof(RAWINPUTDEVICE));
+#ifdef WITH_INPUT_NDOF
+#define DEVICE_COUNT 2
+#else
+#define DEVICE_COUNT 1
+#endif
 
-       // multi-axis mouse (SpaceNavigator, etc.)
-       devices[0].usUsagePage = 0x01;
-       devices[0].usUsage = 0x08;
+       RAWINPUTDEVICE devices[DEVICE_COUNT];
+       memset(devices, 0, DEVICE_COUNT * sizeof(RAWINPUTDEVICE));
 
        // Initiates WM_INPUT messages from keyboard
        // That way GHOST can retrieve true keys
+       devices[0].usUsagePage = 0x01;
+       devices[0].usUsage = 0x06; /* http://msdn.microsoft.com/en-us/windows/hardware/gg487473.aspx */
+
+#ifdef WITH_INPUT_NDOF
+       // multi-axis mouse (SpaceNavigator, etc.)
        devices[1].usUsagePage = 0x01;
-       devices[1].usUsage = 0x06; /* http://msdn.microsoft.com/en-us/windows/hardware/gg487473.aspx */
+       devices[1].usUsage = 0x08;
+#endif
 
-       if (RegisterRawInputDevices(devices, 2, sizeof(RAWINPUTDEVICE)))
-               puts("registered for RawInput (spacenav & keyboard)");
+       if (RegisterRawInputDevices(devices, DEVICE_COUNT, sizeof(RAWINPUTDEVICE)))
+               ; // yay!
        else
                printf("could not register for RawInput: %d\n", (int)GetLastError());
+
+#undef DEVICE_COUNT
 }
 
 GHOST_SystemWin32::GHOST_SystemWin32()
@@ -808,6 +820,7 @@ bool GHOST_SystemWin32::processNDOF(RAWINPUT const& raw)
                case 1: // translation
                {
                        short* axis = (short*)(data + 1);
+                       // massage into blender view coords (same goes for rotation)
                        short t[3] = {axis[0], -axis[2], axis[1]};
                        m_ndofManager->updateTranslation(t, now);
 
@@ -830,14 +843,6 @@ bool GHOST_SystemWin32::processNDOF(RAWINPUT const& raw)
                }
                case 3: // buttons
                {
-#if 0
-                       // I'm getting garbage bits -- examine whole report:
-                       printf("ndof: HID report for buttons [");
-                       for (int i = 0; i < raw.data.hid.dwSizeHid; ++i)
-                               printf(" %02X", data[i]);
-                       printf(" ]\n");
-#endif
-
                        int button_bits;
                        memcpy(&button_bits, data + 1, sizeof(button_bits));
                        m_ndofManager->updateButtons(button_bits, now);
@@ -892,12 +897,12 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                                                        GHOST_PRINT(" key ignored\n")
                                                }
                                                break;
-                                       case RIM_TYPEHID:
 #ifdef WITH_INPUT_NDOF
+                                       case RIM_TYPEHID:
                                                if (system->processNDOF(raw))
                                                        eventHandled = true;
-#endif
                                                break;
+#endif
                                        }
                                break;
                                }