Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Author Topic: OIS Mac patch: Optional mouse grab  (Read 940 times)

ivucica

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 5
    • View Profile
OIS Mac patch: Optional mouse grab
« on: October 22, 2009, 04:08:48 AM »

I am including patch for optional mousegrab. It includes a modification to console demo, and a fix for when window is being sent as a parameter.

Please note that the fix is not complete. Absolute pointer positions are notably incorrect. I plan on implementing separate input system for getting mouse position using Carbon, and the goal here was basically to make OIS not do the grab. Before anyone objects to my anti-pattern solution: While there may have been some other way to do this, I am working on porting some legacy code which does similar trick under win32, so I'm just replicating the behavior on Mac.

Code: [Select]
Index: demos/OISConsole.cpp
===================================================================
RCS file: /cvsroot/wgois/ois/demos/OISConsole.cpp,v
retrieving revision 1.57
diff -U3 -r1.57 OISConsole.cpp
--- demos/OISConsole.cpp 22 Nov 2007 06:27:21 -0000 1.57
+++ demos/OISConsole.cpp 22 Oct 2009 11:58:54 -0000
@@ -320,6 +320,9 @@
  wnd << (unsigned int)mWin; //cast to int so it gets encoded correctly (else it gets stored as a hex string)
     std::cout << "WindowRef: " << mWin << " WindowRef as int: " << wnd.str() << "\n";
  pl.insert(std::make_pair(std::string("WINDOW"), wnd.str()));
+
+ //pl.insert(std::make_pair(std::string("MacGrabMouse"), std::string("false")));
+
 #endif
 
  //This never returns null.. it will raise an exception on errors
Index: includes/mac/MacInputManager.h
===================================================================
RCS file: /cvsroot/wgois/ois/includes/mac/MacInputManager.h,v
retrieving revision 1.7
diff -U3 -r1.7 MacInputManager.h
--- includes/mac/MacInputManager.h 17 Nov 2007 21:18:51 -0000 1.7
+++ includes/mac/MacInputManager.h 22 Oct 2009 11:58:54 -0000
@@ -87,6 +87,7 @@
         // settings
         bool mHideMouse;
         bool mUseRepeat;
+ bool mGrabMouse;
 
  //! Used to know if we used up keyboard
  bool keyboardUsed;
Index: includes/mac/MacMouse.h
===================================================================
RCS file: /cvsroot/wgois/ois/includes/mac/MacMouse.h,v
retrieving revision 1.9
diff -U3 -r1.9 MacMouse.h
--- includes/mac/MacMouse.h 3 Jan 2008 15:28:34 -0000 1.9
+++ includes/mac/MacMouse.h 22 Oct 2009 11:58:54 -0000
@@ -12,7 +12,7 @@
  class MacMouse : public Mouse
     {
  public:
- MacMouse( InputManager* creator, bool buffered );
+ MacMouse( InputManager* creator, bool buffered, bool grab=true );
  virtual ~MacMouse();
 
  /** @copydoc Object::setBuffered */
@@ -42,6 +42,7 @@
 
  bool mNeedsToRegainFocus;
  bool mMouseWarped;
+ bool mGrabMouse;
 
  MouseState mTempState;
  };
Index: src/mac/MacInputManager.cpp
===================================================================
RCS file: /cvsroot/wgois/ois/src/mac/MacInputManager.cpp,v
retrieving revision 1.11
diff -U3 -r1.11 MacInputManager.cpp
--- src/mac/MacInputManager.cpp 18 Nov 2007 04:28:03 -0000 1.11
+++ src/mac/MacInputManager.cpp 22 Oct 2009 11:58:55 -0000
@@ -38,6 +38,7 @@
 {
     mHideMouse = true;
     mUseRepeat = false;
+ mGrabMouse = true;
     mEventTargetRef = NULL;
  mWindow = NULL;
 
@@ -83,8 +84,8 @@
  }
  else
  {
- //mEventTargetRef = GetWindowEventTarget(mWindow);
- mEventTargetRef = GetApplicationEventTarget();
+ mEventTargetRef = GetWindowEventTarget(mWindow);
+ //mEventTargetRef = GetApplicationEventTarget();
  }
     }
  else
@@ -98,8 +99,8 @@
  }
  else
  {
- //mEventTargetRef = GetWindowEventTarget(mWindow);
- mEventTargetRef = GetApplicationEventTarget();
+ mEventTargetRef = GetWindowEventTarget(mWindow);
+ //mEventTargetRef = GetApplicationEventTarget();
  }
  }
 
@@ -114,6 +115,16 @@
             mUseRepeat = true;
         }
     }
+
+ // Mouse
+    if(paramList.find("MacGrabMouse") != paramList.end())
+ {
+        if(paramList.find("MacGrabMouse")->second == "false")
+ {
+            mGrabMouse = false;
+        }
+    }
+
 }
 
 //--------------------------------------------------------------------------------//
@@ -183,7 +194,7 @@
  case OISMouse:
  {
  if( mouseUsed == false )
- obj = new MacMouse(this, bufferMode);
+ obj = new MacMouse(this, bufferMode, mGrabMouse);
  break;
  }
  default:
Index: src/mac/MacMouse.cpp
===================================================================
RCS file: /cvsroot/wgois/ois/src/mac/MacMouse.cpp,v
retrieving revision 1.14
diff -U3 -r1.14 MacMouse.cpp
--- src/mac/MacMouse.cpp 3 Jan 2008 15:31:53 -0000 1.14
+++ src/mac/MacMouse.cpp 22 Oct 2009 11:58:57 -0000
@@ -24,11 +24,12 @@
 const EventTypeSpec WinFocusAcquired [] = {{kEventClassApplication, kEventAppDeactivated}};
 
 //-------------------------------------------------------------------//
-MacMouse::MacMouse( InputManager* creator, bool buffered )
+MacMouse::MacMouse( InputManager* creator, bool buffered, bool grab)
  : Mouse(creator->inputSystemName(), buffered, 0, creator), mNeedsToRegainFocus( false )
 {
     mouseEventRef = NULL;
  mWindowFocusHandler = NULL;
+ mGrabMouse = grab;
 
     // Get a "Univeral procedure pointer" for our callback
     mouseUPP = NewEventHandlerUPP(MouseWrapper);
@@ -99,19 +100,23 @@
 
  //Lock OS Mouse movement
  mNeedsToRegainFocus = false;
- CGAssociateMouseAndMouseCursorPosition(FALSE);
+ if(mGrabMouse)
+ CGAssociateMouseAndMouseCursorPosition(FALSE);
 }
 
 OSStatus MacMouse::WindowFocusChanged(EventHandlerCallRef nextHandler, EventRef event, void* macMouse)
 {
  std::cout << "Window Focus Changed\n";
-
+
  MacMouse* _this = static_cast<MacMouse*>(macMouse);
     if (_this)
  {
- _this->mNeedsToRegainFocus = true;
- CGAssociateMouseAndMouseCursorPosition(TRUE);
-
+ if(_this->mGrabMouse)
+ {
+ _this->mNeedsToRegainFocus = true;
+ CGAssociateMouseAndMouseCursorPosition(TRUE);
+ }
+
         // propagate the event down the chain
         return CallNextEventHandler(nextHandler, event);        
     }
@@ -287,8 +292,11 @@
 
  if(mNeedsToRegainFocus)
  {
- mNeedsToRegainFocus = false;
- CGAssociateMouseAndMouseCursorPosition(false);
+ if(mGrabMouse)
+ {
+ mNeedsToRegainFocus = false;
+ CGAssociateMouseAndMouseCursorPosition(false);
+ }
 
  MacInputManager* im = static_cast<MacInputManager*>(mCreator);
  WindowRef win = im->_getWindow();

I do not follow these forums; contact: [my username]@gmail.com
Just in case there's legal doubt: I hereby release all rights I may have to these modifications.
« Last Edit: October 22, 2009, 04:10:54 AM by ivucica »
Logged

ivucica

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 5
    • View Profile
Re: OIS Mac patch: Optional mouse grab
« Reply #1 on: December 17, 2009, 08:40:00 AM »

Anything happening here?
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2653
    • View Profile
    • http://www.wreckedgames.com
Re: OIS Mac patch: Optional mouse grab
« Reply #2 on: December 19, 2009, 09:02:07 AM »

Would be better to posts patches to sourceforge page. As far as not capturing the mouse, why not just skip creating a mouse?
Logged