source: xplra/src/plugin/src/xplra/MessageWindow.h@ 42:719f590e4878

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

Added initial support for the menu

File size: 5.6 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
70private:
71 /**
72 * The dataref containing the width of the program's window.
73 */
74 XPLMDataRef widthDataRef;
75
76 /**
77 * The dataref containing the height of the program's window.
78 */
79 XPLMDataRef heightDataRef;
80
81 /**
82 * The window ID.
83 */
84 XPLMWindowID windowID;
85
86 /**
87 * The X-coordinate of the left side of the window.
88 */
89 int left;
90
91 /**
92 * The Y-coordinate of the top of the window.
93 */
94 int top;
95
96 /**
97 * The X-coordinate of the right side of the window.
98 */
99 int right;
100
101 /**
102 * The Y-coordinate of the bottom of the window.
103 */
104 int bottom;
105
106 /**
107 * Indicate if the message window should be shown
108 */
109 bool showForced;
110
111 /**
112 * The currently displayed message.
113 */
114 std::string displayedMessage;
115
116 /**
117 * The time to hide the current message. If not positive, no
118 * message is currently shown.
119 */
120 float hideTime;
121
122 /**
123 * The mutex protecting some of the data structures that are used
124 * from both the simulator loop and the server thread.
125 */
126 hu::varadiistvan::scpl::Mutex mutex;
127
128 /**
129 * The message to show.
130 */
131 std::string message;
132
133 /**
134 * The number of seconds for which the message should be shown. If
135 * positive, there is a new message.
136 */
137 float duration;
138
139public:
140 /**
141 * Construct the message window. It creates the X-Plane window and
142 * registers the callback functions. The window is hidden
143 * initially.
144 */
145 MessageWindow();
146
147 /**
148 * Destroy the message window. It destroys the X-Plane window.
149 */
150 ~MessageWindow();
151
152 /**
153 * Force showing the message window.
154 */
155 void show();
156
157 /**
158 * Hide the message window if it does not have to display an
159 * actual message.
160 */
161 void hide();
162
163private:
164 /**
165 * Called from the window drawing callback.
166 */
167 void drawWindow();
168
169 /**
170 * Called from the key handling callback.
171 */
172 void handleKey(char key, XPLMKeyFlags flags, char virtualKey,
173 bool losingFocus);
174
175 /**
176 * Called from the mouse click handling callback.
177 *
178 * @return true if the click is consumed, false otherwise.
179 */
180 bool handleMouseClick(int x, int y, XPLMMouseStatus mouse);
181
182 /**
183 * Get the new message, if any.
184 *
185 * @return the duration of the message, or 0.0 if there is no new
186 * message. The message will be cleared.
187 */
188 float getNewMessage(std::string& dest);
189
190 /**
191 * Set the new message, if any.
192 */
193 void setNewMessage(const std::string& msg, float d);
194
195 friend class MessageRequest;
196};
197
198//------------------------------------------------------------------------------
199
200} /* namespace xplra */
201
202//------------------------------------------------------------------------------
203#endif // XPLRA_MESSAGEWINDOW_H
204
205// Local Variables:
206// mode: C++
207// c-basic-offset: 4
208// indent-tabs-mode: nil
209// End:
Note: See TracBrowser for help on using the repository browser.