- Timestamp:
- Jul 23, 2008, 3:37:29 PM (16 years ago)
- Location:
- code/branches/gui
- Files:
-
- 3 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/core/Core.cc
r1638 r1642 196 196 { 197 197 TclThreadManager::getInstance().tick(dt); 198 InputManager:: tick(dt);198 InputManager::getInstance().tick(dt); 199 199 } 200 200 } -
code/branches/gui/src/core/Exception.h
r1638 r1642 40 40 #include <string> 41 41 #include <exception> 42 #include <cassert> 42 43 #include "core/Debug.h" 43 44 … … 129 130 throw SpecificException<Exception::type>(description, __LINE__, __FILE__, __FUNCTIONNAME__) 130 131 132 // define an assert macro that can display a message 133 #ifndef NDEBUG 134 #define OrxAssert(condition, errorMessage) \ 135 condition ? ((void)0) : (orxonox::OutputHandler::getOutStream().setOutputLevel(ORX_ERROR) << errorMessage << std::endl); \ 136 assert(condition); 137 #else 138 #define OrxAssert(condition, errorMessage) ((void)0) 139 #endif 140 131 141 } 132 142 -
code/branches/gui/src/core/input/ExtendedInputState.cc
r1641 r1642 37 37 #include <assert.h> 38 38 #include "core/Debug.h" 39 #include "core/CoreIncludes.h" 39 40 40 41 namespace orxonox 41 42 { 43 CreateFactory(ExtendedInputState); 44 42 45 using namespace InputDevice; 46 47 ExtendedInputState::ExtendedInputState() 48 { 49 RegisterObject(ExtendedInputState); 50 } 43 51 44 52 void ExtendedInputState::numberOfJoySticksChanged(unsigned int n) -
code/branches/gui/src/core/input/ExtendedInputState.h
r1641 r1642 48 48 { 49 49 public: 50 ExtendedInputState() { }50 ExtendedInputState(); 51 51 ~ExtendedInputState() { } 52 52 -
code/branches/gui/src/core/input/InputManager.cc
r1641 r1642 62 62 SetConsoleCommandShortcut(InputManager, calibrate); 63 63 64 std::string InputManager::bindingCommmandString_s = ""; 65 InputManager* InputManager::singletonRef_s = 0; 66 64 67 using namespace InputDevice; 65 68 66 // ############################### 67 // ### Internal Methods###68 // ########## #####################69 // ############################### 69 // ############################################################ 70 // ##### Initialisation ##### 71 // ########## ########## 72 // ############################################################ 70 73 71 74 /** … … 87 90 { 88 91 RegisterRootObject(InputManager); 89 } 90 91 /** 92 @brief 93 Destructor itself only called at the end of the program, after main. 94 Instance gets registered for destruction with atexit(.). 95 */ 96 InputManager::~InputManager() 97 { 98 _destroy(); 99 } 100 101 /** 102 @brief 103 The one instance of the InputManager is stored in this function. 104 Only for internal use. Public Interface ist static. 105 @return 106 A reference to the only instance of the InputManager 107 */ 108 InputManager& InputManager::_getInstance() 109 { 110 static InputManager theOnlyInstance; 111 return theOnlyInstance; 112 } 113 114 115 // ############################################################ 116 // ##### Initialisation ##### 117 // ########## ########## 118 // ############################################################ 92 93 assert(singletonRef_s == 0); 94 singletonRef_s = this; 95 } 119 96 120 97 /** … … 129 106 The height of the render window 130 107 */ 131 bool InputManager:: _initialise(const size_t windowHnd, int windowWidth, int windowHeight,108 bool InputManager::initialise(const size_t windowHnd, int windowWidth, int windowHeight, 132 109 bool createKeyboard, bool createMouse, bool createJoySticks) 133 110 { … … 431 408 /** 432 409 @brief 433 Destroys all the created input devices. InputManager will be ready for a 434 new initialisation. 435 */ 436 void InputManager::_destroy() 410 Destroys all the created input devices and states. 411 */ 412 InputManager::~InputManager() 437 413 { 438 414 if (inputSystem_) … … 550 526 Delta time 551 527 */ 552 void InputManager:: _tick(float dt)528 void InputManager::tick(float dt) 553 529 { 554 530 if (inputSystem_ == 0) … … 983 959 984 960 // ############################################################ 985 // ##### Static Interface Methods#####961 // ##### Other Public Interface Methods ##### 986 962 // ########## ########## 987 963 // ############################################################ 988 989 std::string InputManager::bindingCommmandString_s = "";990 991 bool InputManager::initialise(const size_t windowHnd, int windowWidth, int windowHeight,992 bool createKeyboard, bool createMouse, bool createJoySticks)993 {994 return _getInstance()._initialise(windowHnd, windowWidth, windowHeight,995 createKeyboard, createMouse, createJoySticks);996 }997 998 int InputManager::numberOfKeyboards()999 {1000 if (_getInstance().keyboard_ != 0)1001 return 1;1002 else1003 return 0;1004 }1005 1006 int InputManager::numberOfMice()1007 {1008 if (_getInstance().mouse_ != 0)1009 return 1;1010 else1011 return 0;1012 }1013 1014 int InputManager::numberOfJoySticks()1015 {1016 return _getInstance().joySticksSize_;1017 }1018 1019 /*bool InputManager::isKeyDown(KeyCode::Enum key)1020 {1021 if (_getInstance().keyboard_)1022 return _getInstance().keyboard_->isKeyDown((OIS::KeyCode)key);1023 else1024 return false;1025 }*/1026 1027 /*bool InputManager::isModifierDown(KeyboardModifier::Enum modifier)1028 {1029 if (_getInstance().keyboard_)1030 return isModifierDown(modifier);1031 else1032 return false;1033 }*/1034 1035 /*const MouseState InputManager::getMouseState()1036 {1037 if (_getInstance().mouse_)1038 return _getInstance().mouse_->getMouseState();1039 else1040 return MouseState();1041 }*/1042 1043 /*const JoyStickState InputManager::getJoyStickState(unsigned int ID)1044 {1045 if (ID < _getInstance().joySticksSize_)1046 return JoyStickState(_getInstance().joySticks_[ID]->getJoyStickState(), ID);1047 else1048 return JoyStickState();1049 }*/1050 1051 void InputManager::destroy()1052 {1053 _getInstance()._destroy();1054 }1055 1056 964 1057 965 /** … … 1066 974 void InputManager::setWindowExtents(const int width, const int height) 1067 975 { 1068 if ( _getInstance().mouse_)976 if (mouse_) 1069 977 { 1070 978 // Set mouse region (if window resizes, we should alter this to reflect as well) 1071 const OIS::MouseState &mouseState = _getInstance().mouse_->getMouseState(); 1072 mouseState.width = width; 1073 mouseState.height = height; 1074 } 1075 } 1076 1077 /** 1078 @brief 1079 Method for easily storing a string with the command executor. It is used by the 1080 KeyDetector to get assign commands. The KeyDetector simply executes 1081 the command 'storeKeyStroke myName' for each button/axis. 1082 @remarks 1083 This is only a temporary hack until we thourouhgly support multiple KeyBinders. 1084 @param name 1085 The name of the button/axis. 1086 */ 1087 void InputManager::storeKeyStroke(const std::string& name) 1088 { 1089 requestLeaveState("detector"); 1090 COUT(0) << "Binding string \"" << bindingCommmandString_s << "\" on key '" << name << "'" << std::endl; 1091 CommandExecutor::execute("config KeyBinder " + name + " " + bindingCommmandString_s, false); 1092 } 1093 1094 /** 1095 @brief 1096 Assigns a command string to a key/button/axis. The name is determined via KeyDetector 1097 and InputManager::storeKeyStroke(.). 1098 @param command 1099 Command string that can be executed by the CommandExecutor 1100 */ 1101 void InputManager::keyBind(const std::string& command) 1102 { 1103 bindingCommmandString_s = command; 1104 requestEnterState("detector"); 1105 COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl; 1106 } 1107 1108 /** 1109 @brief 1110 Starts joy stick calibration. 1111 */ 1112 void InputManager::calibrate() 1113 { 1114 _getInstance().bCalibrating_ = true; 1115 requestEnterState("calibrator"); 1116 } 1117 1118 void InputManager::tick(float dt) 1119 { 1120 _getInstance()._tick(dt); 1121 } 979 mouse_->getMouseState().width = width; 980 mouse_->getMouseState().height = height; 981 } 982 } 983 1122 984 1123 985 // ###### InputStates ###### … … 1139 1001 if (name == "") 1140 1002 return false; 1141 if (_getInstance().inputStatesByName_.find(name) == _getInstance().inputStatesByName_.end()) 1142 { 1143 if (_getInstance().inputStatesByPriority_.find(priority) 1144 == _getInstance().inputStatesByPriority_.end()) 1145 { 1146 _getInstance().inputStatesByName_[name] = state; 1147 _getInstance().inputStatesByPriority_[priority] = state; 1003 if (!state) 1004 return false; 1005 if (inputStatesByName_.find(name) == inputStatesByName_.end()) 1006 { 1007 if (inputStatesByPriority_.find(priority) 1008 == inputStatesByPriority_.end()) 1009 { 1010 inputStatesByName_[name] = state; 1011 inputStatesByPriority_[priority] = state; 1148 1012 state->setNumOfJoySticks(numberOfJoySticks()); 1149 1013 state->setName(name); … … 1172 1036 { 1173 1037 SimpleInputState* state = new SimpleInputState(); 1174 if (_ getInstance()._configureInputState(state, name, priority))1038 if (_configureInputState(state, name, priority)) 1175 1039 return state; 1176 1040 else … … 1188 1052 { 1189 1053 ExtendedInputState* state = new ExtendedInputState(); 1190 if (_getInstance()._configureInputState(state, name, priority)) 1054 if (_configureInputState(state, name, priority)) 1055 return state; 1056 else 1057 { 1058 delete state; 1059 return 0; 1060 } 1061 } 1062 1063 /** 1064 @brief 1065 Returns a new InputState of type 'type' and configures it first. 1066 @param type 1067 String name of the class (used by the factory) 1068 */ 1069 InputState* InputManager::createInputState(const std::string& type, const std::string &name, int priority) 1070 { 1071 InputState* state = dynamic_cast<InputState*>(Factory::getIdentifier(type)->fabricate()); 1072 if (_configureInputState(state, name, priority)) 1191 1073 return state; 1192 1074 else … … 1214 1096 return false; 1215 1097 } 1216 std::map<std::string, InputState*>::iterator it = _getInstance().inputStatesByName_.find(name);1217 if (it != _getInstance().inputStatesByName_.end())1218 { 1219 _ getInstance()._destroyState((*it).second);1098 std::map<std::string, InputState*>::iterator it = inputStatesByName_.find(name); 1099 if (it != inputStatesByName_.end()) 1100 { 1101 _destroyState((*it).second); 1220 1102 return true; 1221 1103 } … … 1233 1115 InputState* InputManager::getState(const std::string& name) 1234 1116 { 1235 std::map<std::string, InputState*>::iterator it = _getInstance().inputStatesByName_.find(name);1236 if (it != _getInstance().inputStatesByName_.end())1117 std::map<std::string, InputState*>::iterator it = inputStatesByName_.find(name); 1118 if (it != inputStatesByName_.end()) 1237 1119 return (*it).second; 1238 1120 else … … 1248 1130 InputState* InputManager::getCurrentState() 1249 1131 { 1250 return (* _getInstance().activeStates_.rbegin()).second;1132 return (*activeStates_.rbegin()).second; 1251 1133 } 1252 1134 … … 1263 1145 { 1264 1146 // get pointer from the map with all stored handlers 1265 std::map<std::string, InputState*>::const_iterator it = _getInstance().inputStatesByName_.find(name);1266 if (it != _getInstance().inputStatesByName_.end())1267 { 1268 _getInstance().stateEnterRequests_.push_back((*it).second);1147 std::map<std::string, InputState*>::const_iterator it = inputStatesByName_.find(name); 1148 if (it != inputStatesByName_.end()) 1149 { 1150 stateEnterRequests_.push_back((*it).second); 1269 1151 return true; 1270 1152 } … … 1283 1165 { 1284 1166 // get pointer from the map with all stored handlers 1285 std::map<std::string, InputState*>::const_iterator it = _getInstance().inputStatesByName_.find(name);1286 if (it != _getInstance().inputStatesByName_.end())1287 { 1288 _getInstance().stateLeaveRequests_.push_back((*it).second);1167 std::map<std::string, InputState*>::const_iterator it = inputStatesByName_.find(name); 1168 if (it != inputStatesByName_.end()) 1169 { 1170 stateLeaveRequests_.push_back((*it).second); 1289 1171 return true; 1290 1172 } 1291 1173 return false; 1292 1174 } 1175 1176 1177 // ############################################################ 1178 // ##### Console Commands ##### 1179 // ########## ########## 1180 // ############################################################ 1181 1182 /** 1183 @brief 1184 Method for easily storing a string with the command executor. It is used by the 1185 KeyDetector to get assign commands. The KeyDetector simply executes 1186 the command 'storeKeyStroke myName' for each button/axis. 1187 @remarks 1188 This is only a temporary hack until we thourouhgly support multiple KeyBinders. 1189 @param name 1190 The name of the button/axis. 1191 */ 1192 void InputManager::storeKeyStroke(const std::string& name) 1193 { 1194 getInstance().requestLeaveState("detector"); 1195 COUT(0) << "Binding string \"" << bindingCommmandString_s << "\" on key '" << name << "'" << std::endl; 1196 CommandExecutor::execute("config KeyBinder " + name + " " + bindingCommmandString_s, false); 1197 } 1198 1199 /** 1200 @brief 1201 Assigns a command string to a key/button/axis. The name is determined via KeyDetector 1202 and InputManager::storeKeyStroke(.). 1203 @param command 1204 Command string that can be executed by the CommandExecutor 1205 */ 1206 void InputManager::keyBind(const std::string& command) 1207 { 1208 bindingCommmandString_s = command; 1209 getInstance().requestEnterState("detector"); 1210 COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl; 1211 } 1212 1213 /** 1214 @brief 1215 Starts joy stick calibration. 1216 */ 1217 void InputManager::calibrate() 1218 { 1219 getInstance().bCalibrating_ = true; 1220 getInstance().requestEnterState("calibrator"); 1221 } 1293 1222 } -
code/branches/gui/src/core/input/InputManager.h
r1641 r1642 86 86 // --> setConfigValues is private 87 87 friend ClassIdentifier<InputManager>; 88 89 public: // static functions 90 static bool initialise(const size_t windowHnd, int windowWidth, int windowHeight, 88 // let Core class use tick(.) 89 friend Core; 90 91 public: 92 InputManager (); 93 ~InputManager(); 94 95 bool initialise(const size_t windowHnd, int windowWidth, int windowHeight, 91 96 bool createKeyboard = true, bool createMouse = true, bool createJoySticks = false); 92 static int numberOfKeyboards(); 93 static int numberOfMice(); 94 static int numberOfJoySticks(); 95 96 static void destroy(); 97 98 //static bool isModifierDown(KeyboardModifier::Enum modifier); 99 //static bool isKeyDown(KeyCode::Enum key); 100 //static const MouseState getMouseState(); 101 //static const JoyStickState getJoyStickState(unsigned int ID); 102 103 static void setWindowExtents(const int width, const int height); 104 97 98 int numberOfKeyboards() { return keyboard_ ? 1 : 0; } 99 int numberOfMice() { return mouse_ ? 1 : 0; } 100 int numberOfJoySticks() { return joySticksSize_; } 101 102 void setWindowExtents(const int width, const int height); 103 104 SimpleInputState* createSimpleInputState (const std::string& name, int priority); 105 ExtendedInputState* createExtendedInputState(const std::string& name, int priority); 106 InputState* createInputState(const std::string& type, const std::string &name, int priority); 107 bool destroyState (const std::string& name); 108 InputState* getState (const std::string& name); 109 InputState* getCurrentState(); 110 bool requestEnterState (const std::string& name); 111 bool requestLeaveState (const std::string& name); 112 113 static InputManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; } 114 static InputManager* getInstancePtr() { return singletonRef_s; } 115 116 public: // console commands 105 117 static void storeKeyStroke(const std::string& name); 106 118 static void keyBind(const std::string& command); 107 108 119 static void calibrate(); 109 110 static void tick(float dt);111 112 static SimpleInputState* createSimpleInputState (const std::string& name, int priority);113 static ExtendedInputState* createExtendedInputState(const std::string& name, int priority);114 static bool destroyState (const std::string& name);115 static InputState* getState (const std::string& name);116 static InputState* getCurrentState();117 static bool requestEnterState (const std::string& name);118 static bool requestLeaveState (const std::string& name);119 120 120 121 private: // functions 121 122 // don't mess with a Singleton 122 InputManager ();123 123 InputManager (const InputManager&); 124 ~InputManager();125 124 126 125 // Intenal methods 127 bool _initialise(const size_t, int, int, bool, bool, bool);128 126 bool _initialiseKeyboard(); 129 127 bool _initialiseMouse(); … … 131 129 void _redimensionLists(); 132 130 133 void _destroy();134 131 void _destroyKeyboard(); 135 132 void _destroyMouse(); … … 142 139 unsigned int _getJoystick(const OIS::JoyStickEvent& arg); 143 140 144 void _tick(float dt);145 146 141 void _updateActiveStates(); 147 142 bool _configureInputState(InputState* state, const std::string& name, int priority); 143 144 void tick(float dt); 148 145 149 146 // input events … … 158 155 bool sliderMoved (const OIS::JoyStickEvent &arg, int id); 159 156 bool povMoved (const OIS::JoyStickEvent &arg, int id); 157 // don't remove that! Or else add OIS as dependency library to orxonox. 158 bool vector3Moved (const OIS::JoyStickEvent &arg, int id) { return true; } 160 159 161 160 void setConfigValues(); 162 163 static InputManager& _getInstance();164 161 165 162 private: // variables … … 204 201 205 202 static std::string bindingCommmandString_s; 206 };207 203 static InputManager* singletonRef_s; 204 }; 208 205 } 209 206 -
code/branches/gui/src/core/input/InputState.h
r1641 r1642 40 40 #include <vector> 41 41 #include "core/Executor.h" 42 #include "core/BaseObject.h" 43 #include "core/CoreIncludes.h" 42 44 #include "InputInterfaces.h" 43 45 44 46 namespace orxonox 45 47 { 46 class _CoreExport InputState 48 class _CoreExport InputState : public BaseObject 47 49 { 48 50 friend class InputManager; 49 51 50 52 public: 51 InputState() : priority_(0), executorOnEnter_(0), executorOnLeave_(0) { } 53 InputState() : priority_(0), executorOnEnter_(0), executorOnLeave_(0) 54 { RegisterObject(InputState); } 52 55 virtual ~InputState() { } 53 56 -
code/branches/gui/src/core/input/SimpleInputState.cc
r1641 r1642 38 38 #include "core/Debug.h" 39 39 #include "core/Executor.h" 40 #include "core/CoreIncludes.h" 40 41 41 42 namespace orxonox 42 43 { 44 CreateFactory(SimpleInputState); 45 43 46 using namespace InputDevice; 44 47 … … 48 51 , joyStickHandlerAll_(0) 49 52 { 53 RegisterObject(SimpleInputState); 50 54 } 51 55 -
code/branches/gui/src/core/input/SimpleInputState.h
r1641 r1642 43 43 namespace orxonox 44 44 { 45 46 45 class _CoreExport SimpleInputState : public InputState 47 46 { 48 49 47 public: 50 48 SimpleInputState(); -
code/branches/gui/src/orxonox/CMakeLists.txt
r1625 r1642 7 7 RadarViewable.cc 8 8 Settings.cc 9 10 gui/GUIManager.cc 11 gui/OgreCEGUIRenderer.cpp 12 gui/OgreCEGUIResourceProvider.cpp 13 gui/OgreCEGUITexture.cpp 9 14 10 15 overlays/OrxonoxOverlay.cc -
code/branches/gui/src/orxonox/Orxonox.cc
r1641 r1642 104 104 */ 105 105 Orxonox::Orxonox() 106 : ogre_(0) 107 , startLevel_(0) 106 : startLevel_(0) 108 107 , hud_(0) 109 , radar_(0)110 108 //, auMan_(0) 111 109 , timer_(0) … … 114 112 , mode_(GameMode::GM_Unspecified) 115 113 , debugRefreshTime_(0.0f) 114 , ogre_(0) 115 , inputManager_(0) 116 , radar_(0) 116 117 { 117 118 RegisterRootObject(Orxonox); 118 119 119 assert(singletonRef_s == 0); 120 //assert(singletonRef_s == 0); 121 OrxAssert(singletonRef_s == 0, "asdfasdfasdfasdfblahblah"); 120 122 singletonRef_s = this; 121 123 } … … 127 129 { 128 130 // keep in mind: the order of deletion is very important! 129 Loader::unload(); 131 if (this->timer_) 132 delete this->timer_; 133 134 Loader::unload(startLevel_); 130 135 if (this->startLevel_) 131 136 delete this->startLevel_; … … 138 143 delete this->radar_; 139 144 140 Loader::close();141 145 //if (this->auMan_) 142 146 // delete this->auMan_; 143 InGameConsole::getInstance().destroy(); 144 if (this->timer_) 145 delete this->timer_; 146 InputManager::destroy(); 147 148 if (this->console_) 149 delete this->console_; 150 151 if (inputManager_) 152 delete inputManager_; 147 153 148 154 if (this->ogre_) … … 153 159 if (server_g) 154 160 delete network::Server::getSingleton(); 161 162 // this call will delete every BaseObject! 163 // But currently this will call methods of objects that exist no more 164 // The only 'memory leak' is the ParticleSpawer. They would be deleted here 165 // and call a sceneNode method that has already been destroy by the corresponding space ship. 166 //Loader::close(); 155 167 156 168 singletonRef_s = 0; … … 247 259 // Calls the InputManager which sets up the input devices. 248 260 // The render window width and height are used to set up the mouse movement. 249 InputManager::initialise(ogre_->getWindowHandle(), 261 inputManager_ = new InputManager(); 262 inputManager_->initialise(ogre_->getWindowHandle(), 250 263 ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true); 251 264 KeyBinder* keyBinder = new KeyBinder(); 252 265 keyBinder->loadBindings(); 253 InputManager::createSimpleInputState("game", 20)->setHandler(keyBinder);266 inputManager_->createSimpleInputState("game", 20)->setHandler(keyBinder); 254 267 255 268 // Load the InGameConsole 256 InGameConsole::getInstance().initialise(); 269 console_ = new InGameConsole(); 270 console_->initialise(); 257 271 258 272 // load the CEGUI interface … … 342 356 if (success) 343 357 { 344 InputManager:: requestEnterState("game");358 InputManager::getInstance().requestEnterState("game"); 345 359 this->mode_ = mode; 346 360 } -
code/branches/gui/src/orxonox/Orxonox.h
r1638 r1642 84 84 85 85 private: 86 GraphicsEngine* ogre_; //!< our dearest graphics engine <387 86 Level* startLevel_; //!< current hard coded default level 88 87 Level* hud_; //!< 'level' object fo the HUD 89 Radar* radar_; //!< represents the Radar (not the HUD part)90 88 //audio::AudioManager* auMan_; //!< audio manager 91 89 Ogre::Timer* timer_; //!< Main loop timer … … 100 98 float debugRefreshTime_; 101 99 100 // By Orxonox managed singleton pointers 101 GraphicsEngine* ogre_; //!< our dearest graphics engine <3 102 InputManager* inputManager_; 103 Radar* radar_; //!< represents the Radar (not the HUD part) 104 InGameConsole* console_; 105 102 106 static Orxonox *singletonRef_s; 103 107 }; -
code/branches/gui/src/orxonox/gui/GUIManager.cc
r1640 r1642 117 117 118 118 // register us as input handler 119 SimpleInputState* state = InputManager:: createSimpleInputState("gui", 30);119 SimpleInputState* state = InputManager::getInstance().createSimpleInputState("gui", 30); 120 120 state->setHandler(this); 121 121 state->setJoyStickHandler(new EmptyHandler()); … … 203 203 this->scriptModule_->executeScriptGlobal("showMainMenu"); 204 204 205 InputManager:: requestEnterState("gui");205 InputManager::getInstance().requestEnterState("gui"); 206 206 207 207 this->state_ = OnDisplay; … … 229 229 this->guiRenderer_->setTargetSceneManager(0); 230 230 this->state_ = Ready; 231 InputManager:: requestLeaveState("gui");231 InputManager::getInstance().requestLeaveState("gui"); 232 232 } 233 233 -
code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc
r1641 r1642 58 58 SetConsoleCommand(InGameConsole, closeConsole, true); 59 59 60 InGameConsole* InGameConsole::singletonRef_s = 0; 61 60 62 /** 61 63 @brief Constructor: Creates and initializes the InGameConsole. … … 71 73 RegisterObject(InGameConsole); 72 74 75 assert(singletonRef_s == 0); 76 singletonRef_s = this; 77 73 78 this->bActive_ = false; 74 79 this->cursor_ = 0.0f; … … 87 92 InGameConsole::~InGameConsole(void) 88 93 { 89 this->destroy();90 }91 92 /**93 @brief Returns a reference to the only existing instance of InGameConsole.94 */95 InGameConsole& InGameConsole::getInstance()96 {97 static InGameConsole instance;98 return instance;99 }100 101 /**102 @brief Sets the config values, describing the size of the console.103 */104 void InGameConsole::setConfigValues()105 {106 SetConfigValue(relativeWidth, 0.8);107 SetConfigValue(relativeHeight, 0.4);108 SetConfigValue(blinkTime, 0.5);109 SetConfigValue(scrollSpeed_, 3.0f);110 SetConfigValue(noiseSize_, 1.0f);111 SetConfigValue(cursorSymbol_, '|');112 }113 114 /**115 @brief Initializes the InGameConsole.116 */117 void InGameConsole::initialise()118 {119 // create the corresponding input state120 InputManager::createSimpleInputState("console", 40)->setKeyHandler(Shell::getInstance().getInputBuffer());121 122 // create overlay and elements123 Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();124 125 // create actual overlay126 this->consoleOverlay_ = ovMan->create("InGameConsoleConsole");127 128 // create a container129 this->consoleOverlayContainer_ = static_cast<Ogre::OverlayContainer*>(ovMan->createOverlayElement("Panel", "InGameConsoleContainer"));130 this->consoleOverlayContainer_->setMetricsMode(Ogre::GMM_RELATIVE);131 this->consoleOverlayContainer_->setPosition((1 - this->relativeWidth) / 2, 0);132 this->consoleOverlayContainer_->setDimensions(this->relativeWidth, this->relativeHeight);133 this->consoleOverlay_->add2D(this->consoleOverlayContainer_);134 135 // create BorderPanel136 this->consoleOverlayBorder_ = static_cast<Ogre::BorderPanelOverlayElement*>(ovMan->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel"));137 this->consoleOverlayBorder_->setMetricsMode(Ogre::GMM_PIXELS);138 this->consoleOverlayBorder_->setMaterialName("ConsoleCenter");139 this->consoleOverlayBorder_->setBorderSize(16, 16, 0, 16);140 this->consoleOverlayBorder_->setBorderMaterialName("ConsoleBorder");141 this->consoleOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51);142 this->consoleOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5);143 this->consoleOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0);144 this->consoleOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0);145 this->consoleOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0);146 this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_);147 148 // create a new font to match the requested size exactly149 Ogre::FontPtr font = static_cast<Ogre::FontPtr>150 (Ogre::FontManager::getSingleton().create("MonofurConsole", "General"));151 font->setType(Ogre::FT_TRUETYPE);152 font->setSource("Monofur.ttf");153 font->setTrueTypeSize(18);154 // reto: I don't know why, but setting the resolution twice as high makes the font look a lot clearer155 font->setTrueTypeResolution(192);156 font->addCodePointRange(Ogre::Font::CodePointRange(33, 126));157 font->addCodePointRange(Ogre::Font::CodePointRange(161, 255));158 159 // create the text lines160 this->consoleOverlayTextAreas_ = new Ogre::TextAreaOverlayElement*[LINES];161 for (int i = 0; i < LINES; i++)162 {163 this->consoleOverlayTextAreas_[i] = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleTextArea" + convertToString(i)));164 this->consoleOverlayTextAreas_[i]->setMetricsMode(Ogre::GMM_PIXELS);165 this->consoleOverlayTextAreas_[i]->setFontName("MonofurConsole");166 this->consoleOverlayTextAreas_[i]->setCharHeight(18);167 this->consoleOverlayTextAreas_[i]->setParameter("colour_top", "0.21 0.69 0.21");168 this->consoleOverlayTextAreas_[i]->setLeft(8);169 this->consoleOverlayTextAreas_[i]->setCaption("");170 this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]);171 }172 173 // create cursor (also a text area overlay element)174 this->consoleOverlayCursor_ = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleCursor"));175 this->consoleOverlayCursor_->setMetricsMode(Ogre::GMM_PIXELS);176 this->consoleOverlayCursor_->setFontName("MonofurConsole");177 this->consoleOverlayCursor_->setCharHeight(18);178 this->consoleOverlayCursor_->setParameter("colour_top", "0.21 0.69 0.21");179 this->consoleOverlayCursor_->setLeft(7);180 this->consoleOverlayCursor_->setCaption(std::string(this->cursorSymbol_, 1));181 this->consoleOverlayContainer_->addChild(this->consoleOverlayCursor_);182 183 // create noise184 this->consoleOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "InGameConsoleNoise"));185 this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS);186 this->consoleOverlayNoise_->setPosition(5,0);187 this->consoleOverlayNoise_->setMaterialName("ConsoleNoiseSmall");188 // comment following line to disable noise189 this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_);190 191 this->windowResized(GraphicsEngine::getSingleton().getWindowWidth(), GraphicsEngine::getSingleton().getWindowHeight());192 193 // move overlay "above" the top edge of the screen194 // we take -1.2 because the border makes the panel bigger195 this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight);196 197 Shell::getInstance().addOutputLevel(true);198 199 COUT(4) << "Info: InGameConsole initialized" << std::endl;200 }201 202 /**203 @brief Destroys all the elements if necessary.204 */205 void InGameConsole::destroy()206 {207 94 this->deactivate(); 208 95 209 // destroy the input state previously created 210 SimpleInputState * inputState = dynamic_cast<SimpleInputState*>(InputManager::getState("console")); 211 if (inputState) 212 InputManager::destroyState("console"); 96 // destroy the input state previously created (InputBuffer gets destroyed by the Shell) 97 InputManager::getInstance().destroyState("console"); 213 98 214 99 Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr(); … … 239 124 this->consoleOverlayTextAreas_ = 0; 240 125 } 126 127 singletonRef_s = 0; 128 } 129 130 /** 131 @brief Sets the config values, describing the size of the console. 132 */ 133 void InGameConsole::setConfigValues() 134 { 135 SetConfigValue(relativeWidth, 0.8); 136 SetConfigValue(relativeHeight, 0.4); 137 SetConfigValue(blinkTime, 0.5); 138 SetConfigValue(scrollSpeed_, 3.0f); 139 SetConfigValue(noiseSize_, 1.0f); 140 SetConfigValue(cursorSymbol_, '|'); 141 } 142 143 /** 144 @brief Initializes the InGameConsole. 145 */ 146 void InGameConsole::initialise() 147 { 148 // create the corresponding input state 149 InputManager::getInstance().createSimpleInputState("console", 40) 150 ->setKeyHandler(Shell::getInstance().getInputBuffer()); 151 152 // create overlay and elements 153 Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr(); 154 155 // create actual overlay 156 this->consoleOverlay_ = ovMan->create("InGameConsoleConsole"); 157 158 // create a container 159 this->consoleOverlayContainer_ = static_cast<Ogre::OverlayContainer*>(ovMan->createOverlayElement("Panel", "InGameConsoleContainer")); 160 this->consoleOverlayContainer_->setMetricsMode(Ogre::GMM_RELATIVE); 161 this->consoleOverlayContainer_->setPosition((1 - this->relativeWidth) / 2, 0); 162 this->consoleOverlayContainer_->setDimensions(this->relativeWidth, this->relativeHeight); 163 this->consoleOverlay_->add2D(this->consoleOverlayContainer_); 164 165 // create BorderPanel 166 this->consoleOverlayBorder_ = static_cast<Ogre::BorderPanelOverlayElement*>(ovMan->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel")); 167 this->consoleOverlayBorder_->setMetricsMode(Ogre::GMM_PIXELS); 168 this->consoleOverlayBorder_->setMaterialName("ConsoleCenter"); 169 this->consoleOverlayBorder_->setBorderSize(16, 16, 0, 16); 170 this->consoleOverlayBorder_->setBorderMaterialName("ConsoleBorder"); 171 this->consoleOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51); 172 this->consoleOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5); 173 this->consoleOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0); 174 this->consoleOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0); 175 this->consoleOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0); 176 this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_); 177 178 // create a new font to match the requested size exactly 179 Ogre::FontPtr font = static_cast<Ogre::FontPtr> 180 (Ogre::FontManager::getSingleton().create("MonofurConsole", "General")); 181 font->setType(Ogre::FT_TRUETYPE); 182 font->setSource("Monofur.ttf"); 183 font->setTrueTypeSize(18); 184 // reto: I don't know why, but setting the resolution twice as high makes the font look a lot clearer 185 font->setTrueTypeResolution(192); 186 font->addCodePointRange(Ogre::Font::CodePointRange(33, 126)); 187 font->addCodePointRange(Ogre::Font::CodePointRange(161, 255)); 188 189 // create the text lines 190 this->consoleOverlayTextAreas_ = new Ogre::TextAreaOverlayElement*[LINES]; 191 for (int i = 0; i < LINES; i++) 192 { 193 this->consoleOverlayTextAreas_[i] = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleTextArea" + convertToString(i))); 194 this->consoleOverlayTextAreas_[i]->setMetricsMode(Ogre::GMM_PIXELS); 195 this->consoleOverlayTextAreas_[i]->setFontName("MonofurConsole"); 196 this->consoleOverlayTextAreas_[i]->setCharHeight(18); 197 this->consoleOverlayTextAreas_[i]->setParameter("colour_top", "0.21 0.69 0.21"); 198 this->consoleOverlayTextAreas_[i]->setLeft(8); 199 this->consoleOverlayTextAreas_[i]->setCaption(""); 200 this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]); 201 } 202 203 // create cursor (also a text area overlay element) 204 this->consoleOverlayCursor_ = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleCursor")); 205 this->consoleOverlayCursor_->setMetricsMode(Ogre::GMM_PIXELS); 206 this->consoleOverlayCursor_->setFontName("MonofurConsole"); 207 this->consoleOverlayCursor_->setCharHeight(18); 208 this->consoleOverlayCursor_->setParameter("colour_top", "0.21 0.69 0.21"); 209 this->consoleOverlayCursor_->setLeft(7); 210 this->consoleOverlayCursor_->setCaption(std::string(this->cursorSymbol_, 1)); 211 this->consoleOverlayContainer_->addChild(this->consoleOverlayCursor_); 212 213 // create noise 214 this->consoleOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "InGameConsoleNoise")); 215 this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS); 216 this->consoleOverlayNoise_->setPosition(5,0); 217 this->consoleOverlayNoise_->setMaterialName("ConsoleNoiseSmall"); 218 // comment following line to disable noise 219 this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_); 220 221 this->windowResized(GraphicsEngine::getSingleton().getWindowWidth(), GraphicsEngine::getSingleton().getWindowHeight()); 222 223 // move overlay "above" the top edge of the screen 224 // we take -1.2 because the border makes the panel bigger 225 this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight); 226 227 Shell::getInstance().addOutputLevel(true); 228 229 COUT(4) << "Info: InGameConsole initialized" << std::endl; 241 230 } 242 231 … … 491 480 { 492 481 this->bActive_ = true; 493 InputManager:: requestEnterState("console");482 InputManager::getInstance().requestEnterState("console"); 494 483 Shell::getInstance().registerListener(this); 495 484 … … 513 502 { 514 503 this->bActive_ = false; 515 InputManager:: requestLeaveState("console");504 InputManager::getInstance().requestLeaveState("console"); 516 505 Shell::getInstance().unregisterListener(this); 517 506 -
code/branches/gui/src/orxonox/overlays/console/InGameConsole.h
r1641 r1642 46 46 { 47 47 public: // functions 48 InGameConsole(); 49 ~InGameConsole(); 50 48 51 void initialise(); 49 52 void destroy(); … … 52 55 void tick(float dt); 53 56 54 static InGameConsole& getInstance(); 57 static InGameConsole& getInstance() { assert(singletonRef_s); return *singletonRef_s; } 58 static InGameConsole* getInstancePtr() { return singletonRef_s; } 55 59 56 60 static void openConsole(); … … 58 62 59 63 private: // functions 60 InGameConsole();61 64 InGameConsole(const InGameConsole& other) {} 62 ~InGameConsole();63 65 64 66 void activate(); … … 107 109 float noiseSize_; 108 110 char cursorSymbol_; 111 112 static InGameConsole* singletonRef_s; 109 113 }; 110 114 } -
code/branches/gui/src/tolua/CMakeLists.txt
r1582 r1642 15 15 SET (TOLUAEXE_SRC_FILES 16 16 tolua.c 17 toluabind .c17 toluabind_orxonox.c 18 18 ) 19 19 -
code/branches/gui/visual_studio/base_properties.vsprops
r1638 r1642 9 9 Name="VCCLCompilerTool" 10 10 AdditionalIncludeDirectories=""$(RootDir)";"$(RootDir)src";"$(RootDir)src\orxonox";"$(RootDir)src\tolua";"$(RootDir)src\ois";"$(LibDir)ogre-1.4.8\OgreMain\include";"$(LibDir)boost-1.35.0";"$(LibDir)cegui-0.6.1\include";"$(LibDir)cegui-0.6.1\ScriptingModules\CEGUILua\LuaScriptModule\include";"$(LibDir)enet-1.2\include";"$(LibDir)libogg-1.1.3\include";"$(LibDir)libvorbis-1.2.0\include";"$(LibDir)lua-5.1.3\src";"$(LibDir)openal-1.1\include";"$(LibDir)openal-1.1\alut\include";"$(LibDir)tcl-8.5.\generic";"$(LibDir)zlib-1.2.3";"$(LibDir)ogre-1.4.9\Samples\Common\CEGUIRenderer\include"" 11 AdditionalOptions="/MP2"12 11 PreprocessorDefinitions="WIN32;__WIN32__;_WIN32;BOOST_ALL_DYN_LINK;OIS_DYNAMIC_LIB; ZLIB_WINAPI" 13 12 WarningLevel="3" -
code/branches/gui/visual_studio/core_properties.vsprops
r1572 r1642 8 8 <Tool 9 9 Name="VCCLCompilerTool" 10 AdditionalOptions="/MP2" 10 11 PreprocessorDefinitions="CORE_SHARED_BUILD" 11 12 /> -
code/branches/gui/visual_studio/network_properties.vsprops
r1293 r1642 8 8 <Tool 9 9 Name="VCCLCompilerTool" 10 AdditionalOptions="/MP2" 10 11 PreprocessorDefinitions="ORXONOX_NO_EXPORTS;NETWORK_STATIC_BUILD;WIN32_LEAN_AND_MEAN" 11 12 /> -
code/branches/gui/visual_studio/orxonox_properties.vsprops
r1638 r1642 8 8 <Tool 9 9 Name="VCCLCompilerTool" 10 AdditionalOptions="/MP2" 10 11 PreprocessorDefinitions="ORXONOX_NO_EXPORTS;NETWORK_STATIC_BUILD;OGRE_GUIRENDERER_EXPORTS" 11 12 UsePrecompiledHeader="2"
Note: See TracChangeset
for help on using the changeset viewer.