1 // WindowsMouseCursor.cxx - mouse cursor using Cocoa APIs
3 // Copyright (C) 2013 James Turner <zakalawe@mac.com>
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "WindowsMouseCursor.hxx"
30 #include <Main/globals.hxx>
32 class WindowsMouseCursor::WindowsMouseCursorPrivate
35 Cursor activeCursorKey;
37 typedef std::map<Cursor, HCURSOR> CursorMap;
41 HCURSOR windowsCursorForKey(FGMouseCursor::Cursor aKey)
46 NSString* path = [NSString stringWithCString:globals->get_fg_root().c_str()
47 encoding:NSUTF8StringEncoding];
48 path = [path stringByAppendingPathComponent:@"gui"];
51 case FGMouseCursor::CURSOR_HAND: return [NSCursor pointingHandCursor];
52 case FGMouseCursor::CURSOR_CROSSHAIR: return [NSCursor crosshairCursor];
53 case FGMouseCursor::CURSOR_IBEAM: return [NSCursor IBeamCursor];
55 // FIXME - use a proper left-right cursor here.
56 case FGMouseCursor::CURSOR_LEFT_RIGHT: return [NSCursor resizeLeftRightCursor];
58 case FGMouseCursor::CURSOR_SPIN_CW:
59 path = [path stringByAppendingPathComponent:@"cursor-spin-cw.png"];
60 img = [[NSImage alloc] initWithContentsOfFile:path];
61 return [[NSCursor alloc] initWithImage:img hotSpot:NSMakePoint(16,16)];
63 case FGMouseCursor::CURSOR_SPIN_CCW:
64 path = [path stringByAppendingPathComponent:@"cursor-spin-cw.png"];
65 img = [[NSImage alloc] initWithContentsOfFile:path];
66 return [[NSCursor alloc] initWithImage:img hotSpot:NSMakePoint(16,16)];
68 default: return [NSCursor arrowCursor];
74 WindowsMouseCursor::WindowsMouseCursor() :
75 d(new WindowsMouseCursorPrivate)
80 WindowsMouseCursor::~WindowsMouseCursor()
87 void WindowsMouseCursor::setCursor(Cursor aCursor)
89 if (aCursor == d->activeCursorKey) {
93 d->activeCursorKey = aCursor;
94 if (d->cursors.find(aCursor) == d->cursors.end()) {
95 d->cursors[key] = windowsCursorForKey(aCursor);
99 SetCursor(windowsCursorForKey(d->cursors[key]));
102 void WindowsMouseCursor::setCursorVisible(bool aVis)
104 d->hideUntilMove = false; // cancel this
114 void WindowsMouseCursor::hideCursorUntilMouseMove()
116 if (d->hideUntilMove) {
120 d->hideUntilMove = true;
124 void WindowsMouseCursor::mouseMoved()
126 if (d->hideUntilMove) {
127 d->hideUntilMove = false;