Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/overlays/console/InGameConsole.cc @ 1878

Last change on this file since 1878 was 1878, checked in by rgrieder, 16 years ago

Fixed two issues with input:

  • Buffer gets cleared now when the window focus changes
  • Added a configValue in the InGameConsole:

Until now the input was always transparent to the level when activating the console (exception keyboard input of course)
bHidesAllInput_ can change that setting (configured in orxonox.ini)

@Oli: Sorry, couldn't apply the patch in the network branch because of conflicts (I have already made some changes to the InputManager in the trunk)

  • Property svn:eol-style set to native
File size: 23.0 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Felix Schulthess
24 *   Co-authors:
25 *      Fabian 'x3n' Landau
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30
31#include "InGameConsole.h"
32
33#include <string>
34#include <OgreOverlay.h>
35#include <OgreOverlayElement.h>
36#include <OgreOverlayManager.h>
37#include <OgreOverlayContainer.h>
38#include <OgreFontManager.h>
39#include <OgreFont.h>
40
41#include "util/Math.h"
42#include "util/Convert.h"
43#include "util/Debug.h"
44#include "core/CoreIncludes.h"
45#include "core/ConfigValueIncludes.h"
46#include "core/ConsoleCommand.h"
47#include "core/input/InputManager.h"
48#include "core/input/SimpleInputState.h"
49#include "core/input/InputBuffer.h"
50#include "GraphicsEngine.h"
51
52namespace orxonox
53{
54    const int LINES = 30;
55    const float CHAR_WIDTH = 7.45f; // fix this please - determine the char-width dynamically
56
57    SetConsoleCommand(InGameConsole, openConsole, true);
58    SetConsoleCommand(InGameConsole, closeConsole, true);
59
60    InGameConsole* InGameConsole::singletonRef_s = 0;
61
62    /**
63        @brief Constructor: Creates and initializes the InGameConsole.
64    */
65    InGameConsole::InGameConsole()
66        : consoleOverlay_(0)
67        , consoleOverlayContainer_(0)
68        , consoleOverlayNoise_(0)
69        , consoleOverlayCursor_(0)
70        , consoleOverlayBorder_(0)
71        , consoleOverlayTextAreas_(0)
72        , inputState_(0)
73    {
74        RegisterObject(InGameConsole);
75
76        assert(singletonRef_s == 0);
77        singletonRef_s = this;
78
79        this->bActive_ = false;
80        this->cursor_ = 0.0f;
81        this->cursorSymbol_ = '|';
82        this->inputWindowStart_ = 0;
83        this->numLinesShifted_ = LINES - 1;
84        // for the beginning, don't scroll
85        this->scroll_ = 0;
86
87        this->setConfigValues();
88    }
89
90    /**
91        @brief Destructor: Destroys the TextAreas.
92    */
93    InGameConsole::~InGameConsole(void)
94    {
95        this->deactivate();
96
97        // destroy the input state previously created (InputBuffer gets destroyed by the Shell)
98        InputManager::getInstance().requestDestroyState("console");
99
100        Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
101        if (ovMan)
102        {
103            if (this->consoleOverlayNoise_)
104                Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->consoleOverlayNoise_);
105            if (this->consoleOverlayCursor_)
106                Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->consoleOverlayCursor_);
107            Ogre::FontManager::getSingleton().remove("MonofurConsole");
108            if (this->consoleOverlayBorder_)
109                Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->consoleOverlayBorder_);
110            if (this->consoleOverlayTextAreas_)
111            {
112                for (int i = 0; i < LINES; i++)
113                {
114                    if (this->consoleOverlayTextAreas_[i])
115                      Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->consoleOverlayTextAreas_[i]);
116                    this->consoleOverlayTextAreas_[i] = 0;
117                }
118
119            }
120            if (this->consoleOverlayContainer_)
121                Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->consoleOverlayContainer_);
122        }
123        if (this->consoleOverlayTextAreas_)
124        {
125            delete[] this->consoleOverlayTextAreas_;
126            this->consoleOverlayTextAreas_ = 0;
127        }
128
129        if (this->consoleOverlay_)
130            Ogre::OverlayManager::getSingleton().destroy(consoleOverlay_);
131
132        singletonRef_s = 0;
133    }
134
135    /**
136        @brief Sets the config values, describing the size of the console.
137    */
138    void InGameConsole::setConfigValues()
139    {
140        SetConfigValue(relativeWidth, 0.8);
141        SetConfigValue(relativeHeight, 0.4);
142        SetConfigValue(blinkTime, 0.5);
143        SetConfigValue(scrollSpeed_, 3.0f);
144        SetConfigValue(noiseSize_, 1.0f);
145        SetConfigValue(cursorSymbol_, '|');
146        SetConfigValue(bHidesAllInput_, false).callback(this, &InGameConsole::bHidesAllInputChanged);
147    }
148
149    /**
150        @brief Called whenever bHidesAllInput_ changes.
151    */
152    void InGameConsole::bHidesAllInputChanged()
153    {
154        if (inputState_)
155        {
156            if (bHidesAllInput_)
157            {
158                inputState_->setMouseHandler(&InputManager::EMPTY_HANDLER);
159                inputState_->setJoyStickHandler(&InputManager::EMPTY_HANDLER);
160            }
161            else
162            {
163                inputState_->setMouseHandler(0);
164                inputState_->setJoyStickHandler(0);
165            }
166        }
167    }
168
169    /**
170        @brief Initializes the InGameConsole.
171    */
172    void InGameConsole::initialise()
173    {
174        // create the corresponding input state
175        inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("console", 40);
176        inputState_->setKeyHandler(Shell::getInstance().getInputBuffer());
177        bHidesAllInputChanged();
178
179        // create overlay and elements
180        Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
181
182        // create actual overlay
183        this->consoleOverlay_ = ovMan->create("InGameConsoleConsole");
184
185        // create a container
186        this->consoleOverlayContainer_ = static_cast<Ogre::OverlayContainer*>(ovMan->createOverlayElement("Panel", "InGameConsoleContainer"));
187        this->consoleOverlayContainer_->setMetricsMode(Ogre::GMM_RELATIVE);
188        this->consoleOverlayContainer_->setPosition((1 - this->relativeWidth) / 2, 0);
189        this->consoleOverlayContainer_->setDimensions(this->relativeWidth, this->relativeHeight);
190        this->consoleOverlay_->add2D(this->consoleOverlayContainer_);
191
192        // create BorderPanel
193        this->consoleOverlayBorder_ = static_cast<Ogre::BorderPanelOverlayElement*>(ovMan->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel"));
194        this->consoleOverlayBorder_->setMetricsMode(Ogre::GMM_PIXELS);
195        this->consoleOverlayBorder_->setMaterialName("ConsoleCenter");
196        this->consoleOverlayBorder_->setBorderSize(16, 16, 0, 16);
197        this->consoleOverlayBorder_->setBorderMaterialName("ConsoleBorder");
198        this->consoleOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51);
199        this->consoleOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5);
200        this->consoleOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0);
201        this->consoleOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0);
202        this->consoleOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0);
203        this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_);
204
205        // create a new font to match the requested size exactly
206        Ogre::FontPtr font = static_cast<Ogre::FontPtr>
207            (Ogre::FontManager::getSingleton().create("MonofurConsole", "General"));
208        font->setType(Ogre::FT_TRUETYPE);
209        font->setSource("Monofur.ttf");
210        font->setTrueTypeSize(18);
211        // reto: I don't know why, but setting the resolution twice as high makes the font look a lot clearer
212        font->setTrueTypeResolution(192);
213        font->addCodePointRange(Ogre::Font::CodePointRange(33, 126));
214        font->addCodePointRange(Ogre::Font::CodePointRange(161, 255));
215
216        // create the text lines
217        this->consoleOverlayTextAreas_ = new Ogre::TextAreaOverlayElement*[LINES];
218        for (int i = 0; i < LINES; i++)
219        {
220            this->consoleOverlayTextAreas_[i] = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleTextArea" + convertToString(i)));
221            this->consoleOverlayTextAreas_[i]->setMetricsMode(Ogre::GMM_PIXELS);
222            this->consoleOverlayTextAreas_[i]->setFontName("MonofurConsole");
223            this->consoleOverlayTextAreas_[i]->setCharHeight(18);
224            this->consoleOverlayTextAreas_[i]->setParameter("colour_top", "0.21 0.69 0.21");
225            this->consoleOverlayTextAreas_[i]->setLeft(8);
226            this->consoleOverlayTextAreas_[i]->setCaption("");
227            this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]);
228        }
229
230        // create cursor (also a text area overlay element)
231        this->consoleOverlayCursor_ = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleCursor"));
232        this->consoleOverlayCursor_->setMetricsMode(Ogre::GMM_PIXELS);
233        this->consoleOverlayCursor_->setFontName("MonofurConsole");
234        this->consoleOverlayCursor_->setCharHeight(18);
235        this->consoleOverlayCursor_->setParameter("colour_top", "0.21 0.69 0.21");
236        this->consoleOverlayCursor_->setLeft(7);
237        this->consoleOverlayCursor_->setCaption(std::string(this->cursorSymbol_, 1));
238        this->consoleOverlayContainer_->addChild(this->consoleOverlayCursor_);
239
240        // create noise
241        this->consoleOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "InGameConsoleNoise"));
242        this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS);
243        this->consoleOverlayNoise_->setPosition(5,0);
244        this->consoleOverlayNoise_->setMaterialName("ConsoleNoiseSmall");
245        // comment following line to disable noise
246        this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_);
247
248        this->windowResized(GraphicsEngine::getInstance().getWindowWidth(), GraphicsEngine::getInstance().getWindowHeight());
249
250        // move overlay "above" the top edge of the screen
251        // we take -1.2 because the border makes the panel bigger
252        this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight);
253
254        Shell::getInstance().addOutputLevel(true);
255
256        COUT(4) << "Info: InGameConsole initialized" << std::endl;
257    }
258
259    // ###############################
260    // ###  ShellListener methods  ###
261    // ###############################
262
263    /**
264        @brief Called if all output-lines have to be redrawn.
265    */
266    void InGameConsole::linesChanged()
267    {
268        std::list<std::string>::const_iterator it = Shell::getInstance().getNewestLineIterator();
269        int max = 0;
270        for (int i = 1; i < LINES; ++i)
271        {
272            if (it != Shell::getInstance().getEndIterator())
273            {
274                ++it;
275                max = i;
276            }
277            else
278                break;
279        }
280
281        for (int i = LINES - 1; i > max; --i)
282            this->print("", i, true);
283
284        for (int i = max; i >= 1; --i)
285        {
286            --it;
287            this->print(*it, i, true);
288        }
289    }
290
291    /**
292        @brief Called if only the last output-line has changed.
293    */
294    void InGameConsole::onlyLastLineChanged()
295    {
296        if (LINES > 1)
297            this->print(*Shell::getInstance().getNewestLineIterator(), 1);
298    }
299
300    /**
301        @brief Called if a new output-line was added.
302    */
303    void InGameConsole::lineAdded()
304    {
305        this->numLinesShifted_ = 0;
306        this->shiftLines();
307        this->onlyLastLineChanged();
308    }
309
310    /**
311        @brief Called if the text in the input-line has changed.
312    */
313    void InGameConsole::inputChanged()
314    {
315        if (LINES > 0)
316            this->print(Shell::getInstance().getInput(), 0);
317
318        if (Shell::getInstance().getInput() == "" || Shell::getInstance().getInput().size() == 0)
319            this->inputWindowStart_ = 0;
320    }
321
322    /**
323        @brief Called if the position of the cursor in the input-line has changed.
324    */
325    void InGameConsole::cursorChanged()
326    {
327        unsigned int pos = Shell::getInstance().getCursorPosition() - inputWindowStart_;
328        if (pos > maxCharsPerLine_)
329            pos = maxCharsPerLine_;
330        else if (pos < 0)
331            pos = 0;
332
333        this->consoleOverlayCursor_->setCaption(std::string(pos,' ') + cursorSymbol_);
334        this->consoleOverlayCursor_->setTop((int) this->windowH_ * this->relativeHeight - 24);
335    }
336
337    /**
338        @brief Called if the console gets closed.
339    */
340    void InGameConsole::exit()
341    {
342        this->deactivate();
343    }
344
345    // ###############################
346    // ###  other external calls   ###
347    // ###############################
348
349    /**
350        @brief Used to control the actual scrolling and the cursor.
351    */
352    void InGameConsole::tick(float dt)
353    {
354        if (this->scroll_ != 0)
355        {
356            float oldTop = this->consoleOverlayContainer_->getTop();
357
358            if (this->scroll_ > 0)
359            {
360                // scrolling down
361                // enlarge oldTop a little bit so that this exponential function
362                // reaches 0 before infinite time has passed...
363                float deltaScroll = (oldTop - 0.01) * dt * this->scrollSpeed_;
364                if (oldTop - deltaScroll >= 0)
365                {
366                    // window has completely scrolled down
367                    this->consoleOverlayContainer_->setTop(0);
368                    this->scroll_ = 0;
369                }
370                else
371                    this->consoleOverlayContainer_->setTop(oldTop - deltaScroll);
372            }
373
374            else
375            {
376                // scrolling up
377                // note: +0.01 for the same reason as when scrolling down
378                float deltaScroll = (1.2 * this->relativeHeight + 0.01 + oldTop) * dt * this->scrollSpeed_;
379                if (oldTop - deltaScroll <= -1.2 * this->relativeHeight)
380                {
381                    // window has completely scrolled up
382                    this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight);
383                    this->scroll_ = 0;
384                    this->consoleOverlay_->hide();
385                }
386                else
387                    this->consoleOverlayContainer_->setTop(oldTop - deltaScroll);
388            }
389        }
390
391        if (this->bActive_)
392        {
393            this->cursor_ += dt;
394            if (this->cursor_ >= this->blinkTime)
395            {
396                this->cursor_ = 0;
397                bShowCursor_ = !bShowCursor_;
398                if (bShowCursor_)
399                    this->consoleOverlayCursor_->show();
400                else
401                    this->consoleOverlayCursor_->hide();
402            }
403
404            // this creates a flickering effect (extracts exactly 80% of the texture at a random location)
405            float uRand = (rand() & 1023) / 1023.0f * 0.2f;
406            float vRand = (rand() & 1023) / 1023.0f * 0.2f;
407            this->consoleOverlayNoise_->setUV(uRand, vRand, 0.8f + uRand, 0.8f + vRand);
408        }
409    }
410
411    /**
412        @brief Resizes the console elements. Call if window size changes.
413    */
414    void InGameConsole::windowResized(int newWidth, int newHeight)
415    {
416        this->windowW_ = newWidth;
417        this->windowH_ = newHeight;
418        this->consoleOverlayBorder_->setWidth((int) this->windowW_* this->relativeWidth);
419        this->consoleOverlayBorder_->setHeight((int) this->windowH_ * this->relativeHeight);
420        this->consoleOverlayNoise_->setWidth((int) this->windowW_ * this->relativeWidth - 10);
421        this->consoleOverlayNoise_->setHeight((int) this->windowH_ * this->relativeHeight - 5);
422        this->consoleOverlayNoise_->setTiling(consoleOverlayNoise_->getWidth() / (50.0f * this->noiseSize_), consoleOverlayNoise_->getHeight() / (50.0f * this->noiseSize_));
423
424        // now adjust the text lines...
425        this->desiredTextWidth_ = (int) (this->windowW_ * this->relativeWidth) - 12;
426
427        if (LINES > 0)
428            this->maxCharsPerLine_ = max((unsigned int)10, (unsigned int) ((float)this->desiredTextWidth_ / CHAR_WIDTH));
429        else
430            this->maxCharsPerLine_ = 10;
431
432        for (int i = 0; i < LINES; i++)
433        {
434            this->consoleOverlayTextAreas_[i]->setWidth(this->desiredTextWidth_);
435            this->consoleOverlayTextAreas_[i]->setTop((int) this->windowH_ * this->relativeHeight - 24 - 14*i);
436        }
437
438        this->linesChanged();
439        this->cursorChanged();
440    }
441
442    // ###############################
443    // ###    internal methods     ###
444    // ###############################
445
446    /**
447        @brief Prints string to bottom line.
448        @param s String to be printed
449    */
450    void InGameConsole::print(const std::string& text, int index, bool alwaysShift)
451    {
452        char level = 0;
453        if (text.size() > 0)
454            level = text[0];
455
456        std::string output = text;
457
458        if (level >= -1 && level <= 5)
459            output.erase(0, 1);
460
461        if (LINES > index)
462        {
463            this->colourLine(level, index);
464
465            if (index > 0)
466            {
467                unsigned int linesUsed = 1;
468                while (output.size() > this->maxCharsPerLine_)
469                {
470                    ++linesUsed;
471                    this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output.substr(0, this->maxCharsPerLine_)));
472                    output.erase(0, this->maxCharsPerLine_);
473                    output.insert(0, 1, ' ');
474                    if (linesUsed > numLinesShifted_ || alwaysShift)
475                        this->shiftLines();
476                    this->colourLine(level, index);
477                }
478                this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output));
479                this->displayedText_ = output;
480                this->numLinesShifted_ = linesUsed;
481            }
482            else
483            {
484                if (output.size() > this->maxCharsPerLine_)
485                {
486                    if (Shell::getInstance().getInputBuffer()->getCursorPosition() < this->inputWindowStart_)
487                        this->inputWindowStart_ = Shell::getInstance().getInputBuffer()->getCursorPosition();
488                    else if (Shell::getInstance().getInputBuffer()->getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1))
489                        this->inputWindowStart_ = Shell::getInstance().getInputBuffer()->getCursorPosition() - this->maxCharsPerLine_ + 1;
490
491                    output = output.substr(this->inputWindowStart_, this->maxCharsPerLine_);
492                }
493                else
494                  this->inputWindowStart_ = 0;
495                this->displayedText_ = output;
496                this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output));
497            }
498        }
499    }
500
501    /**
502        @brief Shows the InGameConsole.
503    */
504    void InGameConsole::activate()
505    {
506        if (!this->bActive_)
507        {
508            this->bActive_ = true;
509            InputManager::getInstance().requestEnterState("console");
510            Shell::getInstance().registerListener(this);
511
512            this->windowResized(this->windowW_, this->windowH_);
513            this->linesChanged();
514            this->cursorChanged();
515            this->consoleOverlay_->show();
516
517            // scroll down
518            this->scroll_ = 1;
519            // the rest is done by tick
520        }
521    }
522
523    /**
524    @brief Hides the InGameConsole.
525    */
526    void InGameConsole::deactivate()
527    {
528        if (this->bActive_)
529        {
530            this->bActive_ = false;
531            InputManager::getInstance().requestLeaveState("console");
532            Shell::getInstance().unregisterListener(this);
533
534            // scroll up
535            this->scroll_ = -1;
536            // the rest is done by tick
537        }
538    }
539
540    /**
541        @brief Shifts all output lines one line up
542    */
543    void InGameConsole::shiftLines()
544    {
545        for (unsigned int i = LINES - 1; i > 1; --i)
546        {
547            this->consoleOverlayTextAreas_[i]->setCaption(this->consoleOverlayTextAreas_[i - 1]->getCaption());
548            this->consoleOverlayTextAreas_[i]->setColourTop(this->consoleOverlayTextAreas_[i - 1]->getColourTop());
549            this->consoleOverlayTextAreas_[i]->setColourBottom(this->consoleOverlayTextAreas_[i - 1]->getColourBottom());
550        }
551    }
552
553    void InGameConsole::colourLine(int colourcode, int index)
554    {
555        if (colourcode == -1)
556        {
557            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.90, 0.90, 0.90, 1.00));
558            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 1.00, 1.00, 1.00));
559        }
560        else if (colourcode == 1)
561        {
562            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.95, 0.25, 0.25, 1.00));
563            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.50, 0.50, 1.00));
564        }
565        else if (colourcode == 2)
566        {
567            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.95, 0.50, 0.20, 1.00));
568            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.70, 0.50, 1.00));
569        }
570        else if (colourcode == 3)
571        {
572            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.50, 0.50, 0.95, 1.00));
573            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.80, 1.00, 1.00));
574        }
575        else if (colourcode == 4)
576        {
577            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.65, 0.48, 0.44, 1.00));
578            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.90, 0.90, 1.00));
579        }
580        else if (colourcode == 5)
581        {
582            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.40, 0.20, 0.40, 1.00));
583            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.60, 0.80, 1.00));
584        }
585        else
586        {
587            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.21, 0.69, 0.21, 1.00));
588            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 1.00, 0.80, 1.00));
589        }
590    }
591
592    // ###############################
593    // ###      satic methods      ###
594    // ###############################
595
596    /**
597        @brief Activates the console.
598    */
599    /*static*/ void InGameConsole::openConsole()
600    {
601        InGameConsole::getInstance().activate();
602    }
603
604    /**
605        @brief Deactivates the console.
606    */
607    /*static*/ void InGameConsole::closeConsole()
608    {
609        InGameConsole::getInstance().deactivate();
610    }
611
612    /**
613        @brief Converts a string into an Ogre::UTFString.
614        @param s The string to convert
615        @return The converted string
616    */
617    /*static*/ Ogre::UTFString InGameConsole::convert2UTF(std::string s)
618    {
619        Ogre::UTFString utf;
620        Ogre::UTFString::code_point cp;
621        for (unsigned int i = 0; i < s.size(); ++i)
622        {
623          cp = s[i];
624          cp &= 0xFF;
625          utf.append(1, cp);
626        }
627        return utf;
628    }
629}
Note: See TracBrowser for help on using the repository browser.