Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5095 in orxonox.OLD


Ignore:
Timestamp:
Aug 21, 2005, 11:50:07 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: auto-repeat-function

Location:
trunk/src/util
Files:
2 edited

Legend:

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

    r5094 r5095  
    4646  this->setBufferSize(100);
    4747  this->setBufferDisplaySize(10);
    48   this->setAbsCoor2D(2, GraphicsEngine::getInstance()->getResolutionY());
    49   this->setAbsDir2D(0);
     48  this->setAbsCoor2D(3, GraphicsEngine::getInstance()->getResolutionY());
     49  this->repeatDelay = .15;
     50  this->delayed = 0;
     51  this->pressedKey = SDLK_FIRST;
    5052
    5153  this->inputLineText = TextEngine::getInstance()->createText("fonts/earth.ttf", 10, TEXT_DYNAMIC, 255, 0, 0);
     54  this->inputLineText->setAlignment(TEXT_ALIGN_LEFT);
    5255  this->inputLineText->setText(NULL);
    5356  this->inputLine = new char[1];
    5457  this->inputLine[0] = '\0';
    55 
    56   EventHandler::getInstance()->subscribe(this, ES_GAME, SDLK_BACKQUOTE);
     58  this->inputLineText->setParent2D(this);
     59
    5760
    5861  EventHandler* evh = EventHandler::getInstance();
    59   for (int i = 1; i < EV_NUMBER; i++)
    60     EventHandler::getInstance()->subscribe(this, ES_SHELL, i);
     62  evh->subscribe(this, ES_GAME, SDLK_BACKQUOTE);
     63  for (int i = 1; i < SDLK_F15; i++)
     64    evh->subscribe(this, ES_SHELL, i);
    6165}
    6266
     
    97101    this->bufferText[i] = TextEngine::getInstance()->createText("fonts/earth.ttf", this->textSize, TEXT_DYNAMIC, 255, 0, 0);
    98102    this->bufferText[i]->setAlignment(TEXT_ALIGN_LEFT);
    99     this->bufferText[i]->setRelCoor2D(5, 12*i);
     103    this->bufferText[i]->setRelCoor2D(5, 12+12*i);
    100104    this->bufferText[i]->setText(NULL);
    101105    this->bufferText[i]->setParent2D(this);
     
    320324      this->autoComplete();
    321325    else if (event.type == SDLK_BACKSPACE)
     326    {
     327      this->delayed = this->repeatDelay;
     328      this->pressedKey = SDLK_BACKSPACE;
    322329      this->removeCharacters(1);
     330    }
    323331    else if (event.type < 127)
     332    {
     333      this->delayed = this->repeatDelay;
     334      this->pressedKey = event.type;
    324335      this->addCharacter(event.type);
     336    }
     337  }
     338  else // if(!event.bPressed)
     339  {
     340    if (this->pressedKey == event.type)
     341      this->pressedKey = SDLK_FIRST;
     342    this->delayed = 0.0;
    325343  }
    326344}
     
    330348 * @param dt the elapsed time since the last tick();
    331349 */
    332 //void Shell::tick(float dt)
    333 //{
    334 //}
     350void Shell::tick(float dt)
     351{
     352  if (this->delayed > 0.0)
     353    this->delayed -= dt;
     354  else if (this->pressedKey != SDLK_FIRST )
     355  {
     356    this->delayed = this->repeatDelay;
     357    if (this->pressedKey == SDLK_BACKSPACE)
     358      this->removeCharacters(1);
     359    else if (pressedKey < 127)
     360      this->addCharacter(this->pressedKey);
     361  }
     362}
    335363
    336364/**
  • trunk/src/util/shell.h

    r5080 r5095  
    5858
    5959    // Element2D-functions
    60 //    void tick(float dt);
     60    void tick(float dt);
    6161    virtual void draw() const;
    6262
     
    7474    unsigned int           bufferDisplaySize;      //!< The Size of the Display-buffer, in lines (not in characters)
    7575
     76    Text*                  inputLineText;          //!< The inputLine of the Shell
    7677    char*                  inputLine;              //!< the Char-Array of the Buffer
     78    float                  repeatDelay;            //!< The Repeat-Delay.
     79    float                  delayed;                //!< how much of the delay is remaining.
     80    int                    pressedKey;             //!< the pressed key that will be repeated.
    7781
    7882    tList<char>*           buffer;                 //!< A list of stored char-arrays(strings) to store the history
    7983
    8084    Text**                 bufferText;             //!< A list of stored bufferTexts for the display of the buffer
    81     Text*                  inputLineText;          //!< The inputLine of the Shell
    8285    unsigned int           textSize;               //!< The size of the text.
    8386    unsigned int           lineSpacing;            //!< The Spacing between lines.
Note: See TracChangeset for help on using the changeset viewer.