]> git.mxchange.org Git - flightgear.git/blob - src/GUI/WindowsMouseCursor.cxx
Windows cursor handling stubs.
[flightgear.git] / src / GUI / WindowsMouseCursor.cxx
1 // WindowsMouseCursor.cxx - mouse cursor using Cocoa 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     
37     typedef std::map<Cursor, HCURSOR> CursorMap;
38     CursorMap cursors;
39 };
40
41 HCURSOR windowsCursorForKey(FGMouseCursor::Cursor aKey)
42 {
43     #if 0
44     NSImage* img = nil;
45     
46     NSString* path = [NSString stringWithCString:globals->get_fg_root().c_str()
47                                             encoding:NSUTF8StringEncoding];
48     path = [path stringByAppendingPathComponent:@"gui"];
49     
50     switch (aKey) {
51     case FGMouseCursor::CURSOR_HAND: return [NSCursor pointingHandCursor];
52     case FGMouseCursor::CURSOR_CROSSHAIR: return [NSCursor crosshairCursor];
53     case FGMouseCursor::CURSOR_IBEAM: return [NSCursor IBeamCursor];
54     
55     // FIXME - use a proper left-right cursor here.
56     case FGMouseCursor::CURSOR_LEFT_RIGHT: return [NSCursor resizeLeftRightCursor];
57             
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)];
62             
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)];
67             
68     default: return [NSCursor arrowCursor];
69     }
70 #endif
71     
72 }
73
74 WindowsMouseCursor::WindowsMouseCursor() :
75     d(new WindowsMouseCursorPrivate)
76 {
77     
78 }
79
80 WindowsMouseCursor::~WindowsMouseCursor()
81 {
82     
83     
84 }
85
86
87 void WindowsMouseCursor::setCursor(Cursor aCursor)
88 {
89     if (aCursor == d->activeCursorKey) {
90         return;
91     }
92     
93     d->activeCursorKey = aCursor;
94     if (d->cursors.find(aCursor) == d->cursors.end()) {
95         d->cursors[key] = windowsCursorForKey(aCursor);
96     }
97     
98
99     SetCursor(windowsCursorForKey(d->cursors[key]));
100 }
101
102 void WindowsMouseCursor::setCursorVisible(bool aVis)
103 {
104     d->hideUntilMove = false; // cancel this
105     
106     if (aVis) {
107         ShowCursor();
108     } else {
109         
110         HideCursor();
111     }
112 }
113
114 void WindowsMouseCursor::hideCursorUntilMouseMove()
115 {
116     if (d->hideUntilMove) {
117         return;
118     }
119     
120     d->hideUntilMove = true;
121     HideCursor();
122 }
123
124 void WindowsMouseCursor::mouseMoved()
125 {
126     if (d->hideUntilMove) {
127         d->hideUntilMove = false;
128         ShowCursor();
129     }
130 }