Changeset 8619 in orxonox.OLD for trunk/src/lib/gui/gl
- Timestamp:
- Jun 20, 2006, 1:24:11 PM (19 years ago)
- Location:
- trunk/src/lib/gui/gl
- Files:
-
- 2 deleted
- 17 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/gui/gl/Makefile.am
r8518 r8619 12 12 glmenu/glmenu_imagescreen.cc \ 13 13 \ 14 glgui_style.cc \15 14 glgui_handler.cc \ 16 15 signal_connector.cc \ … … 27 26 glgui_inputline.cc \ 28 27 glgui_textfield.cc \ 28 glgui_table.cc \ 29 29 glgui_image.cc \ 30 30 glgui_window.cc \ … … 37 37 glmenu/glmenu_imagescreen.h \ 38 38 \ 39 glgui_style.h \40 39 signal_connector.h \ 41 40 glgui.h \ … … 54 53 glgui_inputline.h \ 55 54 glgui_textfield.h \ 55 glgui_table.h \ 56 56 glgui_image.h \ 57 57 glgui_window.h \ -
trunk/src/lib/gui/gl/glgui.h
r8145 r8619 16 16 #include "glgui_button.h" 17 17 #include "glgui_checkbutton.h" 18 //#include "glgui_colorselector.h"19 18 #include "glgui_pushbutton.h" 20 19 #include "glgui_slider.h" … … 22 21 #include "glgui_inputline.h" 23 22 #include "glgui_textfield.h" 23 #include "glgui_table.h" 24 24 #include "glgui_image.h" 25 25 -
trunk/src/lib/gui/gl/glgui_box.cc
r8450 r8619 110 110 if (orientation() == OrxGui::Vertical) 111 111 { 112 float height = this->borderTop();112 float height = borderTop(); 113 113 float width = 0.0f; 114 114 std::vector<GLGuiWidget*>::iterator widget; … … 117 117 for (widget = this->children.begin(); widget != this->children.end(); ++widget) 118 118 { 119 (*widget)->setRelCoor2D( this->borderLeft(), height);119 (*widget)->setRelCoor2D(borderLeft(), height); 120 120 height += (*widget)->getSizeY2D(); 121 121 width = fmax(width, (*widget)->getSizeX2D()); 122 122 } 123 123 124 width += this->borderLeft() + this->borderRight();125 height += this->borderBottom(); /* *2 done further up */124 width += borderLeft() + borderRight(); 125 height += borderBottom(); /* *2 done further up */ 126 126 127 127 printf("%f %f\n", width, height); … … 130 130 else 131 131 { 132 float height = this->borderTop();133 float width = this->borderLeft();132 float height = borderTop(); 133 float width = borderLeft(); 134 134 std::vector<GLGuiWidget*>::iterator widget; 135 135 … … 137 137 for (widget = this->children.begin(); widget != this->children.end(); ++widget) 138 138 { 139 (*widget)->setRelCoor2D(width, this->borderTop());139 (*widget)->setRelCoor2D(width, borderTop()); 140 140 height = fmax(height, (*widget)->getSizeY2D()); 141 141 width += (*widget)->getSizeX2D(); 142 142 } 143 143 144 width += this->borderRight() ;145 height += this->borderBottom(); /* *2 done further up */144 width += borderRight() ; 145 height += borderBottom(); /* *2 done further up */ 146 146 147 147 printf("%f %f\n", width, height); -
trunk/src/lib/gui/gl/glgui_button.cc
r8448 r8619 55 55 56 56 this->_label.setFont("fonts/final_frontier.ttf", 20); 57 this->_label.setColor(this->f rontColor());57 this->_label.setColor(this->foregroundColor() ); 58 58 59 59 this->_label.setParent2D(this); … … 71 71 void GLGuiButton::updateFrontColor() 72 72 { 73 this->_label.setColor(this->f rontColor());73 this->_label.setColor(this->foregroundColor()); 74 74 } 75 75 -
trunk/src/lib/gui/gl/glgui_button.h
r8448 r8619 36 36 virtual ~GLGuiButton(); 37 37 38 const std::string& label() const { return this->_label. getText(); };38 const std::string& label() const { return this->_label.text(); }; 39 39 void setLabel(const std::string& label); 40 40 -
trunk/src/lib/gui/gl/glgui_checkbutton.cc
r8448 r8619 96 96 // this->frontMaterial().select(); 97 97 // this->drawRect(this->frontRect()); 98 99 98 if (this->bActive) 100 99 { 101 glColor3fv( &this->f rontColor()[0]);100 glColor3fv( &this->foregroundColor()[0]); 102 101 this->drawRect(this->_checkBox); 103 102 … … 124 123 else 125 124 { 126 glColor3fv( &this->f rontColor()[0]);125 glColor3fv( &this->foregroundColor()[0]); 127 126 this->drawRect(this->_checkBox); 128 127 } -
trunk/src/lib/gui/gl/glgui_container.cc
r8145 r8619 43 43 this->setClassID(CL_GLGUI_CONTAINER, "GLGuiContainer"); 44 44 45 this->setBackgroundTexture("gui_container_background.png"); 46 45 47 } 46 48 -
trunk/src/lib/gui/gl/glgui_cursor.cc
r8324 r8619 57 57 this->setClassID(CL_GLGUI_CURSOR, "GLGuiCursor"); 58 58 59 this->backMaterial().setDiffuse(1.0,0.0,0.0); 60 this->backMaterial().setDiffuseMap("cursor.png"); 61 this->backMaterial().setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 59 this->setBackgroundColor(Color(1.0, 1.0, 1.0, 1.0)); 60 this->setBackgroundTexture("cursor.png"); 62 61 this->setSize2D(50, 50); 63 62 this->setAbsCoor2D(100, 100); 64 63 this->setLayer(E2D_LAYER_ABOVE_ALL); 65 64 this->color = 0.0f; 65 this->frameNumber = 0.0f; 66 66 67 67 this->resize(); … … 79 79 bool GLGuiCursor::loadTextureSequence(const std::string& imageNameSubstitue, unsigned int from, unsigned int to) 80 80 { 81 this->backMaterial().setDiffuse(1.0, 1.0, 1.0);81 //this->background().setDiffuse(1.0, 1.0, 1.0); 82 82 return this->seq.loadImageSeries(imageNameSubstitue, from, to); 83 83 } … … 97 97 this->color -= 360.0; 98 98 Vector color = Color::HSVtoRGB(Vector(this->color, 1.0, 1.0)); 99 this->backMaterial().setDiffuse(color.x, color.y, color.z); 99 //this->setBackgroundColor(color.x, color.y, color.z); 100 /// FIXME 101 100 102 } 101 103 //if (this->movement != Vector2D()) … … 125 127 this->beginDraw(); 126 128 127 this->back Material().select();129 this->background().select(); 128 130 if (!this->seq.empty()) 129 131 glBindTexture(GL_TEXTURE_2D, this->seq.getFrameTexture((int)frameNumber)); -
trunk/src/lib/gui/gl/glgui_defs.h
r8448 r8619 22 22 } Orientation; 23 23 24 //! Names of Orientations 24 25 const std::string OrientationString[] = { 25 26 "Horizontal", … … 30 31 typedef enum { 31 32 Normal, //!< Normal state of the GUI's Widgets. 32 Active, //!< If the widget is Active.33 Focused, //!< If the widget is Active. 33 34 Selected, //!< If the Widget is Selected. 34 35 Insensitive //!< If the Widget is insensitive. … … 38 39 #define GLGUI_DEFAULT_STYLE OrxGui::Normal 39 40 41 //! names of the States. 40 42 const std::string StateString[] = 41 43 { 42 44 "Normal", 43 " Active",45 "Focused", 44 46 "Selected", 45 47 "Insensitive" … … 54 56 } FeaturePosition; 55 57 58 //! Names of Feature-Positions 56 59 const std::string FeaturePositionString[] = 57 60 { -
trunk/src/lib/gui/gl/glgui_image.cc
r8448 r8619 47 47 this->setClassID(CL_GLGUI_IMAGE, "GLGuiImage"); 48 48 49 this->setForegroundColor(Color(1,1,1,1)); 49 50 this->_imageMaterial.setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 50 51 … … 76 77 void GLGuiImage::updateFrontColor() 77 78 { 78 this->_imageMaterial.setDiffuseColor( this->frontColor());79 this->_imageMaterial.setDiffuseColor(foregroundColor()); 79 80 } 80 81 81 82 void GLGuiImage::resize() 82 83 { 83 this->_imagePlane.setTopLeft( this->borderLeft(), this->borderTop());84 this->_imagePlane.setTopLeft(borderLeft(), borderTop()); 84 85 this->_imagePlane.setSize(this->getSizeX2D() - (borderLeft() + borderRight()), this->getSizeY2D() - (borderTop() + borderBottom()) ); 85 86 GLGuiWidget::resize(); -
trunk/src/lib/gui/gl/glgui_inputline.cc
r8518 r8619 52 52 this->_text.setRelCoor2D(4,4); 53 53 this->_text.setFont("fonts/final_frontier.ttf", 20); 54 this->_text.setColor(this->frontColor()); 54 this->_text.setLineWidth(400); 55 this->_text.setDotsPosition(LimitedWidthText::Begin); 56 this->_text.setColor(foregroundColor()); 55 57 this->_text.setVisibility(false); 56 58 this->resize(); 59 60 this->delayNext = 0.0; 61 this->pressedKey = SDLK_FIRST; 62 this->pressedKeyName = SDLK_FIRST; 57 63 58 64 } … … 116 122 this->resize(); 117 123 this->setFrontColor(Color(1,1,1,1), true); 118 this->setFrontColor(Color(0,1,0,1)); 119 emit(this->textChanged(this->_text.getText())); 124 emit(this->textChanged(this->_text.text())); 120 125 } 121 126 … … 139 144 void GLGuiInputLine::pushEnter() 140 145 { 141 emit(this->enterPushed(this->_text. getText()));146 emit(this->enterPushed(this->_text.text())); 142 147 if (this->_clearOnEnter) 143 148 this->clear(); … … 197 202 void GLGuiInputLine::resize() 198 203 { 199 this->_text.setRelCoor2D( this->borderLeft(), this->borderTop());204 this->_text.setRelCoor2D(borderLeft(), borderTop()); 200 205 this->setSize2D( this->_text.getSize2D() + Vector2D(borderLeft() + borderRight(), borderTop() + borderBottom())); 201 206 GLGuiWidget::resize(); 202 /* this->frontRect().setTopLeft(borderLeft(), borderTop());203 this->frontRect().setSize(this->getSize2D() - Vector2D(borderLeft() + borderRight(), borderTop() + borderBottom()));*/207 /* this->frontRect().setTopLeft(borderLeft(), borderTop()); 208 this->frontRect().setSize(this->getSize2D() - Vector2D(borderLeft() + borderRight(), borderTop() + borderBottom()));*/ 204 209 } 205 210 206 211 void GLGuiInputLine::updateFrontColor() 207 212 { 208 this->_text.setColor( this->frontColor());213 this->_text.setColor(foregroundColor()); 209 214 } 210 215 … … 228 233 if (this->delayNext > 0.0) 229 234 this->delayNext -= dt; 230 235 else if (this->pressedKey != SDLK_FIRST ) 231 236 { 232 237 this->delayNext = GLGuiInputLine::repeatRate; … … 237 242 break; 238 243 default: 239 {240 if (likely(this->pressedKey < 127))241 this->appendCharacter(this->pressedKeyName);242 }244 { 245 if (likely(this->pressedKey < 127)) 246 this->appendCharacter(this->pressedKeyName); 247 } 243 248 } 244 249 } … … 255 260 GLGuiWidget::draw(); 256 261 257 // this->frontMaterial().select();258 // GLGuiWidget::drawRect(this->frontRect());262 // this->frontMaterial().select(); 263 // GLGuiWidget::drawRect(this->frontRect()); 259 264 260 265 this->endDraw(); -
trunk/src/lib/gui/gl/glgui_inputline.h
r8518 r8619 9 9 10 10 #include "glgui_widget.h" 11 #include " text.h"11 #include "limited_width_text.h" 12 12 #include "event.h" 13 13 … … 32 32 33 33 /** @returns the text of the inputLine */ 34 const std::string& _getText() const { return this->_text. getText(); };34 const std::string& _getText() const { return this->_text.text(); }; 35 35 36 36 void setText(const std::string& text); … … 66 66 67 67 private: 68 Text_text; //!< The Text to display inside of the InputLine.68 LimitedWidthText _text; //!< The Text to display inside of the InputLine. 69 69 bool _clearOnEnter; //!< Clear on Enter 70 70 -
trunk/src/lib/gui/gl/glgui_slider.cc
r8448 r8619 74 74 else 75 75 this->_value = value; 76 this->_handle.setCenter(this->sliderPosition(), this->borderTop() + (this->getSizeY2D() - this->borderTop() - borderBottom()) / 2.0);76 this->_handle.setCenter(this->sliderPosition(), borderTop() + (this->getSizeY2D() - borderTop() - borderBottom()) / 2.0); 77 77 78 78 emit(valueChanged(this->_value)); … … 165 165 // this->frontRect().setTopLeft(this->borderLeft(), this->getSizeY2D()/2.0 - 2.0); 166 166 // this->frontRect().setSize(this->getSizeX2D() - borderLeft() - borderRight(), 4.0); 167 this->_slider.setTopLeft( this->borderLeft(), this->getSizeY2D() / 2.0 -2.0);167 this->_slider.setTopLeft(borderLeft(), this->getSizeY2D() / 2.0 -2.0); 168 168 this->_slider.setSize(this->getSizeX2D() - borderLeft() - borderRight(), 4.0); 169 169 this->_handle.setSize(this->_sliderWidth, this->getSizeY2D() - borderTop() - borderBottom()); … … 211 211 { 212 212 return (this->_value - this->_minValue)/( this->_maxValue - this->_minValue) * 213 214 213 (this->getSizeX2D() - (borderLeft() + borderRight() + 2.0*_sliderWidth)) + 214 (borderLeft() +_sliderWidth); 215 215 } 216 216 … … 239 239 GLGuiWidget::draw(); 240 240 241 glColor4fv(&this->f rontColor()[0]);241 glColor4fv(&this->foregroundColor()[0]); 242 242 this->drawRect(this->_slider); 243 243 this->drawRect(this->_handle); -
trunk/src/lib/gui/gl/glgui_widget.cc
r8448 r8619 14 14 */ 15 15 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI16 #define DEBUG_SPECIAL_MODULE 4//DEBUG_MODULE_GUI 17 17 18 18 #include "glgui_widget.h" … … 23 23 24 24 #include "debug.h" 25 26 #include "loading/load_param.h" 25 27 26 28 namespace OrxGui … … 39 41 40 42 /** 43 * @brief loads Parameters for a Style from XML 44 * @param root the XML-Element to load from. 45 */ 46 void GLGuiWidget::loadParams(const TiXmlElement* root) 47 { 48 49 /// STYLE 50 LoadParam(root, "border-left", this, GLGuiWidget, setBorderLeft); 51 LoadParam(root, "border-right", this, GLGuiWidget, setBorderRight); 52 LoadParam(root, "border-top", this, GLGuiWidget, setBorderTop); 53 LoadParam(root, "border-bottom", this, GLGuiWidget, setBorderBottom); 54 55 LoadParam(root, "text-size", this, GLGuiWidget, setTextSize); 56 LoadParam(root, "background-color", this, GLGuiWidget, setBackgroundColorS); 57 LoadParam(root, "foreground-color", this, GLGuiWidget, setForegroundColorS); 58 59 // LoadParamXML(root, "backmat", this, GLGuiWidget, loadBackgroundMaterial); 60 // LoadParamXML(root, "frontmat", this, GLGuiWidget, loadForegroundMaterial); 61 62 LoadParam(root, "feature-position", this, GLGuiWidget, setFeaturePositionS); 63 LoadParam(root, "Font", this, GLGuiWidget, setFont); 64 65 LoadParam(root, "animated-state-changes", this, GLGuiWidget, setAnimatedStateChanges); 66 } 67 68 69 /** 41 70 * @brief standard deconstructor 42 71 */ … … 45 74 if (this == GLGuiWidget::_focused) 46 75 GLGuiWidget::_focused = NULL; 47 48 if (this->_toFrontColor)49 delete this->_toFrontColor;50 76 } 51 77 … … 66 92 this->_clickable = false; 67 93 this->_pushed = false; 94 this->_state = OrxGui::Normal; 95 96 97 this->_font = NULL; 98 this->resetStyle(); 99 100 this->_animating = false; 101 this->_animationCycle = 0.0; 102 this->_animationDuration = 1.0; 103 104 105 this->setBackgroundColor(Color(.51, .3, .3, .5)); 106 this->setBackgroundColor(Color(.3, .5, .3, 1), OrxGui::Selected); 107 this->_style[0]._background.setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 108 this->_style[1]._background.setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 109 this->_style[2]._background.setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 110 this->_style[3]._background.setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 111 112 this->setForegroundColor(Color(1, 0, 0, 1), OrxGui::Normal); 113 this->setForegroundColor(Color(0, 0, 1, 1), OrxGui::Selected); 114 this->setForegroundColor(Color(0, 1, 0, 1), OrxGui::Focused); 115 this->setForegroundColor(Color(.1, .1, .1, 1), OrxGui::Insensitive); 68 116 69 117 this->setVisibility(GLGUI_WIDGET_DEFAULT_VISIBLE); 70 118 71 this->_backMat.setDiffuseColor(Color(1.0, 0.5, 0.4, 1.0)); 72 this->_backMat.setDiffuseMap("gui_element_background.png"); 73 this->_frontColor = Color(1.0, 0.0, 0.0); 74 this->_toFrontColor = NULL; 75 76 77 this->_borderLeft = 15.0; 78 this->_borderRight = 1.0; 79 this->_borderTop = 1.0; 80 this->_borderBottom = 1.0; 119 this->setBorderLeft(15); 120 this->setBackgroundTexture("gui_element_background.png"); 121 122 this->switchState(_state); 123 this->_currentStyle = this->_style[_state]; 81 124 } 82 125 … … 121 164 } 122 165 166 167 123 168 void GLGuiWidget::setFrontColor(const Color& frontColor, bool instantaniously) 124 169 { 125 if (instantaniously) 126 { 127 this->_frontColor = frontColor; 128 if (this->_toFrontColor != NULL) 129 { 130 delete this->_toFrontColor; 131 this->_toFrontColor = NULL; 132 } 133 } 134 else if (!this->_toFrontColor) 135 this->_toFrontColor = new Color(frontColor); 136 else 137 *this->_toFrontColor = frontColor; 138 //this->_frontColor = frontColor; 139 //this->updateFrontColor(); 170 this->_currentStyle._foreground.setDiffuseColor(frontColor); 171 this->animateBack(); 140 172 }; 141 142 143 void GLGuiWidget::setBorderSize(float borderSize)144 {145 this->_borderLeft = borderSize;146 this->_borderRight = borderSize;147 this->_borderTop = borderSize;148 this->_borderBottom = borderSize;149 this->resize();150 }151 152 void GLGuiWidget::setBorderLeft(float borderLeft)153 {154 this->_borderLeft = borderLeft;155 this->resize();156 }157 void GLGuiWidget::setBorderRight(float borderRight)158 {159 this->_borderRight = borderRight;160 this->resize();161 }162 void GLGuiWidget::setBorderTop(float borderTop)163 {164 this->_borderTop = borderTop;165 this->resize();166 }167 void GLGuiWidget::setBorderBottom(float borderBottom)168 {169 this->_borderBottom = borderBottom;170 this->resize();171 }172 173 173 174 174 … … 201 201 void GLGuiWidget::clicking(const Vector2D& pos) 202 202 { 203 this->setFrontColor(Color(0, 0, 1)); 204 203 this->switchState(OrxGui::Selected); 205 204 } 206 205 207 206 void GLGuiWidget::releasing(const Vector2D& pos) 208 207 { 209 this->setFrontColor(Color(0,1,0)); 210 208 this->switchState(OrxGui::Normal); 211 209 } 212 210 213 211 void GLGuiWidget::receivedFocus() 214 212 { 215 this->s etFrontColor(Color(0, 1, 0));213 this->switchState(OrxGui::Focused); 216 214 } 217 215 218 216 void GLGuiWidget::removedFocus() 219 217 { 220 this->s etFrontColor(Color(1, 0, 0));218 this->switchState(OrxGui::Normal); 221 219 222 220 } … … 267 265 } 268 266 269 void GLGuiWidget::tick(float dt) 270 { 271 if (this->_toFrontColor) 267 268 /** 269 * @brief resets the Style to the default Settings. 270 */ 271 void GLGuiWidget::resetStyle() 272 { 273 this->setBorderLeft(1.0); 274 this->setBorderRight(1.0); 275 this->setBorderTop(1.0); 276 this->setBorderBottom(1.0); 277 278 this->setTextSize(20.0); 279 this->setBackgroundColor(1.0); 280 this->setForegroundColor(1.0); 281 282 this->setFeaturePosition(FeatureLeft); 283 this->setFont(NULL); 284 285 this->setAnimatedStateChanges(true); 286 } 287 288 289 /** 290 * @brief sets the Width of the left border for all States 291 * @param value the borderWidth 292 */ 293 void GLGuiWidget::setBorderLeft(float value) 294 { 295 for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) 296 setBorderLeft(value, (OrxGui::State)i); 297 } 298 299 /** 300 * @brief sets the Width of the left border. 301 * @param value the borderWidth 302 * @param state the State to set the borderwidth to 303 */ 304 void GLGuiWidget::setBorderLeft(float value, OrxGui::State state) 305 { 306 _style[state]._borderLeft = value; 307 if (state == _state) 308 _currentStyle._borderLeft = value; 309 } 310 311 /** 312 * @brief sets the Width of the left border. 313 * @param value the borderWidth 314 * @param stateName the State to set the borderwidth to 315 */ 316 void GLGuiWidget::setBorderLeftS(float value, const std::string& stateName) 317 { 318 OrxGui::State state; 319 if (getState(stateName, &state)) 320 this->setBorderLeft(value, state); 321 else 322 this->setBorderLeft(value); 323 } 324 325 /** 326 * @brief sets the Width of the right border for all states. 327 * @param value the borderWidth 328 */ 329 void GLGuiWidget::setBorderRight(float value) 330 { 331 for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) 332 setBorderRight(value, (OrxGui::State)i); 333 } 334 335 /** 336 * @brief sets the Width of the right border. 337 * @param value the borderWidth 338 * @param state the State to setup. 339 */ 340 void GLGuiWidget::setBorderRight(float value, OrxGui::State state) 341 { 342 _style[state]._borderRight = value; 343 if (state == _state) 344 _currentStyle._borderRight = value; 345 } 346 347 /** 348 * @brief sets the Width of the right border. 349 * @param value the borderWidth 350 * @param stateName the State to setup. 351 */ 352 void GLGuiWidget::setBorderRightS(float value, const std::string& stateName) 353 { 354 OrxGui::State state; 355 if (getState(stateName, &state)) 356 this->setBorderRight(value, state); 357 else 358 this->setBorderRight(value); 359 } 360 361 362 /** 363 * @brief sets the Width of the top border for all states. 364 * @param value the borderWidth 365 */ 366 void GLGuiWidget::setBorderTop(float value) 367 { 368 for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) 369 setBorderTop(value, (OrxGui::State)i); 370 } 371 372 /** 373 * @brief sets the Width of the top border. 374 * @param value the borderWidth 375 * @param state the State to setup. 376 */ 377 void GLGuiWidget::setBorderTop(float value, OrxGui::State state) 378 { 379 _style[state]._borderTop = value; 380 if (state == _state) 381 _currentStyle._borderTop = value; 382 } 383 384 /** 385 * @brief sets the Width of the top border. 386 * @param value the borderWidth 387 * @param stateName the State to setup. 388 */ 389 void GLGuiWidget::setBorderTopS(float value, const std::string& stateName) 390 { 391 OrxGui::State state; 392 if (getState(stateName, &state)) 393 this->setBorderTop(value, state); 394 else 395 this->setBorderTop(value); 396 } 397 398 399 /** 400 * @brief sets the Width of the bottom border for all states. 401 * @param value the borderWidth 402 */ 403 void GLGuiWidget::setBorderBottom(float value) 404 { 405 for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) 406 setBorderBottom(value, (OrxGui::State)i); 407 } 408 409 /** 410 * @brief sets the Width of the bottom border. 411 * @param value the borderWidth 412 * @param state the State to setup. 413 */ 414 void GLGuiWidget::setBorderBottom(float value, OrxGui::State state) 415 { 416 _style[state]._borderBottom = value; 417 if (state == _state) 418 _currentStyle._borderBottom = value; 419 420 } 421 422 /** 423 * @brief sets the Width of the bottom border for all states. 424 * @param value the borderWidth 425 * @param stateName the State to setup. 426 */ 427 void GLGuiWidget::setBorderBottomS(float value, const std::string& stateName) 428 { 429 OrxGui::State state; 430 if (getState(stateName, &state)) 431 this->setBorderBottom(value, state); 432 else 433 this->setBorderBottom(value); 434 } 435 436 437 /** 438 * @brief sets the TextSize for all states. 439 * @param value the TextSize 440 */ 441 void GLGuiWidget::setTextSize(float value) 442 { 443 for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) 444 setTextSize(value, (OrxGui::State)i); 445 } 446 447 /** 448 * @brief sets the TextSize. 449 * @param value the TextSize. 450 * @param state: the State to setup 451 */ 452 void GLGuiWidget::setTextSize(float value, OrxGui::State state) 453 { 454 _style[state]._textSize = value; 455 if (state == _state) 456 _currentStyle._textSize = value; 457 } 458 459 /** 460 * @brief sets the TextSize. 461 * @param value the TextSize. 462 * @param stateName: the State to setup 463 */ 464 void GLGuiWidget::setTextSizeS(float value, const std::string& stateName) 465 { 466 OrxGui::State state; 467 if (getState(stateName, &state)) 468 this->setTextSize(value, state); 469 else 470 this->setTextSize(value); 471 } 472 473 474 /** 475 * @brief sets the Background Color for all States. 476 * @param color the Color. 477 */ 478 void GLGuiWidget::setBackgroundColor(const Color& color) 479 { 480 for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) 481 setBackgroundColor(color, (OrxGui::State)i); 482 } 483 484 /** 485 * @brief sets the Background Color. 486 * @param color the Color. 487 * @param state: the State to setup 488 */ 489 void GLGuiWidget::setBackgroundColor(const Color& color, OrxGui::State state) 490 { 491 _style[state]._background.setDiffuseColor(color); 492 if (state == _state) 493 _currentStyle._background.setDiffuseColor(color); 494 495 } 496 497 /** 498 * @brief sets the Background Color. 499 * @param r the Color's red part. 500 * @param g the Color's green part. 501 * @param b the Color's blue part. 502 * @param a the Color's alpha part. 503 * @param stateName: the State to setup 504 */ 505 void GLGuiWidget::setBackgroundColorS(float r, float g, float b, float a, const std::string& stateName) 506 { 507 OrxGui::State state; 508 if (getState(stateName, &state)) 509 this->setBackgroundColor(Color(r,g,b,a), state); 510 else 511 this->setBackgroundColor(Color(r,g,b,a)); 512 } 513 514 515 /** 516 * @brief sets the Background Texture for all States. 517 * @param texture the Texture. 518 */ 519 void GLGuiWidget::setBackgroundTexture(const Texture& texture) 520 { 521 for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) 522 setBackgroundTexture(texture, (OrxGui::State)i); 523 } 524 525 /** 526 * @brief sets the Background Texture to all States. 527 * @param textureName the Texture's fileName. 528 */ 529 void GLGuiWidget::setBackgroundTexture(const std::string& textureName) 530 { 531 for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) 532 _style[i]._background.setDiffuseMap(textureName); 533 this->_currentStyle._background.setDiffuseMap(textureName); 534 } 535 536 /** 537 * @brief sets the Background Texture. 538 * @param texture the Texture. 539 * @param state the State to setup. 540 */ 541 void GLGuiWidget::setBackgroundTexture(const Texture& texture, OrxGui::State state) 542 { 543 _style[state]._background.setDiffuseMap(texture); 544 if (state == _state) 545 _currentStyle._background.setDiffuseMap(texture); 546 } 547 548 549 550 /** 551 * @brief sets the Background Texture. 552 * @param texture the Texture. 553 * @param stateName the State to setup. 554 */ 555 void GLGuiWidget::setBackgroundTexture(const std::string& textureName, const std::string& stateName) 556 { 557 OrxGui::State state; 558 if (getState(stateName, &state)) 559 ; /// FIXME this->setBackgroundTexture(textureName, state); 560 else 561 ; /// this->setBackgroundTexture(textureName); 562 } 563 564 565 /** 566 * @brief sets the Foreground Color for all States. 567 * @param color the Color. 568 */ 569 void GLGuiWidget::setForegroundColor(const Color& color) 570 { 571 for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) 572 setForegroundColor(color, (OrxGui::State)i); 573 } 574 575 /** 576 * @brief sets the Foreground Color. 577 * @param color the Color. 578 * @param state the State to setup 579 */ 580 void GLGuiWidget::setForegroundColor(const Color& color, OrxGui::State state) 581 { 582 _style[state]._foreground.setDiffuseColor(color); 583 if (state == _state) 584 _currentStyle._foreground.setDiffuseColor(color); 585 586 } 587 588 /** 589 * @brief sets the Foreground Color. 590 * @param r the Color's red part. 591 * @param g the Color's green part. 592 * @param b the Color's blue part. 593 * @param a the Color's alpha part. 594 * @param stateName: the State to setup 595 */ 596 void GLGuiWidget::setForegroundColorS(float r, float g, float b, float a, const std::string& stateName) 597 { 598 OrxGui::State state; 599 if (getState(stateName, &state)) 600 this->setForegroundColor(Color(r,g,b,a), state); 601 else 602 this->setForegroundColor(Color(r,g,b,a)); 603 } 604 605 606 void GLGuiWidget::loadBackgroundMaterial(const Material& material) 607 { 608 for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) 609 this->loadForegroundMaterial(material, (OrxGui::State)i); 610 } 611 612 void GLGuiWidget::loadBackgroundMaterial(const Material& material, OrxGui::State state) 613 { 614 this->_style[state]._background = material; 615 if (state == _state) 616 _currentStyle._background = material; 617 618 } 619 620 void GLGuiWidget::loadBackgroundMaterial(const TiXmlElement* element) 621 { 622 for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) 623 this->loadBackgroundMaterial(element, (OrxGui::State)i); 624 } 625 626 void GLGuiWidget::loadBackgroundMaterial(const TiXmlElement* element, OrxGui::State state) 627 { 628 this->_style[state]._background.loadParams(element); 629 if (state == _state) 630 this->_currentStyle._background = _style[state]._background; 631 } 632 633 void GLGuiWidget::loadBackgroundMaterialS(const TiXmlElement* element, const std::string& stateName) 634 { 635 OrxGui::State state; 636 if (getState(stateName, &state)) 637 this->loadBackgroundMaterial(element, state); 638 else 639 this->loadBackgroundMaterial(element); 640 } 641 642 void GLGuiWidget::loadForegroundMaterial(const Material& material) 643 {} 644 void GLGuiWidget::loadForegroundMaterial(const Material& material, OrxGui::State state) 645 {} 646 void GLGuiWidget::loadForegroundMaterial(const TiXmlElement* element, OrxGui::State state) 647 {} 648 void GLGuiWidget::loadForegroundMaterialS(const TiXmlElement* element, const std::string& stateName) 649 {} 650 651 652 /** 653 * @brief sets the Feature-Position. 654 * @param featurePosition the Feature-Position. 655 */ 656 void GLGuiWidget::setFeaturePosition(FeaturePosition featurePosition) 657 { 658 this->_featurePosition = featurePosition; 659 } 660 661 /** 662 * @brief sets the Feature-Position by converting from a String. 663 * @param featurePosition the Feature-Position. 664 */ 665 void GLGuiWidget::setFeaturePositionS(const std::string& featurePosition) 666 { 667 for (unsigned int i = 0; i < 4; ++i) 272 668 { 273 this->_frontColor.slerp(*_toFrontColor, dt*3.0); 274 this->updateFrontColor(); 275 if (this->_frontColor.dist(*_toFrontColor) < .1) 669 if (featurePosition == FeaturePositionString[i]) 276 670 { 277 delete _toFrontColor; 278 _toFrontColor = NULL; 671 this->setFeaturePosition((FeaturePosition)i); 279 672 } 280 673 } 281 674 } 282 675 676 /** 677 * @brief sets the Font. 678 * @param font the Font. 679 */ 680 void GLGuiWidget::setFont(Font* font) 681 { 682 this->_font = font; 683 } 684 685 /** 686 * @brief sets the font from a Font-Name. 687 * @param fontName the FileName of the Font. 688 */ 689 void GLGuiWidget::setFont(const std::string& fontName) 690 { 691 //this->font = new Font(fontName); 692 } 693 694 /** 695 * @brief sets the AnimatedState. 696 * @param animated: it states-changes should animate true, otherwise false. 697 */ 698 void GLGuiWidget::setAnimatedStateChanges(bool animated) 699 { 700 this->_animatedStateChanges = animated; 701 } 702 703 704 void GLGuiWidget::switchState(OrxGui::State state) 705 { 706 //this->_currentStyle = this->_style[state]; 707 this->_state = state; 708 PRINTF(3)("Switching to state %s\n", OrxGui::StateString[state].c_str()); 709 710 this->animateBack(); 711 } 712 713 714 void GLGuiWidget::animateBack() 715 { 716 this->_animating = true; 717 this->_animationCycle = 0.0f; 718 } 719 720 721 void GLGuiWidget::tick(float dt) 722 { 723 if (this->_animating) 724 { 725 this->foregroundColor(); 726 727 _animationCycle += dt / _animationDuration; 728 if (_animationCycle >= 1.0) 729 { 730 _currentStyle._foreground.diffuseColor() = this->foregroundColor(_state); 731 _currentStyle._background.diffuseColor() = this->backgroundColor(_state); 732 _animating = false; 733 } 734 else 735 { 736 _currentStyle._foreground.diffuseColor().slerp(this->foregroundColor(_state), _animationCycle); 737 _currentStyle._background.diffuseColor().slerp(this->backgroundColor(_state), _animationCycle); 738 } 739 this->updateFrontColor(); 740 } 741 } 742 283 743 284 744 /** … … 287 747 void GLGuiWidget::draw() const 288 748 { 289 this->back Material().select();749 this->background().select(); 290 750 this->drawRect(this->backRect()); 291 this->backMaterial().unselect(); 292 } 751 this->background().unselect(); 752 } 753 754 755 /** 756 * @param stateName the Name of a State. 757 * @param state the found State is returned here if found. 758 * @returns true if String is found, false otherwise. 759 */ 760 bool GLGuiWidget::getState(const std::string& stateName, OrxGui::State* state) 761 { 762 for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) 763 if (stateName == OrxGui::StateString[i]) 764 { 765 *state = (OrxGui::State)i; 766 return true; 767 } 768 return false; 769 } 770 771 /** 772 * @brief print out some nice debug output about the Widget. 773 */ 774 void GLGuiWidget::debug() const 775 { 776 PRINT(0)("Debug of %s::%s - WidgetPart ", this->getClassName(), this->getName()); 777 if (_parent != NULL) 778 PRINT(0)("- Parent %s::%s ", _parent->getClassName(), _parent->getName()); 779 PRINT(0)("- State: %s", StateString[_state].c_str()); 780 781 if (_focusable) 782 PRINT(0)("- focusable "); 783 if (_clickable) 784 PRINT(0)("- Clickable "); 785 if (_pushed) 786 PRINT(0)("- Pushed "); 787 PRINT(0)("\n"); 788 789 790 PRINT(0)("Minimum Size %0.2f %0.2f ", _minSize.x, _minSize.y); 791 PRINT(0)("Back Rect: "); 792 _backRect.debug(); 793 PRINT(0)("Style:\n"); 794 795 for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) 796 { 797 PRINT(0)("In State %s: \n", StateString[i].c_str()); 798 799 PRINT(0)(" Borders: Left: %0.2f, Right: %0.2f, Top: %0.2f, Bottom %0.2f\n", 800 _style[i]._borderLeft, _style[i]._borderRight, _style[i]._borderTop, _style[i]._borderBottom); 801 PRINT(0)(" TextSize %0.2f\n", _style[i]._textSize); 802 PRINT(0)(" BackgroundColor: "); _style[i]._background.diffuseColor().debug(); 803 PRINT(0)(" ForegroundColor: "); _style[i]._foreground.diffuseColor().debug(); 804 PRINT(0)("\n"); 805 } 806 807 808 PRINT(0)(" Feature at %s ", FeaturePositionString[_featurePosition].c_str()); 809 /// TODO PRINT(0)(""); Font* _font; //!< The Font used in the current Widget. 810 811 if (_animatedStateChanges) 812 PRINT(0)("- AnimatedStateChanges"); 813 PRINT(0)("\n"); 814 815 /* 816 if (_animating) 817 PRINT(0)("- Animated "); 818 819 // 820 float _animationCycle; 821 float _animationDuration; 822 StatedStyle _currentStyle; 823 OrxGui::State _currentState; 824 */ 825 } 826 293 827 294 828 } -
trunk/src/lib/gui/gl/glgui_widget.h
r8518 r8619 9 9 #include "element_2d.h" 10 10 11 #include "glgui_style.h" 11 #include "glgui_defs.h" 12 12 13 #include "material.h" 13 14 #include "rect2D.h" … … 15 16 #include "event.h" 16 17 #include "signal_connector.h" 18 19 class Font; 17 20 18 21 namespace OrxGui … … 66 69 void disconnect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver); 67 70 68 69 GLGuiStyle& style() { return this->_style; }; 70 const GLGuiStyle style() const { return this->_style; }; 71 72 /// MATERIAL (looks) 73 Material& backMaterial() { return this->_backMat; }; 74 const Material& backMaterial() const { return this->_backMat; }; 71 OrxGui::State state() const { return this->_state; }; 72 75 73 Rect2D& backRect() { return this->_backRect; }; 76 74 const Rect2D& backRect() const { return this->_backRect; }; 77 75 78 76 void setFrontColor(const Color& frontColor, bool instantaniously = false); 79 const Color& frontColor() const { return this->_frontColor; };80 81 /** @brief sets all borders to the same value. */82 void setBorderSize(float borderSize);83 void setBorderLeft(float borderLeft);84 void setBorderRight(float borderRight);85 void setBorderTop(float borderTop);86 void setBorderBottom(float borderBottom);87 88 float borderLeft() const { return this->_borderLeft; };89 float borderRight() const { return this->_borderRight; };90 float borderTop() const { return this->_borderTop; };91 float borderBottom() const { return this->_borderBottom; };92 93 77 94 78 void setWidgetSize(const Vector2D& size); 95 79 void setWidgetSize(float x, float y); 96 80 97 98 void setBackgroundColor(float x, float y, float z) { this->backMaterial().setDiffuse(x,y,z); }; 81 void animateBack(); 82 83 /// STYLE 84 //////////////////////////////// 85 /// Retrieve Current Values. /// 86 //////////////////////////////// 87 /** @returns current left borderWidth */ 88 inline float borderLeft() const { return _currentStyle._borderLeft; } 89 /** @returns current right borderWidth */ 90 inline float borderRight() const { return _currentStyle._borderRight; } 91 /** @returns current top borderWidth */ 92 inline float borderTop() const { return _currentStyle._borderTop; } 93 /** @returns burrent bottom borderWidth */ 94 inline float borderBottom() const { return _currentStyle._borderBottom; } 95 96 97 /** @returns current textSize */ 98 inline float textSize() const { return _currentStyle._textSize; } 99 /** @returns the Background Color */ 100 inline const Color& backgroundColor() const { return _currentStyle._background.diffuseColor(); } 101 /** @returns the current Background Material. */ 102 inline const Material& background() const { return _currentStyle._background; } 103 /** @returns the current background Texture. */ 104 inline const Texture& backgroundTexture() const { return _currentStyle._background.diffuseTexture(); } 105 /** @returns the current foreground Color */ 106 inline const Color& foregroundColor() const { return _currentStyle._foreground.diffuseColor(); } 107 /** @returns the current ForeGroung Material. */ 108 inline const Material& foreground() const { return _currentStyle._foreground; } 109 110 111 /** @returns FeaturePosition */ 112 inline FeaturePosition featurePosition() const { return _featurePosition; } 113 /** @returns the font */ 114 inline const Font* const font() const { return _font; } 115 /** @returns true if the Element is Animated */ 116 inline bool animating() const { return _animating; } 117 /** @returns true if State-Changes are animated */ 118 inline bool animatedStateChanges() const { return _animatedStateChanges; } 119 120 121 /////////////////////////////////////////////////////////////// 122 /// Retrieve Values for the Saved Values inside the States. /// 123 /////////////////////////////////////////////////////////////// 124 /** @returns left borderWidth @param state the State to retrieve from */ 125 inline float borderLeft(OrxGui::State state) const { return _style[state]._borderLeft; } 126 /** @returns right borderWidth @param state the State to retrieve from */ 127 inline float borderRight(OrxGui::State state) const { return _style[state]._borderRight; } 128 /** @returns top borderWidth @param state the State to retrieve from */ 129 inline float borderTop(OrxGui::State state) const { return _style[state]._borderTop; } 130 /** @returns bottom borderWidth @param state the State to retrieve from */ 131 inline float borderBottom(OrxGui::State state) const { return _style[state]._borderBottom; } 132 133 /** @returns textSize @param state the State to retrieve from */ 134 inline float textSize(OrxGui::State state) const { return _style[state]._textSize; } 135 /** @returns the Background Color @param state the State to retrieve from */ 136 inline const Color& backgroundColor(OrxGui::State state) const { return _style[state]._background.diffuseColor(); } 137 /** @returns the Background Material. @param state the state to retrieve from */ 138 inline const Material& background(OrxGui::State state) const { return _style[state]._background; } 139 /** @returns background Texture. @param state the State to retrieve from */ 140 inline const Texture& backgroundTexture(OrxGui::State state) const { return _style[state]._background.diffuseTexture(); } 141 /** @returns the foreground Color @param state the State to retrieve from */ 142 inline const Color& foregroundColor(OrxGui::State state) const { return _style[state]._foreground.diffuseColor(); } 143 /** @returns the ForeGroung Material. @param state the state to retrieve from */ 144 inline const Material& foreground(OrxGui::State state) const { return _style[state]._foreground; } 145 146 147 /// SETUP 148 void resetStyle(); 149 void loadParams(const TiXmlElement* root); 150 151 void setBorderLeft(float value); 152 void setBorderLeft(float value, OrxGui::State state); 153 void setBorderLeftS(float value, const std::string& stateName); 154 155 void setBorderRight(float value); 156 void setBorderRight(float value, OrxGui::State state); 157 void setBorderRightS(float value, const std::string& stateName); 158 159 void setBorderTop(float value); 160 void setBorderTop(float value, OrxGui::State state); 161 void setBorderTopS(float value, const std::string& stateName); 162 163 void setBorderBottom(float value); 164 void setBorderBottom(float value, OrxGui::State state); 165 void setBorderBottomS(float value, const std::string& stateName); 166 167 void setTextSize(float value); 168 void setTextSize(float value, OrxGui::State state); 169 void setTextSizeS(float value, const std::string& stateName); 170 171 void setBackgroundColor(const Color& color); 172 void setBackgroundColor(const Color& color, OrxGui::State state); 173 void setBackgroundColorS(float r, float g, float b, float a, const std::string& stateName); 174 175 void setBackgroundTexture(const Texture& texture); 176 void setBackgroundTexture(const std::string& textureName); 177 void setBackgroundTexture(const Texture& texture, OrxGui::State state); 178 void setBackgroundTexture(const std::string& textureName, const std::string& stateName); 179 180 void setForegroundColor(const Color& color); 181 void setForegroundColor(const Color& color, OrxGui::State state); 182 void setForegroundColorS(float r, float g, float b, float a, const std::string& stateName); 183 184 void loadBackgroundMaterial(const Material& material); 185 void loadBackgroundMaterial(const Material& material, OrxGui::State state); 186 void loadBackgroundMaterial(const TiXmlElement* element); 187 void loadBackgroundMaterial(const TiXmlElement* element, OrxGui::State state); 188 void loadBackgroundMaterialS(const TiXmlElement* element, const std::string& stateName); 189 190 void loadForegroundMaterial(const Material& material); 191 void loadForegroundMaterial(const Material& material, OrxGui::State state); 192 void loadForegroundMaterial(const TiXmlElement* element, OrxGui::State state); 193 void loadForegroundMaterialS(const TiXmlElement* element, const std::string& stateName); 194 195 void setFeaturePosition(FeaturePosition featurePosition); 196 void setFeaturePositionS(const std::string& featurePosition); 197 198 void setFont(Font* font); 199 void setFont(const std::string& fontName); 200 201 void setAnimatedStateChanges(bool animated); 202 void switchState(OrxGui::State state); 203 204 99 205 100 206 inline void drawRect(const Rect2D& rect) const … … 116 222 virtual bool processEvent(const Event& event) { return false; }; 117 223 224 bool getState(const std::string& stateName, OrxGui::State* state); 118 225 119 226 protected: … … 137 244 virtual void destroyed(); 138 245 246 virtual void debug() const; 247 139 248 private: 140 249 void init(); 141 250 142 251 private: 252 static GLGuiWidget* _selected; //!< The currently selected Widget. 253 static GLGuiWidget* _focused; //!< The currently Focused Widget. 254 static GLGuiWidget* _inputGrabber; //!< The Widget that grabs input. 255 256 257 /// WIDGET 143 258 GLGuiWidget* _parent; //!< The parent of this Widget. 144 259 145 260 /// LOOKS 146 Material _backMat;147 261 Rect2D _backRect; 148 149 Color _frontColor;150 Color* _toFrontColor;151 152 float _borderLeft;153 float _borderRight;154 float _borderTop;155 float _borderBottom;156 157 262 Vector2D _minSize; 158 263 159 GLGuiStyle _style;160 264 161 265 /// EVENTS 266 OrxGui::State _state; 267 162 268 bool _focusable; //!< If this widget can receive focus. 163 269 bool _clickable; //!< if this widget can be clicked upon. … … 166 272 167 273 168 static GLGuiWidget* _selected; //!< The currently selected Widget. 169 static GLGuiWidget* _focused; //!< The currently Focused Widget. 170 171 static GLGuiWidget* _inputGrabber; //!< The Widget that grabs input. 274 275 /// STYLE - Variables. 276 typedef struct 277 { 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 starts 281 float _borderBottom; //!< The Distance to the bottom Border of the widget, before any internal Element starts 282 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. 288 } 289 StatedStyle; 290 291 292 StatedStyle _style[GLGUI_STATE_COUNT]; //!< Styles configured for different States 293 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. 296 297 298 /// 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; 305 172 306 }; 173 307 } -
trunk/src/lib/gui/gl/specials/glgui_notifier.cc
r8518 r8619 25 25 26 26 /** 27 * standard constructor27 * @brief standard constructor 28 28 */ 29 29 GLGuiNotifier::GLGuiNotifier () … … 34 34 this->lineSpacing = 0; 35 35 this->linesProcessed = 0; 36 this->_fadeAge = 3.0; 37 this->setHideAge(4.0); 36 38 37 39 this->setDisplayLineCount(10); … … 57 59 } 58 60 61 /** 62 * @brief push a message onto the notifier. 63 * @param message the message to be pushed. 64 * 65 * @note it is not guaranteed, that the message is delivered instantaniously 66 * The possibility may arise, that the DisplayLines are all in use, then one 67 * has to wait until a line gets hidden, until a new one can be pushed to be 68 * displayed. 69 */ 59 70 void GLGuiNotifier::pushNotifyMessage(const std::string& message) 60 71 { 61 72 if (!this->hiddenText.empty()) 62 73 { 63 printf("%s\n", message.c_str()); 64 DisplayLine dl; 74 DisplayLine dl; // put everything in here, and then display it 75 76 // retrieve a Text. 65 77 dl.text = this->hiddenText.top(); 66 78 this->hiddenText.pop(); 79 80 // setup Text 67 81 dl.text->setBlending(1.0f); 68 82 dl.text->setText(message); 69 this->hiddenText.pop(); 83 dl.text->setVisibility(true); 84 dl.text->setRelCoor2D(this->calculateLinePosition(0)); 85 70 86 dl.age = 0.0f; 71 87 this->displayLines.push_front(dl); 72 73 dl.text->setVisibility(true);74 dl.text->setRelCoor2D(this->calculateLinePosition(0));75 88 this->repositionText(); 76 89 } 77 90 else 78 91 { 92 // push it onto the List of messages we still need. 79 93 this->inputBuffer.push_front(message); 80 //printf("grumble... must be fixed\n"); 81 } 82 } 83 84 94 } 95 } 96 97 98 /** 99 * @brief sets the Dipsplay Line Count of the Notifier. 100 * @param coun the count of displayLines. 101 */ 85 102 void GLGuiNotifier::setDisplayLineCount(unsigned int count) 86 103 { … … 96 113 } 97 114 115 void GLGuiNotifier::setFadeAge(float fadeAge) 116 { 117 this->_fadeAge = fadeAge; 118 this->_transformAge = hideAge() - this->fadeAge(); 119 } 120 121 void GLGuiNotifier::setHideAge(float hideAge) 122 { 123 this->_hideAge = hideAge; 124 this->_transformAge = this->hideAge() - fadeAge(); 125 } 126 98 127 99 128 /** … … 119 148 void GLGuiNotifier::applyTextSettings(MultiLineText* text) 120 149 { 121 text->setSize(this-> style().textSize());150 text->setSize(this->textSize()); 122 151 text->setLineWidth( 300 ); 123 text->setFont("fonts/final_frontier.ttf", (int)this-> style().textSize());124 125 text->setColor(this-> style().foregroundColor() );152 text->setFont("fonts/final_frontier.ttf", (int)this->textSize()); 153 154 text->setColor(this->foregroundColor() ); 126 155 if (text->getParent2D() != this) 127 156 text->setParent2D(this); … … 129 158 130 159 160 /** 161 * @brief ticks the entire Notifier. 162 * @param dt the time passed since the last Tick 163 */ 131 164 void GLGuiNotifier::tick(float dt) 132 165 { … … 135 168 { 136 169 (*line).age+=dt; 137 if ((*line).age > 3.0f)170 if ((*line).age > this->fadeAge()) 138 171 { 139 (*line).text->setBlending( 4.0 - (*line).age);140 if ((*line).age > 4.0f)172 (*line).text->setBlending((hideAge() - (*line).age)/_transformAge); 173 if ((*line).age > hideAge()) 141 174 { 142 175 std::list<DisplayLine>::iterator tmp = line; … … 167 200 this->beginDraw(); 168 201 169 this->back Material().select();202 this->background().select(); 170 203 this->drawRect(this->backRect()); 171 204 this->endDraw(); … … 183 216 Vector2D GLGuiNotifier::calculateLinePosition(unsigned int lineNumber) 184 217 { 185 return Vector2D(0.0f, (float)(t his->style().textSize() + this->lineSpacing)*(float)((int)this->bufferDisplaySize - (int)lineNumber - (int)1));218 return Vector2D(0.0f, (float)(textSize() + this->lineSpacing)*(float)((int)this->bufferDisplaySize - (int)lineNumber - (int)1)); 186 219 } 187 220 -
trunk/src/lib/gui/gl/specials/glgui_notifier.h
r8518 r8619 30 30 void pushNotifyMessage(const std::string& message); 31 31 32 // BUFFERS32 /// Setup 33 33 void setDisplayLineCount(unsigned int count); 34 void setFadeAge(float fadeAge); 35 void setHideAge(float hideAge); 36 37 /** @returns the beginning of the Hiding process */ 38 inline float fadeAge() const { return _fadeAge; }; 39 /** @returns at what age elements should be fully hidden */ 40 inline float hideAge() const { return _hideAge; }; 34 41 35 42 void clear(); … … 54 61 55 62 private: 63 //! structure that defines a Displayed line. 56 64 typedef struct 57 65 { … … 59 67 MultiLineText* text; 60 68 61 } 62 DisplayLine; 69 } DisplayLine; 70 71 72 float _fadeAge; 73 float _hideAge; 74 float _transformAge; 63 75 64 76 unsigned int lineSpacing; //!< The Spacing between lines. … … 72 84 73 85 unsigned long linesProcessed; //!< How many Lines have been processed so far. 74 std::list<std::string> inputBuffer; //!< 86 std::list<std::string> inputBuffer; //!< The input buffer for lines that were not yet printet out, because there is too much input. 75 87 76 88 };
Note: See TracChangeset
for help on using the changeset viewer.