Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/lib/gui/gl/glgui_widget.cc @ 10221

Last change on this file since 10221 was 10221, checked in by patrick, 17 years ago

another test

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