Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7341 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Apr 19, 2006, 3:58:03 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: shell in c++-style now

Location:
trunk/src/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/render2D/element_2d.cc

    r7332 r7341  
    202202void Element2D::setLayer(E2D_LAYER layer)
    203203{
     204  if (unlikely(this->layer == layer)) return;
     205
    204206  if (this->parent != NULL && this->parent->getLayer() > layer)
    205207  {
  • trunk/src/lib/shell/shell.cc

    r7340 r7341  
    3636
    3737SHELL_COMMAND(clear, Shell, clear)
    38     ->describe("Clears the shell from unwanted lines (empties all buffers)")
    39     ->setAlias("clear");
     38->describe("Clears the shell from unwanted lines (empties all buffers)")
     39->setAlias("clear");
    4040SHELL_COMMAND(deactivate, Shell, deactivate)
    41     ->describe("Deactivates the Shell. (moves it into background)")
    42     ->setAlias("hide");
     41->describe("Deactivates the Shell. (moves it into background)")
     42->setAlias("hide");
    4343SHELL_COMMAND(textsize, Shell, setTextSize)
    44     ->describe("Sets the size of the Text size, linespacing")
    45     ->defaultValues(15, 0);
     44->describe("Sets the size of the Text size, linespacing")
     45->defaultValues(15, 0);
    4646SHELL_COMMAND(textcolor, Shell, setTextColor)
    47     ->describe("Sets the Color of the Shells Text (red, green, blue, alpha)")
    48     ->defaultValues(SHELL_DEFAULT_TEXT_COLOR);
     47->describe("Sets the Color of the Shells Text (red, green, blue, alpha)")
     48->defaultValues(SHELL_DEFAULT_TEXT_COLOR);
    4949SHELL_COMMAND(backgroundcolor, Shell, setBackgroundColor)
    50     ->describe("Sets the Color of the Shells Background (red, green, blue, alpha)")
    51     ->defaultValues(SHELL_DEFAULT_BACKGROUND_COLOR);
     50->describe("Sets the Color of the Shells Background (red, green, blue, alpha)")
     51->defaultValues(SHELL_DEFAULT_BACKGROUND_COLOR);
    5252SHELL_COMMAND(backgroundimage, Shell, setBackgroundImage)
    53     ->describe("sets the background image to load for the Shell");
     53->describe("sets the background image to load for the Shell");
    5454SHELL_COMMAND(font, Shell, setFont)
    55     ->describe("Sets the font of the Shell")
    56     ->defaultValues(SHELL_DEFAULT_FONT);
     55->describe("Sets the font of the Shell")
     56->defaultValues(SHELL_DEFAULT_FONT);
    5757
    5858/**
     
    7171
    7272  // BUFFER
    73   this->bufferText = NULL;
    74   this->bufferDisplaySize = 10;
    7573  this->bufferOffset = 0;
    7674  this->bufferIterator = ShellBuffer::getInstance()->getBuffer().begin();
    7775
    7876  // INPUT LINE
    79   this->shellInput = new ShellInput;
    80   this->shellInput->setLayer(E2D_LAYER_ABOVE_ALL);
     77  this->setLayer(E2D_LAYER_ABOVE_ALL);
     78  this->shellInput.setLayer(E2D_LAYER_ABOVE_ALL);
    8179
    8280  this->backgroundMaterial = new Material;
     81
    8382  // Element2D and generals
    8483  this->setAbsCoor2D(3, -400);
    85   this->setLayer(E2D_LAYER_ABOVE_ALL);
    8684  this->textSize = 20;
    8785  this->lineSpacing = 0;
     
    8987  this->fontFile = SHELL_DEFAULT_FONT;
    9088
    91 
    92   this->rebuildText();
     89  this->setBufferDisplaySize(10);
    9390
    9491  this->setTextColor(SHELL_DEFAULT_TEXT_COLOR);
    9592  this->setBackgroundColor(SHELL_DEFAULT_BACKGROUND_COLOR);
     93
    9694
    9795  this->deactivate();
     
    10199
    102100/**
    103  * standard deconstructor
     101 * @brief standard deconstructor
    104102 */
    105103Shell::~Shell ()
     
    108106
    109107  // delete the displayable Buffers
    110   for (unsigned int i = 0; i < this->bufferDisplaySize; i++)
    111     delete this->bufferText[i];
    112   delete[] this->bufferText;
     108  while (!this->bufferText.empty())
     109  {
     110    delete this->bufferText.front();
     111    this->bufferText.pop_front();
     112  }
     113
    113114  // delete the inputLine
    114   delete this->shellInput;
    115115  delete this->backgroundMaterial;
    116116}
    117117
    118118/**
    119  * activates the shell
     119 * @brief activates the shell
    120120 *
    121121 * This also feeds the Last few lines from the main buffers into the displayBuffer
     
    134134  list<std::string>::const_iterator textLine = --ShellBuffer::getInstance()->getBuffer().end();
    135135  bool top = false;
    136   for (int i = 0; i < this->bufferDisplaySize; i++)
    137   {
    138     this->bufferText[i]->setVisibility(true);
     136  for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
     137  {
     138    (*text)->setVisibility(true);
    139139    if (!top)
    140140    {
    141       this->bufferText[i]->setText((*textLine));
    142     if (textLine != ShellBuffer::getInstance()->getBuffer().begin())
    143       top = true;
     141      (*text)->setText((*textLine));
     142      if (textLine != ShellBuffer::getInstance()->getBuffer().begin())
     143        top = true;
    144144      textLine--;
    145145    }
     
    161161  this->setRelCoorSoft2D(0, -(int)this->shellHeight, 5);
    162162
    163   list<std::string>::const_iterator textLine = --ShellBuffer::getInstance()->getBuffer().end();
    164   for (int i = 0; i < this->bufferDisplaySize; i++)
    165   {
    166     this->bufferText[i]->setVisibility(false);
    167     if (textLine != ShellBuffer::getInstance()->getBuffer().begin())
    168     {
    169       this->bufferText[i]->setText((*textLine));
    170       textLine--;
    171     }
    172   }
     163  for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
     164    (*text)->setVisibility(false);
    173165  this->bufferOffset = 0;
    174166}
     
    183175void Shell::setFont(const std::string& fontFile)
    184176{
    185 //   if (!ResourceManager::isInDataDir(fontFile))
    186 //     return false;
     177  //   if (!ResourceManager::isInDataDir(fontFile))
     178  //     return false;
    187179
    188180  this->fontFile = fontFile;
    189181
    190   this->rebuildText();
     182  this->resetValues();
    191183}
    192184
     
    203195  this->textSize = textSize;
    204196  this->lineSpacing = lineSpacing;
     197
    205198  this->resetValues();
    206199}
    207200
    208201/**
    209  * sets the color of the Font.
     202 * @brief sets the color of the Font.
    210203 * @param r: red
    211204 * @param g: green
     
    225218
    226219/**
    227  * sets the color of the Backgrond.
     220 * @brief sets the color of the Backgrond.
    228221 * @param r: red
    229222 * @param g: green
     
    238231
    239232/**
    240  * sets a nice background image to the Shell's background
     233 * @brief sets a nice background image to the Shell's background
    241234 * @param fileName the filename of the Image to load
    242235 */
     
    248241
    249242/**
    250  * resets the Values of all visible shell's commandos to the Shell's stored values
     243 * @brief resets the Values of all visible shell's commandos to the Shell's stored values
    251244 *
    252245 * this functions synchronizes the stored Data with the visible one.
     
    254247void Shell::resetValues()
    255248{
    256   if (this->shellInput != NULL)
    257   {
    258     this->shellInput->setSize(this->textSize);
    259     this->shellInput->setColor(this->textColor[0], this->textColor[1], this->textColor[2]);
    260     this->shellInput->setBlending(this->textColor[3]);
    261     this->shellInput->setRelCoor2D(5, (this->textSize + this->lineSpacing)*(this->bufferDisplaySize));
    262   }
    263 
    264   if (this->bufferText != NULL)
    265   {
    266     for (unsigned int i = 0; i < this->bufferDisplaySize; i++)
    267     {
    268       if (this->bufferText[i] != NULL)
    269       {
    270         this->bufferText[i]->setSize(this->textSize);
    271         this->bufferText[i]->setColor(this->textColor[0], this->textColor[1], this->textColor[2]);
    272         this->bufferText[i]->setBlending(this->textColor[3]);
    273         this->bufferText[i]->setRelCoor2D(calculateLinePosition(i));
    274       }
    275     }
     249  this->shellInput.setFont(this->fontFile, this->textSize);
     250  this->shellInput.setColor(this->textColor[0], this->textColor[1], this->textColor[2]);
     251  this->shellInput.setBlending(this->textColor[3]);
     252  this->shellInput.setRelCoor2D(5, (this->textSize + this->lineSpacing)*(this->bufferDisplaySize));
     253  this->shellInput.setLayer(this->getLayer());
     254  if (shellInput.getParent2D() != this)
     255    this->shellInput.setParent2D(this);
     256
     257  unsigned int i = 0;
     258  for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text, ++i)
     259  {
     260    (*text)->setFont(this->fontFile, this->textSize);
     261    (*text)->setColor(this->textColor[0], this->textColor[1], this->textColor[2]);
     262    (*text)->setBlending(this->textColor[3]);
     263    (*text)->setRelCoor2D( calculateLinePosition(i) );
     264    (*text)->setLayer(this->getLayer());
     265    if ((*text)->getParent2D() != this)
     266      (*text)->setParent2D(this);
    276267  }
    277268  this->shellHeight = (this->textSize + this->lineSpacing) * (bufferDisplaySize+1);
    278269}
    279270
    280 /**
    281  * rebuilds the Text's
    282  *
    283  * use this function, if you changed the Font/Size or something else.
    284  */
    285 void Shell::rebuildText()
    286 {
    287   this->shellInput->setFont(this->fontFile, this->textSize);
    288   this->shellInput->setAlignment(TEXT_ALIGN_LEFT);
    289   if (shellInput->getParent2D() != this)
    290     this->shellInput->setParent2D(this);
    291 
    292   this->setBufferDisplaySize(this->bufferDisplaySize);
    293 }
    294 
    295 /**
    296  * sets The count of Lines to display in the buffer.
     271
     272/**
     273 * @brief sets The count of Lines to display in the buffer.
    297274 * @param bufferDisplaySize the count of lines to display in the Shell-Buffer.
    298275 */
    299276void Shell::setBufferDisplaySize(unsigned int bufferDisplaySize)
    300277{
    301   Text** bufferText = this->bufferText;
    302   this->bufferText = NULL;
    303   if (bufferText != NULL)
    304   {
    305     for (unsigned int i = 0; i < this->bufferDisplaySize; i++)
    306       delete bufferText[i];
    307     delete[] bufferText;
    308   }
    309 
    310   list<std::string>::const_iterator textLine = --ShellBuffer::getInstance()->getBuffer().end();
    311   bufferText = new Text*[bufferDisplaySize];
    312   for (unsigned int i = 0; i < bufferDisplaySize; i++)
    313   {
    314     bufferText[i] = new Text(this->fontFile, this->textSize);
    315     bufferText[i]->setLayer(E2D_LAYER_ABOVE_ALL);
    316     bufferText[i]->setAlignment(TEXT_ALIGN_LEFT);
    317     bufferText[i]->setParent2D(this);
    318     if(textLine != ShellBuffer::getInstance()->getBuffer().begin())
    319     {
    320       bufferText[i]->setText(*textLine);
    321       textLine--;
     278  unsigned int oldSize = this->bufferText.size();
     279  if (oldSize > bufferDisplaySize)
     280  {
     281    for (unsigned int i = bufferDisplaySize; i <= oldSize; i++)
     282    {
     283      delete this->bufferText.back();
     284      this->bufferText.pop_back();
     285    }
     286  }
     287  else if (oldSize < bufferDisplaySize)
     288  {
     289    for (unsigned int i = oldSize; i <= bufferDisplaySize; i++)
     290    {
     291      this->bufferText.push_back(new Text);
    322292    }
    323293  }
    324294  this->bufferDisplaySize = bufferDisplaySize;
    325 
    326   this->bufferText = bufferText;
    327   this->shellHeight = (this->textSize + this->lineSpacing) * (bufferDisplaySize+1);
    328 }
    329 
    330 /**
    331  * deletes all the Buffers
     295  this->resetValues();
     296}
     297
     298/**
     299 * @brief deletes all the Buffers
    332300 */
    333301void Shell::flush()
    334302{
    335   // remove all chars from the BufferTexts.
    336   if (this->bufferText != NULL)
    337     for (int i = 0; i < this->bufferDisplaySize; i++)
    338     {
    339       this->bufferText[i]->setText("");
    340     }
    341 
    342     ShellBuffer::getInstance()->flush();
    343     // BUFFER FLUSHING
    344 }
    345 
    346 /**
    347  * prints out some text to the input-buffers
     303  for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
     304  {
     305    (*text)->setText("");  // remove all chars from the BufferTexts.
     306  }
     307  ShellBuffer::getInstance()->flush();
     308  // BUFFER FLUSHING
     309}
     310
     311/**
     312 * @brief prints out some text to the input-buffers
    348313 * @param text the text to output.
    349314 */
    350315void Shell::printToDisplayBuffer(const std::string& text)
    351316{
    352   if(likely(bufferText != NULL))
    353   {
    354     Text* lastText = this->bufferText[this->bufferDisplaySize-1];
    355 
    356     Text* swapText;
    357     Text* moveText = this->bufferText[0];
    358     for (unsigned int i = 0; i < this->bufferDisplaySize; i++)
    359     {
    360       if ( i < this->bufferDisplaySize-1)
    361         this->bufferText[i]->setRelCoorSoft2D(this->calculateLinePosition(i+1), 5);
    362       swapText = this->bufferText[i];
    363       this->bufferText[i] = moveText;
    364       moveText = swapText;
    365     }
     317  this->bufferText.push_front(this->bufferText.back());
     318  this->bufferText.pop_back();
     319
     320
     321  unsigned int i = 0;
     322  for (std::list<Text*>::iterator textIt = ++this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt, i++)
     323  {
     324    (*textIt)->setRelCoorSoft2D(this->calculateLinePosition(i+1), 5);
     325  }
     326
     327  this->bufferText.front()->setRelCoor2D(this->calculateLinePosition(0)- Vector2D(-1000,0));
     328  this->bufferText.front()->setRelCoorSoft2D(this->calculateLinePosition(0),10);
    366329
    367330  /*  FANCY EFFECTS :)
     
    370333        lastText->setRelCoorSoft2D(this->calculateLinePosition(0),10);
    371334    2:
    372   */
    373335    lastText->setRelDir2D(-90);
    374336    lastText->setRelDirSoft2D(0, 20);
    375     lastText->setRelCoor2D(this->calculateLinePosition(0)- Vector2D(-1000,0));
    376     lastText->setRelCoorSoft2D(this->calculateLinePosition(0),10);
    377 
    378  //   lastText->setRelCoor2D(this->calculateLinePosition(0));
    379     this->bufferText[0] = lastText;
    380 
    381     this->bufferText[0]->setText(text);
    382   }
     337  */
     338
     339  //   lastText->setRelCoor2D(this->calculateLinePosition(0));
     340
     341  this->bufferText.front()->setText(text);
    383342}
    384343
     
    392351{
    393352  if (this->bufferOffset == 0)
    394    {
    395      this->bufferIterator = ShellBuffer::getInstance()->getBuffer().end();
    396 //     for (unsigned int i = 0; i < this->bufferDisplaySize; i++)
    397 //       this->bufferIterator->prevStep();
    398    }
     353  {
     354    this->bufferIterator = ShellBuffer::getInstance()->getBuffer().end();
     355    //     for (unsigned int i = 0; i < this->bufferDisplaySize; i++)
     356    //       this->bufferIterator->prevStep();
     357  }
    399358
    400359  // boundraries
     
    422381  // redisplay the buffers
    423382  list<std::string>::const_iterator it = this->bufferIterator;
    424   for (unsigned int i = 0; i < this->bufferDisplaySize; i++)
    425   {
    426     this->bufferText[i]->setText((*it));
     383  for (std::list<Text*>::iterator textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt)
     384  {
     385    (*textIt)->setText((*it));
    427386    it--;
    428387  }
     
    514473  PRINT(3)("Debugging output to console (not this shell)\n");
    515474
    516 //   if (this->pressedKey != SDLK_FIRST)
    517 //     printf("%s::%f %f\n", SDLKToKeyname(this->pressedKey), this->delayed, this->repeatDelay);
     475  //   if (this->pressedKey != SDLK_FIRST)
     476  //     printf("%s::%f %f\n", SDLKToKeyname(this->pressedKey), this->delayed, this->repeatDelay);
    518477
    519478
  • trunk/src/lib/shell/shell.h

    r7316 r7341  
    1313#include "event_listener.h"
    1414
    15 #include <stdarg.h>
     15#include "shell_input.h"
    1616
    1717#define         SHELL_DEFAULT_FONT              "fonts/dpquake_.ttf"
     
    6060
    6161    void resetValues();
    62     void rebuildText();
    6362
    6463    // BUFFERS
     
    9998
    10099    // HANDLING TEXT INPUT
    101     ShellInput*                 shellInput;             //!< The inputLine of the Shell.
     100    ShellInput                  shellInput;             //!< The inputLine of the Shell.
    102101    // BUFFER
    103102    unsigned int                bufferDisplaySize;      //!< The Size of the Display-buffer, in lines (not in characters).
    104     Text**                      bufferText;             //!< A list of stored bufferTexts for the display of the buffer.
     103    std::list<Text*>            bufferText;             //!< A list of stored bufferTexts for the display of the buffer.
    105104    int                         bufferOffset;           //!< how many lines from the bottom up we display the Buffer.
    106105    std::list<std::string>::const_iterator  bufferIterator;         //!< used to move through and print the Buffer
  • trunk/src/lib/shell/shell_input.cc

    r7221 r7341  
    6060      evh->subscribe(this, ES_SHELL, i);
    6161  }
     62  // unsubscribe unused TODO improve.
     63  evh->unsubscribe(ES_SHELL, SDLK_BACKQUOTE);
     64  evh->unsubscribe(ES_SHELL, SDLK_F12);
     65  evh->unsubscribe(ES_SHELL, SDLK_PAGEUP);
     66  evh->unsubscribe(ES_SHELL, SDLK_PAGEDOWN);
     67
    6268  this->completion = new ShellCompletion(this);
    6369}
Note: See TracChangeset for help on using the changeset viewer.