Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8359 was 8145, checked in by bensch, 19 years ago

trunk: merged the gui back
merged with command:
svn merge -r8114:HEAD https://svn.orxonox.net/orxonox/branches/gui .
→ no conflicts

File size: 4.8 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
[7779]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
[7892]50    this->text.setParent2D(this);
[7894]51    this->text.setRelCoor2D(4,4);
[7892]52    this->text.setFont("fonts/final_frontier.ttf", 20);
[8116]53    this->text.setVisibility(false);
[8035]54    this->resize();
[8116]55
[7779]56  }
[5360]57
[8035]58
59  /**
60   * @brief sets the Text of the InputLine
61   * @param text The new Text.
62   */
[7892]63  void GLGuiInputLine::setText(const std::string& text)
64  {
65    this->text.setText(text);
[7894]66    this->resize();
[8035]67
68    emit(this->textChanged(this->getText()));
[7892]69  }
70
[8035]71  /**
72   * @brief appends text to the InputLine
73   * @param appendText the Text to append
74   */
[7892]75  void GLGuiInputLine::append(const std::string& appendText)
76  {
77    this->text.append(appendText);
[7894]78    this->resize();
[8035]79    emit(this->textChanged(this->text.getText()));
[7893]80  }
[7892]81
[8035]82
83  /**
84   * @brief appends a Character to the InputLine
85   * @param character the Character to append.
86   */
[7893]87  void GLGuiInputLine::appendCharacter(char character)
88  {
89    this->text.appendCharacter(character);
[7894]90    this->resize();
[8035]91    emit(this->textChanged(this->text.getText()));
[7892]92  }
93
[7893]94
[8035]95  /**
96   * @brief Removes Characters from the InputLine
97   * @param chars The count of characters to remove
98   */
[7892]99  void GLGuiInputLine::removeCharacters(unsigned int chars)
100  {
101    this->text.removeCharacters(chars);
[7894]102    this->resize();
[8035]103    emit(this->textChanged(this->text.getText()));
[7892]104  }
105
[7896]106
[8035]107  /**
108   * removes the focus from this Widget.
109   */
[7896]110  void GLGuiInputLine::removedFocus()
111  {
112    GLGuiWidget::removedFocus();
113    this->pressedKey = 0;
114    this->pressedKeyName = 0;
115  }
116
117
[8035]118  /**
119   * Processes an Event.
120   * @param event The event to be processed
121   * @return true if the event was catched.
122   */
[7893]123  bool GLGuiInputLine::processEvent(const Event& event)
124  {
[7894]125    if (event.bPressed)
126    {
127      if (event.type == SDLK_BACKSPACE)
128      {
129        this->delayNext = GLGuiInputLine::repeatDelay;
130        this->pressedKey = SDLK_BACKSPACE;
131        this->pressedKeyName = SDLK_BACKSPACE;
132        this->removeCharacters(1);
133        return true;
134      }
135      // any other keyboard key
136      else if (likely(event.type < 127))
137      {
[7895]138        this->delayNext = GLGuiInputLine::repeatDelay;
139
[7894]140        this->appendCharacter(event.x);
141        this->pressedKey = event.type;
142        this->pressedKeyName = event.x;
143        return true;
144      }
145    }
146    else // if(!event.bPressed)
147    {
148      if (this->pressedKey == event.type)
149      {
150        this->pressedKeyName = 0;
151        this->pressedKey = 0;
152        this->delayNext = 0.0;
153        return true;
154      }
155    }
156
[7893]157    return false;
158  }
[7892]159
[7893]160
[8035]161  /**
162   * @brief Resizes the Widget to the new Size-constraints.
163   */
[7894]164  void GLGuiInputLine::resize()
165  {
[8116]166    this->text.setRelCoor2D(this->borderLeft() + 2.0,this->borderTop() + 2.0);
167    this->setSize2D( this->text.getSize2D() + Vector2D(borderLeft() + borderRight() + 4.0, borderTop() + borderBottom() + 4.0));
[8035]168    GLGuiWidget::resize();
[8115]169    this->frontRect().setTopLeft(borderLeft(), borderTop());
[8116]170    this->frontRect().setSize(this->getSize2D() - Vector2D(borderLeft() + borderRight(), borderTop() + borderBottom()));
[7894]171  }
172
173
[8116]174  void GLGuiInputLine::hiding()
175  {
176    this->text.setVisibility(false);
177  }
178
179  void GLGuiInputLine::showing()
180  {
181    this->text.setVisibility(true);
182  }
183
184
[8035]185  /**
186   * ticks the InputLine
187   * @param dt the time passed.
188   */
[7894]189  void GLGuiInputLine::tick(float dt)
190  {
191    if (this->delayNext > 0.0)
192      this->delayNext -= dt;
[7895]193        else if (this->pressedKey != SDLK_FIRST )
194    {
195      this->delayNext = GLGuiInputLine::repeatRate;
196      switch (this->pressedKey)
197      {
198        case SDLK_BACKSPACE:
199          this->removeCharacters(1);
200          break;
201        default:
202        {
203          if (likely(this->pressedKey < 127))
204            this->appendCharacter(this->pressedKeyName);
205        }
206      }
207    }
208
209
[7894]210  }
211
[7779]212  /**
[8035]213   * @brief draws the GLGuiInputLine
[7779]214   */
[7892]215  void GLGuiInputLine::draw() const
[7779]216  {
[8035]217    this->beginDraw();
[7892]218    GLGuiWidget::draw();
219
220    this->frontMaterial().select();
[8035]221    GLGuiWidget::drawRect(this->frontRect());
[7892]222
223    this->endDraw();
[7779]224  }
[5360]225}
Note: See TracBrowser for help on using the repository browser.