1 // WindowsMouseCursor.cxx - mouse cursor using Windows 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;
38 typedef std::map<Cursor, HCURSOR> CursorMap;
42 HCURSOR windowsCursorForKey(FGMouseCursor::Cursor aKey)
45 case FGMouseCursor::CURSOR_HAND: return LoadCursor(NULL, IDC_HAND);
46 case FGMouseCursor::CURSOR_CROSSHAIR: return LoadCursor(NULL, IDC_CROSS);
47 case FGMouseCursor::CURSOR_IBEAM: return LoadCursor(NULL, IDC_IBEAM);
48 case FGMouseCursor::CURSOR_LEFT_RIGHT: return LoadCursor( NULL, IDC_SIZEWE );
51 case FGMouseCursor::CURSOR_SPIN_CW:
52 path = [path stringByAppendingPathComponent:@"cursor-spin-cw.png"];
53 img = [[NSImage alloc] initWithContentsOfFile:path];
54 return [[NSCursor alloc] initWithImage:img hotSpot:NSMakePoint(16,16)];
56 case FGMouseCursor::CURSOR_SPIN_CCW:
57 path = [path stringByAppendingPathComponent:@"cursor-spin-cw.png"];
58 img = [[NSImage alloc] initWithContentsOfFile:path];
59 return [[NSCursor alloc] initWithImage:img hotSpot:NSMakePoint(16,16)];
61 default: return LoadCursor(NULL, IDC_ARROW);
66 WindowsMouseCursor::WindowsMouseCursor() :
67 d(new WindowsMouseCursorPrivate)
69 d->hideUntilMove = false;
70 d->activeCursorKey = CURSOR_ARROW;
73 WindowsMouseCursor::~WindowsMouseCursor()
80 void WindowsMouseCursor::setCursor(Cursor aCursor)
82 if (aCursor == d->activeCursorKey) {
86 d->activeCursorKey = aCursor;
87 if (d->cursors.find(aCursor) == d->cursors.end()) {
88 d->cursors[aCursor] = windowsCursorForKey(aCursor);
91 SetCursor(d->cursors[aCursor]);
94 void WindowsMouseCursor::setCursorVisible(bool aVis)
96 d->hideUntilMove = false; // cancel this
100 void WindowsMouseCursor::hideCursorUntilMouseMove()
102 if (d->hideUntilMove) {
106 d->hideUntilMove = true;
110 void WindowsMouseCursor::mouseMoved()
112 if (d->hideUntilMove) {
113 d->hideUntilMove = false;