// Copyright (c) 2013 by István Váradi // This file is part of XPLRA, a remote-access plugin for X-Plane // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // 1. Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // The views and conclusions contained in the software and documentation are those // of the authors and should not be interpreted as representing official policies, // either expressed or implied, of the FreeBSD Project. #ifndef XPLRA_MESSAGEWINDOW_H #define XPLRA_MESSAGEWINDOW_H //------------------------------------------------------------------------------ #include #include #include #include //------------------------------------------------------------------------------ namespace xplra { //------------------------------------------------------------------------------ /** * Class to handle the activities related to the message window. */ class MessageWindow { private: /** * Window drawing callback. */ static void drawWindowCallback(XPLMWindowID windowID, void* refCon); /** * Handle the keypresses. */ static void handleKeyCallback(XPLMWindowID windowID, char key, XPLMKeyFlags flags, char virtualKey, void* refCon, int losingFocus); /** * Handle the mouse clicks. */ static int handleMouseClickCallback(XPLMWindowID windowID, int x, int y, XPLMMouseStatus mouse, void* refCon); private: /** * The dataref containing the width of the program's window. */ XPLMDataRef widthDataRef; /** * The dataref containing the height of the program's window. */ XPLMDataRef heightDataRef; /** * The window ID. */ XPLMWindowID windowID; /** * The X-coordinate of the left side of the window. */ int left; /** * The Y-coordinate of the top of the window. */ int top; /** * The X-coordinate of the right side of the window. */ int right; /** * The Y-coordinate of the bottom of the window. */ int bottom; /** * Indicate if the message window should be shown */ bool showForced; /** * The currently displayed message. */ std::string displayedMessage; /** * The time to hide the current message. If not positive, no * message is currently shown. */ float hideTime; /** * The mutex protecting some of the data structures that are used * from both the simulator loop and the server thread. */ hu::varadiistvan::scpl::Mutex mutex; /** * The message to show. */ std::string message; /** * The number of seconds for which the message should be shown. If * positive, there is a new message. */ float duration; public: /** * Construct the message window. It creates the X-Plane window and * registers the callback functions. The window is hidden * initially. */ MessageWindow(); /** * Destroy the message window. It destroys the X-Plane window. */ ~MessageWindow(); /** * Force showing the message window. */ void show(); /** * Hide the message window if it does not have to display an * actual message. */ void hide(); private: /** * Called from the window drawing callback. */ void drawWindow(); /** * Called from the key handling callback. */ void handleKey(char key, XPLMKeyFlags flags, char virtualKey, bool losingFocus); /** * Called from the mouse click handling callback. * * @return true if the click is consumed, false otherwise. */ bool handleMouseClick(int x, int y, XPLMMouseStatus mouse); /** * Get the new message, if any. * * @return the duration of the message, or 0.0 if there is no new * message. The message will be cleared. */ float getNewMessage(std::string& dest); /** * Set the new message, if any. */ void setNewMessage(const std::string& msg, float d); friend class MessageRequest; }; //------------------------------------------------------------------------------ } /* namespace xplra */ //------------------------------------------------------------------------------ #endif // XPLRA_MESSAGEWINDOW_H // Local Variables: // mode: C++ // c-basic-offset: 4 // indent-tabs-mode: nil // End: