Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

font-loading hack, until fonts are real resources, and can be loaded as such

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