[38] | 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 |
|
---|
| 46 | /**
|
---|
| 47 | * Class to handle the activities related to the message window.
|
---|
| 48 | */
|
---|
| 49 | class MessageWindow
|
---|
| 50 | {
|
---|
| 51 | private:
|
---|
| 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 | private:
|
---|
| 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 | * The currently displayed message.
|
---|
| 108 | */
|
---|
| 109 | std::string displayedMessage;
|
---|
| 110 |
|
---|
| 111 | /**
|
---|
| 112 | * The time to hide the current message. If not positive, no
|
---|
| 113 | * message is currently shown.
|
---|
| 114 | */
|
---|
| 115 | float hideTime;
|
---|
| 116 |
|
---|
| 117 | /**
|
---|
| 118 | * The mutex protecting some of the data structures that are used
|
---|
| 119 | * from both the simulator loop and the server thread.
|
---|
| 120 | */
|
---|
| 121 | hu::varadiistvan::scpl::Mutex mutex;
|
---|
| 122 |
|
---|
| 123 | /**
|
---|
| 124 | * The message to show.
|
---|
| 125 | */
|
---|
| 126 | std::string message;
|
---|
| 127 |
|
---|
| 128 | /**
|
---|
| 129 | * The number of seconds for which the message should be shown. If
|
---|
| 130 | * positive, there is a new message.
|
---|
| 131 | */
|
---|
| 132 | float duration;
|
---|
| 133 |
|
---|
| 134 | public:
|
---|
| 135 | /**
|
---|
| 136 | * Construct the message window. It creates the X-Plane window and
|
---|
| 137 | * registers the callback functions. The window is hidden
|
---|
| 138 | * initially.
|
---|
| 139 | */
|
---|
| 140 | MessageWindow();
|
---|
| 141 |
|
---|
| 142 | /**
|
---|
| 143 | * Destroy the message window. It destroys the X-Plane window.
|
---|
| 144 | */
|
---|
| 145 | ~MessageWindow();
|
---|
| 146 |
|
---|
| 147 | private:
|
---|
| 148 | /**
|
---|
| 149 | * Called from the window drawing callback.
|
---|
| 150 | */
|
---|
| 151 | void drawWindow();
|
---|
| 152 |
|
---|
| 153 | /**
|
---|
| 154 | * Called from the key handling callback.
|
---|
| 155 | */
|
---|
| 156 | void handleKey(char key, XPLMKeyFlags flags, char virtualKey,
|
---|
| 157 | bool losingFocus);
|
---|
| 158 |
|
---|
| 159 | /**
|
---|
| 160 | * Called from the mouse click handling callback.
|
---|
| 161 | *
|
---|
| 162 | * @return true if the click is consumed, false otherwise.
|
---|
| 163 | */
|
---|
| 164 | bool handleMouseClick(int x, int y, XPLMMouseStatus mouse);
|
---|
| 165 |
|
---|
| 166 | /**
|
---|
| 167 | * Get the new message, if any.
|
---|
| 168 | *
|
---|
| 169 | * @return the duration of the message, or 0.0 if there is no new
|
---|
| 170 | * message. The message will be cleared.
|
---|
| 171 | */
|
---|
| 172 | float getNewMessage(std::string& dest);
|
---|
| 173 |
|
---|
| 174 | /**
|
---|
| 175 | * Set the new message, if any.
|
---|
| 176 | */
|
---|
| 177 | void setNewMessage(const std::string& msg, float d);
|
---|
| 178 |
|
---|
| 179 | friend class MessageRequest;
|
---|
| 180 | };
|
---|
| 181 |
|
---|
| 182 | //------------------------------------------------------------------------------
|
---|
| 183 |
|
---|
| 184 | } /* namespace xplra */
|
---|
| 185 |
|
---|
| 186 | //------------------------------------------------------------------------------
|
---|
| 187 | #endif // XPLRA_MESSAGEWINDOW_H
|
---|
| 188 |
|
---|
| 189 | // Local Variables:
|
---|
| 190 | // mode: C++
|
---|
| 191 | // c-basic-offset: 4
|
---|
| 192 | // indent-tabs-mode: nil
|
---|
| 193 | // End:
|
---|