Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7894 in orxonox.OLD


Ignore:
Timestamp:
May 27, 2006, 4:30:30 AM (18 years ago)
Author:
bensch
Message:

Safer InputLine

Location:
branches/gui/src/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/gui/src/lib/graphics/text_engine/text.cc

    r7893 r7894  
    149149/**
    150150 * @brief removes char characters from the Text.
     151 *
     152 * @note this function checks, if the count can be removed, and if so does it.
     153 * Otherwise the maximum count of characters will be removed.
    151154 */
    152155void Text::removeCharacters(unsigned int chars)
    153156{
    154   this->text.resize(this->text.size()-chars);
     157  if (text.size() > chars)
     158    this->text.resize(this->text.size()-chars);
     159  else if (!text.empty())
     160    text.clear();
     161  this->setupTextWidth();
    155162}
    156163
  • branches/gui/src/lib/gui/gl_gui/glgui_inputline.cc

    r7893 r7894  
    3434  */
    3535  GLGuiInputLine::~GLGuiInputLine()
    36   {
    37   }
     36  {}
     37
     38  float GLGuiInputLine::repeatDelay = 1.0;
     39  float GLGuiInputLine::repeatRate = .1;
     40
    3841
    3942  /**
     
    4851
    4952    this->text.setParent2D(this);
     53    this->text.setRelCoor2D(4,4);
    5054    this->text.setFont("fonts/final_frontier.ttf", 20);
    5155
    5256    this->setText("SUPERTEST");
    53     this->setSize2D( this->text.getSize2D());
    5457  }
    5558
     
    5760  {
    5861    this->text.setText(text);
     62    this->resize();
    5963  }
    6064
     
    6266  {
    6367    this->text.append(appendText);
     68    this->resize();
    6469  }
    6570
     
    6772  {
    6873    this->text.appendCharacter(character);
     74    this->resize();
    6975  }
    7076
     
    7379  {
    7480    this->text.removeCharacters(chars);
     81    this->resize();
    7582  }
    7683
    7784  bool GLGuiInputLine::processEvent(const Event& event)
    7885  {
     86    if (event.bPressed)
     87    {
     88      if (event.type == SDLK_BACKSPACE)
     89      {
     90        this->delayNext = GLGuiInputLine::repeatDelay;
     91        this->pressedKey = SDLK_BACKSPACE;
     92        this->pressedKeyName = SDLK_BACKSPACE;
     93        this->removeCharacters(1);
     94        return true;
     95      }
     96      // any other keyboard key
     97      else if (likely(event.type < 127))
     98      {
     99        this->appendCharacter(event.x);
     100        this->pressedKey = event.type;
     101        this->pressedKeyName = event.x;
     102        return true;
     103      }
     104      this->delayNext = this->repeatDelay;
     105    }
     106    else // if(!event.bPressed)
     107    {
     108      if (this->pressedKey == event.type)
     109      {
     110        this->pressedKeyName = 0;
     111        this->pressedKey = 0;
     112        this->delayNext = 0.0;
     113        return true;
     114      }
     115    }
     116
    79117    if (likely(event.type < 127))
    80118    {
    81       this->appendCharacter(event.x);
     119      this->appendCharacter(event.type);
    82120      return true;
    83121    }
     
    86124  }
    87125
     126
     127  void GLGuiInputLine::resize()
     128  {
     129    this->setSize2D( this->text.getSize2D() + Vector2D(8, 8));
     130  }
     131
     132
     133  void GLGuiInputLine::tick(float dt)
     134  {
     135    if (this->delayNext > 0.0)
     136      this->delayNext -= dt;
     137  }
    88138
    89139  /**
  • branches/gui/src/lib/gui/gl_gui/glgui_inputline.h

    r7893 r7894  
    3535    const std::string& getName() const { return this->text.getText(); };
    3636
     37
     38    virtual void tick(float dt);
    3739    virtual void draw() const;
    3840
    3941    virtual bool processEvent(const Event& event);
    4042
     43    private:
     44      void resize();
     45
     46
    4147  private:
    42     Text                    text;
     48    Text                    text;             //!< The Text to display inside of the InputLine.
     49
     50    Uint16                  pressedKey;       //!< the pressed key that will be repeated.
     51    Uint16                  pressedKeyName;   //!< The Name of the Key, that was pressed.
     52
     53    float                   delayNext;        //!< How much time must pass before next output.
     54
     55    static float            repeatDelay;
     56    static float            repeatRate;
     57
     58
    4359  };
    4460}
Note: See TracChangeset for help on using the changeset viewer.