Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain.older/src/lib/gui/gl/glgui_widget.cc @ 10764

Last change on this file since 10764 was 9019, checked in by bensch, 18 years ago

orxonox/trunk: OggPlayer retrieves Information about the current Title
The Title Played is relayed to the Hud's Notifier

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