]> git.mxchange.org Git - flightgear.git/blob - src/GUI/WindowsMouseCursor.cxx
Support for multiple data dirs.
[flightgear.git] / src / GUI / WindowsMouseCursor.cxx
1 // WindowsMouseCursor.cxx - mouse cursor using Windows APIs
2
3 // Copyright (C) 2013 James Turner <zakalawe@mac.com>
4 //
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.
9 //
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.
14 //
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.
18 //
19
20 #ifdef HAVE_CONFIG_H
21     #include "config.h"
22 #endif
23
24 #include "WindowsMouseCursor.hxx"
25
26 #include "windows.h"
27
28 #include <map>
29
30 #include <Main/globals.hxx>
31
32 class WindowsMouseCursor::WindowsMouseCursorPrivate
33 {
34 public:
35     Cursor activeCursorKey;
36     bool hideUntilMove;
37
38     typedef std::map<Cursor, HCURSOR> CursorMap;
39     CursorMap cursors;
40 };
41
42 HCURSOR windowsCursorForKey(FGMouseCursor::Cursor aKey)
43 {
44     switch (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 );
49     
50 #if 0       
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)];
55             
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)];
60 #endif       
61     default: return LoadCursor(NULL, IDC_ARROW);
62     }
63     
64 }
65
66 WindowsMouseCursor::WindowsMouseCursor() :
67     d(new WindowsMouseCursorPrivate)
68 {
69     d->hideUntilMove = false;
70         d->activeCursorKey = CURSOR_ARROW;
71 }
72
73 WindowsMouseCursor::~WindowsMouseCursor()
74 {
75     
76     
77 }
78
79
80 void WindowsMouseCursor::setCursor(Cursor aCursor)
81 {
82     if (aCursor == d->activeCursorKey) {
83         return;
84     }
85     
86     d->activeCursorKey = aCursor;
87     if (d->cursors.find(aCursor) == d->cursors.end()) {
88         d->cursors[aCursor] = windowsCursorForKey(aCursor);
89     }
90
91     SetCursor(d->cursors[aCursor]);
92 }
93
94 void WindowsMouseCursor::setCursorVisible(bool aVis)
95 {
96     d->hideUntilMove = false; // cancel this
97     ShowCursor(aVis);
98 }
99
100 void WindowsMouseCursor::hideCursorUntilMouseMove()
101 {
102     if (d->hideUntilMove) {
103         return;
104     }
105     
106     d->hideUntilMove = true;
107     ShowCursor(false);
108 }
109
110 void WindowsMouseCursor::mouseMoved()
111 {
112     if (d->hideUntilMove) {
113         d->hideUntilMove = false;
114         ShowCursor(true);
115     }
116 }