Implemented WindowImplCocoa::GetCursorPosition()

This commit is contained in:
Marco Antognini 2011-07-06 03:05:58 +02:00
parent 99341c31db
commit a609a7114e
6 changed files with 36 additions and 10 deletions

View File

@ -100,4 +100,10 @@ namespace sf {
-(void)enableKeyRepeat;
-(void)disableKeyRepeat;
////////////////////////////////////////////////////////////
/// Compute the position of the cursor.
///
////////////////////////////////////////////////////////////
-(NSPoint)cursorPositionFromEvent:(NSEvent *)eventOrNil;
@end

View File

@ -103,12 +103,6 @@ sf::Keyboard::Key NonLocalizedKeys(unsigned short keycode);
////////////////////////////////////////////////////////////
-(void)initModifiersState;
////////////////////////////////////////////////////////////
/// Compute the position of the cursor.
///
////////////////////////////////////////////////////////////
-(NSPoint)cursorPositionFromEvent:(NSEvent *)event;
////////////////////////////////////////////////////////////
/// Converte the NSEvent mouse button type to SFML type.
///
@ -904,9 +898,16 @@ sf::Keyboard::Key NonLocalizedKeys(unsigned short keycode);
////////////////////////////////////////////////////////
-(NSPoint)cursorPositionFromEvent:(NSEvent *)event
-(NSPoint)cursorPositionFromEvent:(NSEvent *)eventOrNil
{
NSPoint loc = [self convertPoint:[event locationInWindow] fromView:nil];
NSPoint loc;
// If no event given then get current mouse pos.
if (eventOrNil == nil) {
NSPoint rawPos = [[self window] mouseLocationOutsideOfEventStream];
loc = [self convertPoint:rawPos fromView:nil];
} else {
loc = [self convertPoint:[eventOrNil locationInWindow] fromView:nil];
}
// Don't forget to change to SFML coord system.
float h = [self frame].size.height;

View File

@ -195,6 +195,13 @@
}
////////////////////////////////////////////////////////
-(NSPoint)cursorPosition
{
return [myOGLView cursorPositionFromEvent:nil];
}
////////////////////////////////////////////////////////.
-(void)setWindowPositionToX:(unsigned int)x Y:(unsigned int)y
{

View File

@ -287,6 +287,12 @@
[myOGLView setCursorPositionToX:x Y:y];
}
////////////////////////////////////////////////////////
-(NSPoint)cursorPosition
{
return [myOGLView cursorPositionFromEvent:nil];
}
////////////////////////////////////////////////////////.
-(void)setWindowPositionToX:(unsigned int)x Y:(unsigned int)y

View File

@ -348,8 +348,8 @@ void WindowImplCocoa::SetCursorPosition(unsigned int x, unsigned int y)
////////////////////////////////////////////////////////////
Vector2i WindowImplCocoa::GetCursorPosition() const
{
// @to be implemented
return Vector2i();
NSPoint pos = [myDelegate cursorPosition];
return Vector2i(pos.x, pos.y);
}

View File

@ -89,6 +89,12 @@ namespace sf {
////////////////////////////////////////////////////////////
-(void)setCursorPositionToX:(unsigned int)x Y:(unsigned int)y;
////////////////////////////////////////////////////////////
/// Get the mouse cursor position (SFML Coordinates).
///
////////////////////////////////////////////////////////////
-(NSPoint)cursorPosition;
////////////////////////////////////////////////////////////
/// Move the window (not the view if we handle not a window) (SFML Coordinates).
///