summaryrefslogtreecommitdiff
path: root/src/SFML/Window/OSX
diff options
context:
space:
mode:
Diffstat (limited to 'src/SFML/Window/OSX')
-rw-r--r--src/SFML/Window/OSX/CursorImpl.mm44
1 files changed, 38 insertions, 6 deletions
diff --git a/src/SFML/Window/OSX/CursorImpl.mm b/src/SFML/Window/OSX/CursorImpl.mm
index 5f41376..ed905ef 100644
--- a/src/SFML/Window/OSX/CursorImpl.mm
+++ b/src/SFML/Window/OSX/CursorImpl.mm
@@ -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,10 +82,11 @@ bool CursorImpl::loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hot
return m_cursor != nil;
}
-
////////////////////////////////////////////////////////////
bool CursorImpl::loadFromSystem(Cursor::Type type)
{
+ [m_cursor release];
+
switch (type)
{
default: return false;
@@ -80,14 +98,28 @@ bool CursorImpl::loadFromSystem(Cursor::Type type)
case Cursor::SizeVertical: m_cursor = [NSCursor resizeUpDownCursor]; break;
case Cursor::Cross: m_cursor = [NSCursor crosshairCursor]; break;
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:
+ m_cursor = loadFromSelector(@selector(_windowResizeNorthEastSouthWestCursor));
+ break;
+
+ case Cursor::SizeTopLeftBottomRight:
+ m_cursor = loadFromSelector(@selector(_windowResizeNorthWestSouthEastCursor));
+ break;
+
+ case Cursor::Help:
+ 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;
}