mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Improved macOS implementation for Cursor
- remove Wait and SizeAll cursors as they don't look nice (Wait is not spining and produces a broken rendering, SizeAll is a simple white cursor.) - fix memory management for NSCursor. - ignore selector warnings.
This commit is contained in:
parent
9c2e7cbb51
commit
9f7d8101a9
@ -53,21 +53,21 @@ public:
|
||||
/// Refer to the following table to determine which cursor
|
||||
/// is available on which platform.
|
||||
///
|
||||
/// Type | Linux | Mac OS X | Windows
|
||||
/// ------------------------------------|:-----:|:--------:|:--------:
|
||||
/// sf::Cursor::Arrow | yes | yes | yes
|
||||
/// sf::Cursor::ArrowWait | no | no | yes
|
||||
/// sf::Cursor::Wait | yes | no | yes
|
||||
/// sf::Cursor::Text | yes | yes | yes
|
||||
/// sf::Cursor::Hand | yes | yes | yes
|
||||
/// sf::Cursor::SizeHorizontal | yes | yes | yes
|
||||
/// sf::Cursor::SizeVertical | yes | yes | yes
|
||||
/// sf::Cursor::SizeTopLeftBottomRight | no | yes* | yes
|
||||
/// sf::Cursor::SizeBottomLeftTopRight | no | yes* | yes
|
||||
/// sf::Cursor::SizeAll | yes | no | yes
|
||||
/// sf::Cursor::Cross | yes | yes | yes
|
||||
/// sf::Cursor::Help | yes | yes* | yes
|
||||
/// sf::Cursor::NotAllowed | yes | yes | yes
|
||||
/// Type | Linux | Mac OS X | Windows |
|
||||
/// ------------------------------------|:-----:|:--------:|:--------:|
|
||||
/// sf::Cursor::Arrow | yes | yes | yes |
|
||||
/// sf::Cursor::ArrowWait | no | no | yes |
|
||||
/// sf::Cursor::Wait | yes | no | yes |
|
||||
/// sf::Cursor::Text | yes | yes | yes |
|
||||
/// sf::Cursor::Hand | yes | yes | yes |
|
||||
/// sf::Cursor::SizeHorizontal | yes | yes | yes |
|
||||
/// sf::Cursor::SizeVertical | yes | yes | yes |
|
||||
/// sf::Cursor::SizeTopLeftBottomRight | no | yes* | yes |
|
||||
/// sf::Cursor::SizeBottomLeftTopRight | no | yes* | yes |
|
||||
/// sf::Cursor::SizeAll | yes | no | yes |
|
||||
/// sf::Cursor::Cross | yes | yes | yes |
|
||||
/// sf::Cursor::Help | yes | yes* | yes |
|
||||
/// sf::Cursor::NotAllowed | yes | yes | yes |
|
||||
///
|
||||
/// * These cursor types are undocumented so may not
|
||||
/// be available on all versions, but have been tested on 10.13
|
||||
|
@ -32,6 +32,21 @@
|
||||
#import <SFML/Window/OSX/NSImage+raw.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
NSCursor* loadFromSelector(SEL selector)
|
||||
{
|
||||
// The caller is responsible for retaining the cursor.
|
||||
if ([NSCursor respondsToSelector:selector])
|
||||
return [NSCursor performSelector:selector];
|
||||
else
|
||||
return nil;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
@ -56,6 +71,8 @@ CursorImpl::~CursorImpl()
|
||||
////////////////////////////////////////////////////////////
|
||||
bool CursorImpl::loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hotspot)
|
||||
{
|
||||
[m_cursor release];
|
||||
|
||||
NSSize nssize = NSMakeSize(size.x, size.y);
|
||||
NSImage* image = [NSImage imageWithRawData:pixels andSize:nssize];
|
||||
NSPoint nshotspot = NSMakePoint(hotspot.x, hotspot.y);
|
||||
@ -65,20 +82,11 @@ bool CursorImpl::loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hot
|
||||
return m_cursor != nil;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromSelector(SEL selector, NSCursorRef& cursor)
|
||||
{
|
||||
if ([NSCursor respondsToSelector:selector])
|
||||
{
|
||||
cursor = [NSCursor performSelector:selector];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool CursorImpl::loadFromSystem(Cursor::Type type)
|
||||
{
|
||||
[m_cursor release];
|
||||
|
||||
switch (type)
|
||||
{
|
||||
default: return false;
|
||||
@ -92,24 +100,26 @@ bool CursorImpl::loadFromSystem(Cursor::Type type)
|
||||
case Cursor::NotAllowed: m_cursor = [NSCursor operationNotAllowedCursor]; break;
|
||||
|
||||
// These cursor types are undocumented, may not be available on some platforms
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wundeclared-selector"
|
||||
case Cursor::SizeBottomLeftTopRight:
|
||||
return loadFromSelector(@selector(_windowResizeNorthEastSouthWestCursor), m_cursor);
|
||||
m_cursor = loadFromSelector(@selector(_windowResizeNorthEastSouthWestCursor));
|
||||
break;
|
||||
|
||||
case Cursor::SizeTopLeftBottomRight:
|
||||
return loadFromSelector(@selector(_windowResizeNorthWestSouthEastCursor), m_cursor);
|
||||
case Cursor::SizeAll:
|
||||
return loadFromSelector(@selector(_moveCursor), m_cursor);
|
||||
case Cursor::Wait:
|
||||
return loadFromSelector(@selector(_waitCursor), m_cursor);
|
||||
m_cursor = loadFromSelector(@selector(_windowResizeNorthWestSouthEastCursor));
|
||||
break;
|
||||
|
||||
case Cursor::Help:
|
||||
return loadFromSelector(@selector(_helpCursor), m_cursor);
|
||||
m_cursor = loadFromSelector(@selector(_helpCursor));
|
||||
break;
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
// Since we didn't allocate the cursor ourself, we have to retain it
|
||||
// in order to not break the retain count.
|
||||
[m_cursor retain];
|
||||
if (m_cursor)
|
||||
[m_cursor retain];
|
||||
|
||||
// For all non-default cases, it was a success.
|
||||
return true;
|
||||
return m_cursor != nil;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user