Changeset 1642 for code/branches/gui/src/orxonox/overlays/console
- Timestamp:
- Jul 23, 2008, 3:37:29 PM (16 years ago)
- Location:
- code/branches/gui/src/orxonox/overlays/console
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.