Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7422 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Apr 28, 2006, 4:54:38 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: completing file-system entries

Location:
trunk/src/lib
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/Makefile.am

    r7329 r7422  
    4343                util/preferences.h \
    4444                util/threading.h \
     45                util/osdir.h \
    4546                \
    4647                util/loading/resource_manager.h \
  • trunk/src/lib/shell/shell.cc

    r7374 r7422  
    3636{
    3737
    38 SHELL_COMMAND(clear, Shell, clear)
    39 ->describe("Clears the shell from unwanted lines (empties all buffers)")
    40 ->setAlias("clear");
    41 SHELL_COMMAND(deactivate, Shell, deactivate)
    42 ->describe("Deactivates the Shell. (moves it into background)")
    43 ->setAlias("hide");
    44 SHELL_COMMAND(textsize, Shell, setTextSize)
    45 ->describe("Sets the size of the Text size, linespacing")
    46 ->defaultValues(15, 0);
    47 SHELL_COMMAND(textcolor, Shell, setTextColor)
    48 ->describe("Sets the Color of the Shells Text (red, green, blue, alpha)")
    49 ->defaultValues(SHELL_DEFAULT_TEXT_COLOR);
    50 SHELL_COMMAND(backgroundcolor, Shell, setBackgroundColor)
    51 ->describe("Sets the Color of the Shells Background (red, green, blue, alpha)")
    52 ->defaultValues(SHELL_DEFAULT_BACKGROUND_COLOR);
    53 SHELL_COMMAND(backgroundimage, Shell, setBackgroundImage)
    54 ->describe("sets the background image to load for the Shell");
    55 SHELL_COMMAND(font, Shell, setFont)
    56 ->describe("Sets the font of the Shell")
    57 ->defaultValues(SHELL_DEFAULT_FONT);
    58 
    59 /**
    60  * standard constructor
    61  */
    62 Shell::Shell ()
    63 {
    64   this->setClassID(CL_SHELL, "Shell");
    65   this->setName("Shell");
    66 
    67   // EVENT-Handler subscription of '`' to all States.
    68   EventHandler::getInstance()->subscribe(this, ES_ALL, SDLK_BACKQUOTE);
    69   EventHandler::getInstance()->subscribe(this, ES_ALL, SDLK_F12);
    70   EventHandler::getInstance()->subscribe(this, ES_SHELL, SDLK_PAGEUP);
    71   EventHandler::getInstance()->subscribe(this, ES_SHELL, SDLK_PAGEDOWN);
    72 
    73   // BUFFER
    74   this->bufferOffset = 0;
    75   this->bufferIterator = ShellBuffer::getInstance()->getBuffer().begin();
    76 
    77   // INPUT LINE
    78   this->setLayer(E2D_LAYER_ABOVE_ALL);
    79   this->shellInput.setLayer(E2D_LAYER_ABOVE_ALL);
    80 
    81   this->backgroundMaterial = new Material;
    82 
    83   // Element2D and generals
    84   this->setAbsCoor2D(3, -400);
    85   this->textSize = 20;
    86   this->lineSpacing = 0;
    87   this->bActive = true;
    88   this->fontFile = SHELL_DEFAULT_FONT;
    89 
    90   this->setBufferDisplaySize(10);
    91 
    92   this->setTextColor(SHELL_DEFAULT_TEXT_COLOR);
    93   this->setBackgroundColor(SHELL_DEFAULT_BACKGROUND_COLOR);
    94 
    95 
    96   this->deactivate();
    97   // register the shell at the ShellBuffer
    98   ShellBuffer::getInstance()->registerShell(this);
    99 }
    100 
    101 /**
    102  * @brief standard deconstructor
    103  */
    104 Shell::~Shell ()
    105 {
    106   ShellBuffer::getInstance()->unregisterShell(this);
    107 
    108   // delete the displayable Buffers
    109   while (!this->bufferText.empty())
    110   {
    111     delete this->bufferText.front();
    112     this->bufferText.pop_front();
    113   }
    114 
    115   // delete the inputLine
    116   delete this->backgroundMaterial;
    117 }
    118 
    119 /**
    120  * @brief activates the shell
    121  *
    122  * This also feeds the Last few lines from the main buffers into the displayBuffer
    123  */
    124 void Shell::activate()
    125 {
    126   if (this->bActive == true)
    127     PRINTF(3)("The shell is already active\n");
    128   this->bActive = true;
    129 
    130   EventHandler::getInstance()->pushState(ES_SHELL);
    131   EventHandler::getInstance()->withUNICODE(true);
    132 
    133   this->setRelCoorSoft2D(0, 0, 5);
    134 
    135   std::list<std::string>::const_iterator textLine = --ShellBuffer::getInstance()->getBuffer().end();
    136   bool top = false;
    137   for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
    138   {
    139     (*text)->setVisibility(true);
    140     if (!top)
    141     {
    142       (*text)->setText((*textLine));
    143       if (textLine != ShellBuffer::getInstance()->getBuffer().begin())
    144         top = true;
    145       textLine--;
    146     }
    147   }
    148 }
    149 
    150 /**
    151  * @brief deactiveates the Shell.
    152  */
    153 void Shell::deactivate()
    154 {
    155   if (this->bActive == false)
    156     PRINTF(3)("The shell is already inactive\n");
    157   this->bActive = false;
    158 
    159   EventHandler::getInstance()->withUNICODE(false);
    160   EventHandler::getInstance()->popState();
    161 
    162   this->setRelCoorSoft2D(0, -(int)this->shellHeight, 5);
    163 
    164   for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
    165     (*text)->setVisibility(false);
    166   this->bufferOffset = 0;
    167 }
    168 
    169 /**
    170  * @brief sets the File to load the fonts from
    171  * @param fontFile the file to load the font from
    172  *
    173  * it is quite important, that the font pointed too really exists!
    174  * (be aware that within orxonox fontFile is relative to the Data-Dir)
    175  */
    176 void Shell::setFont(const std::string& fontFile)
    177 {
    178   //   if (!ResourceManager::isInDataDir(fontFile))
    179   //     return false;
    180 
    181   this->fontFile = fontFile;
    182 
    183   this->resetValues();
    184 }
    185 
    186 /**
    187  * @brief sets the size of the text and spacing
    188  * @param textSize the size of the Text in Pixels
    189  * @param lineSpacing the size of the Spacing between two lines in pixels
    190  *
    191  * this also rebuilds the entire Text, inputLine and displayBuffer,
    192  * to be accurate again.
    193  */
    194 void Shell::setTextSize(unsigned int textSize, unsigned int lineSpacing)
    195 {
    196   this->textSize = textSize;
    197   this->lineSpacing = lineSpacing;
    198 
    199   this->resetValues();
    200 }
    201 
    202 /**
    203  * @brief sets the color of the Font.
    204  * @param r: red
    205  * @param g: green
    206  * @param b: blue
    207  * @param a: alpha-value.
    208  */
    209 void Shell::setTextColor(float r, float g, float b, float a)
    210 {
    211   this->textColor[0] = r;
    212   this->textColor[1] = g;
    213   this->textColor[2] = b;
    214   this->textColor[3] = a;
    215 
    216   this->resetValues();
    217 }
    218 
    219 
    220 /**
    221  * @brief sets the color of the Backgrond.
    222  * @param r: red
    223  * @param g: green
    224  * @param b: blue
    225  * @param a: alpha-value.
    226  */
    227 void Shell::setBackgroundColor(float r, float g, float b, float a)
    228 {
    229   this->backgroundMaterial->setDiffuse(r, g, b);
    230   this->backgroundMaterial->setTransparency(a);
    231 }
    232 
    233 /**
    234  * @brief sets a nice background image to the Shell's background
    235  * @param fileName the filename of the Image to load
    236  */
    237 void Shell::setBackgroundImage(const std::string& fileName)
    238 {
    239   this->backgroundMaterial->setDiffuseMap(fileName);
    240 }
    241 
    242 
    243 /**
    244  * @brief resets the Values of all visible shell's commandos to the Shell's stored values
    245  *
    246  * this functions synchronizes the stored Data with the visible one.
    247  */
    248 void Shell::resetValues()
    249 {
    250   this->shellInput.setFont(this->fontFile, this->textSize);
    251   this->shellInput.setColor(this->textColor[0], this->textColor[1], this->textColor[2]);
    252   this->shellInput.setBlending(this->textColor[3]);
    253   this->shellInput.setRelCoor2D(5, (this->textSize + this->lineSpacing)*(this->bufferDisplaySize));
    254   this->shellInput.setLayer(this->getLayer());
    255   if (shellInput.getParent2D() != this)
    256     this->shellInput.setParent2D(this);
    257 
    258   unsigned int i = 0;
    259   for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text, ++i)
    260   {
    261     (*text)->setFont(this->fontFile, this->textSize);
    262     (*text)->setColor(this->textColor[0], this->textColor[1], this->textColor[2]);
    263     (*text)->setBlending(this->textColor[3]);
    264     (*text)->setRelCoor2D( calculateLinePosition(i) );
    265     (*text)->setLayer(this->getLayer());
    266     if ((*text)->getParent2D() != this)
    267       (*text)->setParent2D(this);
    268   }
    269   this->shellHeight = (this->textSize + this->lineSpacing) * (bufferDisplaySize+1);
    270 }
    271 
    272 
    273 /**
    274  * @brief sets The count of Lines to display in the buffer.
    275  * @param bufferDisplaySize the count of lines to display in the Shell-Buffer.
    276  */
    277 void Shell::setBufferDisplaySize(unsigned int bufferDisplaySize)
    278 {
    279   unsigned int oldSize = this->bufferText.size();
    280   if (oldSize > bufferDisplaySize)
    281   {
    282     for (unsigned int i = bufferDisplaySize; i <= oldSize; i++)
    283     {
    284       delete this->bufferText.back();
    285       this->bufferText.pop_back();
    286     }
    287   }
    288   else if (oldSize < bufferDisplaySize)
    289   {
    290     for (unsigned int i = oldSize; i <= bufferDisplaySize; i++)
    291     {
    292       this->bufferText.push_back(new Text);
    293     }
    294   }
    295   this->bufferDisplaySize = bufferDisplaySize;
    296   this->resetValues();
    297 }
    298 
    299 /**
    300  * @brief deletes all the Buffers
    301  */
    302 void Shell::flush()
    303 {
    304   for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
    305   {
    306     (*text)->setText("");  // remove all chars from the BufferTexts.
    307   }
    308   ShellBuffer::getInstance()->flush();
    309   // BUFFER FLUSHING
    310 }
    311 
    312 /**
    313  * @brief prints out some text to the input-buffers
    314  * @param text the text to output.
    315  */
    316 void Shell::printToDisplayBuffer(const std::string& text)
    317 {
    318   this->bufferText.push_front(this->bufferText.back());
    319   this->bufferText.pop_back();
    320 
    321 
    322   unsigned int i = 0;
    323   for (std::list<Text*>::iterator textIt = ++this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt, i++)
    324   {
    325     (*textIt)->setRelCoorSoft2D(this->calculateLinePosition(i+1), 5);
    326   }
    327 
    328   this->bufferText.front()->setRelCoor2D(this->calculateLinePosition(0)- Vector2D(-1000,0));
    329   this->bufferText.front()->setRelCoorSoft2D(this->calculateLinePosition(0),10);
    330 
    331   /*  FANCY EFFECTS :)
    332     1:
    333         lastText->setRelCoor2D(this->calculateLinePosition(0)- Vector(-1000,0,0));
    334         lastText->setRelCoorSoft2D(this->calculateLinePosition(0),10);
    335     2:
    336     lastText->setRelDir2D(-90);
    337     lastText->setRelDirSoft2D(0, 20);
    338   */
    339 
    340   this->bufferText.front()->setText(text);
    341 }
    342 
    343 /**
    344  * moves the Display buffer (up + or down - )
    345  * @param lineCount the count by which to shift the InputBuffer.
    346  *
    347  * @todo make this work
    348  */
    349 void Shell::moveDisplayBuffer(int lineCount)
    350 {
    351   if (this->bufferOffset == 0)
    352   {
    353     this->bufferIterator = ShellBuffer::getInstance()->getBuffer().end();
    354     //     for (unsigned int i = 0; i < this->bufferDisplaySize; i++)
    355     //       this->bufferIterator->prevStep();
    356   }
    357 
    358   // boundraries
    359   if (this->bufferOffset + lineCount > (int)ShellBuffer::getInstance()->getBuffer().size())
    360     lineCount = (int)ShellBuffer::getInstance()->getBuffer().size()- this->bufferOffset;
    361   else if (this->bufferOffset + lineCount < 0)
    362     lineCount = -bufferOffset;
    363   this->bufferOffset += lineCount;
    364 
    365   // moving the iterator to the right position
    366   int move = 0;
    367   while (move != lineCount)
    368   {
    369     if (move < lineCount)
    370     {
    371       ++move;
    372       this->bufferIterator--;
    373     }
    374     else
    375     {
    376       --move;
    377       this->bufferIterator++;
    378     }
    379   }
    380   // redisplay the buffers
    381   std::list<std::string>::const_iterator it = this->bufferIterator;
    382   if (it == ShellBuffer::getInstance()->getBuffer().end())
    383   {
    384     /// FIXME
    385     PRINTF(1)("Should not heappen\n");
    386     it--;
    387   }
    388   for (std::list<Text*>::iterator textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt)
    389   {
    390     (*textIt)->setText((*it));
    391     if (it == ShellBuffer::getInstance()->getBuffer().begin())
     38  SHELL_COMMAND(clear, Shell, clear)
     39  ->describe("Clears the shell from unwanted lines (empties all buffers)")
     40  ->setAlias("clear");
     41  SHELL_COMMAND(deactivate, Shell, deactivate)
     42  ->describe("Deactivates the Shell. (moves it into background)")
     43  ->setAlias("hide");
     44  SHELL_COMMAND(textsize, Shell, setTextSize)
     45  ->describe("Sets the size of the Text size, linespacing")
     46  ->defaultValues(15, 0);
     47  SHELL_COMMAND(textcolor, Shell, setTextColor)
     48  ->describe("Sets the Color of the Shells Text (red, green, blue, alpha)")
     49  ->defaultValues(SHELL_DEFAULT_TEXT_COLOR);
     50  SHELL_COMMAND(backgroundcolor, Shell, setBackgroundColor)
     51  ->describe("Sets the Color of the Shells Background (red, green, blue, alpha)")
     52  ->defaultValues(SHELL_DEFAULT_BACKGROUND_COLOR);
     53  SHELL_COMMAND(backgroundimage, Shell, setBackgroundImage)
     54  ->describe("sets the background image to load for the Shell")
     55  ->completionPlugin(0, OrxShell::CompletorFileSystem());
     56  SHELL_COMMAND(font, Shell, setFont)
     57  ->describe("Sets the font of the Shell")
     58  ->defaultValues(SHELL_DEFAULT_FONT)
     59      ->completionPlugin(0, OrxShell::CompletorFileSystem(".ttf", "fonts/"));
     60
     61  /**
     62   * standard constructor
     63   */
     64  Shell::Shell ()
     65  {
     66    this->setClassID(CL_SHELL, "Shell");
     67    this->setName("Shell");
     68
     69    // EVENT-Handler subscription of '`' to all States.
     70    EventHandler::getInstance()->subscribe(this, ES_ALL, SDLK_BACKQUOTE);
     71    EventHandler::getInstance()->subscribe(this, ES_ALL, SDLK_F12);
     72    EventHandler::getInstance()->subscribe(this, ES_SHELL, SDLK_PAGEUP);
     73    EventHandler::getInstance()->subscribe(this, ES_SHELL, SDLK_PAGEDOWN);
     74
     75    // BUFFER
     76    this->bufferOffset = 0;
     77    this->bufferIterator = ShellBuffer::getInstance()->getBuffer().begin();
     78
     79    // INPUT LINE
     80    this->setLayer(E2D_LAYER_ABOVE_ALL);
     81    this->shellInput.setLayer(E2D_LAYER_ABOVE_ALL);
     82
     83    this->backgroundMaterial = new Material;
     84
     85    // Element2D and generals
     86    this->setAbsCoor2D(3, -400);
     87    this->textSize = 20;
     88    this->lineSpacing = 0;
     89    this->bActive = true;
     90    this->fontFile = SHELL_DEFAULT_FONT;
     91
     92    this->setBufferDisplaySize(10);
     93
     94    this->setTextColor(SHELL_DEFAULT_TEXT_COLOR);
     95    this->setBackgroundColor(SHELL_DEFAULT_BACKGROUND_COLOR);
     96
     97
     98    this->deactivate();
     99    // register the shell at the ShellBuffer
     100    ShellBuffer::getInstance()->registerShell(this);
     101  }
     102
     103  /**
     104   * @brief standard deconstructor
     105   */
     106  Shell::~Shell ()
     107  {
     108    ShellBuffer::getInstance()->unregisterShell(this);
     109
     110    // delete the displayable Buffers
     111    while (!this->bufferText.empty())
     112    {
     113      delete this->bufferText.front();
     114      this->bufferText.pop_front();
     115    }
     116
     117    // delete the inputLine
     118    delete this->backgroundMaterial;
     119  }
     120
     121  /**
     122   * @brief activates the shell
     123   *
     124   * This also feeds the Last few lines from the main buffers into the displayBuffer
     125   */
     126  void Shell::activate()
     127  {
     128    if (this->bActive == true)
     129      PRINTF(3)("The shell is already active\n");
     130    this->bActive = true;
     131
     132    EventHandler::getInstance()->pushState(ES_SHELL);
     133    EventHandler::getInstance()->withUNICODE(true);
     134
     135    this->setRelCoorSoft2D(0, 0, 5);
     136
     137    std::list<std::string>::const_iterator textLine = --ShellBuffer::getInstance()->getBuffer().end();
     138    bool top = false;
     139    for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
     140    {
     141      (*text)->setVisibility(true);
     142      if (!top)
     143      {
     144        (*text)->setText((*textLine));
     145        if (textLine != ShellBuffer::getInstance()->getBuffer().begin())
     146          top = true;
     147        textLine--;
     148      }
     149    }
     150  }
     151
     152  /**
     153   * @brief deactiveates the Shell.
     154   */
     155  void Shell::deactivate()
     156  {
     157    if (this->bActive == false)
     158      PRINTF(3)("The shell is already inactive\n");
     159    this->bActive = false;
     160
     161    EventHandler::getInstance()->withUNICODE(false);
     162    EventHandler::getInstance()->popState();
     163
     164    this->setRelCoorSoft2D(0, -(int)this->shellHeight, 5);
     165
     166    for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
     167      (*text)->setVisibility(false);
     168    this->bufferOffset = 0;
     169  }
     170
     171  /**
     172   * @brief sets the File to load the fonts from
     173   * @param fontFile the file to load the font from
     174   *
     175   * it is quite important, that the font pointed too really exists!
     176   * (be aware that within orxonox fontFile is relative to the Data-Dir)
     177   */
     178  void Shell::setFont(const std::string& fontFile)
     179  {
     180    //   if (!ResourceManager::isInDataDir(fontFile))
     181    //     return false;
     182
     183    this->fontFile = fontFile;
     184
     185    this->resetValues();
     186  }
     187
     188  /**
     189   * @brief sets the size of the text and spacing
     190   * @param textSize the size of the Text in Pixels
     191   * @param lineSpacing the size of the Spacing between two lines in pixels
     192   *
     193   * this also rebuilds the entire Text, inputLine and displayBuffer,
     194   * to be accurate again.
     195   */
     196  void Shell::setTextSize(unsigned int textSize, unsigned int lineSpacing)
     197  {
     198    this->textSize = textSize;
     199    this->lineSpacing = lineSpacing;
     200
     201    this->resetValues();
     202  }
     203
     204  /**
     205   * @brief sets the color of the Font.
     206   * @param r: red
     207   * @param g: green
     208   * @param b: blue
     209   * @param a: alpha-value.
     210   */
     211  void Shell::setTextColor(float r, float g, float b, float a)
     212  {
     213    this->textColor[0] = r;
     214    this->textColor[1] = g;
     215    this->textColor[2] = b;
     216    this->textColor[3] = a;
     217
     218    this->resetValues();
     219  }
     220
     221
     222  /**
     223   * @brief sets the color of the Backgrond.
     224   * @param r: red
     225   * @param g: green
     226   * @param b: blue
     227   * @param a: alpha-value.
     228   */
     229  void Shell::setBackgroundColor(float r, float g, float b, float a)
     230  {
     231    this->backgroundMaterial->setDiffuse(r, g, b);
     232    this->backgroundMaterial->setTransparency(a);
     233  }
     234
     235  /**
     236   * @brief sets a nice background image to the Shell's background
     237   * @param fileName the filename of the Image to load
     238   */
     239  void Shell::setBackgroundImage(const std::string& fileName)
     240  {
     241    this->backgroundMaterial->setDiffuseMap(fileName);
     242  }
     243
     244
     245  /**
     246   * @brief resets the Values of all visible shell's commandos to the Shell's stored values
     247   *
     248   * this functions synchronizes the stored Data with the visible one.
     249   */
     250  void Shell::resetValues()
     251  {
     252    this->shellInput.setFont(this->fontFile, this->textSize);
     253    this->shellInput.setColor(this->textColor[0], this->textColor[1], this->textColor[2]);
     254    this->shellInput.setBlending(this->textColor[3]);
     255    this->shellInput.setRelCoor2D(5, (this->textSize + this->lineSpacing)*(this->bufferDisplaySize));
     256    this->shellInput.setLayer(this->getLayer());
     257    if (shellInput.getParent2D() != this)
     258      this->shellInput.setParent2D(this);
     259
     260    unsigned int i = 0;
     261    for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text, ++i)
     262    {
     263      (*text)->setFont(this->fontFile, this->textSize);
     264      (*text)->setColor(this->textColor[0], this->textColor[1], this->textColor[2]);
     265      (*text)->setBlending(this->textColor[3]);
     266      (*text)->setRelCoor2D( calculateLinePosition(i) );
     267      (*text)->setLayer(this->getLayer());
     268      if ((*text)->getParent2D() != this)
     269        (*text)->setParent2D(this);
     270    }
     271    this->shellHeight = (this->textSize + this->lineSpacing) * (bufferDisplaySize+1);
     272  }
     273
     274
     275  /**
     276   * @brief sets The count of Lines to display in the buffer.
     277   * @param bufferDisplaySize the count of lines to display in the Shell-Buffer.
     278   */
     279  void Shell::setBufferDisplaySize(unsigned int bufferDisplaySize)
     280  {
     281    unsigned int oldSize = this->bufferText.size();
     282    if (oldSize > bufferDisplaySize)
     283    {
     284      for (unsigned int i = bufferDisplaySize; i <= oldSize; i++)
     285      {
     286        delete this->bufferText.back();
     287        this->bufferText.pop_back();
     288      }
     289    }
     290    else if (oldSize < bufferDisplaySize)
     291    {
     292      for (unsigned int i = oldSize; i <= bufferDisplaySize; i++)
     293      {
     294        this->bufferText.push_back(new Text);
     295      }
     296    }
     297    this->bufferDisplaySize = bufferDisplaySize;
     298    this->resetValues();
     299  }
     300
     301  /**
     302   * @brief deletes all the Buffers
     303   */
     304  void Shell::flush()
     305  {
     306    for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)
     307    {
     308      (*text)->setText("");  // remove all chars from the BufferTexts.
     309    }
     310    ShellBuffer::getInstance()->flush();
     311    // BUFFER FLUSHING
     312  }
     313
     314  /**
     315   * @brief prints out some text to the input-buffers
     316   * @param text the text to output.
     317   */
     318  void Shell::printToDisplayBuffer(const std::string& text)
     319  {
     320    this->bufferText.push_front(this->bufferText.back());
     321    this->bufferText.pop_back();
     322
     323
     324    unsigned int i = 0;
     325    for (std::list<Text*>::iterator textIt = ++this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt, i++)
     326    {
     327      (*textIt)->setRelCoorSoft2D(this->calculateLinePosition(i+1), 5);
     328    }
     329
     330    this->bufferText.front()->setRelCoor2D(this->calculateLinePosition(0)- Vector2D(-1000,0));
     331    this->bufferText.front()->setRelCoorSoft2D(this->calculateLinePosition(0),10);
     332
     333    /*  FANCY EFFECTS :)
     334      1:
     335          lastText->setRelCoor2D(this->calculateLinePosition(0)- Vector(-1000,0,0));
     336          lastText->setRelCoorSoft2D(this->calculateLinePosition(0),10);
     337      2:
     338      lastText->setRelDir2D(-90);
     339      lastText->setRelDirSoft2D(0, 20);
     340    */
     341
     342    this->bufferText.front()->setText(text);
     343  }
     344
     345  /**
     346   * moves the Display buffer (up + or down - )
     347   * @param lineCount the count by which to shift the InputBuffer.
     348   *
     349   * @todo make this work
     350   */
     351  void Shell::moveDisplayBuffer(int lineCount)
     352  {
     353    if (this->bufferOffset == 0)
     354    {
     355      this->bufferIterator = ShellBuffer::getInstance()->getBuffer().end();
     356      //     for (unsigned int i = 0; i < this->bufferDisplaySize; i++)
     357      //       this->bufferIterator->prevStep();
     358    }
     359
     360    // boundraries
     361    if (this->bufferOffset + lineCount > (int)ShellBuffer::getInstance()->getBuffer().size())
     362      lineCount = (int)ShellBuffer::getInstance()->getBuffer().size()- this->bufferOffset;
     363    else if (this->bufferOffset + lineCount < 0)
     364      lineCount = -bufferOffset;
     365    this->bufferOffset += lineCount;
     366
     367    // moving the iterator to the right position
     368    int move = 0;
     369    while (move != lineCount)
     370    {
     371      if (move < lineCount)
     372      {
     373        ++move;
     374        this->bufferIterator--;
     375      }
     376      else
     377      {
     378        --move;
     379        this->bufferIterator++;
     380      }
     381    }
     382    // redisplay the buffers
     383    std::list<std::string>::const_iterator it = this->bufferIterator;
     384    if (it == ShellBuffer::getInstance()->getBuffer().end())
    392385    {
    393386      /// FIXME
    394387      PRINTF(1)("Should not heappen\n");
    395       break;
    396     }
    397     it--;
    398   }
     388      it--;
     389    }
     390    for (std::list<Text*>::iterator textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt)
     391    {
     392      (*textIt)->setText((*it));
     393      if (it == ShellBuffer::getInstance()->getBuffer().begin())
     394      {
     395        /// FIXME
     396        PRINTF(1)("Should not heappen\n");
     397        break;
     398      }
     399      it--;
     400    }
     401  }
     402
     403  /**
     404   * clears the Shell (empties all buffers)
     405   */
     406  void Shell::clear()
     407  {
     408    this->flush();
     409    ShellBuffer::addBufferLineStatic("orxonox - shell\n ==================== \n", NULL);
     410  }
     411
     412  /**
     413   * listens for some event
     414   * @param event the Event happened
     415   */
     416  void Shell::process(const Event &event)
     417  {
     418    if (event.bPressed)
     419    {
     420      if (event.type == SDLK_BACKQUOTE || event.type == SDLK_F12)
     421      {
     422        if (this->bActive == false)
     423          this->activate();
     424        else
     425          this->deactivate();
     426      }
     427      else if (event.type == SDLK_PAGEUP)
     428      {
     429        this->moveDisplayBuffer(+this->bufferDisplaySize-1);
     430      }
     431      else if (event.type == SDLK_PAGEDOWN)
     432      {
     433        this->moveDisplayBuffer(-this->bufferDisplaySize+1);
     434      }
     435    }
     436  }
     437
     438  /**
     439   * displays the Shell
     440   */
     441  void Shell::draw() const
     442  {
     443    // transform for alignment.
     444    // setting the Blending effects
     445
     446    this->backgroundMaterial->select();
     447
     448    glBegin(GL_TRIANGLE_STRIP);
     449
     450    glTexCoord2f(0, 0);
     451    glVertex2f(this->getAbsCoor2D().x,   this->getAbsCoor2D().y  );
     452
     453    glTexCoord2f(1, 0);
     454    glVertex2f(GraphicsEngine::getInstance()->getResolutionX() - this->getAbsCoor2D().x, this->getAbsCoor2D().y  );
     455
     456    glTexCoord2f(0, 1);
     457    glVertex2f(this->getAbsCoor2D().x, this->getAbsCoor2D().y + this->shellHeight);
     458
     459    glTexCoord2f(1, 1);
     460    glVertex2f(GraphicsEngine::getInstance()->getResolutionX() - this->getAbsCoor2D().x, this->getAbsCoor2D().y + this->shellHeight);
     461
     462    glEnd();
     463  }
     464
     465  ///////////////////////
     466  // HELPER FUNCTIONS  //
     467  ///////////////////////
     468
     469  /**
     470   * @brief calculates the position of a Buffer-Display Line
     471   * @param lineNumber the lineNumber from the bottom to calculate the position from
     472   * @returns the Position of the Line.
     473   */
     474  Vector2D Shell::calculateLinePosition(unsigned int lineNumber)
     475  {
     476    return Vector2D(5, (this->textSize + this->lineSpacing)*(this->bufferDisplaySize - lineNumber - 2) + this->textSize);
     477  }
     478
     479
     480
     481  /**
     482   * @brief displays some nice output from the Shell
     483   */
     484  void Shell::debug() const
     485  {
     486    PRINT(3)("Debugging output to console (not this shell)\n");
     487
     488    //   if (this->pressedKey != SDLK_FIRST)
     489    //     printf("%s::%f %f\n", SDLKToKeyname(this->pressedKey), this->delayed, this->repeatDelay);
     490
     491
     492    ShellBuffer::getInstance()->debug();
     493  }
     494
     495  // void Shell::testI (int i)
     496  // {
     497  //   PRINTF(3)("This is the Test for one Int '%d'\n", i);
     498  // }
     499  //
     500  // void Shell::testS (const char* s)
     501  // {
     502  //   PRINTF(3)("This is the Test for one String '%s'\n", s);
     503  // }
     504  //
     505  // void Shell::testB (bool b)
     506  // {
     507  //   PRINTF(3)("This is the Test for one Bool: ");
     508  //   if (b)
     509  //     PRINTF(3)("true\n");
     510  //   else
     511  //     PRINTF(3)("false\n");
     512  // }
     513  //
     514  // void Shell::testF (float f)
     515  // {
     516  //   PRINTF(3)("This is the Test for one Float '%f'\n", f);
     517  // }
     518  //
     519  // void Shell::testSF (const char* s, float f)
     520  // {
     521  //   PRINTF(3)("This is the Test for one String '%s' and one Float '%f'\n",s , f);
     522  // }
     523
    399524}
    400 
    401 /**
    402  * clears the Shell (empties all buffers)
    403  */
    404 void Shell::clear()
    405 {
    406   this->flush();
    407   ShellBuffer::addBufferLineStatic("orxonox - shell\n ==================== \n", NULL);
    408 }
    409 
    410 /**
    411  * listens for some event
    412  * @param event the Event happened
    413  */
    414 void Shell::process(const Event &event)
    415 {
    416   if (event.bPressed)
    417   {
    418     if (event.type == SDLK_BACKQUOTE || event.type == SDLK_F12)
    419     {
    420       if (this->bActive == false)
    421         this->activate();
    422       else
    423         this->deactivate();
    424     }
    425     else if (event.type == SDLK_PAGEUP)
    426     {
    427       this->moveDisplayBuffer(+this->bufferDisplaySize-1);
    428     }
    429     else if (event.type == SDLK_PAGEDOWN)
    430     {
    431       this->moveDisplayBuffer(-this->bufferDisplaySize+1);
    432     }
    433   }
    434 }
    435 
    436 /**
    437  * displays the Shell
    438  */
    439 void Shell::draw() const
    440 {
    441   // transform for alignment.
    442   // setting the Blending effects
    443 
    444   this->backgroundMaterial->select();
    445 
    446   glBegin(GL_TRIANGLE_STRIP);
    447 
    448   glTexCoord2f(0, 0);
    449   glVertex2f(this->getAbsCoor2D().x,   this->getAbsCoor2D().y  );
    450 
    451   glTexCoord2f(1, 0);
    452   glVertex2f(GraphicsEngine::getInstance()->getResolutionX() - this->getAbsCoor2D().x, this->getAbsCoor2D().y  );
    453 
    454   glTexCoord2f(0, 1);
    455   glVertex2f(this->getAbsCoor2D().x, this->getAbsCoor2D().y + this->shellHeight);
    456 
    457   glTexCoord2f(1, 1);
    458   glVertex2f(GraphicsEngine::getInstance()->getResolutionX() - this->getAbsCoor2D().x, this->getAbsCoor2D().y + this->shellHeight);
    459 
    460   glEnd();
    461 }
    462 
    463 ///////////////////////
    464 // HELPER FUNCTIONS  //
    465 ///////////////////////
    466 
    467 /**
    468  * @brief calculates the position of a Buffer-Display Line
    469  * @param lineNumber the lineNumber from the bottom to calculate the position from
    470  * @returns the Position of the Line.
    471  */
    472 Vector2D Shell::calculateLinePosition(unsigned int lineNumber)
    473 {
    474   return Vector2D(5, (this->textSize + this->lineSpacing)*(this->bufferDisplaySize - lineNumber - 2) + this->textSize);
    475 }
    476 
    477 
    478 
    479 /**
    480  * @brief displays some nice output from the Shell
    481  */
    482 void Shell::debug() const
    483 {
    484   PRINT(3)("Debugging output to console (not this shell)\n");
    485 
    486   //   if (this->pressedKey != SDLK_FIRST)
    487   //     printf("%s::%f %f\n", SDLKToKeyname(this->pressedKey), this->delayed, this->repeatDelay);
    488 
    489 
    490   ShellBuffer::getInstance()->debug();
    491 }
    492 
    493 // void Shell::testI (int i)
    494 // {
    495 //   PRINTF(3)("This is the Test for one Int '%d'\n", i);
    496 // }
    497 //
    498 // void Shell::testS (const char* s)
    499 // {
    500 //   PRINTF(3)("This is the Test for one String '%s'\n", s);
    501 // }
    502 //
    503 // void Shell::testB (bool b)
    504 // {
    505 //   PRINTF(3)("This is the Test for one Bool: ");
    506 //   if (b)
    507 //     PRINTF(3)("true\n");
    508 //   else
    509 //     PRINTF(3)("false\n");
    510 // }
    511 //
    512 // void Shell::testF (float f)
    513 // {
    514 //   PRINTF(3)("This is the Test for one Float '%f'\n", f);
    515 // }
    516 //
    517 // void Shell::testSF (const char* s, float f)
    518 // {
    519 //   PRINTF(3)("This is the Test for one String '%s' and one Float '%f'\n",s , f);
    520 // }
    521 
    522 }
  • trunk/src/lib/shell/shell_command.cc

    r7421 r7422  
    173173        // Search for Objects.
    174174        if (strings.size() == 1)
    175           fillObjectList("", (*alias)->getCommand(), boList);
     175        {
     176          if (fillObjectList("", (*alias)->getCommand(), boList))
     177            ;
     178        }
    176179        else
    177180        {
  • trunk/src/lib/shell/shell_completion_plugin.cc

    r7412 r7422  
    2323#include "substring.h"
    2424#include "class_list.h"
     25#include "loading/resource_manager.h"
     26
     27#include "osdir.h"
    2528#include "debug.h"
    2629
     
    8487
    8588  CompletorFileSystem::CompletorFileSystem(const std::string& fileExtension,
    86       StartDirectory startDir,
    87       const std::string& subDir)
     89                                           const std::string& subDir,
     90                                           StartDirectory startDir)
    8891  : _fileExtension(fileExtension), _startDir(startDir), _subDir(subDir)
    8992  {  }
     
    9497    if (completionBegin.empty()) // if we do not yet have the beginning of the line, start with the chosen startDir.
    9598    {
     99      OS::Directory dir;
     100      if (this->_startDir == StartAtDataDir)
     101      {
     102        dir.open(ResourceManager::getInstance()->getDataDir());
     103      }
    96104
     105      else if(this->_startDir == StartAtRoot)
     106        dir.open("/");
     107      else
     108        dir.open(ResourceManager::homeDirCheck("~/"));
    97109
     110      while(dir)
     111      {
     112        printf("%s\n", "one\n");
     113        completionList.push_back(dir.next());
     114      }
    98115    }
    99116  }
    100117  CompletorPlugin* CompletorFileSystem::clone() const
    101118  {
    102     return new CompletorFileSystem(this->_fileExtension, this->_startDir, this->_subDir);
     119    return new CompletorFileSystem(this->_fileExtension, this->_subDir, this->_startDir);
    103120  }
    104121
  • trunk/src/lib/shell/shell_completion_plugin.h

    r7407 r7422  
    7979
    8080    CompletorFileSystem(const std::string& fileExtension = "",
    81                         StartDirectory startDir = StartAtDataDir,
    82                         const std::string& subDir = "");
     81                        const std::string& subDir = "",
     82                        StartDirectory startDir = StartAtDataDir);
    8383    virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const;
    8484    virtual CompletorPlugin* clone() const;
Note: See TracChangeset for help on using the changeset viewer.