svn merge -r38814:38905 https://svn.blender.org/svnroot/bf-blender/trunk/blender . merwin-spacenav
authorMike Erwin <significant.bit@gmail.com>
Tue, 2 Aug 2011 01:01:56 +0000 (01:01 +0000)
committerMike Erwin <significant.bit@gmail.com>
Tue, 2 Aug 2011 01:01:56 +0000 (01:01 +0000)
1  2 
CMakeLists.txt
intern/ghost/intern/GHOST_SystemCocoa.mm
intern/ghost/intern/GHOST_SystemWin32.cpp
source/blender/editors/interface/resources.c
source/blender/editors/transform/transform.c

diff --combined CMakeLists.txt
index 9f833aef31efd47dc233c5edd79f2a577306899e,455c3070e8f32e0acf571102a8e1b98243889f82..d91d4a1349ddfd39b329ef50cb78a33048e227f3
@@@ -179,7 -179,6 +179,7 @@@ option(WITH_LZO           "Enable fast 
  option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
  
  # Misc
 +option(WITH_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ON)
  option(WITH_RAYOPTIMIZATION   "Enable use of SIMD (SSE) optimizations for the raytracer" ON) 
  if(UNIX AND NOT APPLE)
        option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
@@@ -453,15 -452,6 +453,15 @@@ if(UNIX AND NOT APPLE
                endif()
        endif()
  
 +      if (WITH_NDOF)
 +              if(CMAKE_SYSTEM_NAME MATCHES "Linux")
 +                      set(NDOF /usr)
 +                      set(NDOF_INC ${NDOF}/include)
 +                      set(NDOF_LIBRARY spnav)
 +                      set(NDOF_LIBPATH ${NDOF}/lib)
 +              endif()
 +      endif()
 +
        # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
        set(PLATFORM_LINKLIBS "-lutil -lc -lm -lpthread -lstdc++")
  
@@@ -1039,11 -1029,6 +1039,11 @@@ elseif(APPLE
                set(TIFF_LIBPATH ${TIFF}/lib)
        endif()
  
 +      if (WITH_NDOF)
 +              # GHOST_NDOFManagerCocoa.mm needs "-fpascal-strings"
 +              # linker needs "-weak_framework 3DconnexionClient"
 +      endif()
 +
        set(EXETYPE MACOSX_BUNDLE)
  
        set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
@@@ -1069,20 -1054,34 +1069,34 @@@ if(APPLE OR WIN32
        endif()
  endif()
  
+ # See TEST_SSE_SUPPORT() for how this is defined.
  if(WITH_RAYOPTIMIZATION)
        if(CMAKE_COMPILER_IS_GNUCC)
-               if(SUPPORT_SSE_BUILD)
-                       set(PLATFORM_CFLAGS " -msse ${PLATFORM_CFLAGS}")
-                       add_definitions(-D__SSE__ -D__MMX__)
-               endif()
-               if(SUPPORT_SSE2_BUILD)
-                       set(PLATFORM_CFLAGS " -msse2 ${PLATFORM_CFLAGS}")
-                       add_definitions(-D__SSE2__)
-                       if(NOT SUPPORT_SSE_BUILD) # dont double up
-                               add_definitions(-D__MMX__)
-                       endif()
+               set(_sse "-msse")
+               set(_sse2 "-msse2")
+       elseif(MSVC)
+               set(_sse "/arch:SSE")
+               set(_sse2 "/arch:SSE2")
+       else()
+               message(WARNING "SSE flags for this compiler not known")
+               set(_sse)
+               set(_sse2)
+       endif()
+       if(SUPPORT_SSE_BUILD)
+               set(PLATFORM_CFLAGS " ${_sse} ${PLATFORM_CFLAGS}")
+               add_definitions(-D__SSE__ -D__MMX__)
+       endif()
+       if(SUPPORT_SSE2_BUILD)
+               set(PLATFORM_CFLAGS " ${_sse2} ${PLATFORM_CFLAGS}")
+               add_definitions(-D__SSE2__)
+               if(NOT SUPPORT_SSE_BUILD) # dont double up
+                       add_definitions(-D__MMX__)
                endif()
        endif()
+       unset(_sse)
+       unset(_sse2)
  endif()
  
  if(WITH_IMAGE_OPENJPEG)
index 5f27eab9d8c98284bc102330a57ba7128e8a4965,5c88523d4063220eb15501c4392024fa589272c7..8f2df4c396dac0e7d64ac1f0fb0e7112fdc4a6f0
@@@ -52,7 -52,7 +52,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
@@@ -596,9 -596,6 +596,9 @@@ GHOST_TSuccess GHOST_SystemCocoa::init(
        
      GHOST_TSuccess success = GHOST_System::init();
      if (success) {
 +
 +              m_ndofManager = new GHOST_NDOFManagerCocoa(*this);
 +
                //ProcessSerialNumber psn;
                
                //Carbon stuff to move window & menu to foreground
@@@ -1010,11 -1007,6 +1010,11 @@@ GHOST_TSuccess GHOST_SystemCocoa::handl
        return GHOST_kSuccess;
  }
  
 +void GHOST_SystemCocoa::notifyExternalEventProcessed()
 +{
 +      m_outsideLoopEventProcessed = true;
 +}
 +
  //Note: called from NSWindow delegate
  GHOST_TSuccess GHOST_SystemCocoa::handleWindowEvent(GHOST_TEventType eventType, GHOST_WindowCocoa* window)
  {
@@@ -1568,6 -1560,8 +1568,8 @@@ GHOST_TSuccess GHOST_SystemCocoa::handl
                                        GHOST_TInt32 delta;
                                        
                                        double deltaF = [event deltaY];
+                                       if (deltaF == 0.0) deltaF = [event deltaX]; // make blender decide if it's horizontal scroll
                                        if (deltaF == 0.0) break; //discard trackpad delta=0 events
                                        
                                        delta = deltaF > 0.0 ? 1 : -1;
index 2a3eb74d1e20dcc3dc9dd21dfe871c1206379369,95b3456ce3bca4ad45e9a2f507209f2979353c84..1b43fa92bb26771d0d0d2567e5ec367c43da22c6
   * @date      May 7, 2001
   */
  
 +#ifdef BF_GHOST_DEBUG
  #include <iostream>
 -
 -#ifdef FREE_WINDOWS
 -#  define WINVER 0x0501 /* GetConsoleWindow() for MinGW */
  #endif
  
 +#include <stdio.h> // [mce] temporary debug, remove soon!
 +
  #include "GHOST_SystemWin32.h"
  #include "GHOST_EventDragnDrop.h"
  
 -#define WIN32_LEAN_AND_MEAN
 -#ifdef _WIN32_IE
 -#undef _WIN32_IE
 +#ifndef _WIN32_IE
 +#define _WIN32_IE 0x0501 /* shipped before XP, so doesn't impose additional requirements */
  #endif
 -#define _WIN32_IE 0x0501
 -#include <windows.h>
  #include <shlobj.h>
+ #include <tlhelp32.h>
  
  // win64 doesn't define GWL_USERDATA
  #ifdef WIN32
  #endif
  #endif
  
 -/*
 - * According to the docs the mouse wheel message is supported from windows 98 
 - * upwards. Leaving WINVER at default value, the WM_MOUSEWHEEL message and the 
 - * wheel detent value are undefined.
 - */
 -#ifndef WM_MOUSEWHEEL
 -#define WM_MOUSEWHEEL 0x020A
 -#endif // WM_MOUSEWHEEL
 -#ifndef WHEEL_DELTA
 -#define WHEEL_DELTA 120       /* Value for rolling one detent, (old convention! MS changed it) */
 -#endif // WHEEL_DELTA
 -
 -/* 
 - * Defines for mouse buttons 4 and 5 aka xbutton1 and xbutton2.
 - * MSDN: Declared in Winuser.h, include Windows.h 
 - * This does not seem to work with MinGW so we define our own here.
 - */
 -#ifndef XBUTTON1
 -#define XBUTTON1 0x0001
 -#endif // XBUTTON1
 -#ifndef XBUTTON2
 -#define XBUTTON2 0x0002
 -#endif // XBUTTON2
 -#ifndef WM_XBUTTONUP
 -#define WM_XBUTTONUP 524
 -#endif // WM_XBUTTONUP
 -#ifndef WM_XBUTTONDOWN
 -#define WM_XBUTTONDOWN 523
 -#endif // WM_XBUTTONDOWN
 -
  #include "GHOST_Debug.h"
  #include "GHOST_DisplayManagerWin32.h"
  #include "GHOST_EventButton.h"
  #include "GHOST_EventCursor.h"
  #include "GHOST_EventKey.h"
  #include "GHOST_EventWheel.h"
 -#include "GHOST_EventNDOF.h"
  #include "GHOST_TimerTask.h"
  #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
  #define VK_MEDIA_PLAY_PAUSE   0xB3
  #endif // VK_MEDIA_PLAY_PAUSE
  
 -/*
 -      Initiates WM_INPUT messages from keyboard
 -      That way GHOST can retrieve true keys
 -*/
 -GHOST_TInt32 GHOST_SystemWin32::initKeyboardRawInput(void)
 +static void initRawInput()
  {
 -      RAWINPUTDEVICE device = {0};
 -      device.usUsagePage      = 0x01; /* usUsagePage & usUsage for keyboard*/
 -      device.usUsage          = 0x06; /* http://msdn.microsoft.com/en-us/windows/hardware/gg487473.aspx */
 +      RAWINPUTDEVICE devices[2];
 +      memset(devices, 0, 2 * sizeof(RAWINPUTDEVICE));
  
 -      return RegisterRawInputDevices(&device, 1, sizeof(device));
 -};
 +      // multi-axis mouse (SpaceNavigator, etc.)
 +      devices[0].usUsagePage = 0x01;
 +      devices[0].usUsage = 0x08;
 +
 +      // Initiates WM_INPUT messages from keyboard
 +      // That way GHOST can retrieve true keys
 +      devices[1].usUsagePage = 0x01;
 +      devices[1].usUsage = 0x06; /* http://msdn.microsoft.com/en-us/windows/hardware/gg487473.aspx */
 +
 +      if (RegisterRawInputDevices(devices, 2, sizeof(RAWINPUTDEVICE)))
 +              puts("registered for RawInput (spacenav & keyboard)");
 +      else
 +              printf("could not register for RawInput: %d\n", (int)GetLastError());
 +}
  
  GHOST_SystemWin32::GHOST_SystemWin32()
  : m_hasPerformanceCounter(false), m_freq(0), m_start(0)
        this->handleKeyboardChange();
        // Require COM for GHOST_DropTargetWin32 created in GHOST_WindowWin32.
        OleInitialize(0);
 +
 +      m_ndofManager = new GHOST_NDOFManagerWin32(*this);
  }
  
  GHOST_SystemWin32::~GHOST_SystemWin32()
@@@ -219,7 -245,6 +220,7 @@@ GHOST_IWindow* GHOST_SystemWin32::creat
                        // Store the pointer to the window
  //                    if (state != GHOST_kWindowStateFullScreen) {
                                m_windowManager->addWindow(window);
 +                              m_windowManager->setActiveWindow(window);
  //                    }
                }
                else {
@@@ -360,15 -385,22 +361,15 @@@ GHOST_TSuccess GHOST_SystemWin32::init(
        GHOST_TSuccess success = GHOST_System::init();
        
        /* Disable scaling on high DPI displays on Vista */
 +      HMODULE
        user32 = ::LoadLibraryA("user32.dll");
        typedef BOOL (WINAPI * LPFNSETPROCESSDPIAWARE)();
        LPFNSETPROCESSDPIAWARE SetProcessDPIAware =
                (LPFNSETPROCESSDPIAWARE)GetProcAddress(user32, "SetProcessDPIAware");
        if (SetProcessDPIAware)
                SetProcessDPIAware();
 -      #ifdef NEED_RAW_PROC
 -              pRegisterRawInputDevices = (LPFNDLLRRID)GetProcAddress(user32, "RegisterRawInputDevices");
 -              pGetRawInputData = (LPFNDLLGRID)GetProcAddress(user32, "GetRawInputData");
 -      #else
 -              FreeLibrary(user32);
 -      #endif
 -
 -      /*      Initiates WM_INPUT messages from keyboard */
 -      initKeyboardRawInput();
 -
 +      FreeLibrary(user32);
 +      initRawInput();
  
        // Determine whether this system has a high frequency performance counter. */
        m_hasPerformanceCounter = ::QueryPerformanceFrequency((LARGE_INTEGER*)&m_freq) == TRUE;
  
  GHOST_TSuccess GHOST_SystemWin32::exit()
  {
 -      #ifdef NEED_RAW_PROC
 -      FreeLibrary(user32);
 -      #endif
 -
        return GHOST_System::exit();
  }
  
 -GHOST_TKey GHOST_SystemWin32::hardKey(GHOST_IWindow *window, WPARAM wParam, LPARAM lParam, int * keyDown, char * vk)
 +GHOST_TKey GHOST_SystemWin32::hardKey(GHOST_IWindow *window, RAWINPUT const& raw, int * keyDown, char * vk)
  {
 -      unsigned int size = 0;
 -      char * data;
        GHOST_TKey key = GHOST_kKeyUnknown;
  
  
        if(!keyDown)
                return GHOST_kKeyUnknown;
  
 -      GetRawInputData((HRAWINPUT)lParam, RID_INPUT, 0, &size, sizeof(RAWINPUTHEADER));
  
 +      GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)getSystem();
  
 -      if((data = (char*)malloc(size)) &&
 -              GetRawInputData((HRAWINPUT)lParam, RID_INPUT, data, &size, sizeof(RAWINPUTHEADER)))
 +      GHOST_ModifierKeys modifiers;
 +      system->retrieveModifierKeys(modifiers);
 +      
 +      *keyDown = !(raw.data.keyboard.Flags & RI_KEY_BREAK);
 +      key = this->convertKey(window, raw.data.keyboard.VKey, raw.data.keyboard.MakeCode, (raw.data.keyboard.Flags&(RI_KEY_E1|RI_KEY_E0)));
 +      
 +      // extra handling of modifier keys: don't send repeats out from GHOST
 +      if(key >= GHOST_kKeyLeftShift && key <= GHOST_kKeyRightAlt)
        {
 -              RAWINPUT ri;
 -              memcpy(&ri,data,(size < sizeof(ri)) ? size : sizeof(ri));
 -
 -              if (ri.header.dwType == RIM_TYPEKEYBOARD)
 -              {
 -                      GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)getSystem();
 -                      
 -                      GHOST_ModifierKeys modifiers;
 -                      system->retrieveModifierKeys(modifiers);
 -                      
 -                      *keyDown = !(ri.data.keyboard.Flags & RI_KEY_BREAK);
 -                      key = this->convertKey(window, ri.data.keyboard.VKey, ri.data.keyboard.MakeCode, (ri.data.keyboard.Flags&(RI_KEY_E1|RI_KEY_E0)));
 -                      
 -                      // extra handling of modifier keys: don't send repeats out from GHOST
 -                      if(key >= GHOST_kKeyLeftShift && key <= GHOST_kKeyRightAlt)
 -                      {
 -                              bool changed = false;
 -                              GHOST_TModifierKeyMask modifier;
 -                              switch(key) {
 -                                      case GHOST_kKeyLeftShift:
 -                                              {
 -                                                      changed = (modifiers.get(GHOST_kModifierKeyLeftShift) != (bool)*keyDown);
 -                                                      modifier = GHOST_kModifierKeyLeftShift;
 -                                              }
 -                                              break;
 -                                      case GHOST_kKeyRightShift:
 -                                              {
 -                                                      changed = (modifiers.get(GHOST_kModifierKeyRightShift) != (bool)*keyDown);
 -                                                      modifier = GHOST_kModifierKeyRightShift;
 -                                              }
 -                                              break;
 -                                      case GHOST_kKeyLeftControl:
 -                                              {
 -                                                      changed = (modifiers.get(GHOST_kModifierKeyLeftControl) != (bool)*keyDown);
 -                                                      modifier = GHOST_kModifierKeyLeftControl;
 -                                              }
 -                                              break;
 -                                      case GHOST_kKeyRightControl:
 -                                              {
 -                                                      changed = (modifiers.get(GHOST_kModifierKeyRightControl) != (bool)*keyDown);
 -                                                      modifier = GHOST_kModifierKeyRightControl;
 -                                              }
 -                                              break;
 -                                      case GHOST_kKeyLeftAlt:
 -                                              {
 -                                                      changed = (modifiers.get(GHOST_kModifierKeyLeftAlt) != (bool)*keyDown);
 -                                                      modifier = GHOST_kModifierKeyLeftAlt;
 -                                              }
 -                                              break;
 -                                      case GHOST_kKeyRightAlt:
 -                                              {
 -                                                      changed = (modifiers.get(GHOST_kModifierKeyRightAlt) != (bool)*keyDown);
 -                                                      modifier = GHOST_kModifierKeyRightAlt;
 -                                              }
 -                                              break;
 -                                      default: break;
 +              bool changed = false;
 +              GHOST_TModifierKeyMask modifier;
 +              switch(key) {
 +                      case GHOST_kKeyLeftShift:
 +                              {
 +                                      changed = (modifiers.get(GHOST_kModifierKeyLeftShift) != (bool)*keyDown);
 +                                      modifier = GHOST_kModifierKeyLeftShift;
                                }
 -                              
 -                              if(changed)
 +                              break;
 +                      case GHOST_kKeyRightShift:
                                {
 -                                      modifiers.set(modifier, (bool)*keyDown);
 -                                      system->storeModifierKeys(modifiers);
 +                                      changed = (modifiers.get(GHOST_kModifierKeyRightShift) != (bool)*keyDown);
 +                                      modifier = GHOST_kModifierKeyRightShift;
                                }
 -                              else
 +                              break;
 +                      case GHOST_kKeyLeftControl:
                                {
 -                                      key = GHOST_kKeyUnknown;
 +                                      changed = (modifiers.get(GHOST_kModifierKeyLeftControl) != (bool)*keyDown);
 +                                      modifier = GHOST_kModifierKeyLeftControl;
                                }
 -                      }
 -                      
 +                              break;
 +                      case GHOST_kKeyRightControl:
 +                              {
 +                                      changed = (modifiers.get(GHOST_kModifierKeyRightControl) != (bool)*keyDown);
 +                                      modifier = GHOST_kModifierKeyRightControl;
 +                              }
 +                              break;
 +                      case GHOST_kKeyLeftAlt:
 +                              {
 +                                      changed = (modifiers.get(GHOST_kModifierKeyLeftAlt) != (bool)*keyDown);
 +                                      modifier = GHOST_kModifierKeyLeftAlt;
 +                              }
 +                              break;
 +                      case GHOST_kKeyRightAlt:
 +                              {
 +                                      changed = (modifiers.get(GHOST_kModifierKeyRightAlt) != (bool)*keyDown);
 +                                      modifier = GHOST_kModifierKeyRightAlt;
 +                              }
 +                              break;
 +                      default: break;
 +              }
 +              
 +              if(changed)
 +              {
 +                      modifiers.set(modifier, (bool)*keyDown);
 +                      system->storeModifierKeys(modifiers);
 +              }
 +              else
 +              {
 +                      key = GHOST_kKeyUnknown;
 +              }
 +      }
        
 -                      if(vk) *vk = ri.data.keyboard.VKey;
 -              };
  
 -      };
 -      free(data);
 +      if(vk) *vk = raw.data.keyboard.VKey;
  
        return key;
  }
@@@ -690,12 -742,12 +691,12 @@@ GHOST_EventWheel* GHOST_SystemWin32::pr
  }
  
  
 -GHOST_EventKey* GHOST_SystemWin32::processKeyEvent(GHOST_IWindow *window, WPARAM wParam, LPARAM lParam)
 +GHOST_EventKey* GHOST_SystemWin32::processKeyEvent(GHOST_IWindow *window, RAWINPUT const& raw)
  {
        int keyDown=0;
        char vk;
        GHOST_SystemWin32 * system = (GHOST_SystemWin32 *)getSystem();
 -      GHOST_TKey key = system->hardKey(window, wParam, lParam, &keyDown, &vk);
 +      GHOST_TKey key = system->hardKey(window, raw, &keyDown, &vk);
        GHOST_EventKey* event;
        if (key != GHOST_kKeyUnknown) {
                char ascii = '\0';
  
  GHOST_Event* GHOST_SystemWin32::processWindowEvent(GHOST_TEventType type, GHOST_IWindow* window)
  {
 -      return new GHOST_Event(getSystem()->getMilliSeconds(), type, window);
 +      GHOST_System* system = (GHOST_System*)getSystem();
 +
 +      if (type == GHOST_kEventWindowActivate)
 +              {
 +              puts("activating window");
 +              system->getWindowManager()->setActiveWindow(window);
 +              }
 +
 +      return new GHOST_Event(system->getMilliSeconds(), type, window);
  }
  
  GHOST_TSuccess GHOST_SystemWin32::pushDragDropEvent(GHOST_TEventType eventType, 
@@@ -756,101 -800,9 +757,101 @@@ void GHOST_SystemWin32::processMinMaxIn
        minmax->ptMinTrackSize.y=240;
  }
  
 +bool GHOST_SystemWin32::processNDOF(RAWINPUT const& raw)
 +{
 +      bool eventSent = false;
 +      GHOST_TUns64 now = getMilliSeconds();
 +
 +      static bool firstEvent = true;
 +      if (firstEvent)
 +              { // determine exactly which device is plugged in
 +              RID_DEVICE_INFO info;
 +              unsigned infoSize = sizeof(RID_DEVICE_INFO);
 +              info.cbSize = infoSize;
 +
 +              GetRawInputDeviceInfo(raw.header.hDevice, RIDI_DEVICEINFO, &info, &infoSize);
 +              if (info.dwType == RIM_TYPEHID)
 +                      m_ndofManager->setDevice(info.hid.dwVendorId, info.hid.dwProductId);
 +              else
 +            puts("<!> not a HID device... mouse/kb perhaps?");
 +
 +              firstEvent = false;
 +              }
 +
 +      // The NDOF manager sends button changes immediately, and *pretends* to
 +      // send motion. Mark as 'sent' so motion will always get dispatched.
 +      eventSent = true;
 +
 +#ifdef _MSC_VER
 +    // using Microsoft compiler & header files
 +    // they invented the RawInput API, so this version is (probably) correct
 +      BYTE const* data = raw.data.hid.bRawData;
 +      // struct RAWHID {
 +      // DWORD dwSizeHid;
 +      // DWORD dwCount;
 +      // BYTE  bRawData[1];
 +      // };
 +#else
 +      // MinGW's definition (below) doesn't agree, so we need a slight
 +      // workaround until it's fixed
 +      BYTE const* data = &raw.data.hid.bRawData;
 +      // struct RAWHID {
 +      // DWORD dwSizeHid;
 +      // DWORD dwCount;
 +      // BYTE bRawData; // <== isn't this s'posed to be a BYTE*?
 +      // };
 +#endif
 +
 +      BYTE packetType = data[0];
 +      switch (packetType)
 +              {
 +              case 1: // translation
 +                      {
 +                      short* axis = (short*)(data + 1);
 +                      short t[3] = {axis[0], -axis[2], axis[1]};
 +                      m_ndofManager->updateTranslation(t, now);
 +
 +                      if (raw.data.hid.dwSizeHid == 13)
 +                              { // this report also includes rotation
 +                              short r[3] = {-axis[3], axis[5], -axis[4]};
 +                              m_ndofManager->updateRotation(r, now);
 +
 +                              // I've never gotten one of these, has anyone else?
 +                              puts("ndof: combined T + R");
 +                              }
 +                      break;
 +                      }
 +              case 2: // rotation
 +                      {
 +                      short* axis = (short*)(data + 1);
 +                      short r[3] = {-axis[0], axis[2], -axis[1]};
 +                      m_ndofManager->updateRotation(r, now);
 +                      break;
 +                      }
 +              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);
 +                      break;
 +                      }
 +              }
 +      return eventSent;
 +}
 +
  LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  {
        GHOST_Event* event = 0;
 +      bool eventHandled = false;
 +
        LRESULT lResult = 0;
        GHOST_SystemWin32* system = ((GHOST_SystemWin32*)getSystem());
        GHOST_ASSERT(system, "GHOST_SystemWin32::s_wndProc(): system not initialized")
                                // Keyboard events, processed
                                ////////////////////////////////////////////////////////////////////////
                                case WM_INPUT:
 +                              {
                                        // check WM_INPUT from input sink when ghost window is not in the foreground
                                        if (wParam == RIM_INPUTSINK) {
                                                if (GetFocus() != hwnd) // WM_INPUT message not for this window
                                                        return 0;
 -                                      } //else wPAram == RIM_INPUT
 -                                      event = processKeyEvent(window, wParam, lParam);
 -                                      if (!event) {
 -                                              GHOST_PRINT("GHOST_SystemWin32::wndProc: key event ")
 -                                              GHOST_PRINT(msg)
 -                                              GHOST_PRINT(" key ignored\n")
 +                                      } //else wParam == RIM_INPUT
 +
 +                                      RAWINPUT raw;
 +                                      RAWINPUT* raw_ptr = &raw;
 +                                      UINT rawSize = sizeof(RAWINPUT);
 +
 +                                      GetRawInputData((HRAWINPUT)lParam, RID_INPUT, raw_ptr, &rawSize, sizeof(RAWINPUTHEADER));
 +
 +                                      switch (raw.header.dwType)
 +                                      {
 +                                      case RIM_TYPEKEYBOARD:
 +                                              event = processKeyEvent(window, raw);
 +                                              if (!event) {
 +                                                      GHOST_PRINT("GHOST_SystemWin32::wndProc: key event ")
 +                                                      GHOST_PRINT(msg)
 +                                                      GHOST_PRINT(" key ignored\n")
 +                                              }
 +                                              break;
 +                                      case RIM_TYPEHID:
 +                                              if (system->processNDOF(raw))
 +                                                      eventHandled = true;
 +                                              break;
                                        }
 -                                      break;
 +                              break;
 +                              }
                                ////////////////////////////////////////////////////////////////////////
                                // Keyboard events, ignored
                                ////////////////////////////////////////////////////////////////////////
                                case WM_SYSKEYUP:
                                        /* These functions were replaced by WM_INPUT*/
                                case WM_CHAR:
 -                                      /* The WM_CHAR message is posted to the window with the keyboard focus when 
 -                                       * a WM_KEYDOWN message is translated by the TranslateMessage function. WM_CHAR 
 -                                       * contains the character code of the key that was pressed. 
 +                                      /* The WM_CHAR message is posted to the window with the keyboard focus when
 +                                       * a WM_KEYDOWN message is translated by the TranslateMessage function. WM_CHAR
 +                                       * contains the character code of the key that was pressed.
                                         */
                                case WM_DEADCHAR:
                                        /* The WM_DEADCHAR message is posted to the window with the keyboard focus when a
                                         * procedure of the top-level window being activated. If the windows use different input queues,
                                         * the message is sent asynchronously, so the window is activated immediately. 
                                         */
+                                       {
+                                       GHOST_ModifierKeys modifiers;
+                                       modifiers.clear();
+                                       system->storeModifierKeys(modifiers);
                                        event = processWindowEvent(LOWORD(wParam) ? GHOST_kEventWindowActivate : GHOST_kEventWindowDeactivate, window);
                                        /* WARNING: Let DefWindowProc handle WM_ACTIVATE, otherwise WM_MOUSEWHEEL
                                        will not be dispatched to OUR active window if we minimize one of OUR windows. */
                                        lResult = ::DefWindowProc(hwnd, msg, wParam, lParam);
                                        break;
+                                       }
                                case WM_PAINT:
                                        /* An application sends the WM_PAINT message when the system or another application 
                                         * makes a request to paint a portion of an application's window. The message is sent
                                         * In GHOST, we let DefWindowProc call the timer callback.
                                         */
                                        break;
 -                              case WM_BLND_NDOF_AXIS:
 -                                      {
 -                                              GHOST_TEventNDOFData ndofdata;
 -                                              system->m_ndofManager->GHOST_NDOFGetDatas(ndofdata);
 -                                              system->m_eventManager->
 -                                                      pushEvent(new GHOST_EventNDOF(
 -                                                              system->getMilliSeconds(), 
 -                                                              GHOST_kEventNDOFMotion, 
 -                                                              window, ndofdata));
 -                                      }
 -                                      break;
 -                              case WM_BLND_NDOF_BTN:
 -                                      {
 -                                              GHOST_TEventNDOFData ndofdata;
 -                                              system->m_ndofManager->GHOST_NDOFGetDatas(ndofdata);
 -                                              system->m_eventManager->
 -                                                      pushEvent(new GHOST_EventNDOF(
 -                                                              system->getMilliSeconds(), 
 -                                                              GHOST_kEventNDOFButton, 
 -                                                              window, ndofdata));
 -                                      }
 -                                      break;
                        }
                }
                else {
  
        if (event) {
                system->pushEvent(event);
 +              eventHandled = true;
        }
 -      else {
 +
 +      if (!eventHandled)
                lResult = ::DefWindowProc(hwnd, msg, wParam, lParam);
 -      }
 +
        return lResult;
  }
  
@@@ -1284,8 -1243,32 +1290,32 @@@ int GHOST_SystemWin32::toggleConsole(in
        {
                case 3: //hide if no console
                        {
-                       CONSOLE_SCREEN_BUFFER_INFO csbi = {{0}};
-                       if(!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi) || csbi.dwCursorPosition.X || csbi.dwCursorPosition.Y>1)
+                               DWORD sp = GetCurrentProcessId();
+                               HANDLE ptree = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
+                               PROCESSENTRY32 e = {0}; e.dwSize = sizeof(PROCESSENTRY32);
+                               
+                               if( Process32First(ptree, &e)) {
+                                       do { //Searches for Blender's PROCESSENTRY32
+                                                       if (e.th32ProcessID == sp) {
+                                                               sp = e.th32ParentProcessID;
+                                                               Process32First(ptree, &e);
+                                                                       do { //Got parent id, searches for its PROCESSENTRY32
+                                                                               if (e.th32ProcessID == sp) {
+                                                                                       if(strcmp("explorer.exe",e.szExeFile)==0)
+                                                                                       { //If explorer, hide cmd
+                                                                                               ShowWindow(GetConsoleWindow(),SW_HIDE);
+                                                                                               m_consoleStatus = 0;
+                                                                                       }
+                                                                                       break;
+                                                                               }
+                                                                       } while( Process32Next(ptree, &e));
+                                                               break;
+                                                       }
+                                       } while( Process32Next(ptree, &e));
+                               }
+                               CloseHandle(ptree);
                                break;
                        }
                case 0: //hide
index cdc839e084a13fdfc989846757d5455e6439506a,2b4003c7af055463b2f8285cddc0ac5992a8231c..16f3789ecb1757cd9c6c5ecdd91f2ef3347942fc
@@@ -1,6 -1,3 +1,3 @@@
- /** \file blender/editors/interface/resources.c
-  *  \ingroup edinterface
-  */
  /*
   * $Id$
   *
   * ***** END GPL/BL DUAL LICENSE BLOCK *****
   */
  
+ /** \file blender/editors/interface/resources.c
+  *  \ingroup edinterface
+  */
  #include <math.h>
  #include <stdlib.h>
  #include <string.h>
@@@ -1584,12 -1585,6 +1585,12 @@@ void init_userdef_do_versions(void
        if (U.anisotropic_filter <= 0)
                U.anisotropic_filter = 1;
  
 +      if (U.ndof_sensitivity == 0.0f) {
 +              U.ndof_sensitivity = 1.0f;
 +              U.ndof_flag = NDOF_SHOW_GUIDE | NDOF_LOCK_HORIZON |
 +                      NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM | NDOF_SHOULD_ROTATE;
 +      }
 +
        /* funny name, but it is GE stuff, moves userdef stuff to engine */
  // XXX        space_set_commmandline_options();
        /* this timer uses U */
index 7f8d5976e866c1ad56a61d5285d79bb294f0aae0,59e9e681e2b83bca3949a83d17cc7d8d7f8ec0ff..92ac8471172f0d61f665e28daf2ccf0e1b7ede5e
@@@ -1006,11 -1006,9 +1006,11 @@@ int transformEvent(TransInfo *t, wmEven
                        else view_editmove(event->type);
                        t->redraw= 1;
                        break;
 -//            case NDOFMOTION:
 -//            viewmoveNDOF(1);
 -  //         break;
 +#if 0
 +              case NDOF_MOTION:
 +                      // should have been caught by tranform_modal
 +                      return OPERATOR_PASS_THROUGH;
 +#endif
                default:
                        handled = 0;
                        break;
                // Numerical input events
                t->redraw |= handleNumInput(&(t->num), event);
  
 -              // NDof input events
 -              switch(handleNDofInput(&(t->ndof), event))
 -              {
 -                      case NDOF_CONFIRM:
 -                              if ((t->options & CTX_NDOF) == 0)
 -                              {
 -                                      /* Confirm on normal transform only */
 -                                      t->state = TRANS_CONFIRM;
 -                              }
 -                              break;
 -                      case NDOF_CANCEL:
 -                              if (t->options & CTX_NDOF)
 -                              {
 -                                      /* Cancel on pure NDOF transform */
 -                                      t->state = TRANS_CANCEL;
 -                              }
 -                              else
 -                              {
 -                                      /* Otherwise, just redraw, NDof input was cancelled */
 -                                      t->redraw |= TREDRAW_HARD;
 -                              }
 -                              break;
 -                      case NDOF_NOMOVE:
 -                              if (t->options & CTX_NDOF)
 -                              {
 -                                      /* Confirm on pure NDOF transform */
 -                                      t->state = TRANS_CONFIRM;
 -                              }
 -                              break;
 -                      case NDOF_REFRESH:
 -                              t->redraw |= TREDRAW_HARD;
 -                              break;
 -                      default:
 -                              handled = 0;
 -                              break;
 -              }
 -
                // Snapping events
                t->redraw |= handleSnapping(t, event);
  
@@@ -2851,6 -2886,10 +2851,6 @@@ void initRotation(TransInfo *t
        setInputPostFct(&t->mouse, postInputRotation);
        initMouseInputMode(t, &t->mouse, INPUT_ANGLE);
        
 -      t->ndof.axis = 16;
 -      /* Scale down and flip input for rotation */
 -      t->ndof.factor[0] = -0.2f;
 -      
        t->idx_max = 0;
        t->num.idx_max = 0;
        t->snap[0] = 0.0f;
@@@ -3122,6 -3161,8 +3122,6 @@@ int Rotation(TransInfo *t, const int UN
  
        final = t->values[0];
        
 -      applyNDofInput(&t->ndof, &final);
 -      
        snapGrid(t, &final);
        
        if ((t->con.mode & CON_APPLY) && t->con.applyRot) {
@@@ -3175,6 -3216,11 +3175,6 @@@ void initTrackball(TransInfo *t
  
        initMouseInputMode(t, &t->mouse, INPUT_TRACKBALL);
  
 -      t->ndof.axis = 40;
 -      /* Scale down input for rotation */
 -      t->ndof.factor[0] = 0.2f;
 -      t->ndof.factor[1] = 0.2f;
 -
        t->idx_max = 1;
        t->num.idx_max = 1;
        t->snap[0] = 0.0f;
@@@ -3230,6 -3276,8 +3230,6 @@@ int Trackball(TransInfo *t, const int U
        phi[0] = t->values[0];
        phi[1] = t->values[1];
  
 -      applyNDofInput(&t->ndof, phi);
 -
        snapGrid(t, phi);
  
        if (hasNumInput(&t->num)) {
@@@ -3283,6 -3331,8 +3283,6 @@@ void initTranslation(TransInfo *t
        t->num.flag = 0;
        t->num.idx_max = t->idx_max;
  
 -      t->ndof.axis = (t->flag & T_2D_EDIT)? 1|2: 1|2|4;
 -
        if(t->spacetype == SPACE_VIEW3D) {
                RegionView3D *rv3d = t->ar->regiondata;
  
@@@ -3457,6 -3507,7 +3457,6 @@@ int Translation(TransInfo *t, const in
                headerTranslation(t, pvec, str);
        }
        else {
 -              applyNDofInput(&t->ndof, t->values);
                snapGrid(t, t->values);
                applyNumInput(&t->num, t->values);
                if (hasNumInput(&t->num)) {
@@@ -3565,6 -3616,10 +3565,6 @@@ void initTilt(TransInfo *t
  
        initMouseInputMode(t, &t->mouse, INPUT_ANGLE);
  
 -      t->ndof.axis = 16;
 -      /* Scale down and flip input for rotation */
 -      t->ndof.factor[0] = -0.2f;
 -
        t->idx_max = 0;
        t->num.idx_max = 0;
        t->snap[0] = 0.0f;
@@@ -3588,6 -3643,8 +3588,6 @@@ int Tilt(TransInfo *t, const int UNUSED
  
        final = t->values[0];
  
 -      applyNDofInput(&t->ndof, &final);
 -
        snapGrid(t, &final);
  
        if (hasNumInput(&t->num)) {
@@@ -3702,6 -3759,10 +3702,6 @@@ void initPushPull(TransInfo *t
  
        initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
  
 -      t->ndof.axis = 4;
 -      /* Flip direction */
 -      t->ndof.factor[0] = -1.0f;
 -
        t->idx_max = 0;
        t->num.idx_max = 0;
        t->snap[0] = 0.0f;
@@@ -3722,6 -3783,8 +3722,6 @@@ int PushPull(TransInfo *t, const int UN
  
        distance = t->values[0];
  
 -      applyNDofInput(&t->ndof, &distance);
 -
        snapGrid(t, &distance);
  
        applyNumInput(&t->num, &distance);
@@@ -4596,7 -4659,7 +4596,7 @@@ static int createSlideVerts(TransInfo *
  #define EDGE_SLIDE_MIN 30
        if (len_squared_v2v2(start, end) < (EDGE_SLIDE_MIN * EDGE_SLIDE_MIN)) {
                if(ABS(start[0]-end[0]) + ABS(start[1]-end[1]) < 4.0f) {
-                       /* even more exceptional case, points are ontop of eachother */
+                       /* even more exceptional case, points are ontop of each other */
                        end[0]= start[0];
                        end[1]= start[1] + EDGE_SLIDE_MIN;
                }
@@@ -5246,6 -5309,8 +5246,6 @@@ void initSeqSlide(TransInfo *t
        t->num.flag = 0;
        t->num.idx_max = t->idx_max;
  
 -      t->ndof.axis = 1|2;
 -
        t->snap[0] = 0.0f;
        t->snap[1] = floor(t->scene->r.frs_sec / t->scene->r.frs_sec_base);
        t->snap[2] = 10.0f;
@@@ -5300,6 -5365,7 +5300,6 @@@ int SeqSlide(TransInfo *t, const int UN
                VECCOPY(t->values, tvec);
        }
        else {
 -              applyNDofInput(&t->ndof, t->values);
                snapGrid(t, t->values);
                applyNumInput(&t->num, t->values);
        }
@@@ -5859,3 -5925,54 +5859,3 @@@ void BIF_TransformSetUndo(char *UNUSED(
        // TRANSFORM_FIX_ME
        //Trans.undostr= str;
  }
 -
 -
 -#if 0 // TRANSFORM_FIX_ME
 -static void NDofTransform(void)
 -{
 -      float fval[7];
 -      float maxval = 50.0f; // also serves as threshold
 -      int axis = -1;
 -      int mode = 0;
 -      int i;
 -
 -      getndof(fval);
 -
 -      for(i = 0; i < 6; i++)
 -      {
 -              float val = fabs(fval[i]);
 -              if (val > maxval)
 -              {
 -                      axis = i;
 -                      maxval = val;
 -              }
 -      }
 -
 -      switch(axis)
 -      {
 -              case -1:
 -                      /* No proper axis found */
 -                      break;
 -              case 0:
 -              case 1:
 -              case 2:
 -                      mode = TFM_TRANSLATION;
 -                      break;
 -              case 4:
 -                      mode = TFM_ROTATION;
 -                      break;
 -              case 3:
 -              case 5:
 -                      mode = TFM_TRACKBALL;
 -                      break;
 -              default:
 -                      printf("ndof: what we are doing here ?");
 -      }
 -
 -      if (mode != 0)
 -      {
 -              initTransform(mode, CTX_NDOF);
 -              Transform();
 -      }
 -}
 -#endif