mirror of
https://github.com/SFML/SFML.git
synced 2025-02-08 01:18:02 +08:00
Improved cursor hiding on OS X
This commit is contained in:
parent
330ea0bbe3
commit
7159e4ba43
@ -133,4 +133,12 @@ namespace sf {
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
-(NSPoint)cursorPositionFromEvent:(NSEvent*)eventOrNil;
|
-(NSPoint)cursorPositionFromEvent:(NSEvent*)eventOrNil;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Determine where the mouse is
|
||||||
|
///
|
||||||
|
/// \return true when the mouse is inside the OpenGL view, false otherwise
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
-(BOOL)isMouseInside;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -67,14 +67,6 @@ BOOL isValidTextUnicode(NSEvent* event);
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
-(void)viewDidEndLiveResize;
|
-(void)viewDidEndLiveResize;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Determine where the mouse is
|
|
||||||
///
|
|
||||||
/// \return true when the mouse is inside the OpenGL view, false otherwise
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
-(BOOL)isMouseInside;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Update the mouse state (in or out)
|
/// \brief Update the mouse state (in or out)
|
||||||
///
|
///
|
||||||
|
@ -115,16 +115,9 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)hideMouseCursor
|
-(BOOL)isMouseInside
|
||||||
{
|
{
|
||||||
[NSCursor hide];
|
return [m_oglView isMouseInside];
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
|
||||||
-(void)showMouseCursor
|
|
||||||
{
|
|
||||||
[NSCursor unhide];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -332,16 +332,9 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)hideMouseCursor
|
-(BOOL)isMouseInside
|
||||||
{
|
{
|
||||||
[NSCursor hide];
|
return [m_oglView isMouseInside];
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
|
||||||
-(void)showMouseCursor
|
|
||||||
{
|
|
||||||
[NSCursor unhide];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -112,6 +112,41 @@ void scaleOutXY(T& out, id<WindowImplDelegateProtocol> delegate)
|
|||||||
scaleOut(out.y, delegate);
|
scaleOut(out.y, delegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// According to Apple's documentation, each invocation of
|
||||||
|
/// unhide must be balanced by an invocation of hide in
|
||||||
|
/// order for the cursor display to be correct.
|
||||||
|
/// So we keep track of those calls ourself.
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
bool isCursorHidden = false; // initially, the cursor is visible
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////
|
||||||
|
void hideMouseCursor()
|
||||||
|
{
|
||||||
|
if (!isCursorHidden)
|
||||||
|
{
|
||||||
|
[NSCursor hide];
|
||||||
|
isCursorHidden = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////
|
||||||
|
void showMouseCursor()
|
||||||
|
{
|
||||||
|
if (isCursorHidden)
|
||||||
|
{
|
||||||
|
[NSCursor unhide];
|
||||||
|
isCursorHidden = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark
|
#pragma mark
|
||||||
#pragma mark WindowImplCocoa's ctor/dtor
|
#pragma mark WindowImplCocoa's ctor/dtor
|
||||||
|
|
||||||
@ -268,8 +303,8 @@ void WindowImplCocoa::windowResized(unsigned int width, unsigned int height)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void WindowImplCocoa::windowLostFocus(void)
|
void WindowImplCocoa::windowLostFocus(void)
|
||||||
{
|
{
|
||||||
if (!m_showCursor)
|
if (!m_showCursor && [m_delegate isMouseInside])
|
||||||
[m_delegate showMouseCursor]; // Make sure the cursor is visible
|
showMouseCursor(); // Make sure the cursor is visible
|
||||||
|
|
||||||
Event event;
|
Event event;
|
||||||
event.type = Event::LostFocus;
|
event.type = Event::LostFocus;
|
||||||
@ -281,8 +316,8 @@ void WindowImplCocoa::windowLostFocus(void)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void WindowImplCocoa::windowGainedFocus(void)
|
void WindowImplCocoa::windowGainedFocus(void)
|
||||||
{
|
{
|
||||||
if (!m_showCursor)
|
if (!m_showCursor && [m_delegate isMouseInside])
|
||||||
[m_delegate hideMouseCursor]; // Restore user's setting
|
hideMouseCursor(); // Restore user's setting
|
||||||
|
|
||||||
Event event;
|
Event event;
|
||||||
event.type = Event::GainedFocus;
|
event.type = Event::GainedFocus;
|
||||||
@ -351,7 +386,7 @@ void WindowImplCocoa::mouseWheelScrolledAt(float delta, int x, int y)
|
|||||||
void WindowImplCocoa::mouseMovedIn(void)
|
void WindowImplCocoa::mouseMovedIn(void)
|
||||||
{
|
{
|
||||||
if (!m_showCursor)
|
if (!m_showCursor)
|
||||||
[m_delegate hideMouseCursor]; // Restore user's setting
|
hideMouseCursor(); // Restore user's setting
|
||||||
|
|
||||||
Event event;
|
Event event;
|
||||||
event.type = Event::MouseEntered;
|
event.type = Event::MouseEntered;
|
||||||
@ -363,7 +398,7 @@ void WindowImplCocoa::mouseMovedIn(void)
|
|||||||
void WindowImplCocoa::mouseMovedOut(void)
|
void WindowImplCocoa::mouseMovedOut(void)
|
||||||
{
|
{
|
||||||
if (!m_showCursor)
|
if (!m_showCursor)
|
||||||
[m_delegate showMouseCursor]; // Make sure the cursor is visible
|
showMouseCursor(); // Make sure the cursor is visible
|
||||||
|
|
||||||
Event event;
|
Event event;
|
||||||
event.type = Event::MouseLeft;
|
event.type = Event::MouseLeft;
|
||||||
@ -496,10 +531,14 @@ void WindowImplCocoa::setMouseCursorVisible(bool visible)
|
|||||||
{
|
{
|
||||||
m_showCursor = visible;
|
m_showCursor = visible;
|
||||||
|
|
||||||
|
// If the mouse is over the window, we apply the new setting
|
||||||
|
if ([m_delegate isMouseInside])
|
||||||
|
{
|
||||||
if (m_showCursor)
|
if (m_showCursor)
|
||||||
[m_delegate showMouseCursor];
|
showMouseCursor();
|
||||||
else
|
else
|
||||||
[m_delegate hideMouseCursor];
|
hideMouseCursor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,16 +89,12 @@ namespace sf {
|
|||||||
-(sf::WindowHandle)getSystemHandle;
|
-(sf::WindowHandle)getSystemHandle;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Hide the mouse cursor
|
/// \brief Determine where the mouse is
|
||||||
|
///
|
||||||
|
/// \return true when the mouse is inside the OpenGL view, false otherwise
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
-(void)hideMouseCursor;
|
-(BOOL)isMouseInside;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Show the mouse cursor
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
-(void)showMouseCursor;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get window position
|
/// \brief Get window position
|
||||||
|
Loading…
x
Reference in New Issue
Block a user