Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10613 was 10489, checked in by patrick, 18 years ago

nicer gui entries

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