Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gl/glgui_inputline.cc @ 8453

Last change on this file since 8453 was 8448, checked in by bensch, 18 years ago

merged gui back to the trunk
merged with command
merge -r8377:HEAD https://svn.orxonox.net/orxonox/branches/gui .

File size: 5.2 KB
RevLine 
[4744]1/*
[1853]2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
[1855]10
11   ### File Specific:
[5360]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[5360]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI
[1853]17
[7892]18#include "glgui_inputline.h"
[1853]19
[7779]20namespace OrxGui
[3365]21{
[7779]22  /**
[8035]23   * @brief standard constructor
[8448]24   */
[7892]25  GLGuiInputLine::GLGuiInputLine ()
[7779]26  {
27    this->init();
28  }
[1853]29
30
[7779]31  /**
[8035]32   * @brief standard deconstructor
33   */
[7892]34  GLGuiInputLine::~GLGuiInputLine()
[7894]35  {}
[5360]36
[7895]37  float GLGuiInputLine::repeatDelay = 0.3f;
38  float GLGuiInputLine::repeatRate  = 0.01f;
[7894]39
40
[7779]41  /**
[8035]42   * @brief initializes the GUI-element
[7779]43   */
[7892]44  void GLGuiInputLine::init()
[7779]45  {
[7892]46    this->setClassID(CL_GLGUI_INPUTLINE, "GLGuiInputLine");
[7893]47
48    this->setFocusable(true);
49
[8448]50    this->_text.setParent2D(this);
51    this->_text.setRelCoor2D(4,4);
52    this->_text.setFont("fonts/final_frontier.ttf", 20);
53    this->_text.setColor(this->frontColor());
54    this->_text.setVisibility(false);
[8035]55    this->resize();
[8116]56
[7779]57  }
[5360]58
[8035]59
60  /**
61   * @brief sets the Text of the InputLine
62   * @param text The new Text.
63   */
[7892]64  void GLGuiInputLine::setText(const std::string& text)
65  {
[8448]66    this->_text.setText(text);
67    this->changedText();
[7892]68  }
69
[8035]70  /**
71   * @brief appends text to the InputLine
72   * @param appendText the Text to append
73   */
[7892]74  void GLGuiInputLine::append(const std::string& appendText)
75  {
[8448]76    this->_text.append(appendText);
77    this->changedText();
[7893]78  }
[7892]79
[8035]80
81  /**
82   * @brief appends a Character to the InputLine
83   * @param character the Character to append.
84   */
[7893]85  void GLGuiInputLine::appendCharacter(char character)
86  {
[8448]87    this->_text.appendCharacter(character);
88    this->changedText();
[7892]89  }
90
[7893]91
[8035]92  /**
93   * @brief Removes Characters from the InputLine
94   * @param chars The count of characters to remove
95   */
[7892]96  void GLGuiInputLine::removeCharacters(unsigned int chars)
97  {
[8448]98    this->_text.removeCharacters(chars);
99    this->changedText();
100  }
101
102  /**
103   * @brief If the Text has been changed this function is called.
104   *
105   * This Function also emits the Signal textChanged.
106   */
107  void GLGuiInputLine::changedText()
108  {
[7894]109    this->resize();
[8448]110    this->setFrontColor(Color(1,1,1,1), true);
111    this->setFrontColor(Color(0,1,0,1));
112    emit(this->textChanged(this->_text.getText()));
[7892]113  }
114
[7896]115
[8035]116  /**
117   * removes the focus from this Widget.
118   */
[7896]119  void GLGuiInputLine::removedFocus()
120  {
121    GLGuiWidget::removedFocus();
122    this->pressedKey = 0;
123    this->pressedKeyName = 0;
124  }
125
126
[8035]127  /**
[8448]128   * @brief Processes an Event.
[8035]129   * @param event The event to be processed
130   * @return true if the event was catched.
131   */
[7893]132  bool GLGuiInputLine::processEvent(const Event& event)
133  {
[7894]134    if (event.bPressed)
135    {
136      if (event.type == SDLK_BACKSPACE)
137      {
138        this->delayNext = GLGuiInputLine::repeatDelay;
139        this->pressedKey = SDLK_BACKSPACE;
140        this->pressedKeyName = SDLK_BACKSPACE;
141        this->removeCharacters(1);
142        return true;
143      }
144      // any other keyboard key
145      else if (likely(event.type < 127))
146      {
[7895]147        this->delayNext = GLGuiInputLine::repeatDelay;
148
[7894]149        this->appendCharacter(event.x);
150        this->pressedKey = event.type;
151        this->pressedKeyName = event.x;
152        return true;
153      }
154    }
155    else // if(!event.bPressed)
156    {
157      if (this->pressedKey == event.type)
158      {
159        this->pressedKeyName = 0;
160        this->pressedKey = 0;
161        this->delayNext = 0.0;
162        return true;
163      }
164    }
[7893]165    return false;
166  }
[7892]167
[7893]168
[8035]169  /**
170   * @brief Resizes the Widget to the new Size-constraints.
171   */
[7894]172  void GLGuiInputLine::resize()
173  {
[8448]174    this->_text.setRelCoor2D(this->borderLeft(), this->borderTop());
175    this->setSize2D( this->_text.getSize2D() + Vector2D(borderLeft() + borderRight(), borderTop() + borderBottom()));
[8035]176    GLGuiWidget::resize();
[8448]177/*    this->frontRect().setTopLeft(borderLeft(), borderTop());
178    this->frontRect().setSize(this->getSize2D() - Vector2D(borderLeft() + borderRight(), borderTop() + borderBottom()));*/
[7894]179  }
180
[8448]181  void GLGuiInputLine::updateFrontColor()
182  {
183    this->_text.setColor(this->frontColor());
184  }
[7894]185
[8116]186  void GLGuiInputLine::hiding()
187  {
[8448]188    this->_text.setVisibility(false);
[8116]189  }
190
191  void GLGuiInputLine::showing()
192  {
[8448]193    this->_text.setVisibility(true);
[8116]194  }
195
[8035]196  /**
[8448]197   * @brief ticks the InputLine
[8035]198   * @param dt the time passed.
199   */
[7894]200  void GLGuiInputLine::tick(float dt)
201  {
[8448]202    GLGuiWidget::tick(dt);
[7894]203    if (this->delayNext > 0.0)
204      this->delayNext -= dt;
[7895]205        else if (this->pressedKey != SDLK_FIRST )
206    {
207      this->delayNext = GLGuiInputLine::repeatRate;
208      switch (this->pressedKey)
209      {
210        case SDLK_BACKSPACE:
211          this->removeCharacters(1);
212          break;
213        default:
214        {
215          if (likely(this->pressedKey < 127))
216            this->appendCharacter(this->pressedKeyName);
217        }
218      }
219    }
220
221
[7894]222  }
223
[7779]224  /**
[8035]225   * @brief draws the GLGuiInputLine
[7779]226   */
[7892]227  void GLGuiInputLine::draw() const
[7779]228  {
[8035]229    this->beginDraw();
[7892]230    GLGuiWidget::draw();
231
[8448]232//     this->frontMaterial().select();
233//     GLGuiWidget::drawRect(this->frontRect());
[7892]234
235    this->endDraw();
[7779]236  }
[5360]237}
Note: See TracBrowser for help on using the repository browser.