X-Plane Remote Access Plugin and Client Library
MessageWindow.h
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 
42 namespace xplra {
43 
44 //------------------------------------------------------------------------------
45 
50 {
51 private:
55  static void drawWindowCallback(XPLMWindowID windowID, void* refCon);
56 
60  static void handleKeyCallback(XPLMWindowID windowID, char key,
61  XPLMKeyFlags flags, char virtualKey,
62  void* refCon, int losingFocus);
63 
67  static int handleMouseClickCallback(XPLMWindowID windowID, int x, int y,
68  XPLMMouseStatus mouse, void* refCon);
69 
70 
74  static const int minimalWidth = 150;
75 
79  static const int resizeArea = 50;
80 
84  static const int horizontalMarginSize = 25;
85 
89  static const int verticalMarginSize = 5;
90 
94  static const int baseLineSize = 2;
95 
100  static constexpr float scrollTimeout = 1.0;
101 
105  static constexpr float scrollInterval = 0.1;
106 
107 private:
111  XPLMDataRef widthDataRef;
112 
116  XPLMDataRef heightDataRef;
117 
122 
127 
131  XPLMWindowID windowID;
132 
136  int left;
137 
141  int top;
142 
146  int right;
147 
151  int bottom;
152 
157 
162 
166  std::string displayedMessage;
167 
171  float showTime;
172 
177  float hideTime;
178 
182  enum {
183  // Move the message area
184  MOUSE_MOVE,
185 
186  // Resize the message area from the left
187  MOUSE_RESIZE_LEFT,
188 
189  // Resize the message area from the right.
190  MOUSE_RESIZE_RIGHT
192 
196  int clickedX;
197 
201  int clickedY;
202 
207 
212 
217 
222 
227  hu::varadiistvan::scpl::Mutex mutex;
228 
232  std::string message;
233 
238  float duration;
239 
240 public:
246  MessageWindow();
247 
251  ~MessageWindow();
252 
256  void show();
257 
262  void hide();
263 
267  void reset();
268 
269 private:
273  void drawWindow();
274 
278  void handleKey(char key, XPLMKeyFlags flags, char virtualKey,
279  bool losingFocus);
280 
286  bool handleMouseClick(int x, int y, XPLMMouseStatus mouse);
287 
294  float getNewMessage(std::string& dest);
295 
299  void setNewMessage(const std::string& msg, float d);
300 
304  void resetLocation();
305 
310 
311  friend class MessageRequest;
312 };
313 
314 //------------------------------------------------------------------------------
315 
316 } /* namespace xplra */
317 
318 //------------------------------------------------------------------------------
319 #endif // XPLRA_MESSAGEWINDOW_H
320 
321 // Local Variables:
322 // mode: C++
323 // c-basic-offset: 4
324 // indent-tabs-mode: nil
325 // End:
void setNewMessage(const std::string &msg, float d)
XPLMDataRef widthDataRef
static const int resizeArea
Definition: MessageWindow.h:79
static void handleKeyCallback(XPLMWindowID windowID, char key, XPLMKeyFlags flags, char virtualKey, void *refCon, int losingFocus)
static constexpr float scrollTimeout
static void drawWindowCallback(XPLMWindowID windowID, void *refCon)
void handleKey(char key, XPLMKeyFlags flags, char virtualKey, bool losingFocus)
static const int verticalMarginSize
Definition: MessageWindow.h:89
enum xplra::MessageWindow::@0 mouseMode
XPLMWindowID windowID
bool handleMouseClick(int x, int y, XPLMMouseStatus mouse)
hu::varadiistvan::scpl::Mutex mutex
std::string displayedMessage
void recalculateMaxMessageLength()
float getNewMessage(std::string &dest)
static const int horizontalMarginSize
Definition: MessageWindow.h:84
static const int baseLineSize
Definition: MessageWindow.h:94
static int handleMouseClickCallback(XPLMWindowID windowID, int x, int y, XPLMMouseStatus mouse, void *refCon)
static const int minimalWidth
Definition: MessageWindow.h:74
XPLMDataRef heightDataRef
static constexpr float scrollInterval
Python client module for the X-Plane Remote Access plugin.
Definition: DataRefTask.h:41