[aseprite] 169/250: Impl SkiaWindow::setNativeMouseCursor() on Skia/OSX
Tobias Hansen
thansen at moszumanska.debian.org
Sun Dec 20 15:27:26 UTC 2015
This is an automated email from the git hooks/post-receive script.
thansen pushed a commit to branch master
in repository aseprite.
commit ee7df1f9739cbaae019428dea4253ec61cbc9d19
Author: David Capello <davidcapello at gmail.com>
Date: Wed Oct 14 12:30:48 2015 -0300
Impl SkiaWindow::setNativeMouseCursor() on Skia/OSX
---
src/she/osx/view.h | 5 ++++
src/she/osx/view.mm | 38 +++++++++++++++++++++++++++++
src/she/osx/window.h | 2 ++
src/she/osx/window.mm | 54 +++++++++++++++++++++++++++++++++++++++++
src/she/skia/skia_window_osx.mm | 6 +++++
5 files changed, 105 insertions(+)
diff --git a/src/she/osx/view.h b/src/she/osx/view.h
index d2952f2..c76d0c7 100644
--- a/src/she/osx/view.h
+++ b/src/she/osx/view.h
@@ -13,6 +13,8 @@
@interface OSXView : NSView {
@private
NSTrackingArea* m_trackingArea;
+ NSCursor* m_nsCursor;
+ bool m_visibleMouse;
}
- (id)initWithFrame:(NSRect)frameRect;
- (BOOL)acceptsFirstResponder;
@@ -39,9 +41,12 @@
- (void)handleMouseUp:(NSEvent*)event;
- (void)handleMouseDragged:(NSEvent*)event;
- (void)scrollWheel:(NSEvent*)event;
+- (void)cursorUpdate:(NSEvent*)event;
+- (void)setCursor:(NSCursor*)cursor;
- (void)setFrameSize:(NSSize)newSize;
- (void)createMouseTrackingArea;
- (void)destroyMouseTrackingArea;
+- (void)updateCurrentCursor;
@end
#endif
diff --git a/src/she/osx/view.mm b/src/she/osx/view.mm
index 2127c05..fe8360b 100644
--- a/src/she/osx/view.mm
+++ b/src/she/osx/view.mm
@@ -50,6 +50,9 @@ inline Event::MouseButton get_mouse_buttons(NSEvent* event)
- (id)initWithFrame:(NSRect)frameRect
{
+ m_nsCursor = [NSCursor arrowCursor];
+ m_visibleMouse = true;
+
self = [super initWithFrame:frameRect];
if (self != nil) {
[self createMouseTrackingArea];
@@ -174,6 +177,8 @@ inline Event::MouseButton get_mouse_buttons(NSEvent* event)
- (void)mouseEntered:(NSEvent*)event
{
+ [self updateCurrentCursor];
+
Event ev;
ev.setType(Event::MouseEnter);
ev.setPosition(get_local_mouse_pos(self, event));
@@ -190,6 +195,13 @@ inline Event::MouseButton get_mouse_buttons(NSEvent* event)
- (void)mouseExited:(NSEvent*)event
{
+ // Restore arrow cursor
+ if (!m_visibleMouse) {
+ m_visibleMouse = true;
+ [NSCursor unhide];
+ }
+ [[NSCursor arrowCursor] set];
+
Event ev;
ev.setType(Event::MouseLeave);
ev.setPosition(get_local_mouse_pos(self, event));
@@ -309,6 +321,17 @@ inline Event::MouseButton get_mouse_buttons(NSEvent* event)
queue_event(ev);
}
+- (void)cursorUpdate:(NSEvent*)event
+{
+ [self updateCurrentCursor];
+}
+
+- (void)setCursor:(NSCursor*)cursor
+{
+ m_nsCursor = cursor;
+ [self updateCurrentCursor];
+}
+
- (void)createMouseTrackingArea
{
// Create a tracking area to receive mouseMoved events
@@ -330,4 +353,19 @@ inline Event::MouseButton get_mouse_buttons(NSEvent* event)
m_trackingArea = nil;
}
+- (void)updateCurrentCursor
+{
+ if (m_nsCursor) {
+ if (!m_visibleMouse) {
+ m_visibleMouse = true;
+ [NSCursor unhide];
+ }
+ [m_nsCursor set];
+ }
+ else if (m_visibleMouse) {
+ m_visibleMouse = false;
+ [NSCursor hide];
+ }
+}
+
@end
diff --git a/src/she/osx/window.h b/src/she/osx/window.h
index 12c200e..1636f78 100644
--- a/src/she/osx/window.h
+++ b/src/she/osx/window.h
@@ -14,6 +14,7 @@
#include "gfx/rect.h"
#include "gfx/size.h"
#include "she/keys.h"
+#include "she/native_cursor.h"
namespace she {
KeyScancode cocoavk_to_scancode(UInt16 vk);
@@ -46,6 +47,7 @@ public:
- (gfx::Size)clientSize;
- (gfx::Size)restoredSize;
- (void)setMousePosition:(const gfx::Point&)position;
+- (void)setNativeMouseCursor:(she::NativeCursor)cursor;
@end
#endif
diff --git a/src/she/osx/window.mm b/src/she/osx/window.mm
index 236988b..6713181 100644
--- a/src/she/osx/window.mm
+++ b/src/she/osx/window.mm
@@ -15,6 +15,8 @@
#include "she/osx/view.h"
#include "she/osx/window_delegate.h"
+using namespace she;
+
@implementation OSXWindow
- (OSXWindow*)initWithImpl:(OSXWindowImpl*)impl
@@ -96,4 +98,56 @@
CFRelease(event);
}
+- (void)setNativeMouseCursor:(NativeCursor)cursor
+{
+ NSCursor* nsCursor = nil;
+
+ switch (cursor) {
+ case kArrowCursor:
+ case kWaitCursor:
+ case kHelpCursor:
+ case kSizeNECursor:
+ case kSizeNWCursor:
+ case kSizeSECursor:
+ case kSizeSWCursor:
+ nsCursor = [NSCursor arrowCursor];
+ break;
+ case kIBeamCursor:
+ nsCursor = [NSCursor IBeamCursor];
+ break;
+ case kLinkCursor:
+ nsCursor = [NSCursor pointingHandCursor];
+ break;
+ case kForbiddenCursor:
+ nsCursor = [NSCursor operationNotAllowedCursor];
+ break;
+ case kMoveCursor:
+ nsCursor = [NSCursor openHandCursor];
+ break;
+ case kSizeNSCursor:
+ nsCursor = [NSCursor resizeUpDownCursor];
+ break;
+ case kSizeWECursor:
+ nsCursor = [NSCursor resizeLeftRightCursor];
+ break;
+ case kSizeNCursor:
+ nsCursor = [NSCursor resizeUpCursor];
+ break;
+ case kSizeECursor:
+ nsCursor = [NSCursor resizeRightCursor];
+ break;
+ case kSizeSCursor:
+ nsCursor = [NSCursor resizeDownCursor];
+ break;
+ case kSizeWCursor:
+ nsCursor = [NSCursor resizeLeftCursor];
+ break;
+ default:
+ nsCursor = nil;
+ break;
+ }
+
+ [self.contentView setCursor:nsCursor];
+}
+
@end
diff --git a/src/she/skia/skia_window_osx.mm b/src/she/skia/skia_window_osx.mm
index 0138601..2e36962 100644
--- a/src/she/skia/skia_window_osx.mm
+++ b/src/she/skia/skia_window_osx.mm
@@ -91,6 +91,10 @@ public:
[m_window setMousePosition:position];
}
+ void setNativeMouseCursor(NativeCursor cursor) {
+ [m_window setNativeMouseCursor:cursor];
+ }
+
void updateWindow(const gfx::Rect& bounds) {
int scale = this->scale();
NSView* view = m_window.contentView;
@@ -361,6 +365,8 @@ void SkiaWindow::setMousePosition(const gfx::Point& position)
void SkiaWindow::setNativeMouseCursor(NativeCursor cursor)
{
+ if (m_impl)
+ m_impl->setNativeMouseCursor(cursor);
}
void SkiaWindow::updateWindow(const gfx::Rect& bounds)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git
More information about the Pkg-games-commits
mailing list