Changeset 7894 in orxonox.OLD for branches/gui/src/lib
- Timestamp:
- May 27, 2006, 4:30:30 AM (18 years ago)
- Location:
- branches/gui/src/lib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/gui/src/lib/graphics/text_engine/text.cc
r7893 r7894 149 149 /** 150 150 * @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. 151 154 */ 152 155 void Text::removeCharacters(unsigned int chars) 153 156 { 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(); 155 162 } 156 163 -
branches/gui/src/lib/gui/gl_gui/glgui_inputline.cc
r7893 r7894 34 34 */ 35 35 GLGuiInputLine::~GLGuiInputLine() 36 { 37 } 36 {} 37 38 float GLGuiInputLine::repeatDelay = 1.0; 39 float GLGuiInputLine::repeatRate = .1; 40 38 41 39 42 /** … … 48 51 49 52 this->text.setParent2D(this); 53 this->text.setRelCoor2D(4,4); 50 54 this->text.setFont("fonts/final_frontier.ttf", 20); 51 55 52 56 this->setText("SUPERTEST"); 53 this->setSize2D( this->text.getSize2D());54 57 } 55 58 … … 57 60 { 58 61 this->text.setText(text); 62 this->resize(); 59 63 } 60 64 … … 62 66 { 63 67 this->text.append(appendText); 68 this->resize(); 64 69 } 65 70 … … 67 72 { 68 73 this->text.appendCharacter(character); 74 this->resize(); 69 75 } 70 76 … … 73 79 { 74 80 this->text.removeCharacters(chars); 81 this->resize(); 75 82 } 76 83 77 84 bool GLGuiInputLine::processEvent(const Event& event) 78 85 { 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 79 117 if (likely(event.type < 127)) 80 118 { 81 this->appendCharacter(event. x);119 this->appendCharacter(event.type); 82 120 return true; 83 121 } … … 86 124 } 87 125 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 } 88 138 89 139 /** -
branches/gui/src/lib/gui/gl_gui/glgui_inputline.h
r7893 r7894 35 35 const std::string& getName() const { return this->text.getText(); }; 36 36 37 38 virtual void tick(float dt); 37 39 virtual void draw() const; 38 40 39 41 virtual bool processEvent(const Event& event); 40 42 43 private: 44 void resize(); 45 46 41 47 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 43 59 }; 44 60 }
Note: See TracChangeset
for help on using the changeset viewer.