mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Improved -setWindowPositionToX:Y:
This commit is contained in:
parent
3e8961d05f
commit
d37065e4de
@ -154,34 +154,46 @@ NSUInteger keepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
|
||||
////////////////////////////////////////////////////////
|
||||
-(void)setCursorPositionToX:(unsigned int)x Y:(unsigned int)y
|
||||
{
|
||||
// Flip for SFML window coordinate system
|
||||
y = NSHeight([[self window] frame]) - y;
|
||||
if (m_requester == 0) return;
|
||||
|
||||
// Adjust for view reference instead of window
|
||||
y -= NSHeight([[self window] frame]) - NSHeight([self frame]);
|
||||
|
||||
// Convert to screen coordinates
|
||||
NSPoint screenCoord = [[self window] convertBaseToScreen:NSMakePoint(x, y)];
|
||||
|
||||
// Flip screen coodinates
|
||||
float const screenHeight = NSHeight([[[self window] screen] frame]);
|
||||
screenCoord.y = screenHeight - screenCoord.y;
|
||||
// Create a SFML event.
|
||||
m_requester->mouseMovedAt(x, y);
|
||||
|
||||
// Recompute the mouse pos if required.
|
||||
if (!NSEqualSizes(m_realSize, NSZeroSize)) {
|
||||
screenCoord.x = screenCoord.x / m_realSize.width * [self frame].size.width;
|
||||
screenCoord.y = screenCoord.y / m_realSize.height * [self frame].size.height;
|
||||
x = x / m_realSize.width * [self frame].size.width;
|
||||
y = y / m_realSize.height * [self frame].size.height;
|
||||
}
|
||||
|
||||
// Note : we use rect here because some conversion methods are deprecated
|
||||
// with point.
|
||||
|
||||
// Flip SFML coordinates to match window coordinates
|
||||
y = [self frame].size.height - y;
|
||||
|
||||
// Get the position of (x, y) in the coordinate system of the window.
|
||||
NSRect r = [self convertRect:NSMakeRect(x, y, 1, 1) toView:self];
|
||||
r = [self convertRect:r toView:nil]; // nil means window
|
||||
|
||||
// Converte it to screen coordinates
|
||||
r = [[self window] convertRectToScreen:r];
|
||||
|
||||
// Flip screen coodinates to match CGDisplayMoveCursorToPoint referential.
|
||||
float const screenHeight = [[[self window] screen] frame].size.height;
|
||||
r.origin.y = screenHeight - r.origin.y;
|
||||
|
||||
|
||||
// Get the id of the screen
|
||||
CGDirectDisplayID screenNumber = (CGDirectDisplayID)[[[[[self window] screen] deviceDescription] valueForKey:@"NSScreenNumber"] intValue];
|
||||
|
||||
// Place the cursor.
|
||||
CGEventRef event = CGEventCreateMouseEvent(NULL,
|
||||
kCGEventMouseMoved,
|
||||
CGPointMake(screenCoord.x,
|
||||
screenCoord.y),
|
||||
/*we don't care about this : */0);
|
||||
CGEventPost(kCGHIDEventTap, event);
|
||||
CFRelease(event);
|
||||
// This is a workaround to deprecated CGSetLocalEventsSuppressionInterval function
|
||||
CGDisplayMoveCursorToPoint(screenNumber, CGPointMake(r.origin.x, r.origin.y));
|
||||
/*
|
||||
* CGDisplayMoveCursorToPoint -- Discussion :
|
||||
*
|
||||
* No events are generated as a result of this move.
|
||||
* Points that lie outside the desktop are clipped to the desktop.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -124,36 +124,8 @@
|
||||
////////////////////////////////////////////////////////
|
||||
-(void)setCursorPositionToX:(unsigned int)x Y:(unsigned int)y
|
||||
{
|
||||
// TODO remove this ? use ogl view selector instead ?
|
||||
|
||||
if (m_requester == 0) return;
|
||||
|
||||
// Create a SFML event.
|
||||
m_requester->mouseMovedAt(x, y);
|
||||
|
||||
// Flip for SFML window coordinate system
|
||||
y = NSHeight([[m_view window] frame]) - y;
|
||||
|
||||
// Adjust for view reference instead of window
|
||||
y -= NSHeight([[m_view window] frame]) - NSHeight([m_oglView frame]);
|
||||
|
||||
// Convert to screen coordinates
|
||||
NSPoint screenCoord = [[m_view window] convertBaseToScreen:NSMakePoint(x, y)];
|
||||
|
||||
// Flip screen coodinates
|
||||
float const screenHeight = NSHeight([[[m_view window] screen] frame]);
|
||||
screenCoord.y = screenHeight - screenCoord.y;
|
||||
|
||||
CGDirectDisplayID screenNumber = (CGDirectDisplayID)[[[[[m_view window] screen] deviceDescription] valueForKey:@"NSScreenNumber"] intValue];
|
||||
|
||||
// Place the cursor.
|
||||
CGDisplayMoveCursorToPoint(screenNumber, CGPointMake(screenCoord.x, screenCoord.y));
|
||||
/*
|
||||
CGDisplayMoveCursorToPoint -- Discussion :
|
||||
|
||||
No events are generated as a result of this move.
|
||||
Points that lie outside the desktop are clipped to the desktop.
|
||||
*/
|
||||
// Forward to...
|
||||
[m_oglView setCursorPositionToX:x Y:y];
|
||||
}
|
||||
|
||||
|
||||
@ -175,7 +147,6 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
-(NSSize)size
|
||||
{
|
||||
// TODO scaleUnitSquareToSize: ?
|
||||
return [m_oglView frame].size;
|
||||
}
|
||||
|
||||
@ -183,8 +154,6 @@
|
||||
////////////////////////////////////////////////////////
|
||||
-(void)resizeTo:(unsigned int)width by:(unsigned int)height
|
||||
{
|
||||
// TODO scaleUnitSquareToSize: ?
|
||||
|
||||
NSRect frame = NSMakeRect([m_view frame].origin.x,
|
||||
[m_view frame].origin.y,
|
||||
width,
|
||||
|
@ -317,7 +317,6 @@
|
||||
////////////////////////////////////////////////////////
|
||||
-(NSSize)size
|
||||
{
|
||||
// TODO scaleUnitSquareToSize: ?
|
||||
return [m_oglView frame].size;
|
||||
}
|
||||
|
||||
@ -325,8 +324,6 @@
|
||||
////////////////////////////////////////////////////////
|
||||
-(void)resizeTo:(unsigned int)width by:(unsigned int)height
|
||||
{
|
||||
// TODO scaleUnitSquareToSize: ?
|
||||
|
||||
// Add titlebar height.
|
||||
NSRect frame = NSMakeRect([m_window frame].origin.x,
|
||||
[m_window frame].origin.y,
|
||||
|
Loading…
Reference in New Issue
Block a user