Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gl/glgui_widget.cc @ 10243

Last change on this file since 10243 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 23.5 KB
Line 
1/*
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.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI
17
18#include "glgui_widget.h"
19
20#include "glgui_cursor.h"
21
22#include "material.h"
23
24#include "debug.h"
25
26#include "loading/load_param.h"
27#include "loading/resource_manager.h"
28
29namespace OrxGui
30{
31  ObjectListDefinition(GLGuiWidget);
32  /**
33   * @brief standard constructor
34  */
35  GLGuiWidget::GLGuiWidget (GLGuiWidget* parent)
36  {
37    this->init();
38
39    this->setParentWidget(parent);
40  }
41
42
43  /**
44   * @brief loads Parameters for a Style from XML
45   * @param root the XML-Element to load from.
46   */
47  void GLGuiWidget::loadParams(const TiXmlElement* root)
48  {
49
50    /// STYLE
51    LoadParam(root, "border-left", this, GLGuiWidget, setBorderLeft);
52    LoadParam(root, "border-right", this, GLGuiWidget, setBorderRight);
53    LoadParam(root, "border-top", this, GLGuiWidget, setBorderTop);
54    LoadParam(root, "border-bottom", this, GLGuiWidget, setBorderBottom);
55
56    LoadParam(root, "text-size", this, GLGuiWidget, setTextSize);
57    LoadParam(root, "background-color", this, GLGuiWidget, setBackgroundColorS);
58    LoadParam(root, "foreground-color", this, GLGuiWidget, setForegroundColorS);
59
60    //    LoadParamXML(root, "backmat", this, GLGuiWidget, loadBackgroundMaterial);
61    //    LoadParamXML(root, "frontmat", this, GLGuiWidget, loadForegroundMaterial);
62
63    LoadParam(root, "feature-position", this, GLGuiWidget, setFeaturePositionS);
64    LoadParam(root, "Font", this, GLGuiWidget, setFont);
65
66    LoadParam(root, "animated-state-changes", this, GLGuiWidget, setAnimatedStateChanges);
67  }
68
69
70  /**
71   * @brief standard deconstructor
72   */
73  GLGuiWidget::~GLGuiWidget()
74  {
75    if (this == GLGuiWidget::_mouseFocused)
76      GLGuiWidget::_mouseFocused = NULL;
77    if (this == GLGuiWidget::selected())
78      this->unselect();
79
80    if (this->_parent != NULL)
81      this->_parent->removeChildWidget(this);
82  }
83
84  GLGuiWidget* GLGuiWidget::_selected = NULL;
85  GLGuiWidget* GLGuiWidget::_mouseFocused = NULL;
86  GLGuiWidget* GLGuiWidget::_inputGrabber = NULL;
87  Font* GLGuiWidget::_defaultFont = NULL;
88
89
90  /**
91   * initializes the GUI-element
92   */
93  void GLGuiWidget::init()
94  {
95    this->registerObject(this, GLGuiWidget::_objectList);
96
97    this->_focusable = false;
98    this->_clickable = false;
99    this->_selectable = false;
100    this->_pushed = false;
101    this->_state = OrxGui::Normal;
102
103    if(GLGuiWidget::_defaultFont == NULL)
104      GLGuiWidget::_defaultFont = new Font(Resources::ResourceManager::getInstance()->mainGlobalPath().name() + "/fonts/final_frontier.ttf", 20);
105
106    this->_font = *GLGuiWidget::_defaultFont;
107    this->resetStyle();
108
109    this->_animating = false;
110    this->_animationCycle = 0.0;
111    this->_animationDuration = 1.0;
112
113
114    this->setBackgroundColor(Color(.51, .3, .3, .5));
115    this->setBackgroundColor(Color(.3, .5, .3, 1), OrxGui::Selected);
116    this->_style[0]._background.setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
117    this->_style[1]._background.setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
118    this->_style[2]._background.setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
119    this->_style[3]._background.setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
120
121    this->setForegroundColor(Color(.8, .8, 1, 1), OrxGui::Normal);
122    this->setForegroundColor(Color(0, .4, 1.0, 1), OrxGui::Selected);
123    this->setForegroundColor(Color(0, .0, 1.0, 1), OrxGui::Focused);
124    this->setForegroundColor(Color(.1, .1, .1, 1), OrxGui::Insensitive);
125
126    this->setVisibility(GLGUI_WIDGET_DEFAULT_VISIBLE);
127
128    this->setBorderLeft(15);
129    this->setBackgroundTexture("gui_element_background.png");
130
131    this->switchState(_state);
132    this->_currentStyle = this->_style[_state];
133  }
134
135
136  void GLGuiWidget::setParentWidget(GLGuiWidget* parent)
137  {
138    this->_parent = parent;
139
140    if (parent != NULL)
141      parent->addChild2D(this);
142  }
143
144
145  void GLGuiWidget::setFrontColor(const Color& frontColor, bool instantaniously)
146  {
147    this->_currentStyle._foreground.setDiffuseColor(frontColor);
148    this->animateBack();
149  };
150
151
152  bool GLGuiWidget::focusOverWidget(const Vector2D& position) const
153  {
154    return (this->getAbsCoor2D().x < position.x && this->getAbsCoor2D().x + this->getSizeX2D() > position.x &&
155        this->getAbsCoor2D().y < position.y && this->getAbsCoor2D().y + this->getSizeY2D() > position.y);
156  }
157
158  bool GLGuiWidget::focusOverWidget(const GLGuiCursor* const cursor) const
159  {
160    return this->focusOverWidget(cursor->getAbsCoor2D());
161  }
162
163
164
165  /** @brief gives focus to this widget */
166  void GLGuiWidget::giveMouseFocus()
167  {
168    if (this->_state == OrxGui::Insensitive)
169      return ;
170
171    if (GLGuiWidget::mouseFocused() != NULL)
172      GLGuiWidget::mouseFocused()->breakMouseFocus();
173    GLGuiWidget::_mouseFocused = this;
174
175    this->switchState(OrxGui::Focused);
176
177    this->receivedFocus();
178  };
179
180  void GLGuiWidget::breakMouseFocus()
181  {
182    if (GLGuiWidget::_mouseFocused == this)
183    {
184      GLGuiWidget::_mouseFocused = NULL;
185
186      if (GLGuiWidget::_selected != this)
187        this->switchState(OrxGui::Normal);
188      else
189        this->switchState(OrxGui::Selected);
190
191      this->removedFocus();
192    }
193  };
194
195  /**
196   * @brief selects the Widget, unselecting the old one (if existing)
197   */
198  void GLGuiWidget::select()
199  {
200    if (GLGuiWidget::_selected != NULL)
201      GLGuiWidget::selected()->unselect();
202    GLGuiWidget::_selected = this;
203
204    this->switchState(OrxGui::Selected);
205  }
206
207  /**
208   * @brief unselects the current Widget.
209   *
210   * if the current Widget is not selected, nothing is done here.
211   */
212  void GLGuiWidget::unselect()
213  {
214    if (GLGuiWidget::_selected != this)
215      return;
216
217    if (GLGuiWidget::_mouseFocused == this)
218      this->switchState(OrxGui::Focused);
219    else
220      this->switchState(OrxGui::Normal);
221
222    GLGuiWidget::_selected = NULL;
223  }
224
225
226  void GLGuiWidget::resize()
227  {
228    this->backRect().setSize(this->getSize2D());
229    if (this->parent() != NULL)
230      this->parent()->resize();
231  }
232
233
234  void GLGuiWidget::click(const Vector2D& pos)
235  {
236    assert (!this->_pushed);
237    this->_pushed = true;
238
239    this->clicking(pos);
240  }
241
242  void GLGuiWidget::release(const Vector2D& pos)
243  {
244    if (this->_pushed)
245    {
246      this->releasing(pos, GLGuiWidget::_mouseFocused == this);
247      this->_pushed = false;
248    }
249  }
250
251
252  void GLGuiWidget::clicking(const Vector2D& pos)
253  {}
254
255  void GLGuiWidget::releasing(const Vector2D& pos, bool focused)
256  {}
257
258  void GLGuiWidget::receivedFocus()
259  {
260  }
261
262  void GLGuiWidget::removedFocus()
263  {
264
265  }
266
267  void GLGuiWidget::selecting()
268  {
269  }
270
271  void GLGuiWidget::unselecting()
272  {
273  }
274
275
276  void GLGuiWidget::destroying()
277  {
278  }
279
280
281  void GLGuiWidget::setWidgetSize(const Vector2D& size)
282  {
283    this->setSize2D(size);
284    this->resize();
285
286  }
287
288
289  void GLGuiWidget::setWidgetSize(float x, float y)
290  {
291    this->setWidgetSize(Vector2D(x, y));
292  }
293
294  void GLGuiWidget::show()
295  {
296    this->setVisibility(true);
297    this->showing();
298  }
299
300
301
302  void GLGuiWidget::hide()
303  {
304    this->setVisibility(false);
305    this->hiding();
306  }
307
308
309  /**
310   * @brief resets the Style to the default Settings.
311   */
312  void GLGuiWidget::resetStyle()
313  {
314    this->setBorderLeft(1.0);
315    this->setBorderRight(1.0);
316    this->setBorderTop(1.0);
317    this->setBorderBottom(1.0);
318
319    this->setTextSize(20.0);
320    this->setBackgroundColor(1.0);
321    this->setForegroundColor(1.0);
322
323    this->setFeaturePosition(FeatureLeft);
324
325    this->setAnimatedStateChanges(true);
326  }
327
328
329  /**
330   * @brief sets the Width of the left border for all States
331   * @param value the borderWidth
332   */
333  void GLGuiWidget::setBorderLeft(float value)
334  {
335    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
336      setBorderLeft(value, (OrxGui::State)i);
337  }
338
339  /**
340   * @brief sets the Width of the left border.
341   * @param value the borderWidth
342   * @param state the State to set the borderwidth to
343   */
344  void GLGuiWidget::setBorderLeft(float value, OrxGui::State state)
345  {
346    _style[state]._borderLeft = value;
347    if (state == _state)
348      _currentStyle._borderLeft = value;
349  }
350
351  /**
352   * @brief sets the Width of the left border.
353   * @param value the borderWidth
354   * @param stateName the State to set the borderwidth to
355   */
356  void GLGuiWidget::setBorderLeftS(float value, const std::string& stateName)
357  {
358    OrxGui::State state;
359    if (getState(stateName, &state))
360      this->setBorderLeft(value, state);
361    else
362      this->setBorderLeft(value);
363  }
364
365  /**
366   * @brief sets the Width of the right border for all states.
367   * @param value the borderWidth
368   */
369  void GLGuiWidget::setBorderRight(float value)
370  {
371    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
372      setBorderRight(value, (OrxGui::State)i);
373  }
374
375  /**
376   * @brief sets the Width of the right border.
377   * @param value the borderWidth
378   * @param state the State to setup.
379   */
380  void GLGuiWidget::setBorderRight(float value, OrxGui::State state)
381  {
382    _style[state]._borderRight = value;
383    if (state == _state)
384      _currentStyle._borderRight = value;
385  }
386
387  /**
388   * @brief sets the Width of the right border.
389   * @param value the borderWidth
390   * @param stateName the State to setup.
391   */
392  void GLGuiWidget::setBorderRightS(float value, const std::string& stateName)
393  {
394    OrxGui::State state;
395    if (getState(stateName, &state))
396      this->setBorderRight(value, state);
397    else
398      this->setBorderRight(value);
399  }
400
401
402  /**
403   * @brief sets the Width of the top border for all states.
404   * @param value the borderWidth
405   */
406  void GLGuiWidget::setBorderTop(float value)
407  {
408    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
409      setBorderTop(value, (OrxGui::State)i);
410  }
411
412  /**
413   * @brief sets the Width of the top border.
414   * @param value the borderWidth
415   * @param state the State to setup.
416   */
417  void GLGuiWidget::setBorderTop(float value, OrxGui::State state)
418  {
419    _style[state]._borderTop = value;
420    if (state == _state)
421      _currentStyle._borderTop = value;
422  }
423
424  /**
425   * @brief sets the Width of the top border.
426   * @param value the borderWidth
427   * @param stateName the State to setup.
428   */
429  void GLGuiWidget::setBorderTopS(float value, const std::string& stateName)
430  {
431    OrxGui::State state;
432    if (getState(stateName, &state))
433      this->setBorderTop(value, state);
434    else
435      this->setBorderTop(value);
436  }
437
438
439  /**
440   * @brief sets the Width of the bottom border for all states.
441   * @param value the borderWidth
442   */
443  void GLGuiWidget::setBorderBottom(float value)
444  {
445    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
446      setBorderBottom(value, (OrxGui::State)i);
447  }
448
449  /**
450   * @brief sets the Width of the bottom border.
451   * @param value the borderWidth
452   * @param state the State to setup.
453   */
454  void GLGuiWidget::setBorderBottom(float value, OrxGui::State state)
455  {
456    _style[state]._borderBottom = value;
457    if (state == _state)
458      _currentStyle._borderBottom = value;
459
460  }
461
462  /**
463   * @brief sets the Width of the bottom border for all states.
464   * @param value the borderWidth
465   * @param stateName the State to setup.
466   */
467  void GLGuiWidget::setBorderBottomS(float value, const std::string& stateName)
468  {
469    OrxGui::State state;
470    if (getState(stateName, &state))
471      this->setBorderBottom(value, state);
472    else
473      this->setBorderBottom(value);
474  }
475
476
477  /**
478   * @brief sets the TextSize for all states.
479   * @param value the TextSize
480   */
481  void GLGuiWidget::setTextSize(float value)
482  {
483    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
484      setTextSize(value, (OrxGui::State)i);
485  }
486
487  /**
488   * @brief sets the TextSize.
489   * @param value the TextSize.
490   * @param state: the State to setup
491   */
492  void GLGuiWidget::setTextSize(float value, OrxGui::State state)
493  {
494    _style[state]._textSize = value;
495    if (state == _state)
496      _currentStyle._textSize = value;
497  }
498
499  /**
500   * @brief sets the TextSize.
501   * @param value the TextSize.
502   * @param stateName: the State to setup
503   */
504  void GLGuiWidget::setTextSizeS(float value, const std::string& stateName)
505  {
506    OrxGui::State state;
507    if (getState(stateName, &state))
508      this->setTextSize(value, state);
509    else
510      this->setTextSize(value);
511  }
512
513
514  /**
515   * @brief sets the Background Color for all States.
516   * @param color the Color.
517   */
518  void GLGuiWidget::setBackgroundColor(const Color& color)
519  {
520    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
521      setBackgroundColor(color, (OrxGui::State)i);
522  }
523
524  /**
525   * @brief sets the Background Color.
526   * @param color the Color.
527   * @param state: the State to setup
528   */
529  void GLGuiWidget::setBackgroundColor(const Color& color, OrxGui::State state)
530  {
531    _style[state]._background.setDiffuseColor(color);
532    if (state == _state)
533      _currentStyle._background.setDiffuseColor(color);
534
535  }
536
537  /**
538   * @brief sets the Background Color.
539   * @param r the Color's red part.
540   * @param g the Color's green part.
541   * @param b the Color's blue part.
542   * @param a the Color's alpha part.
543   * @param stateName: the State to setup
544   */
545  void GLGuiWidget::setBackgroundColorS(float r, float g, float b, float a, const std::string& stateName)
546  {
547    OrxGui::State state;
548    if (getState(stateName, &state))
549      this->setBackgroundColor(Color(r,g,b,a), state);
550    else
551      this->setBackgroundColor(Color(r,g,b,a));
552  }
553
554
555  /**
556   * @brief sets the Background Texture for all States.
557   * @param texture the Texture.
558   */
559  void GLGuiWidget::setBackgroundTexture(const Texture& texture)
560  {
561    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
562      setBackgroundTexture(texture, (OrxGui::State)i);
563  }
564
565  /**
566  * @brief sets the Background Texture to all States.
567  * @param textureName the Texture's fileName.
568   */
569  void GLGuiWidget::setBackgroundTexture(const std::string& textureName)
570  {
571    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
572      _style[i]._background.setDiffuseMap(textureName);
573    this->_currentStyle._background.setDiffuseMap(textureName);
574  }
575
576  /**
577   * @brief sets the Background Texture.
578   * @param texture the Texture.
579   * @param state the State to setup.
580   */
581  void GLGuiWidget::setBackgroundTexture(const Texture& texture, OrxGui::State state)
582  {
583    _style[state]._background.setDiffuseMap(texture);
584    if (state == _state)
585      _currentStyle._background.setDiffuseMap(texture);
586  }
587
588
589
590  /**
591   * @brief sets the Background Texture.
592   * @param texture the Texture.
593   * @param stateName the State to setup.
594   */
595  void GLGuiWidget::setBackgroundTexture(const std::string& textureName, const std::string& stateName)
596  {
597    OrxGui::State state;
598    if (getState(stateName, &state))
599      ; /// FIXME this->setBackgroundTexture(textureName, state);
600    else
601      ; ///    this->setBackgroundTexture(textureName);
602  }
603
604
605  /**
606   * @brief sets the Foreground Color for all States.
607   * @param color the Color.
608   */
609  void GLGuiWidget::setForegroundColor(const Color& color)
610  {
611    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
612      setForegroundColor(color, (OrxGui::State)i);
613  }
614
615  /**
616   * @brief sets the Foreground Color.
617   * @param color the Color.
618   * @param state the State to setup
619   */
620  void GLGuiWidget::setForegroundColor(const Color& color, OrxGui::State state)
621  {
622    _style[state]._foreground.setDiffuseColor(color);
623    if (state == _state)
624      _currentStyle._foreground.setDiffuseColor(color);
625
626  }
627
628  /**
629   * @brief sets the Foreground Color.
630   * @param r the Color's red part.
631   * @param g the Color's green part.
632   * @param b the Color's blue part.
633   * @param a the Color's alpha part.
634   * @param stateName: the State to setup
635   */
636  void GLGuiWidget::setForegroundColorS(float r, float g, float b, float a, const std::string& stateName)
637  {
638    OrxGui::State state;
639    if (getState(stateName, &state))
640      this->setForegroundColor(Color(r,g,b,a), state);
641    else
642      this->setForegroundColor(Color(r,g,b,a));
643  }
644
645
646    /**
647   * @brief sets the Foreground Texture for all States.
648   * @param texture the Texture.
649     */
650  void GLGuiWidget::setForegroundTexture(const Texture& texture)
651  {
652    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
653      setForegroundTexture(texture, (OrxGui::State)i);
654  }
655
656  /**
657   * @brief sets the Foreground Texture to all States.
658   * @param textureName the Texture's fileName.
659   */
660  void GLGuiWidget::setForegroundTexture(const std::string& textureName)
661  {
662    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
663      _style[i]._foreground.setDiffuseMap(textureName);
664    this->_currentStyle._foreground.setDiffuseMap(textureName);
665  }
666
667  /**
668   * @brief sets the Foreground Texture.
669   * @param texture the Texture.
670   * @param state the State to setup.
671   */
672  void GLGuiWidget::setForegroundTexture(const Texture& texture, OrxGui::State state)
673  {
674    _style[state]._background.setDiffuseMap(texture);
675    if (state == _state)
676      _currentStyle._background.setDiffuseMap(texture);
677  }
678
679
680
681  /**
682   * @brief sets the Foreground Texture.
683   * @param texture the Texture.
684   * @param stateName the State to setup.
685   */
686  void GLGuiWidget::setForegroundTexture(const std::string& textureName, const std::string& stateName)
687  {
688    OrxGui::State state;
689    if (getState(stateName, &state))
690      ; /// FIXME this->setForegroundTexture(textureName, state);
691    else
692      ; ///    this->setForegroundTexture(textureName);
693  }
694
695
696  void GLGuiWidget::loadBackgroundMaterial(const Material& material)
697  {
698    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
699      this->loadForegroundMaterial(material, (OrxGui::State)i);
700  }
701
702  void GLGuiWidget::loadBackgroundMaterial(const Material& material, OrxGui::State state)
703  {
704    this->_style[state]._background = material;
705    if (state == _state)
706      _currentStyle._background = material;
707
708  }
709
710  void GLGuiWidget::loadBackgroundMaterial(const TiXmlElement* element)
711  {
712    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
713      this->loadBackgroundMaterial(element, (OrxGui::State)i);
714  }
715
716  void GLGuiWidget::loadBackgroundMaterial(const TiXmlElement* element, OrxGui::State state)
717  {
718    this->_style[state]._background.loadParams(element);
719    if (state == _state)
720      this->_currentStyle._background = _style[state]._background;
721  }
722
723  void GLGuiWidget::loadBackgroundMaterialS(const TiXmlElement* element, const std::string& stateName)
724  {
725    OrxGui::State state;
726    if (getState(stateName, &state))
727      this->loadBackgroundMaterial(element, state);
728    else
729      this->loadBackgroundMaterial(element);
730  }
731
732  void GLGuiWidget::loadForegroundMaterial(const Material& material)
733{}
734  void GLGuiWidget::loadForegroundMaterial(const Material& material, OrxGui::State state)
735  {}
736  void GLGuiWidget::loadForegroundMaterial(const TiXmlElement* element, OrxGui::State state)
737  {}
738  void GLGuiWidget::loadForegroundMaterialS(const TiXmlElement* element, const std::string& stateName)
739  {}
740
741
742  /**
743   * @brief sets the Feature-Position.
744   * @param featurePosition the Feature-Position.
745   */
746  void GLGuiWidget::setFeaturePosition(FeaturePosition featurePosition)
747  {
748    this->_featurePosition = featurePosition;
749  }
750
751  /**
752   * @brief sets the Feature-Position by converting from a String.
753   * @param featurePosition the Feature-Position.
754   */
755  void GLGuiWidget::setFeaturePositionS(const std::string& featurePosition)
756  {
757    for (unsigned int i = 0; i < 4; ++i)
758    {
759      if (featurePosition == FeaturePositionString[i])
760      {
761        this->setFeaturePosition((FeaturePosition)i);
762      }
763    }
764  }
765
766  /**
767   * @brief sets the Font.
768   * @param font the Font.
769   */
770  void GLGuiWidget::setFont(const Font& font)
771  {
772    this->_font = font;
773  }
774
775  /**
776   * @brief sets the font from a Font-Name.
777   * @param fontName the FileName of the Font.
778   */
779  void GLGuiWidget::setFont(const std::string& fontName, unsigned int renderSize)
780  {
781    this->setFont(Font(fontName, renderSize));
782  }
783
784  /**
785   * @brief sets the AnimatedState.
786   * @param animated: it states-changes should animate true, otherwise false.
787   */
788  void GLGuiWidget::setAnimatedStateChanges(bool animated)
789  {
790    this->_animatedStateChanges = animated;
791  }
792
793
794  void GLGuiWidget::switchState(OrxGui::State state)
795  {
796    //this->_currentStyle = this->_style[state];
797    this->_state = state;
798    PRINTF(4)("%s::%s Switches to state %s\n", this->getClassCName(), this->getCName(), OrxGui::StateString[state].c_str());
799
800    this->animateBack();
801  }
802
803
804  void GLGuiWidget::animateBack()
805  {
806    this->_animating = true;
807    this->_animationCycle = 0.0f;
808  }
809
810
811  void GLGuiWidget::tick(float dt)
812  {
813    if (this->_animating)
814    {
815      this->foregroundColor();
816
817      _animationCycle += dt / _animationDuration;
818      if (_animationCycle >= 1.0)
819      {
820        _currentStyle._foreground.diffuseColor() = this->foregroundColor(_state);
821        _currentStyle._background.diffuseColor() = this->backgroundColor(_state);
822        _animating = false;
823      }
824      else
825      {
826        _currentStyle._foreground.diffuseColor().slerp(this->foregroundColor(_state), _animationCycle);
827        _currentStyle._background.diffuseColor().slerp(this->backgroundColor(_state), _animationCycle);
828      }
829      this->updateFrontColor();
830    }
831  }
832
833
834  /**
835   * USE THIS FUNCTION ONLY FROM DERIVED CLASS
836   */
837  void GLGuiWidget::draw() const
838  {
839    this->background().select();
840    this->drawRect(this->backRect());
841    this->background().unselect();
842  }
843
844
845  /**
846   * @param stateName the Name of a State.
847   * @param state the found State is returned here if found.
848   * @returns true if String is found, false otherwise.
849   */
850  bool GLGuiWidget::getState(const std::string& stateName, OrxGui::State* state)
851  {
852    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
853      if (stateName == OrxGui::StateString[i])
854      {
855        *state = (OrxGui::State)i;
856        return true;
857      }
858    return false;
859  }
860
861  /**
862   * @brief print out some nice debug output about the Widget.
863   */
864  void GLGuiWidget::debug(unsigned int level) const
865  {
866    PRINT(0)("Debug of %s::%s - WidgetPart ", this->getClassCName(), this->getCName());
867    if (_parent != NULL)
868      PRINT(0)("- Parent %s::%s ", _parent->getClassCName(), _parent->getCName());
869    PRINT(0)("- State: %s", StateString[_state].c_str());
870
871    if (_focusable)
872      PRINT(0)("- focusable ");
873    if (_clickable)
874      PRINT(0)("- Clickable ");
875    if (_pushed)
876      PRINT(0)("- Pushed ");
877    PRINT(0)("\n");
878
879
880    PRINT(0)("Minimum Size %0.2f %0.2f ", _minSize.x, _minSize.y);
881    PRINT(0)("Back Rect: ");
882    _backRect.debug();
883    PRINT(0)("Style:\n");
884
885    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
886    {
887      PRINT(0)("In State %s: \n", StateString[i].c_str());
888
889      PRINT(0)("  Borders: Left: %0.2f, Right: %0.2f, Top: %0.2f, Bottom %0.2f\n",
890               _style[i]._borderLeft, _style[i]._borderRight, _style[i]._borderTop, _style[i]._borderBottom);
891      PRINT(0)("  TextSize %0.2f\n", _style[i]._textSize);
892      PRINT(0)("  BackgroundColor: "); _style[i]._background.diffuseColor().debug();
893      PRINT(0)("  ForegroundColor: "); _style[i]._foreground.diffuseColor().debug();
894      PRINT(0)("\n");
895    }
896
897
898    PRINT(0)(" Feature at %s ", FeaturePositionString[_featurePosition].c_str());
899    /// TODO    PRINT(0)("");    Font*               _font;                 //!< The Font used in the current Widget.
900
901    if (_animatedStateChanges)
902      PRINT(0)("- AnimatedStateChanges");
903    PRINT(0)("\n");
904
905    /*
906    if (_animating)
907      PRINT(0)("- Animated ");
908
909    //
910    float               _animationCycle;
911    float               _animationDuration;
912    StatedStyle         _currentStyle;
913    OrxGui::State       _currentState;
914    */
915  }
916
917
918}
Note: See TracBrowser for help on using the repository browser.