Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gl/glgui_textfield.cc @ 9023

Last change on this file since 9023 was 9015, checked in by bensch, 18 years ago

orxonox/trunk: text-field

File size: 3.5 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
[7919]18#include "glgui_textfield.h"
[9015]19
20#include "text.h"
21
[7779]22namespace OrxGui
[3365]23{
[7779]24  /**
25   * standard constructor
26  */
27  GLGuiTextfield::GLGuiTextfield ()
28  {
29    this->init();
[1853]30
[7779]31  }
[1853]32
[5360]33
[7779]34  /**
35   * standard deconstructor
36  */
37  GLGuiTextfield::~GLGuiTextfield()
[9015]38  {}
[5360]39
[7779]40  /**
41   * initializes the GUI-element
42   */
43  void GLGuiTextfield::init()
44  {
[7919]45    this->setClassID(CL_GLGUI_TEXTFIELD, "GLGuiTextfield");
[9015]46
47    this->_text.setParent2D(this);
48    this->_text.setRelCoor2D(4,4);
49    this->_text.setFont("fonts/final_frontier.ttf", 20);
50    this->_text.setLineWidth(400);
51    this->_text.setColor(foregroundColor());
52    this->_text.setVisibility(false);
53    this->_changedTextColor = Color::white;
54    this->resize();
[7779]55  }
[5360]56
[7779]57  /**
[9015]58  * @brief sets the Text of the Text
59  * @param text The new Text.
[7779]60   */
[9015]61  void GLGuiTextfield::setText(const std::string& text)
62  {
63    this->_text.setText(text);
64    this->changedText();
65  }
66
67  /**
68   * @brief appends text to the Text
69   * @param appendText the Text to append
70   */
71  void GLGuiTextfield::append(const std::string& appendText)
72  {
73    this->_text.append(appendText);
74    this->changedText();
75  }
76
77
78  /**
79   * @brief appends a Character to the Text
80   * @param character the Character to append.
81   */
82  void GLGuiTextfield::appendCharacter(char character)
83  {
84    this->_text.appendCharacter(character);
85    this->changedText();
86  }
87
88
89  /**
90   * @brief Removes Characters from the Text
91   * @param chars The count of characters to remove
92   */
93  void GLGuiTextfield::removeCharacters(unsigned int chars)
94  {
95    this->_text.removeCharacters(chars);
96    this->changedText();
97  }
98
99  void GLGuiTextfield::clear()
100  {
101    this->_text.clear();
102    this->changedText();
103  }
104
105  /**
106  * @brief If the Text has been changed this function is called.
107  *
108  * This Function also emits the Signal textChanged.
109   */
110  void GLGuiTextfield::changedText()
111  {
112    this->resize();
113    this->setFrontColor(_changedTextColor, true);
114    emit(this->textChanged(this->_text.text()));
115  }
116
117  void GLGuiTextfield::setChangedTextColor(const Color& color)
118  {
119    this->_changedTextColor = color;
120  }
121
122  /**
123   * @brief Resizes the Widget to the new Size-constraints.
124   */
125  void GLGuiTextfield::resize()
126  {
127    this->_text.setRelCoor2D(borderLeft(), borderTop());
128    this->setSize2D( this->_text.getSize2D() + Vector2D(borderLeft() + borderRight(), borderTop() + borderBottom()));
129    //this->_text.setLineWidth(this->size2D);
130    GLGuiWidget::resize();
131    /*    this->frontRect().setTopLeft(borderLeft(), borderTop());
132    this->frontRect().setSize(this->getSize2D() - Vector2D(borderLeft() + borderRight(), borderTop() + borderBottom()));*/
133  }
134
135  void GLGuiTextfield::updateFrontColor()
136  {
137    this->_text.setColor(foregroundColor());
138  }
139
140  void GLGuiTextfield::hiding()
141  {
142    this->_text.setVisibility(false);
143  }
144
145  void GLGuiTextfield::showing()
146  {
147    this->_text.setVisibility(true);
148  }
149
150
151
152  /**
153   * draws the GLGuiTextfield
154   */
[7919]155  void GLGuiTextfield::draw() const
[7779]156  {
[8035]157    this->beginDraw();
158    GLGuiWidget::draw();
159
[9015]160    //     this->frontMaterial().select();
161    //     GLGuiWidget::drawRect(this->frontRect());
162
[8035]163    this->endDraw();
[7779]164  }
[5360]165}
Note: See TracBrowser for help on using the repository browser.