Implemented OSX/InputImpl::GetMousePosition()

This commit is contained in:
Marco Antognini 2011-07-06 03:36:48 +02:00
parent a609a7114e
commit a55ae4b758
3 changed files with 10 additions and 5 deletions

View File

@ -67,7 +67,7 @@ else() # MACOSX
${SRCROOT}/OSX/cpp_objc_conversion.mm ${SRCROOT}/OSX/cpp_objc_conversion.mm
${SRCROOT}/OSX/cg_sf_conversion.hpp ${SRCROOT}/OSX/cg_sf_conversion.hpp
${SRCROOT}/OSX/cg_sf_conversion.cpp ${SRCROOT}/OSX/cg_sf_conversion.cpp
${SRCROOT}/OSX/InputImpl.cpp ${SRCROOT}/OSX/InputImpl.mm
${SRCROOT}/OSX/InputImpl.hpp ${SRCROOT}/OSX/InputImpl.hpp
${SRCROOT}/OSX/JoystickImpl.cpp ${SRCROOT}/OSX/JoystickImpl.cpp
${SRCROOT}/OSX/JoystickImpl.hpp ${SRCROOT}/OSX/JoystickImpl.hpp

View File

@ -26,7 +26,8 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Window/OSX/InputImpl.hpp> #include <SFML/Window/OSX/InputImpl.hpp>
#include <SFML/Window/VideoMode.hpp>
#import <Cocoa/Cocoa.h>
namespace sf namespace sf
{ {
@ -51,8 +52,11 @@ bool InputImpl::IsMouseButtonPressed(Mouse::Button button)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vector2i InputImpl::GetMousePosition() Vector2i InputImpl::GetMousePosition()
{ {
// @to be implemented // Reverse Y axis to match SFML coord.
return Vector2i(); NSPoint pos = [NSEvent mouseLocation];
pos.y = sf::VideoMode::GetDesktopMode().Height - pos.y;
return Vector2i(pos.x, pos.y);
} }
} // namespace priv } // namespace priv

View File

@ -192,7 +192,8 @@ sf::Keyboard::Key NonLocalizedKeys(unsigned short keycode);
// Place the cursor. // Place the cursor.
CGEventRef event = CGEventCreateMouseEvent(NULL, CGEventRef event = CGEventCreateMouseEvent(NULL,
kCGEventMouseMoved, kCGEventMouseMoved,
CGPointMake(screenCoord.x, screenCoord.y), CGPointMake(screenCoord.x,
screenCoord.y),
/*we don't care about this : */0); /*we don't care about this : */0);
CGEventPost(kCGHIDEventTap, event); CGEventPost(kCGHIDEventTap, event);
CFRelease(event); CFRelease(event);