1 /* 2 * CRRCsim - the Charles River Radio Control Club Flight Simulator Project 3 * 4 * Copyright (C) 2004, 2005, 2008 Jan Reucker (original author) 5 * Copyright (C) 2005, 2008 Jens Wilhelm Wulf 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 9 * as published by the Free Software Foundation. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, 19 * Boston, MA 02111-1307, USA. 20 * 21 */ 22 23 24 #ifndef CRRC_GUIMAIN_H 25 #define CRRC_GUIMAIN_H 26 27 #include <SDL.h> 28 #include <plib/pu.h> 29 30 #include "../mod_fdm/fdm_inputs.h" 31 32 #define N_COMPASS 10 33 34 /** \brief The main GUI object 35 * 36 * This object provides the framework for the CRRCsim GUI. It 37 * contains a single menu widget and handles UI drawing and 38 * incoming SDL events. 39 */ 40 class CGUIMain 41 { 42 public: 43 CGUIMain(bool vis = true); 44 ~CGUIMain(); 45 46 bool keyDownEventHandler(SDL_keysym& key); 47 bool keyUpEventHandler(SDL_keysym& key); 48 bool mouseButtonDownHandler(int btn, int x, int y); 49 bool mouseButtonUpHandler(int btn, int x, int y); 50 bool mouseMotionHandler(int x, int y); 51 52 void reveal(); 53 void hide(); 54 55 void draw(); 56 57 /** \brief Dummy mouse motion handler. 58 * 59 * Always returns false as PUI does not evaluate the 60 * mouse motion. 61 * \param state not used 62 * \param x not used 63 * \param y not used 64 * \return Always false. 65 */ mouseMotionHandler(char state,int x,int y)66 inline bool mouseMotionHandler(char state, int x, int y) 67 { 68 return false; 69 }; 70 71 /** \brief Convert SDL mouse buttons to PUI mouse buttons. 72 * 73 * This inline function simply returns its argument 74 * minus one: SDL counts mouse buttons from 1, PUI 75 * counts from 0. 76 * \param btn Mouse button in SDL numeration. 77 * \return Mouse button in PUI numeration. 78 */ translateMouse(int btn)79 inline int translateMouse(int btn){return (btn-1);}; 80 81 /** \brief Determine if the GUI is currently visible. 82 * 83 * \return true if the GUI is visible, false otherwise. 84 */ isVisible()85 inline bool isVisible() {return visible;}; 86 87 /** 88 * Set text of verbose output 89 */ 90 void setVerboseText(const char* msg); 91 92 /** 93 * Draw or hide the HUD compass labels 94 */ 95 void doHUDCompass(const float field_of_view); 96 97 /** 98 * Show error message 99 */ 100 void errorMsg(const char* message); 101 102 void doQuitDialog(); 103 104 /** 105 * Propagate the simulation control input values 106 * to the GUI. 107 */ 108 void setInputValues(TSimInputs *in); 109 110 /** 111 * The GUI's "idle" function. 112 **/ 113 void GUI_IdleFunction(TSimInputs *in); 114 115 /** 116 * Access the local copy of the control input values. 117 */ 118 TSimInputs * getInputValues(); 119 120 private: 121 int translateKey(const SDL_keysym& keysym); 122 123 bool visible; 124 125 puMenuBar *main_menu_bar; 126 puText* verboseOutput; 127 TSimInputs input; 128 129 fntTexFont *VerbosityFont; 130 131 static const int nCompass = N_COMPASS; 132 puText* compass_x[N_COMPASS+1]; 133 puText* compass_y[N_COMPASS+1]; 134 std::string compass_msg_x[N_COMPASS+1]; 135 std::string compass_msg_y[N_COMPASS+1]; 136 }; 137 138 139 #endif // CRRC_GUIMAIN_H 140 141