Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

gui: using style.

File size: 5.1 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
[5359]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
[7779]26namespace OrxGui
[3365]27{
[1853]28
[7779]29  /**
[8035]30   * @brief standard constructor
[7779]31  */
[8035]32  GLGuiWidget::GLGuiWidget (GLGuiWidget* parent)
[7779]33  {
34    this->init();
[8035]35
36    this->setParentWidget(parent);
[7779]37  }
[1853]38
[5359]39
[7779]40  /**
[8035]41   * @brief standard deconstructor
[7779]42   */
43  GLGuiWidget::~GLGuiWidget()
44  {
[7919]45    if (this == GLGuiWidget::_focused)
46      GLGuiWidget::_focused = NULL;
[8448]47
48    if (this->_toFrontColor)
49      delete this->_toFrontColor;
[7779]50  }
[5359]51
[8035]52  GLGuiWidget* GLGuiWidget::_selected = NULL;
[7919]53  GLGuiWidget* GLGuiWidget::_focused = NULL;
54  GLGuiWidget* GLGuiWidget::_inputGrabber = NULL;
[5362]55
[7919]56
57
[7779]58  /**
59   * initializes the GUI-element
60   */
61  void GLGuiWidget::init()
62  {
63    this->setClassID(CL_GLGUI_WIDGET, "GLGuiWidget");
[5392]64
[7919]65    this->_focusable = false;
66    this->_clickable = false;
67    this->_pushed = false;
[8583]68    this->_state = OrxGui::Normal;
[7919]69
[7779]70    this->setVisibility(GLGUI_WIDGET_DEFAULT_VISIBLE);
[5392]71
[8583]72/*    this->_backMat.setDiffuseColor(Color(1.0, 0.5, 0.4, 1.0));
[8448]73    this->_backMat.setDiffuseMap("gui_element_background.png");
[8583]74    this->_frontColor = Color(1.0, 0.0, 0.0);*/
[8448]75    this->_toFrontColor = NULL;
[8035]76  }
[6287]77
[8035]78
79  void GLGuiWidget::setParentWidget(GLGuiWidget* parent)
80  {
81    this->_parent = parent;
82
83    if (parent != NULL)
84      parent->addChild2D(this);
[7779]85  }
[5392]86
[7919]87  /** @brief gives focus to this widget */
88  void GLGuiWidget::giveFocus()
[7779]89  {
[7919]90    if (GLGuiWidget::focused() != NULL)
91      GLGuiWidget::focused()->breakFocus();
92    GLGuiWidget::_focused = this;
93    this->receivedFocus();
94  };
95
96  void GLGuiWidget::breakFocus()
97  {
98    if (GLGuiWidget::_focused == this)
99    {
100      GLGuiWidget::_focused = NULL;
101      this->_pushed = false;
102      this->removedFocus();
103    }
104  };
105
106
107  bool GLGuiWidget::focusOverWidget(const Vector2D& position) const
108  {
109    return (this->getAbsCoor2D().x < position.x && this->getAbsCoor2D().x + this->getSizeX2D() > position.x &&
[8035]110            this->getAbsCoor2D().y < position.y && this->getAbsCoor2D().y + this->getSizeY2D() > position.y);
[7779]111  }
[5391]112
[7919]113  bool GLGuiWidget::focusOverWidget(const GLGuiCursor* const cursor) const
114  {
115    return this->focusOverWidget(cursor->getAbsCoor2D());
116  }
117
[8448]118  void GLGuiWidget::setFrontColor(const Color& frontColor, bool instantaniously)
119  {
120    if (instantaniously)
121    {
[8583]122      this->style().setForegroundColor(frontColor);
[8448]123      if (this->_toFrontColor != NULL)
124      {
125        delete this->_toFrontColor;
126        this->_toFrontColor = NULL;
127      }
128    }
129    else if (!this->_toFrontColor)
130      this->_toFrontColor = new Color(frontColor);
131    else
132      *this->_toFrontColor = frontColor;
133    //this->_frontColor = frontColor;
134    //this->updateFrontColor();
135  };
[8035]136
[8448]137
[8035]138  void GLGuiWidget::resize()
139  {
140    this->backRect().setSize(this->getSize2D());
141    if (this->parent() != NULL)
142      this->parent()->resize();
143  }
144
145
146  void GLGuiWidget::click(const Vector2D& pos)
147  {
[7919]148    assert (!this->_pushed);
149    this->_pushed = true;
150
[8035]151    this->clicking(pos);
[7919]152  }
153
[8035]154  void GLGuiWidget::release(const Vector2D& pos)
[7919]155  {
156    if (this->_pushed)
157    {
[8035]158      this->releasing(pos);
[7919]159      this->_pushed = false;
160    }
161  }
162
163
[8035]164  void GLGuiWidget::clicking(const Vector2D& pos)
[7919]165  {
[8448]166    this->setFrontColor(Color(0, 0, 1));
[7919]167
168  }
169
[8035]170  void GLGuiWidget::releasing(const Vector2D& pos)
[7919]171  {
[8448]172    this->setFrontColor(Color(0,1,0));
[7919]173
174  }
175
176  void GLGuiWidget::receivedFocus()
177  {
[8448]178    this->setFrontColor(Color(0, 1, 0));
[7919]179  }
180
181  void GLGuiWidget::removedFocus()
182  {
[8448]183    this->setFrontColor(Color(1, 0, 0));
[7919]184
185  }
186
187  void GLGuiWidget::destroyed()
[8035]188  {}
189  ;
190
[8448]191
[8035]192  void GLGuiWidget::setWidgetSize(const Vector2D& size)
[7919]193  {
[8035]194    this->setSize2D(size);
195    this->resize();
[7919]196
[8035]197  }
[7919]198
199
[8035]200  void GLGuiWidget::setWidgetSize(float x, float y)
[7779]201  {
[8035]202    this->setWidgetSize(Vector2D(x, y));
203  }
[5391]204
[5392]205
[8035]206
207  void GLGuiWidget::connect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver, Slot executor)
208  {
209    sender->connect(signal, receiver, executor);
[7779]210  }
[5392]211
[8035]212  void GLGuiWidget::connect(Signal& signal, BaseObject* receiver, Slot executor)
[7779]213  {
[8035]214    signal.push_back(SignalConnector(receiver, executor));
[7779]215  }
[5366]216
[5395]217
[7779]218  void GLGuiWidget::show()
219  {
220    this->setVisibility(true);
[8115]221    this->showing();
[7779]222  }
[6287]223
[8035]224
[8312]225
[7779]226  void GLGuiWidget::hide()
227  {
228    this->setVisibility(false);
[8115]229    this->hiding();
[7779]230  }
[6287]231
[8448]232  void GLGuiWidget::tick(float dt)
233  {
234    if (this->_toFrontColor)
235    {
[8583]236      this->_style.foregroundColor(_state).slerp(*_toFrontColor, dt*3.0);
[8448]237      this->updateFrontColor();
[8583]238      if (this->style().foregroundColor(_state).dist(*_toFrontColor) < .1)
[8448]239      {
240        delete _toFrontColor;
241        _toFrontColor = NULL;
242      }
243    }
244  }
[6431]245
[8448]246
[8035]247  /**
248   * USE THIS FUNCTION ONLY FROM DERIVED CLASS
249   */
[7779]250  void GLGuiWidget::draw() const
251  {
[8583]252    this->background().select();
[8035]253    this->drawRect(this->backRect());
[8583]254    this->background().unselect();
[7779]255  }
256
[6287]257}
Note: See TracBrowser for help on using the repository browser.