Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged the proxy bache back with no conflicts

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"
27
[8982]28/// TODO TAKE THIS OUT OF HERE
29#include "loading/resource_manager.h"
30
[7779]31namespace OrxGui
[3365]32{
[1853]33
[7779]34  /**
[8035]35   * @brief standard constructor
[7779]36  */
[8035]37  GLGuiWidget::GLGuiWidget (GLGuiWidget* parent)
[7779]38  {
39    this->init();
[8035]40
41    this->setParentWidget(parent);
[7779]42  }
[1853]43
[5359]44
[7779]45  /**
[8619]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  /**
[8035]73   * @brief standard deconstructor
[7779]74   */
75  GLGuiWidget::~GLGuiWidget()
76  {
[8717]77    if (this == GLGuiWidget::_mouseFocused)
78      GLGuiWidget::_mouseFocused = NULL;
79    if (this == GLGuiWidget::selected())
80      this->unselect();
[9656]81
82    if (this->_parent != NULL)
83      this->_parent->removeChildWidget(this);
[7779]84  }
[5359]85
[8035]86  GLGuiWidget* GLGuiWidget::_selected = NULL;
[8717]87  GLGuiWidget* GLGuiWidget::_mouseFocused = NULL;
[7919]88  GLGuiWidget* GLGuiWidget::_inputGrabber = NULL;
[9656]89  Font* GLGuiWidget::_defaultFont = NULL;
[5362]90
[7919]91
[7779]92  /**
93   * initializes the GUI-element
94   */
95  void GLGuiWidget::init()
96  {
97    this->setClassID(CL_GLGUI_WIDGET, "GLGuiWidget");
[5392]98
[7919]99    this->_focusable = false;
100    this->_clickable = false;
[8717]101    this->_selectable = false;
[7919]102    this->_pushed = false;
[8619]103    this->_state = OrxGui::Normal;
[7919]104
[9656]105    if(GLGuiWidget::_defaultFont == NULL)
106      GLGuiWidget::_defaultFont = new Font(ResourceManager::getInstance()->getDataDir() + "/fonts/final_frontier.ttf", 20);
[8619]107
[9656]108    this->_font = *GLGuiWidget::_defaultFont;
[8619]109    this->resetStyle();
110
111    this->_animating = false;
112    this->_animationCycle = 0.0;
113    this->_animationDuration = 1.0;
114
115
116    this->setBackgroundColor(Color(.51, .3, .3, .5));
117    this->setBackgroundColor(Color(.3, .5, .3, 1), OrxGui::Selected);
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
[9019]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);
[8619]126    this->setForegroundColor(Color(.1, .1, .1, 1), OrxGui::Insensitive);
127
[7779]128    this->setVisibility(GLGUI_WIDGET_DEFAULT_VISIBLE);
[5392]129
[8619]130    this->setBorderLeft(15);
131    this->setBackgroundTexture("gui_element_background.png");
[8115]132
[8619]133    this->switchState(_state);
134    this->_currentStyle = this->_style[_state];
[8035]135  }
[6287]136
[8035]137
138  void GLGuiWidget::setParentWidget(GLGuiWidget* parent)
139  {
140    this->_parent = parent;
141
142    if (parent != NULL)
143      parent->addChild2D(this);
[7779]144  }
[5392]145
[7919]146
[8717]147  void GLGuiWidget::setFrontColor(const Color& frontColor, bool instantaniously)
[7919]148  {
[8717]149    this->_currentStyle._foreground.setDiffuseColor(frontColor);
150    this->animateBack();
[7919]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 &&
[8717]157        this->getAbsCoor2D().y < position.y && this->getAbsCoor2D().y + this->getSizeY2D() > position.y);
[7779]158  }
[5391]159
[7919]160  bool GLGuiWidget::focusOverWidget(const GLGuiCursor* const cursor) const
161  {
162    return this->focusOverWidget(cursor->getAbsCoor2D());
163  }
164
[8619]165
166
[8717]167  /** @brief gives focus to this widget */
168  void GLGuiWidget::giveMouseFocus()
[8448]169  {
[8717]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();
[8448]180  };
[8035]181
[8717]182  void GLGuiWidget::breakMouseFocus()
183  {
184    if (GLGuiWidget::_mouseFocused == this)
185    {
186      GLGuiWidget::_mouseFocused = NULL;
[8448]187
[8717]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
[8035]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  {
[7919]238    assert (!this->_pushed);
239    this->_pushed = true;
240
[8035]241    this->clicking(pos);
[7919]242  }
243
[8035]244  void GLGuiWidget::release(const Vector2D& pos)
[7919]245  {
246    if (this->_pushed)
247    {
[8717]248      this->releasing(pos, GLGuiWidget::_mouseFocused == this);
[7919]249      this->_pushed = false;
250    }
251  }
252
253
[8035]254  void GLGuiWidget::clicking(const Vector2D& pos)
[8717]255  {}
256
257  void GLGuiWidget::releasing(const Vector2D& pos, bool focused)
258  {}
259
260  void GLGuiWidget::receivedFocus()
[7919]261  {
262  }
263
[8717]264  void GLGuiWidget::removedFocus()
[7919]265  {
[8717]266
[7919]267  }
268
[8717]269  void GLGuiWidget::selecting()
[7919]270  {
271  }
272
[8717]273  void GLGuiWidget::unselecting()
[7919]274  {
[8717]275  }
[7919]276
[8717]277
278  void GLGuiWidget::destroying()
279  {
[7919]280  }
281
[8035]282
283  void GLGuiWidget::setWidgetSize(const Vector2D& size)
[7919]284  {
[8035]285    this->setSize2D(size);
286    this->resize();
[7919]287
[8035]288  }
[7919]289
290
[8035]291  void GLGuiWidget::setWidgetSize(float x, float y)
[7779]292  {
[8035]293    this->setWidgetSize(Vector2D(x, y));
294  }
[5391]295
[7779]296  void GLGuiWidget::show()
297  {
298    this->setVisibility(true);
[8115]299    this->showing();
[7779]300  }
[6287]301
[8035]302
[8312]303
[7779]304  void GLGuiWidget::hide()
305  {
306    this->setVisibility(false);
[8115]307    this->hiding();
[7779]308  }
[6287]309
[8619]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  * @brief sets the Background Texture to all States.
569  * @param textureName the Texture's fileName.
570   */
571  void GLGuiWidget::setBackgroundTexture(const std::string& textureName)
572  {
573    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
574      _style[i]._background.setDiffuseMap(textureName);
575    this->_currentStyle._background.setDiffuseMap(textureName);
576  }
577
578  /**
579   * @brief sets the Background Texture.
580   * @param texture the Texture.
581   * @param state the State to setup.
582   */
583  void GLGuiWidget::setBackgroundTexture(const Texture& texture, OrxGui::State state)
584  {
585    _style[state]._background.setDiffuseMap(texture);
586    if (state == _state)
587      _currentStyle._background.setDiffuseMap(texture);
588  }
589
590
591
592  /**
593   * @brief sets the Background Texture.
594   * @param texture the Texture.
595   * @param stateName the State to setup.
596   */
597  void GLGuiWidget::setBackgroundTexture(const std::string& textureName, const std::string& stateName)
598  {
599    OrxGui::State state;
600    if (getState(stateName, &state))
601      ; /// FIXME this->setBackgroundTexture(textureName, state);
602    else
603      ; ///    this->setBackgroundTexture(textureName);
604  }
605
606
607  /**
608   * @brief sets the Foreground Color for all States.
609   * @param color the Color.
610   */
611  void GLGuiWidget::setForegroundColor(const Color& color)
612  {
613    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
614      setForegroundColor(color, (OrxGui::State)i);
615  }
616
617  /**
618   * @brief sets the Foreground Color.
619   * @param color the Color.
620   * @param state the State to setup
621   */
622  void GLGuiWidget::setForegroundColor(const Color& color, OrxGui::State state)
623  {
624    _style[state]._foreground.setDiffuseColor(color);
625    if (state == _state)
626      _currentStyle._foreground.setDiffuseColor(color);
627
628  }
629
630  /**
631   * @brief sets the Foreground Color.
632   * @param r the Color's red part.
633   * @param g the Color's green part.
634   * @param b the Color's blue part.
635   * @param a the Color's alpha part.
636   * @param stateName: the State to setup
637   */
638  void GLGuiWidget::setForegroundColorS(float r, float g, float b, float a, const std::string& stateName)
639  {
640    OrxGui::State state;
641    if (getState(stateName, &state))
642      this->setForegroundColor(Color(r,g,b,a), state);
643    else
644      this->setForegroundColor(Color(r,g,b,a));
645  }
646
647
[8990]648    /**
649   * @brief sets the Foreground Texture for all States.
650   * @param texture the Texture.
651     */
652  void GLGuiWidget::setForegroundTexture(const Texture& texture)
653  {
654    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
655      setForegroundTexture(texture, (OrxGui::State)i);
656  }
657
658  /**
659   * @brief sets the Foreground Texture to all States.
660   * @param textureName the Texture's fileName.
661   */
662  void GLGuiWidget::setForegroundTexture(const std::string& textureName)
663  {
664    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
665      _style[i]._foreground.setDiffuseMap(textureName);
666    this->_currentStyle._foreground.setDiffuseMap(textureName);
667  }
668
669  /**
670   * @brief sets the Foreground Texture.
671   * @param texture the Texture.
672   * @param state the State to setup.
673   */
674  void GLGuiWidget::setForegroundTexture(const Texture& texture, OrxGui::State state)
675  {
676    _style[state]._background.setDiffuseMap(texture);
677    if (state == _state)
678      _currentStyle._background.setDiffuseMap(texture);
679  }
680
681
682
683  /**
684   * @brief sets the Foreground Texture.
685   * @param texture the Texture.
686   * @param stateName the State to setup.
687   */
688  void GLGuiWidget::setForegroundTexture(const std::string& textureName, const std::string& stateName)
689  {
690    OrxGui::State state;
691    if (getState(stateName, &state))
692      ; /// FIXME this->setForegroundTexture(textureName, state);
693    else
694      ; ///    this->setForegroundTexture(textureName);
695  }
696
697
[8619]698  void GLGuiWidget::loadBackgroundMaterial(const Material& material)
699  {
700    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
701      this->loadForegroundMaterial(material, (OrxGui::State)i);
702  }
703
704  void GLGuiWidget::loadBackgroundMaterial(const Material& material, OrxGui::State state)
705  {
706    this->_style[state]._background = material;
707    if (state == _state)
708      _currentStyle._background = material;
709
710  }
711
712  void GLGuiWidget::loadBackgroundMaterial(const TiXmlElement* element)
713  {
714    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
715      this->loadBackgroundMaterial(element, (OrxGui::State)i);
716  }
717
718  void GLGuiWidget::loadBackgroundMaterial(const TiXmlElement* element, OrxGui::State state)
719  {
720    this->_style[state]._background.loadParams(element);
721    if (state == _state)
722      this->_currentStyle._background = _style[state]._background;
723  }
724
725  void GLGuiWidget::loadBackgroundMaterialS(const TiXmlElement* element, const std::string& stateName)
726  {
727    OrxGui::State state;
728    if (getState(stateName, &state))
729      this->loadBackgroundMaterial(element, state);
730    else
731      this->loadBackgroundMaterial(element);
732  }
733
734  void GLGuiWidget::loadForegroundMaterial(const Material& material)
735{}
736  void GLGuiWidget::loadForegroundMaterial(const Material& material, OrxGui::State state)
737  {}
738  void GLGuiWidget::loadForegroundMaterial(const TiXmlElement* element, OrxGui::State state)
739  {}
740  void GLGuiWidget::loadForegroundMaterialS(const TiXmlElement* element, const std::string& stateName)
741  {}
742
743
744  /**
745   * @brief sets the Feature-Position.
746   * @param featurePosition the Feature-Position.
747   */
748  void GLGuiWidget::setFeaturePosition(FeaturePosition featurePosition)
749  {
750    this->_featurePosition = featurePosition;
751  }
752
753  /**
754   * @brief sets the Feature-Position by converting from a String.
755   * @param featurePosition the Feature-Position.
756   */
757  void GLGuiWidget::setFeaturePositionS(const std::string& featurePosition)
758  {
759    for (unsigned int i = 0; i < 4; ++i)
760    {
761      if (featurePosition == FeaturePositionString[i])
762      {
763        this->setFeaturePosition((FeaturePosition)i);
764      }
765    }
766  }
767
768  /**
769   * @brief sets the Font.
770   * @param font the Font.
771   */
[8769]772  void GLGuiWidget::setFont(const Font& font)
[8619]773  {
774    this->_font = font;
775  }
776
777  /**
778   * @brief sets the font from a Font-Name.
779   * @param fontName the FileName of the Font.
780   */
[8769]781  void GLGuiWidget::setFont(const std::string& fontName, unsigned int renderSize)
[8619]782  {
[9656]783    this->setFont(Font(fontName, renderSize));
[8619]784  }
785
786  /**
787   * @brief sets the AnimatedState.
788   * @param animated: it states-changes should animate true, otherwise false.
789   */
790  void GLGuiWidget::setAnimatedStateChanges(bool animated)
791  {
792    this->_animatedStateChanges = animated;
793  }
794
795
796  void GLGuiWidget::switchState(OrxGui::State state)
797  {
798    //this->_currentStyle = this->_style[state];
799    this->_state = state;
[9406]800    PRINTF(4)("%s::%s Switches to state %s\n", this->getClassCName(), this->getCName(), OrxGui::StateString[state].c_str());
[8619]801
802    this->animateBack();
803  }
804
805
806  void GLGuiWidget::animateBack()
807  {
808    this->_animating = true;
809    this->_animationCycle = 0.0f;
810  }
811
812
[8448]813  void GLGuiWidget::tick(float dt)
814  {
[8619]815    if (this->_animating)
[8448]816    {
[8619]817      this->foregroundColor();
818
819      _animationCycle += dt / _animationDuration;
820      if (_animationCycle >= 1.0)
[8448]821      {
[8619]822        _currentStyle._foreground.diffuseColor() = this->foregroundColor(_state);
823        _currentStyle._background.diffuseColor() = this->backgroundColor(_state);
824        _animating = false;
[8448]825      }
[8619]826      else
827      {
828        _currentStyle._foreground.diffuseColor().slerp(this->foregroundColor(_state), _animationCycle);
829        _currentStyle._background.diffuseColor().slerp(this->backgroundColor(_state), _animationCycle);
830      }
831      this->updateFrontColor();
[8448]832    }
833  }
[6431]834
[8448]835
[8035]836  /**
837   * USE THIS FUNCTION ONLY FROM DERIVED CLASS
838   */
[7779]839  void GLGuiWidget::draw() const
840  {
[8619]841    this->background().select();
[8035]842    this->drawRect(this->backRect());
[8619]843    this->background().unselect();
[7779]844  }
845
[8619]846
847  /**
848   * @param stateName the Name of a State.
849   * @param state the found State is returned here if found.
850   * @returns true if String is found, false otherwise.
851   */
852  bool GLGuiWidget::getState(const std::string& stateName, OrxGui::State* state)
853  {
854    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
855      if (stateName == OrxGui::StateString[i])
[8717]856      {
857        *state = (OrxGui::State)i;
858        return true;
859      }
[8619]860    return false;
861  }
862
863  /**
864   * @brief print out some nice debug output about the Widget.
865   */
[8717]866  void GLGuiWidget::debug(unsigned int level) const
[8619]867  {
[9406]868    PRINT(0)("Debug of %s::%s - WidgetPart ", this->getClassCName(), this->getCName());
[8619]869    if (_parent != NULL)
[9406]870      PRINT(0)("- Parent %s::%s ", _parent->getClassCName(), _parent->getCName());
[8619]871    PRINT(0)("- State: %s", StateString[_state].c_str());
872
873    if (_focusable)
874      PRINT(0)("- focusable ");
875    if (_clickable)
876      PRINT(0)("- Clickable ");
877    if (_pushed)
878      PRINT(0)("- Pushed ");
879    PRINT(0)("\n");
880
881
882    PRINT(0)("Minimum Size %0.2f %0.2f ", _minSize.x, _minSize.y);
883    PRINT(0)("Back Rect: ");
884    _backRect.debug();
885    PRINT(0)("Style:\n");
886
887    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
888    {
889      PRINT(0)("In State %s: \n", StateString[i].c_str());
890
891      PRINT(0)("  Borders: Left: %0.2f, Right: %0.2f, Top: %0.2f, Bottom %0.2f\n",
892               _style[i]._borderLeft, _style[i]._borderRight, _style[i]._borderTop, _style[i]._borderBottom);
893      PRINT(0)("  TextSize %0.2f\n", _style[i]._textSize);
894      PRINT(0)("  BackgroundColor: "); _style[i]._background.diffuseColor().debug();
895      PRINT(0)("  ForegroundColor: "); _style[i]._foreground.diffuseColor().debug();
896      PRINT(0)("\n");
897    }
898
899
900    PRINT(0)(" Feature at %s ", FeaturePositionString[_featurePosition].c_str());
901    /// TODO    PRINT(0)("");    Font*               _font;                 //!< The Font used in the current Widget.
902
903    if (_animatedStateChanges)
904      PRINT(0)("- AnimatedStateChanges");
905    PRINT(0)("\n");
906
907    /*
908    if (_animating)
909      PRINT(0)("- Animated ");
910
911    //
912    float               _animationCycle;
913    float               _animationDuration;
914    StatedStyle         _currentStyle;
915    OrxGui::State       _currentState;
916    */
917  }
918
919
[6287]920}
Note: See TracBrowser for help on using the repository browser.