Просмотр исходного кода

Warp mouse Cocoa implementation

Ivan Safrin 13 лет назад
Родитель
Сommit
490211cbd1

+ 1 - 0
Core/Contents/Include/PolyCocoaCore.h

@@ -116,6 +116,7 @@ namespace Polycode {
 		vector<String> openFilePicker(vector<CoreFileExtension> extensions, bool allowMultiple);
 		
 		void setCursor(int cursorType);
+		void warpCursor(int x, int y);
 		
 		void openURL(String url);
 		

+ 7 - 0
Core/Contents/Include/PolyCore.h

@@ -95,6 +95,13 @@ namespace Polycode {
 		*/
 		virtual void setCursor(int cursorType) = 0;
 		
+		/**
+		* Warps the cursor to a specified point in the window.
+		* @param x New cursor x position 
+		* @param y New cursor y position 		
+		*/
+		virtual void warpCursor(int x, int y) {}
+		
 		/**
 		* Launches a Threaded class into its own thread. See the documentation for Threaded for information on how to crated threaded classes.
 		* @param target Target threaded class.

+ 13 - 0
Core/Contents/Source/PolyCocoaCore.mm

@@ -335,6 +335,19 @@ void CocoaCore::setCursor(int cursorType) {
 	[[glView window] invalidateCursorRectsForView: (NSView*)glView];
 }
 
+void CocoaCore::warpCursor(int x, int y) {
+
+	CGSetLocalEventsSuppressionInterval(0);
+	NSArray *theScreens = [NSScreen screens];
+	for (NSScreen *theScreen in theScreens) {
+		CGPoint CenterOfWindow = CGPointMake([glView window].frame.origin.x+x, (-1)*([glView window].frame.origin.y-theScreen.frame.size.height)-yRes+y);
+		CGDisplayMoveCursorToPoint (kCGDirectMainDisplay, CenterOfWindow);		
+		break;
+	}
+	lastMouseX = x;
+	lastMouseY = y;
+}
+
 void CocoaCore::checkEvents() {
 	lockMutex(eventMutex);
 	CocoaEvent event;