Changeset 8717 in orxonox.OLD for trunk/src/lib/gui
- Timestamp:
- Jun 22, 2006, 2:04:28 PM (19 years ago)
- Location:
- trunk/src/lib/gui/gl
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/gui/gl/Makefile.am
r8619 r8717 60 60 specials/glgui_notifier.h 61 61 62 63 64 65 66 62 EXTRA_DIST = 67 -
trunk/src/lib/gui/gl/glgui_box.cc
r8619 r8717 125 125 height += borderBottom(); /* *2 done further up */ 126 126 127 printf("%f %f\n", width, height);128 127 this->setSize2D(width, height); 129 128 } … … 145 144 height += borderBottom(); /* *2 done further up */ 146 145 147 printf("%f %f\n", width, height);148 146 this->setSize2D(width, height); 149 147 } -
trunk/src/lib/gui/gl/glgui_button.cc
r8619 r8717 51 51 { 52 52 this->setClassID(CL_GLGUI_BUTTON, "GLGuiButton"); 53 54 this->setSelectable(true); 53 55 this->setFocusable(true); 54 56 this->setClickable(true); … … 79 81 emit(clicked()); 80 82 } 81 void GLGuiButton::releasing(const Vector2D& pos )83 void GLGuiButton::releasing(const Vector2D& pos, bool focused) 82 84 { 83 GLGuiWidget::releasing(pos );85 GLGuiWidget::releasing(pos, focused); 84 86 emit(released()); 85 87 } … … 96 98 97 99 100 bool GLGuiButton::processEvent(const Event& event) 101 { 102 if (event.type == SDLK_SPACE && !event.bPressed) 103 { 104 emit(released()); 105 return true; 106 } 107 return false; 108 } 109 110 98 111 /** 99 112 * @brief draws the GLGuiButton -
trunk/src/lib/gui/gl/glgui_button.h
r8619 r8717 40 40 41 41 virtual void draw() const; 42 virtual bool processEvent(const Event& event); 42 43 43 44 DeclareSignal0(clicked); 44 45 DeclareSignal0(released); 46 45 47 46 48 protected: … … 48 50 49 51 virtual void clicking(const Vector2D& pos); 50 virtual void releasing(const Vector2D& pos );52 virtual void releasing(const Vector2D& pos, bool focused); 51 53 virtual void hiding(); 52 54 virtual void showing(); -
trunk/src/lib/gui/gl/glgui_checkbutton.cc
r8619 r8717 78 78 79 79 80 void GLGuiCheckButton::releasing(const Vector2D& pos )80 void GLGuiCheckButton::releasing(const Vector2D& pos, bool focused) 81 81 { 82 GLGuiButton::releasing(pos); 83 this->toggleActiveState(); 82 GLGuiButton::releasing(pos, focused); 83 if (focused) 84 this->toggleActiveState(); 84 85 } 85 86 -
trunk/src/lib/gui/gl/glgui_checkbutton.h
r8448 r8717 38 38 protected: 39 39 virtual void resize(); 40 virtual void releasing(const Vector2D& pos );40 virtual void releasing(const Vector2D& pos, bool focused); 41 41 42 42 private: -
trunk/src/lib/gui/gl/glgui_handler.cc
r8711 r8717 25 25 #include <cassert> 26 26 27 #include "debug.h" 28 27 29 #include <cassert> 28 30 … … 99 101 } 100 102 103 void GLGuiHandler::selectNext() 104 { 105 // retrieve Objects. 106 const std::list<BaseObject*>* objects = ClassList::getList(CL_GLGUI_WIDGET); 107 108 if (objects) 109 { 110 std::list<BaseObject*>::const_iterator it ; 111 std::list<BaseObject*>::const_iterator currentIt = objects->end(); 112 113 if (GLGuiWidget::selected() != NULL) 114 { 115 it = std::find(objects->begin(), objects->end(), GLGuiWidget::selected()); 116 if (it != objects->end()) 117 { 118 currentIt = it; 119 it++; 120 } 121 } 122 else 123 { 124 it = objects->begin(); 125 } 126 127 bool cycledOnce = false; 128 129 for (; it != currentIt; ++it) 130 { 131 if (it == objects->end() && !cycledOnce) 132 { 133 it = objects->begin(); 134 cycledOnce = true; 135 } 136 137 if (dynamic_cast<GLGuiWidget*>(*it)->selectable()) 138 { 139 dynamic_cast<GLGuiWidget*>(*it)->select(); 140 return; 141 } 142 } 143 144 } 145 else 146 { 147 PRINTF(0)("NO GUI-ELEMENTS EXISTING\n"); 148 } 149 } 150 151 void GLGuiHandler::selectPrevious() 152 { 153 // retrieve Objects. 154 const std::list<BaseObject*>* objects = ClassList::getList(CL_GLGUI_WIDGET); 155 156 if (objects) 157 { 158 std::list<BaseObject*>::const_iterator it ; 159 std::list<BaseObject*>::const_iterator currentIt = objects->begin(); 160 161 if (GLGuiWidget::selected() != NULL) 162 { 163 it = std::find(objects->begin(), objects->end(), GLGuiWidget::selected()); 164 if (it != objects->end()) 165 { 166 currentIt = it; 167 it--; 168 } 169 } 170 else 171 { 172 it = objects->end(); 173 } 174 175 bool cycledOnce = false; 176 177 for (; it != currentIt; --it) 178 { 179 if (it == objects->end() && !cycledOnce) 180 { 181 --it ; 182 cycledOnce = true; 183 } 184 185 if (dynamic_cast<GLGuiWidget*>(*it)->selectable()) 186 { 187 dynamic_cast<GLGuiWidget*>(*it)->select(); 188 return; 189 } 190 } 191 192 } 193 else 194 { 195 PRINTF(0)("NO GUI-ELEMENTS EXISTING\n"); 196 } 197 } 198 199 101 200 102 201 void GLGuiHandler::process(const Event &event) … … 105 204 { 106 205 case EV_MOUSE_BUTTON_LEFT: 107 if (GLGuiWidget::focused() != NULL) 108 { 109 if (event.bPressed) 206 if (GLGuiWidget::mouseFocused() != NULL && event.bPressed) 207 { 208 // if clickable select the Widget. 209 if (GLGuiWidget::mouseFocused()->clickable()) 110 210 { 111 if (GLGuiWidget::focused()->clickable()) 112 { 113 Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y); 114 GLGuiWidget::focused()->click(cursorPos - GLGuiWidget::focused()->getAbsCoor2D()); 115 } 211 Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y); 212 GLGuiWidget::mouseFocused()->select(); 213 GLGuiWidget::mouseFocused()->click(cursorPos - GLGuiWidget::mouseFocused()->getAbsCoor2D()); 116 214 } 117 else 215 } 216 else if (GLGuiWidget::selected() != NULL && !event.bPressed) 217 { 218 if (GLGuiWidget::selected()->clickable()) 118 219 { 119 if (GLGuiWidget::focused()->clickable()) 120 { 121 Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y); 122 GLGuiWidget::focused()->release(cursorPos - GLGuiWidget::focused()->getAbsCoor2D()); 123 } 220 Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y); 221 GLGuiWidget::selected()->release(cursorPos - GLGuiWidget::selected()->getAbsCoor2D()); 124 222 } 125 223 } 224 126 225 break; 127 226 case EV_LEAVE_STATE: 128 if (GLGuiWidget::focused() != NULL) 129 GLGuiWidget::focused()->breakFocus(); 227 if (GLGuiWidget::selected() != NULL) 228 GLGuiWidget::selected()->unselect(); 229 230 if (GLGuiWidget::mouseFocused() != NULL) 231 GLGuiWidget::mouseFocused()->breakMouseFocus(); 130 232 break; 131 233 … … 134 236 this->_cursor->setMaxBorders(Vector2D(event.resize.w, event.resize.h)); 135 237 break; 136 } 137 138 139 140 if (GLGuiWidget::focused()) 141 { 142 GLGuiWidget::focused()->processEvent(event); 238 case SDLK_TAB: 239 if (event.bPressed) 240 this->selectNext(); 241 break; 242 } 243 244 if (GLGuiWidget::selected() != NULL) 245 { 246 GLGuiWidget::selected()->processEvent(event); 143 247 } 144 248 … … 160 264 return Vector2D::nullVector(); 161 265 } 266 162 267 Vector2D GLGuiHandler::cursorPositionRel(const GLGuiWidget* const widget) const 163 268 { … … 170 275 171 276 172 void GLGuiHandler::draw() 173 { 174 // GLGuiMainWidget::getInstance()->draw2D(E2D_LAYER_TOP); 175 } 176 177 178 void GLGuiHandler::tick(float dt) 179 { 180 181 // CHECK THE COLLISIONS. 277 void GLGuiHandler::checkFocus() 278 { 279 // CHECK THE COLLISIONS. 182 280 const std::list<BaseObject*>* objects = ClassList::getList(CL_GLGUI_WIDGET); 183 281 … … 193 291 { 194 292 // receiving Focus 195 if (GLGuiWidget:: focused() != widget)293 if (GLGuiWidget::mouseFocused() != widget) 196 294 { 197 widget->give Focus();295 widget->giveMouseFocus(); 198 296 } 199 297 return ; 200 298 } 201 299 } 202 if (GLGuiWidget::focused() != NULL) 203 GLGuiWidget::focused()->breakFocus(); 204 } 300 if (GLGuiWidget::mouseFocused() != NULL) 301 GLGuiWidget::mouseFocused()->breakMouseFocus(); 302 } 303 } 304 305 void GLGuiHandler::draw() 306 { 307 // GLGuiMainWidget::getInstance()->draw2D(E2D_LAYER_TOP); 308 } 309 310 311 void GLGuiHandler::tick(float dt) 312 { 313 // do not change if we already clicked into a Widget. 314 // if (GLGuiWidget::selected() != NULL && GLGuiWidget::selected()->pushed()) 315 // return ; 316 317 this->checkFocus(); 205 318 } 206 319 } -
trunk/src/lib/gui/gl/glgui_handler.h
r8324 r8717 34 34 Vector2D cursorPositionRel(const GLGuiWidget* const widget) const; 35 35 36 void selectNext(); 37 void selectPrevious(); 38 36 39 void activate(); 37 40 void deactivate(); 38 41 42 void checkFocus(); 39 43 40 44 virtual void process(const Event &event); -
trunk/src/lib/gui/gl/glgui_inputline.cc
r8619 r8717 47 47 48 48 this->setFocusable(true); 49 this->setClickable(true); 50 this->setSelectable(true); 49 51 50 52 this->_clearOnEnter = false; -
trunk/src/lib/gui/gl/glgui_pushbutton.cc
r8448 r8717 63 63 void GLGuiPushButton::receivedFocus() 64 64 { 65 printf("%s received focus\n", this->label().c_str());66 65 GLGuiWidget::receivedFocus(); 67 66 } … … 69 68 void GLGuiPushButton::removedFocus() 70 69 { 71 printf("%s removed focus\n", this->label().c_str());72 70 GLGuiWidget::removedFocus(); 73 71 … … 76 74 void GLGuiPushButton::clicking(const Vector2D& pos) 77 75 { 78 printf("%s clicked\n", this->label().c_str());79 76 GLGuiButton::clicking(pos); 80 77 } 81 78 82 79 83 void GLGuiPushButton::releasing(const Vector2D& pos )80 void GLGuiPushButton::releasing(const Vector2D& pos, bool focused) 84 81 { 85 printf("%s released\n", this->label().c_str());86 GLGuiButton::releasing(pos);82 if (focused) 83 GLGuiButton::releasing(pos, focused); 87 84 } 88 85 -
trunk/src/lib/gui/gl/glgui_pushbutton.h
r8145 r8717 31 31 virtual void draw() const; 32 32 virtual void update(); 33 33 34 protected: 34 35 virtual void resize(); 35 36 virtual void clicking(const Vector2D& pos); 36 virtual void releasing(const Vector2D& pos );37 virtual void releasing(const Vector2D& pos, bool focused); 37 38 virtual void receivedFocus(); 38 39 virtual void removedFocus(); -
trunk/src/lib/gui/gl/glgui_slider.cc
r8619 r8717 48 48 this->setClassID(CL_GLGUI_SLIDER, "GLGuiSlider"); 49 49 50 this->setClickable( ); 51 this->setFocusable( ); 50 this->setClickable(true); 51 this->setFocusable(true); 52 this->setSelectable(true); 52 53 53 54 this->_value = 0.0; … … 193 194 } 194 195 195 void GLGuiSlider::releasing(const Vector2D& pos )196 { 197 GLGuiWidget::releasing(pos );196 void GLGuiSlider::releasing(const Vector2D& pos, bool focused) 197 { 198 GLGuiWidget::releasing(pos, focused); 198 199 this->grabbed = false; 199 200 } … … 202 203 { 203 204 GLGuiWidget::removedFocus(); 204 this->grabbed = false;205 205 } 206 206 -
trunk/src/lib/gui/gl/glgui_slider.h
r8448 r8717 59 59 60 60 virtual void clicking(const Vector2D& pos); 61 virtual void releasing(const Vector2D& pos );61 virtual void releasing(const Vector2D& pos, bool focused); 62 62 virtual void removedFocus(); 63 63 -
trunk/src/lib/gui/gl/glgui_table.cc
r8619 r8717 19 19 #include "debug.h" 20 20 21 #include "glgui_handler.h" 22 21 23 namespace OrxGui 22 24 { … … 25 27 */ 26 28 GLGuiTable::GLGuiTable (unsigned int rows, unsigned int columns) 29 : _selected(-1, -1), _focused(-1, -1) 27 30 { 28 31 this->init(); 32 29 33 this->setRowCount(rows); 30 34 this->setColumnCount(columns); … … 45 49 this->setClassID(CL_GLGUI_TABLE, "GLGuiTable"); 46 50 51 this->setBorderTop(10); 52 47 53 this->setFocusable(true); 48 54 this->setClickable(true); 49 55 50 this->resize();51 56 } 52 57 … … 56 61 57 62 unsigned int currentRowCount = this->rowCount(); 63 64 this->_rowHeights.resize(rowCount, 20); 65 58 66 this->_entries.resize(rowCount); 59 67 for (unsigned int i = currentRowCount; i < this->rowCount(); ++i) … … 65 73 66 74 assert(this->checkIntegrity()); 67 this->debug(); 75 this->repositionText(currentRowCount, 0); 76 77 78 this->resize(); 68 79 69 80 if (!this->isVisible()) … … 75 86 unsigned int i; 76 87 unsigned int currentColumnCount = this->columnCount(); 88 89 this->_columnWidths.resize(columnCount, 100); 77 90 78 91 // setup Headers. … … 89 102 } 90 103 assert(this->checkIntegrity()); 91 this->debug(); 92 104 105 this->repositionText(0, currentColumnCount); 106 107 this->resize(); 93 108 if (!this->isVisible()) 94 109 this->hiding(); … … 111 126 } 112 127 113 void GLGuiTable::setEntry(unsigned int column, unsigned int row, const std::string& name)128 void GLGuiTable::setEntry(unsigned int row, unsigned int column, const std::string& name) 114 129 { 115 130 if (column >= this->columnCount() ) … … 125 140 for (unsigned int i = 0; i < this->rowCount(); ++i) 126 141 this->_entries[i][column].setLineWidth(size); 127 128 } 142 } 143 144 129 145 130 146 /// TODO. … … 144 160 145 161 146 147 162 /** 148 163 * @brief Processes an Event. … … 152 167 bool GLGuiTable::processEvent(const Event& event) 153 168 { 169 if (event.type == EV_MOUSE_MOTION) 170 { 171 this->pixelPositionToElement((OrxGui::GLGuiHandler::getInstance()->cursorPositionRel(this)), &this->_focused.row, &this->_focused.column); 172 return true; 173 } 174 154 175 return false; 155 176 } … … 161 182 void GLGuiTable::resize() 162 183 { 184 Vector2D size; 185 unsigned int i; 186 for(i = 0; i < this->columnCount(); ++i) 187 size.x += this->_columnWidths[i]; 188 189 for(i = 0; i < this->rowCount(); ++i) 190 size.y += this->_rowHeights[i]; 191 192 this->setSize2D(size); 193 this->setSize2D( size + Vector2D(borderLeft() + borderRight(), borderTop() + borderBottom())); 194 163 195 GLGuiWidget::resize(); 164 196 } … … 172 204 this->_entries[j][i].setColor(this->foregroundColor()); 173 205 } 206 174 207 } 175 208 … … 196 229 197 230 /** 198 * @brief ticks the Table199 * @param dt the time passed.200 */201 void GLGuiTable::tick(float dt)202 {}203 204 /**205 231 * @brief draws the GLGuiTable 206 232 */ … … 210 236 GLGuiWidget::draw(); 211 237 212 // this->frontMaterial().select(); 213 // GLGuiWidget::drawRect(this->frontRect()); 238 float columnPos = this->borderLeft(); 239 float rowPos = this->borderTop(); 240 241 unsigned int i; 242 glColor4fv(&this->foregroundColor()[0]); 243 glLineWidth(1.5); 244 glBegin(GL_LINES); 245 246 glVertex2f(columnPos, this->borderTop()); 247 glVertex2f(columnPos, this->getSizeY2D()); 248 for (i = 0; i < this->columnCount(); ++i) 249 { 250 columnPos +=this->_columnWidths[i]; 251 glVertex2f(columnPos, this->borderTop()); 252 glVertex2f(columnPos, this->getSizeY2D()); 253 } 254 255 glVertex2f(this->borderLeft(), rowPos); 256 glVertex2f(this->getSizeX2D(), rowPos); 257 for (i = 0; i < this->rowCount(); ++i) 258 { 259 rowPos +=this->_rowHeights[i]; 260 glVertex2f(this->borderLeft(), rowPos); 261 glVertex2f(this->getSizeX2D(), rowPos); 262 } 263 264 265 glEnd(); 266 267 214 268 215 269 this->endDraw(); 216 270 } 217 271 272 273 void GLGuiTable::pixelPositionToElement(const Vector2D& pixelPosition, int* row, int* column) 274 { 275 *row = 0; 276 *column = 0; 277 float columnPos = this->borderLeft(); 278 float rowPos = this->borderTop(); 279 280 for (*row = 0; *row < (int)this->rowCount(); (*row)++) 281 { 282 if (pixelPosition.y > rowPos && pixelPosition.y < (rowPos += _rowHeights[*row])) 283 break; 284 } 285 for (*column = 0; *column < (int)this->columnCount(); (*column)++) 286 { 287 if (pixelPosition.x > columnPos && pixelPosition.x < (columnPos += _columnWidths[*column])) 288 break; 289 } 290 291 PRINTF(3)("Mouse Over row:%d Column:%d\n", *row, *column); 292 } 293 294 295 void GLGuiTable::repositionText(unsigned int fromLeft, unsigned int fromTop) 296 { 297 float columnPos = this->borderLeft(); 298 float rowPos = this->borderTop(); 299 unsigned int i, j; 300 for (i = 0; i< fromLeft; ++i) 301 columnPos+=this->_columnWidths[i]; 302 for (i = 0; i < fromTop; ++i) 303 rowPos += this->_rowHeights[i]; 304 305 for (i = fromLeft; i < this->columnCount(); ++i) 306 { 307 this->_headers[i].setRelCoor2D(columnPos, rowPos); 308 309 // not required, but a good idea :) 310 this->_headers[i].setLineWidth(_columnWidths[i]); 311 312 float rowPosI = rowPos; 313 for (j = fromTop; j < this->rowCount(); ++j) 314 { 315 this->_entries[j][i].setRelCoor2D(columnPos, rowPosI); 316 this->_entries[j][i].setLineWidth(_columnWidths[i]); 317 rowPosI += _rowHeights[j]; 318 } 319 columnPos+=this->_columnWidths[i]; 320 } 321 } 218 322 219 323 /** … … 224 328 { 225 329 text->setSize(this->textSize()); 226 //text->setLineWidth();330 text->setLineWidth( this->_columnWidths[column] ); 227 331 text->setFont("fonts/final_frontier.ttf", (int)this->textSize()); 332 text->setColor(this->foregroundColor()); 228 333 229 334 text->setColor(this->foregroundColor()); … … 257 362 for (unsigned int i = 0; i < this->rowCount(); ++i) 258 363 if (this->_entries[i].size() != this->columnCount()) 259 {260 PRINTF(1)("COLUMN-COUNT OF ROW %d WRONG (is %d should be %d)\n", i, this->_entries[i].size(), this->columnCount());261 retVal = false;262 }364 { 365 PRINTF(1)("COLUMN-COUNT OF ROW %d WRONG (is %d should be %d)\n", i, this->_entries[i].size(), this->columnCount()); 366 retVal = false; 367 } 263 368 return retVal; 264 369 } -
trunk/src/lib/gui/gl/glgui_table.h
r8619 r8717 39 39 void setHeader(const std::vector<std::string>& headerNames); 40 40 41 void setEntry(unsigned int column, unsigned int row, const std::string& name);41 void setEntry(unsigned int row, unsigned int column, const std::string& name); 42 42 43 43 void setColumnWidth(unsigned int column, float size); 44 44 void setRowHeight(unsigned int row, unsigned int size); 45 45 46 virtual void tick(float dt);47 46 virtual void draw() const; 48 47 … … 60 59 virtual bool processEvent(const Event& event); 61 60 62 63 61 private: 64 62 void init(); 65 63 64 void pixelPositionToElement(const Vector2D& pixelPosition, int* row, int* column); 65 void repositionText(unsigned int fromLeft, unsigned int fromTop); 66 66 void applyTextSettings(unsigned int row, unsigned int column, LimitedWidthText* text); 67 67 bool checkIntegrity() const; 68 68 69 69 private: 70 typedef struct Entry { 71 Entry(int row, int column) :row(row), column(column) {}; 72 int row; 73 int column; 74 }; 75 70 76 typedef std::vector<LimitedWidthText> TableTextList; 71 77 TableTextList _headers; 78 std::vector<float> _columnWidths; 79 std::vector<float> _rowHeights; 80 72 81 std::vector<TableTextList> _entries; //!< inner is by column, outer is by row. 82 83 Entry _selected; 84 Entry _focused; 73 85 74 86 -
trunk/src/lib/gui/gl/glgui_widget.cc
r8619 r8717 72 72 GLGuiWidget::~GLGuiWidget() 73 73 { 74 if (this == GLGuiWidget::_focused) 75 GLGuiWidget::_focused = NULL; 74 if (this == GLGuiWidget::_mouseFocused) 75 GLGuiWidget::_mouseFocused = NULL; 76 if (this == GLGuiWidget::selected()) 77 this->unselect(); 76 78 } 77 79 78 80 GLGuiWidget* GLGuiWidget::_selected = NULL; 79 GLGuiWidget* GLGuiWidget::_ focused = NULL;81 GLGuiWidget* GLGuiWidget::_mouseFocused = NULL; 80 82 GLGuiWidget* GLGuiWidget::_inputGrabber = NULL; 81 83 … … 91 93 this->_focusable = false; 92 94 this->_clickable = false; 95 this->_selectable = false; 93 96 this->_pushed = false; 94 97 this->_state = OrxGui::Normal; … … 133 136 } 134 137 138 139 void GLGuiWidget::setFrontColor(const Color& frontColor, bool instantaniously) 140 { 141 this->_currentStyle._foreground.setDiffuseColor(frontColor); 142 this->animateBack(); 143 }; 144 145 146 bool GLGuiWidget::focusOverWidget(const Vector2D& position) const 147 { 148 return (this->getAbsCoor2D().x < position.x && this->getAbsCoor2D().x + this->getSizeX2D() > position.x && 149 this->getAbsCoor2D().y < position.y && this->getAbsCoor2D().y + this->getSizeY2D() > position.y); 150 } 151 152 bool GLGuiWidget::focusOverWidget(const GLGuiCursor* const cursor) const 153 { 154 return this->focusOverWidget(cursor->getAbsCoor2D()); 155 } 156 157 158 135 159 /** @brief gives focus to this widget */ 136 void GLGuiWidget::giveFocus() 137 { 138 if (GLGuiWidget::focused() != NULL) 139 GLGuiWidget::focused()->breakFocus(); 140 GLGuiWidget::_focused = this; 160 void GLGuiWidget::giveMouseFocus() 161 { 162 if (this->_state == OrxGui::Insensitive) 163 return ; 164 165 if (GLGuiWidget::mouseFocused() != NULL) 166 GLGuiWidget::mouseFocused()->breakMouseFocus(); 167 GLGuiWidget::_mouseFocused = this; 168 169 this->switchState(OrxGui::Focused); 170 141 171 this->receivedFocus(); 142 172 }; 143 173 144 void GLGuiWidget::break Focus()145 { 146 if (GLGuiWidget::_ focused == this)174 void GLGuiWidget::breakMouseFocus() 175 { 176 if (GLGuiWidget::_mouseFocused == this) 147 177 { 148 GLGuiWidget::_focused = NULL; 149 this->_pushed = false; 178 GLGuiWidget::_mouseFocused = NULL; 179 180 if (GLGuiWidget::_selected != this) 181 this->switchState(OrxGui::Normal); 182 else 183 this->switchState(OrxGui::Selected); 184 150 185 this->removedFocus(); 151 186 } 152 187 }; 153 188 154 155 bool GLGuiWidget::focusOverWidget(const Vector2D& position) const 156 { 157 return (this->getAbsCoor2D().x < position.x && this->getAbsCoor2D().x + this->getSizeX2D() > position.x && 158 this->getAbsCoor2D().y < position.y && this->getAbsCoor2D().y + this->getSizeY2D() > position.y); 159 } 160 161 bool GLGuiWidget::focusOverWidget(const GLGuiCursor* const cursor) const 162 { 163 return this->focusOverWidget(cursor->getAbsCoor2D()); 164 } 165 166 167 168 void GLGuiWidget::setFrontColor(const Color& frontColor, bool instantaniously) 169 { 170 this->_currentStyle._foreground.setDiffuseColor(frontColor); 171 this->animateBack(); 172 }; 189 /** 190 * @brief selects the Widget, unselecting the old one (if existing) 191 */ 192 void GLGuiWidget::select() 193 { 194 if (GLGuiWidget::_selected != NULL) 195 GLGuiWidget::selected()->unselect(); 196 GLGuiWidget::_selected = this; 197 198 this->switchState(OrxGui::Selected); 199 } 200 201 /** 202 * @brief unselects the current Widget. 203 * 204 * if the current Widget is not selected, nothing is done here. 205 */ 206 void GLGuiWidget::unselect() 207 { 208 if (GLGuiWidget::_selected != this) 209 return; 210 211 if (GLGuiWidget::_mouseFocused == this) 212 this->switchState(OrxGui::Focused); 213 else 214 this->switchState(OrxGui::Normal); 215 216 GLGuiWidget::_selected = NULL; 217 } 173 218 174 219 … … 193 238 if (this->_pushed) 194 239 { 195 this->releasing(pos );240 this->releasing(pos, GLGuiWidget::_mouseFocused == this); 196 241 this->_pushed = false; 197 242 } … … 200 245 201 246 void GLGuiWidget::clicking(const Vector2D& pos) 202 { 203 this->switchState(OrxGui::Selected); 204 } 205 206 void GLGuiWidget::releasing(const Vector2D& pos) 207 { 208 this->switchState(OrxGui::Normal); 209 } 247 {} 248 249 void GLGuiWidget::releasing(const Vector2D& pos, bool focused) 250 {} 210 251 211 252 void GLGuiWidget::receivedFocus() 212 253 { 213 this->switchState(OrxGui::Focused);214 254 } 215 255 216 256 void GLGuiWidget::removedFocus() 217 257 { 218 this->switchState(OrxGui::Normal); 219 220 } 221 222 void GLGuiWidget::destroyed() 223 {} 224 ; 258 259 } 260 261 void GLGuiWidget::selecting() 262 { 263 } 264 265 void GLGuiWidget::unselecting() 266 { 267 } 268 269 270 void GLGuiWidget::destroying() 271 { 272 } 225 273 226 274 … … 706 754 //this->_currentStyle = this->_style[state]; 707 755 this->_state = state; 708 PRINTF(3)(" Switching to state %s\n", OrxGui::StateString[state].c_str());756 PRINTF(3)("%s::%s Switches to state %s\n", this->getClassName(), this->getName(), OrxGui::StateString[state].c_str()); 709 757 710 758 this->animateBack(); … … 762 810 for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) 763 811 if (stateName == OrxGui::StateString[i]) 764 {765 *state = (OrxGui::State)i;766 return true;767 }812 { 813 *state = (OrxGui::State)i; 814 return true; 815 } 768 816 return false; 769 817 } … … 772 820 * @brief print out some nice debug output about the Widget. 773 821 */ 774 void GLGuiWidget::debug( ) const822 void GLGuiWidget::debug(unsigned int level) const 775 823 { 776 824 PRINT(0)("Debug of %s::%s - WidgetPart ", this->getClassName(), this->getName()); -
trunk/src/lib/gui/gl/glgui_widget.h
r8619 r8717 42 42 43 43 /// FOCUS 44 /** @brief gives focus to this widget */ 45 void giveFocus(); 46 void breakFocus(); 44 /** @brief gives mouse - focus to this widget */ 45 void giveMouseFocus(); 46 void breakMouseFocus(); 47 47 48 /** @returns true if the widget is focusable */ 48 49 bool focusable() const { return this->_focusable; }; 49 /** @param focusable sets if the Widget should be focusable */50 void setFocusable(bool focusable = true) { this->_focusable = focusable; };51 50 /** @returns true if the position is inside of the Widget. @param position the position to check */ 52 51 bool focusOverWidget(const Vector2D& position) const; … … 54 53 bool focusOverWidget(const OrxGui::GLGuiCursor* const cursor) const; 55 54 56 /** @returns the currently focused Widget (NULL if none is selected) */ 57 static GLGuiWidget* focused() { return GLGuiWidget::_focused; }; 58 55 /** @returns the currently mouse - focused Widget (NULL if none is focused). */ 56 static GLGuiWidget* mouseFocused() { return GLGuiWidget::_mouseFocused; }; 57 58 /// SELECT 59 void select(); 60 void unselect(); 61 /** @returns true if the Widget is selectable */ 62 bool selectable() const { return this->_selectable; } 63 64 /** @returns the currently Selected Widget (NULL if none is selected). */ 65 static GLGuiWidget* selected() { return GLGuiWidget::_selected; }; 59 66 60 67 /// CLICK 68 bool pushed() { return _pushed; }; 61 69 void click(const Vector2D& pos); 62 70 void release(const Vector2D& pos); 63 71 bool clickable() const { return this->_clickable; }; 64 void setClickable(bool clickable = true) { this->_clickable = clickable; };65 72 66 73 static void connect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver, Slot executor); … … 81 88 void animateBack(); 82 89 83 /// STYLE 90 /////////////////////////////////////////////////////////////////////////////////// 91 /// STYLE ///////////////////////////////////////////////////////////////////////// 84 92 //////////////////////////////// 85 93 /// Retrieve Current Values. /// … … 201 209 void setAnimatedStateChanges(bool animated); 202 210 void switchState(OrxGui::State state); 203 211 /////////////////////////////////////////////////////////////////////////////////// 204 212 205 213 … … 225 233 226 234 protected: 235 /** @param focusable sets if the Widget should be focusable */ 236 void setFocusable(bool focusable = true) { this->_focusable = focusable; }; 237 /** @param selectable true if the widget should be selectable */ 238 void setSelectable(bool selectable) { this->_selectable = selectable; } 239 /** @param focusable true if the widget should be focusable */ 240 void setClickable(bool clickable = true) { this->_clickable = clickable; }; 241 242 243 /// RENDERING 244 inline void beginDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); }; 245 inline void endDraw() const { glPopMatrix(); }; 246 247 227 248 /// LOOKS 228 249 virtual void resize(); … … 230 251 virtual void hiding() {}; 231 252 virtual void showing() {}; 253 232 254 virtual void updateFrontColor() {}; 233 255 234 inline void beginDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); };235 inline void endDraw() const { glPopMatrix(); };236 256 237 257 /// EVENTS 238 // if something was clickt on the GUI-widget.258 // mouse clicking 239 259 virtual void clicking(const Vector2D& pos); 240 virtual void releasing(const Vector2D& pos); 260 virtual void releasing(const Vector2D& pos, bool focused); 261 // mouse focusing 241 262 virtual void receivedFocus(); 242 263 virtual void removedFocus(); 243 244 virtual void destroyed(); 245 246 virtual void debug() const; 264 // selecting either with the mouse by clicking, or by the keybord traversing to it. 265 virtual void selecting(); 266 virtual void unselecting(); 267 // destroying the Widget. 268 virtual void destroying(); 269 270 271 virtual void debug(unsigned int level) const; 247 272 248 273 private: … … 251 276 private: 252 277 static GLGuiWidget* _selected; //!< The currently selected Widget. 253 static GLGuiWidget* _ focused; //!< The currently Focused Widget.254 static GLGuiWidget* _inputGrabber; //!< The Widget that grabs input .278 static GLGuiWidget* _mouseFocused; //!< The currently Focused Widget (mouse-focus). 279 static GLGuiWidget* _inputGrabber; //!< The Widget that grabs input (keyboard-focus). 255 280 256 281 … … 265 290 /// EVENTS 266 291 OrxGui::State _state; 292 bool _pushed; 267 293 268 294 bool _focusable; //!< If this widget can receive focus. 269 295 bool _clickable; //!< if this widget can be clicked upon. 270 271 bool _pushed; 296 bool _selectable; //!< If this widget can be selected. 297 272 298 273 299 … … 276 302 typedef struct 277 303 { 278 float _borderLeft; //!< The Distance to the left Border of the widget, before any internal Element starts.279 float _borderRight; //!< The Distance to the right Border of the widget, before any internal Element starts.280 float _borderTop; //!< The Distance to the top Border of the widget, before any internal Element starts281 float _borderBottom; //!< The Distance to the bottom Border of the widget, before any internal Element starts282 283 float _textSize; //!< The TextSize of the Widget.284 285 Material _background; //!< The Background Material of the Widget.286 287 Material _foreground; //!< The foreground Material of the Widget.304 float _borderLeft; //!< The Distance to the left Border of the widget, before any internal Element starts. 305 float _borderRight; //!< The Distance to the right Border of the widget, before any internal Element starts. 306 float _borderTop; //!< The Distance to the top Border of the widget, before any internal Element starts 307 float _borderBottom; //!< The Distance to the bottom Border of the widget, before any internal Element starts 308 309 float _textSize; //!< The TextSize of the Widget. 310 311 Material _background; //!< The Background Material of the Widget. 312 313 Material _foreground; //!< The foreground Material of the Widget. 288 314 } 289 315 StatedStyle; 290 316 291 317 292 StatedStyle _style[GLGUI_STATE_COUNT]; //!< Styles configured for different States293 294 FeaturePosition _featurePosition; //!< The Position a Feature will be layed at (checkbox(box), slider(text),...)295 Font* _font; //!< The Font used in the current Widget.318 StatedStyle _style[GLGUI_STATE_COUNT]; //!< Styles configured for different States 319 320 FeaturePosition _featurePosition; //!< The Position a Feature will be layed at (checkbox(box), slider(text),...) 321 Font* _font; //!< The Font used in the current Widget. 296 322 297 323 298 324 /// ANIMATION STUFF: 299 bool _animatedStateChanges; //!< If the Transitions between States are Animated automatically.300 301 bool _animating; //!< If the Widget is animated at the moment (Texture might be an AnimatedTexture.)302 float _animationCycle;303 float _animationDuration;304 StatedStyle _currentStyle;325 bool _animatedStateChanges; //!< If the Transitions between States are Animated automatically. 326 327 bool _animating; //!< If the Widget is animated at the moment (Texture might be an AnimatedTexture.) 328 float _animationCycle; 329 float _animationDuration; 330 StatedStyle _currentStyle; 305 331 306 332 };
Note: See TracChangeset
for help on using the changeset viewer.