more preliminary NDOF handling stuff (untested)
authorMike Erwin <significant.bit@gmail.com>
Thu, 22 Jul 2010 09:30:01 +0000 (09:30 +0000)
committerMike Erwin <significant.bit@gmail.com>
Thu, 22 Jul 2010 09:30:01 +0000 (09:30 +0000)
intern/ghost/intern/GHOST_NDOFManagerCocoa.cpp
intern/ghost/intern/GHOST_NDOFManagerCocoa.h
intern/ghost/intern/GHOST_NDOFManagerWin32.h [new file with mode: 0644]
intern/ghost/intern/GHOST_NDOFManagerX11.h [new file with mode: 0644]
intern/ghost/intern/GHOST_SystemCocoa.mm
intern/ghost/intern/GHOST_SystemWin32.cpp
intern/ghost/intern/GHOST_SystemX11.cpp
intern/ghost/intern/GHOST_SystemX11.h

index 6eac41945607891cb5249acb978f9f81598f3187..0196b2974dde0f47e6d9d55cedd1e5e9b6b16ca7 100644 (file)
@@ -80,10 +80,8 @@ GHOST_NDOFManagerCocoa::GHOST_NDOFManagerCocoa(GHOST_System& sys)
                        return;
                        }
 
-//             char* name = "\pBlender";
-//             name[0] = 7; // convert to Pascal string
-
-               m_clientID = RegisterConnexionClient('blnd', (UInt8*) "\pBlender"/*name*/,
+               // Pascal string *and* a four-letter constant. How old-skool.
+               m_clientID = RegisterConnexionClient('blnd', (UInt8*) "\pBlender",
                        kConnexionClientModeTakeOver, kConnexionMaskAll);
 
                printf("client id = %d\n", m_clientID);
@@ -104,8 +102,5 @@ GHOST_NDOFManagerCocoa::~GHOST_NDOFManagerCocoa()
 bool GHOST_NDOFManagerCocoa::available()
        {
        extern OSErr InstallConnexionHandlers() __attribute__((weak_import));
-// [mce] C likes the above line, but Obj-C++ does not. Make sure it works for
-//       machines without the driver installed! Try it on the QuickSilver.
-
        return InstallConnexionHandlers != NULL;
        }
index 07c4ceb7a6082172e4c99c96ac14daed8eb6f31f..4f2a2274e35a59c71754d602a28e76cbce4eb347 100644 (file)
@@ -25,6 +25,8 @@
 
 #include "GHOST_NDOFManager.h"
 
+// Event capture is handled within the NDOFManager on Macintosh,
+// so there's no need for SystemCocoa to look for them.
 
 class GHOST_NDOFManagerCocoa : public GHOST_NDOFManager
 {
diff --git a/intern/ghost/intern/GHOST_NDOFManagerWin32.h b/intern/ghost/intern/GHOST_NDOFManagerWin32.h
new file mode 100644 (file)
index 0000000..a09808d
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. 
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#ifndef _GHOST_NDOFMANAGERWIN32_H_
+#define _GHOST_NDOFMANAGERWIN32_H_
+
+#include "GHOST_NDOFManager.h"
+
+
+class GHOST_NDOFManagerWin32 : public GHOST_NDOFManager
+{
+public:
+       GHOST_NDOFManagerWin32(GHOST_System& sys)
+               : GHOST_NDOFManager(sys)
+               {}
+
+       // whether multi-axis functionality is available (via the OS or driver)
+       // does not imply that a device is plugged in or being used
+       bool available()
+               {
+               // always available since RawInput is built into Windows
+               return true;
+               }
+};
+
+
+#endif
diff --git a/intern/ghost/intern/GHOST_NDOFManagerX11.h b/intern/ghost/intern/GHOST_NDOFManagerX11.h
new file mode 100644 (file)
index 0000000..8f9c819
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. 
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#ifndef _GHOST_NDOFMANAGERX11_H_
+#define _GHOST_NDOFMANAGERX11_H_
+
+#include "GHOST_NDOFManager.h"
+
+
+class GHOST_NDOFManagerX11 : public GHOST_NDOFManager
+{
+public:
+       GHOST_NDOFManagerX11(GHOST_System& sys)
+               : GHOST_NDOFManager(sys)
+               {}
+
+       // whether multi-axis functionality is available (via the OS or driver)
+       // does not imply that a device is plugged in or being used
+       bool available()
+               {
+               // never available since I've not yet written it!
+               return false;
+               }
+};
+
+
+#endif
index 91da1fb2d4b666208b74515d3d12365281a42454..1ab0794548ef035d63b67529e68ba076e43bbb59 100644 (file)
@@ -54,7 +54,7 @@
 #include "GHOST_TimerTask.h"
 #include "GHOST_WindowManager.h"
 #include "GHOST_WindowCocoa.h"
-#include "GHOST_NDOFManager.h"
+#include "GHOST_NDOFManagerCocoa.h"
 #include "AssertMacros.h"
 
 #pragma mark KeyMap, mouse converters
@@ -601,13 +601,8 @@ GHOST_TSuccess GHOST_SystemCocoa::init()
 {
     GHOST_TSuccess success = GHOST_System::init();
     if (success) {
-               //ProcessSerialNumber psn;
-               
-               //Carbon stuff to move window & menu to foreground
-               /*if (!GetCurrentProcess(&psn)) {
-                       TransformProcessType(&psn, kProcessTransformToForegroundApplication);
-                       SetFrontProcess(&psn);
-               }*/
+
+               m_ndofManager = new GHOST_NDOFManagerCocoa(*this);
                
                NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
                if (NSApp == nil) {
index 829f09973774841696737e5c52baa26a9628dd57..14b6b16e6fbc4bb40fb5e625ccc08ff82c9719be 100644 (file)
@@ -73,7 +73,7 @@
 #include "GHOST_TimerManager.h"
 #include "GHOST_WindowManager.h"
 #include "GHOST_WindowWin32.h"
-#include "GHOST_NDOFManager.h"
+#include "GHOST_NDOFManagerWin32.h"
 
 // Key code values not found in winuser.h
 #ifndef VK_MINUS
@@ -347,6 +347,8 @@ GHOST_TSuccess GHOST_SystemWin32::init()
 {
        GHOST_TSuccess success = GHOST_System::init();
 
+       m_ndofManager = new GHOST_NDOFManagerWin32(*this);
+
        /* Disable scaling on high DPI displays on Vista */
        HMODULE user32 = ::LoadLibraryA("user32.dll");
        typedef BOOL (WINAPI * LPFNSETPROCESSDPIAWARE)();
@@ -736,9 +738,6 @@ vendor ID
 No other registered devices use the c62_ space, so a simple mask will work!
 */
 
-               short t[3], r[3];       // defined here just for quick testing,
-               unsigned short buttons; // will maintain shared copy for all NDOF events
-
                // multiple events per RAWHID? MSDN hints at this.
                printf("%d events\n", raw.data.hid.dwCount);
 
@@ -754,14 +753,24 @@ No other registered devices use the c62_ space, so a simple mask will work!
                switch (packetType)
                        {
                        case 1: // translation
+                               {
+                               short t[3];
                                memcpy(t, data + 1, sizeof(t));
                                printf("T: %+5d %+5d %+5d\n", t[0], t[1], t[2]);
+                               m_ndofManager->updateTranslation(t, getMilliseconds());
                                break;
+                               }
                        case 2: // rotation
+                               {
+                               short r[3];
                                memcpy(r, data + 1, sizeof(r));
                                printf("R: %+5d %+5d %+5d\n", r[0], r[1], r[2]);
+                               m_ndofManager->updateRotation(r, getMilliseconds());
                                break;
+                               }
                        case 3: // buttons
+                               {
+                               unsigned short buttons;
                                memcpy(&buttons, data + 1, sizeof(buttons));
                                printf("buttons:");
                                if (buttons)
@@ -774,7 +783,9 @@ No other registered devices use the c62_ space, so a simple mask will work!
                                        }
                                else
                                        printf(" none\n");
+                               m_ndofManager->updateButtons(buttons, getMilliseconds());
                                break;
+                               }
                        }
                }
 
index 1ae9b666c6bb5930770f4266a5d0d442e7bb44ef..a70162a5039d5a06a22ddc026de613872d8b2818 100644 (file)
 #include "GHOST_EventButton.h"
 #include "GHOST_EventWheel.h"
 #include "GHOST_EventNDOF.h"
-#include "GHOST_NDOFManager.h"
+#include "GHOST_NDOFManagerX11.h"
 #include "GHOST_DisplayManagerX11.h"
 
 #include "GHOST_Debug.h"
 
 #include <X11/Xatom.h>
 #include <X11/keysym.h>
-#include <X11/XKBlib.h> /* allow detectable autorepeate */
+#include <X11/XKBlib.h> /* allow detectable autorepeat */
 
 #ifdef __sgi
 
 #include <stdio.h> // for fprintf only
 #include <cstdlib> // for exit
 
+// [mce] these are for communication with the plugin
 typedef struct NDOFPlatformInfo {
        Display *display;
        Window window;
-       volatile GHOST_TEventNDOFData *currValues;
+//     volatile GHOST_TEventNDOFData *currValues;
        Atom cmdAtom;
        Atom motionAtom;
        Atom btnPressAtom;
@@ -79,7 +80,6 @@ typedef struct NDOFPlatformInfo {
 
 static NDOFPlatformInfo sNdofInfo = {NULL, 0, NULL, 0, 0, 0, 0};
 
-
 //these are for copy and select copy
 static char *txt_cut_buffer= NULL;
 static char *txt_select_buffer= NULL;
@@ -142,7 +142,7 @@ GHOST_SystemX11(
        m_start_time = GHOST_TUns64(tv.tv_sec*1000 + tv.tv_usec/1000);
        
        
-       /* use detectable autorepeate, mac and windows also do this */
+       /* use detectable autorepeat, mac and windows also do this */
        int use_xkb;
        int xkb_opcode, xkb_event, xkb_error;
        int xkb_major = XkbMajorVersion, xkb_minor = XkbMinorVersion;
@@ -168,6 +168,9 @@ init(
        GHOST_TSuccess success = GHOST_System::init();
 
        if (success) {
+
+               m_ndofManager = new GHOST_NDOFManagerX11;
+
                m_displayManager = new GHOST_DisplayManagerX11(this);
 
                if (m_displayManager) {
@@ -246,9 +249,6 @@ createWindow(
        GHOST_WindowX11 * window = 0;
        
        if (!m_display) return 0;
-       
-
-       
 
        window = new GHOST_WindowX11 (
                this,m_display,title, left, top, width, height, state, parentWindow, type, stereoVisual
@@ -628,29 +628,49 @@ GHOST_SystemX11::processEvent(XEvent *xe)
                        } else 
 #endif
                        if (sNdofInfo.currValues) {
-                               static GHOST_TEventNDOFData data = {0,0,0,0,0,0,0,0,0,0,0};
+//                             static GHOST_TEventNDOFData data = {0,0,0,0,0,0,0,0,0,0,0};
                                if (xcme.message_type == sNdofInfo.motionAtom)
                                {
-                                       data.changed = 1;
-                                       data.delta = xcme.data.s[8] - data.time;
-                                       data.time = xcme.data.s[8];
-                                       data.tx = xcme.data.s[2] >> 2;
-                                       data.ty = xcme.data.s[3] >> 2;
-                                       data.tz = xcme.data.s[4] >> 2;
-                                       data.rx = xcme.data.s[5];
-                                       data.ry = xcme.data.s[6];
-                                       data.rz =-xcme.data.s[7];
-                                       g_event = new GHOST_EventNDOF(getMilliSeconds(),
-                                                                     GHOST_kEventNDOFMotion,
-                                                                     window, data);
+//                                     data.changed = 1;
+//                                     data.delta = xcme.data.s[8] - data.time;
+//                                     data.time = xcme.data.s[8];
+//                                     data.tx = xcme.data.s[2] >> 2;
+//                                     data.ty = xcme.data.s[3] >> 2;
+//                                     data.tz = xcme.data.s[4] >> 2;
+//                                     data.rx = xcme.data.s[5];
+//                                     data.ry = xcme.data.s[6];
+//                                     data.rz =-xcme.data.s[7];
+                                               
+                                       short t[3], r[3];
+                                       t[0] = xcme.data.s[2] >> 2;
+                                       t[1] = xcme.data.s[3] >> 2;
+                                       t[2] = xcme.data.s[4] >> 2;
+                                       r[0] = xcme.data.s[5];
+                                       r[1] = xcme.data.s[6];
+                                       r[2] =-xcme.data.s[7];
+
+                                       // [mce] look into this soon, as in find out why some values
+                                       // are shifted and where this message originates.
+
+                                       m_ndofManager->updateTranslation(t, getMilliseconds);
+                                       m_ndofManager->updateRotation(r, getMilliseconds);
+
+//                                     g_event = new GHOST_EventNDOF(getMilliSeconds(),
+//                                                                   GHOST_kEventNDOFMotion,
+//                                                                   window, data);
+
                                } else if (xcme.message_type == sNdofInfo.btnPressAtom) {
-                                       data.changed = 2;
-                                       data.delta = xcme.data.s[8] - data.time;
-                                       data.time = xcme.data.s[8];
-                                       data.buttons = xcme.data.s[2];
-                                       g_event = new GHOST_EventNDOF(getMilliSeconds(),
-                                                                     GHOST_kEventNDOFButton,
-                                                                     window, data);
+//                                     data.changed = 2;
+//                                     data.delta = xcme.data.s[8] - data.time;
+//                                     data.time = xcme.data.s[8];
+//                                     data.buttons = xcme.data.s[2];
+
+                                       unsigned short buttons = xcme.data.s[2];
+                                       m_ndofManager->updateButtons(buttons, getMilliseconds());
+
+//                                     g_event = new GHOST_EventNDOF(getMilliSeconds(),
+//                                                                   GHOST_kEventNDOFButton,
+//                                                                   window, data);
                                }
                        } else if (((Atom)xcme.data.l[0]) == m_wm_take_focus) {
                                XWindowAttributes attr;
@@ -814,6 +834,7 @@ GHOST_SystemX11::processEvent(XEvent *xe)
        }
 }
 
+/*
        void *
 GHOST_SystemX11::
 prepareNdofInfo(volatile GHOST_TEventNDOFData *currentNdofValues)
@@ -825,6 +846,7 @@ prepareNdofInfo(volatile GHOST_TEventNDOFData *currentNdofValues)
        sNdofInfo.currValues = currentNdofValues;
        return (void*)&sNdofInfo;
 }
+*/
 
        GHOST_TSuccess 
 GHOST_SystemX11::
index ee6cbedb2aee88f26d0b2e91aca0ee94b81c06c6..d00f83aa8ea2dfcf48663f5aa8be9eea3bc20086 100644 (file)
@@ -202,10 +202,12 @@ public:
                return m_display;
        }       
 
+/* [mce] is this needed?
                void *
        prepareNdofInfo(
                volatile GHOST_TEventNDOFData *current_values
        );
+*/
 
        /* Helped function for get data from the clipboard. */
        void getClipboard_xcout(XEvent evt, Atom sel, Atom target,
@@ -317,4 +319,3 @@ private :
 };
 
 #endif
-