Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10222 was 10222, checked in by hejja, 17 years ago

more

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