source: xplra/src/plugin/src/xplra/MessageWindow.h@ 48:d853401b7307

Last change on this file since 48:d853401b7307 was 48:d853401b7307, checked in by István Váradi <ivaradi@…>, 11 years ago

Added support for moving and resizing the message area

File size: 6.4 KB
Line 
1// Copyright (c) 2013 by István Váradi
2
3// This file is part of XPLRA, a remote-access plugin for X-Plane
4
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are met:
7
8// 1. Redistributions of source code must retain the above copyright notice, this
9// list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright notice,
11// this list of conditions and the following disclaimer in the documentation
12// and/or other materials provided with the distribution.
13
14// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
25// The views and conclusions contained in the software and documentation are those
26// of the authors and should not be interpreted as representing official policies,
27// either expressed or implied, of the FreeBSD Project.
28
29#ifndef XPLRA_MESSAGEWINDOW_H
30#define XPLRA_MESSAGEWINDOW_H
31//------------------------------------------------------------------------------
32
33#include <hu/varadiistvan/scpl/Mutex.h>
34
35#include <string>
36
37#include <XPLMDataAccess.h>
38#include <XPLMDisplay.h>
39
40//------------------------------------------------------------------------------
41
42namespace xplra {
43
44//------------------------------------------------------------------------------
45
46/**
47 * Class to handle the activities related to the message window.
48 */
49class MessageWindow
50{
51private:
52 /**
53 * Window drawing callback.
54 */
55 static void drawWindowCallback(XPLMWindowID windowID, void* refCon);
56
57 /**
58 * Handle the keypresses.
59 */
60 static void handleKeyCallback(XPLMWindowID windowID, char key,
61 XPLMKeyFlags flags, char virtualKey,
62 void* refCon, int losingFocus);
63
64 /**
65 * Handle the mouse clicks.
66 */
67 static int handleMouseClickCallback(XPLMWindowID windowID, int x, int y,
68 XPLMMouseStatus mouse, void* refCon);
69
70
71 /**
72 * The minimal width of the message area.
73 */
74 static const int minimalWidth = 150;
75
76 /**
77 * The size of the resize sensitivity area.
78 */
79 static const int resizeArea = 50;
80
81private:
82 /**
83 * The dataref containing the width of the program's window.
84 */
85 XPLMDataRef widthDataRef;
86
87 /**
88 * The dataref containing the height of the program's window.
89 */
90 XPLMDataRef heightDataRef;
91
92 /**
93 * The window ID.
94 */
95 XPLMWindowID windowID;
96
97 /**
98 * The X-coordinate of the left side of the window.
99 */
100 int left;
101
102 /**
103 * The Y-coordinate of the top of the window.
104 */
105 int top;
106
107 /**
108 * The X-coordinate of the right side of the window.
109 */
110 int right;
111
112 /**
113 * The Y-coordinate of the bottom of the window.
114 */
115 int bottom;
116
117 /**
118 * Indicate if the message window should be shown
119 */
120 bool showForced;
121
122 /**
123 * The currently displayed message.
124 */
125 std::string displayedMessage;
126
127 /**
128 * The time to hide the current message. If not positive, no
129 * message is currently shown.
130 */
131 float hideTime;
132
133 /**
134 * The mouse mode
135 */
136 enum {
137 // Move the message area
138 MOUSE_MOVE,
139
140 // Resize the message area from the left
141 MOUSE_RESIZE_LEFT,
142
143 // Resize the message area from the right.
144 MOUSE_RESIZE_RIGHT
145 } mouseMode;
146
147 /**
148 * The X-coordinate where the window was clicked.
149 */
150 int clickedX;
151
152 /**
153 * The Y-coordinate where the window was clicked.
154 */
155 int clickedY;
156
157 /**
158 * The mutex protecting some of the data structures that are used
159 * from both the simulator loop and the server thread.
160 */
161 hu::varadiistvan::scpl::Mutex mutex;
162
163 /**
164 * The message to show.
165 */
166 std::string message;
167
168 /**
169 * The number of seconds for which the message should be shown. If
170 * positive, there is a new message.
171 */
172 float duration;
173
174public:
175 /**
176 * Construct the message window. It creates the X-Plane window and
177 * registers the callback functions. The window is hidden
178 * initially.
179 */
180 MessageWindow();
181
182 /**
183 * Destroy the message window. It destroys the X-Plane window.
184 */
185 ~MessageWindow();
186
187 /**
188 * Force showing the message window.
189 */
190 void show();
191
192 /**
193 * Hide the message window if it does not have to display an
194 * actual message.
195 */
196 void hide();
197
198 /**
199 * Reset the location of the message window.
200 */
201 void reset();
202
203private:
204 /**
205 * Called from the window drawing callback.
206 */
207 void drawWindow();
208
209 /**
210 * Called from the key handling callback.
211 */
212 void handleKey(char key, XPLMKeyFlags flags, char virtualKey,
213 bool losingFocus);
214
215 /**
216 * Called from the mouse click handling callback.
217 *
218 * @return true if the click is consumed, false otherwise.
219 */
220 bool handleMouseClick(int x, int y, XPLMMouseStatus mouse);
221
222 /**
223 * Get the new message, if any.
224 *
225 * @return the duration of the message, or 0.0 if there is no new
226 * message. The message will be cleared.
227 */
228 float getNewMessage(std::string& dest);
229
230 /**
231 * Set the new message, if any.
232 */
233 void setNewMessage(const std::string& msg, float d);
234
235 /**
236 * Reset the location of the message window.
237 */
238 void resetLocation();
239
240 friend class MessageRequest;
241};
242
243//------------------------------------------------------------------------------
244
245} /* namespace xplra */
246
247//------------------------------------------------------------------------------
248#endif // XPLRA_MESSAGEWINDOW_H
249
250// Local Variables:
251// mode: C++
252// c-basic-offset: 4
253// indent-tabs-mode: nil
254// End:
Note: See TracBrowser for help on using the repository browser.