Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7737 in orxonox.OLD for trunk/src/lib/shell/shell.cc


Ignore:
Timestamp:
May 19, 2006, 11:38:34 PM (18 years ago)
Author:
bensch
Message:

Using MultiLine-Text in the Shell. This is much faster, and Nicer :)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/shell.cc

    r7426 r7737  
    2121#include "shell_input.h"
    2222
    23 
    24 #include "text.h"
     23#include "multi_line_text.h"
     24
    2525#include "graphics_engine.h"
    2626#include "material.h"
    2727#include "event_handler.h"
    28 #include "debug.h"
    29 #include "class_list.h"
    30 
    31 #include "key_names.h"
    32 #include <stdarg.h>
    33 #include <stdio.h>
    3428
    3529namespace OrxShell
     
    137131    std::list<std::string>::const_iterator textLine = --ShellBuffer::getInstance()->getBuffer().end();
    138132    bool top = false;
    139     for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
     133    for (std::list<MultiLineText*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
    140134    {
    141135      (*text)->setVisibility(true);
     
    164158    this->setRelCoorSoft2D(0, -(int)this->shellHeight, 5);
    165159
    166     for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
     160    for (std::list<MultiLineText*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
    167161      (*text)->setVisibility(false);
    168162    this->bufferOffset = 0;
     
    257251     * output is routed from Some other Thread or by Changing any Values.
    258252     */
    259     std::list<Text*> bufferTextCopy = this->bufferText;
    260     for (std::list<Text*>::iterator text = bufferTextCopy.begin(); text != bufferTextCopy.end(); ++text, ++i)
     253    std::list<MultiLineText*> bufferTextCopy = this->bufferText;
     254    for (std::list<MultiLineText*>::iterator text = bufferTextCopy.begin(); text != bufferTextCopy.end(); ++text, ++i)
    261255    {
    262256      this->resetText(*text, i);
     
    296290      for (unsigned int i = oldSize; i <= bufferDisplaySize; i++)
    297291      {
    298         this->bufferText.push_back(new Text);
     292        this->bufferText.push_back(new MultiLineText);
     293        this->bufferText.back()->setLineWidth(this->getSizeX2D() * GraphicsEngine::getInstance()->getResolutionX());
     294        this->bufferText.back()->setLineSpacing(0);
    299295      }
    300296    }
     
    308304  void Shell::flush()
    309305  {
    310     for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
     306    for (std::list<MultiLineText*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
    311307    {
    312308      (*text)->setText("");  // remove all chars from the BufferTexts.
     
    322318  void Shell::printToDisplayBuffer(const std::string& text)
    323319  {
     320    // Remove Last Entry and prepend it to the front.
    324321    this->bufferText.push_front(this->bufferText.back());
    325322    this->bufferText.pop_back();
    326323
    327 
    328     unsigned int i = 0;
    329     for (std::list<Text*>::iterator textIt = ++this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt, i++)
    330     {
    331       (*textIt)->setRelCoorSoft2D(this->calculateLinePosition(i+1), 5);
    332     }
    333 
    334     this->bufferText.front()->setRelCoor2D(this->calculateLinePosition(0)- Vector2D(-1000,0));
    335     this->bufferText.front()->setRelCoorSoft2D(this->calculateLinePosition(0),10);
     324    // Set the new Text.
     325    this->bufferText.front()->setText(text);
     326
     327    // The LineCount will be started here.
     328    int linePos = -1;
     329
     330    // The First Line gets a special Animation
     331    this->bufferText.front()->setRelCoor2D(this->calculateLinePosition(linePos)- Vector2D(-1000,0));
     332
     333    // Move all lines one Entry up.
     334    for (std::list<MultiLineText*>::iterator textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt)
     335    {
     336      linePos += (*textIt)->getLineCount();
     337      (*textIt)->setRelCoorSoft2D(this->calculateLinePosition(linePos), 8);
     338    }
     339
    336340
    337341    /*  FANCY EFFECTS :)
     
    344348    */
    345349
    346     this->bufferText.front()->setText(text);
    347350  }
    348351
     
    389392    {
    390393      /// FIXME
    391       PRINTF(1)("Should not heappen\n");
     394      PRINTF(1)("Should not happen\n");
    392395      it--;
    393396    }
    394     for (std::list<Text*>::iterator textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt)
     397    for (std::list<MultiLineText*>::iterator textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt)
    395398    {
    396399      (*textIt)->setText((*it));
     
    398401      {
    399402        /// FIXME
    400         PRINTF(1)("Should not heappen\n");
     403        PRINTF(1)("Should not happen\n");
    401404        break;
    402405      }
     
    478481  Vector2D Shell::calculateLinePosition(unsigned int lineNumber)
    479482  {
    480     return Vector2D(5, (this->textSize + this->lineSpacing)*(this->bufferDisplaySize - lineNumber - 2) + this->textSize);
     483    Vector2D val(5, (int)(this->textSize + this->lineSpacing)*(int)((int)this->bufferDisplaySize - (int)lineNumber - (int)2) + (int)this->textSize);
     484     val.debug();
     485     return val;
    481486  }
    482487
Note: See TracChangeset for help on using the changeset viewer.