Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged gui back to the trunk
merged with command
merge -r8377:HEAD https://svn.orxonox.net/orxonox/branches/gui .

File size: 5.8 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;
68
[7779]69    this->setVisibility(GLGUI_WIDGET_DEFAULT_VISIBLE);
[5392]70
[8448]71    this->_backMat.setDiffuseColor(Color(1.0, 0.5, 0.4, 1.0));
72    this->_backMat.setDiffuseMap("gui_element_background.png");
73    this->_frontColor = Color(1.0, 0.0, 0.0);
74    this->_toFrontColor = NULL;
[8115]75
[8448]76
77    this->_borderLeft = 15.0;
[8115]78    this->_borderRight = 1.0;
[8335]79    this->_borderTop = 1.0;
[8115]80    this->_borderBottom = 1.0;
[8035]81  }
[6287]82
[8035]83
84  void GLGuiWidget::setParentWidget(GLGuiWidget* parent)
85  {
86    this->_parent = parent;
87
88    if (parent != NULL)
89      parent->addChild2D(this);
[7779]90  }
[5392]91
[7919]92  /** @brief gives focus to this widget */
93  void GLGuiWidget::giveFocus()
[7779]94  {
[7919]95    if (GLGuiWidget::focused() != NULL)
96      GLGuiWidget::focused()->breakFocus();
97    GLGuiWidget::_focused = this;
98    this->receivedFocus();
99  };
100
101  void GLGuiWidget::breakFocus()
102  {
103    if (GLGuiWidget::_focused == this)
104    {
105      GLGuiWidget::_focused = NULL;
106      this->_pushed = false;
107      this->removedFocus();
108    }
109  };
110
111
112  bool GLGuiWidget::focusOverWidget(const Vector2D& position) const
113  {
114    return (this->getAbsCoor2D().x < position.x && this->getAbsCoor2D().x + this->getSizeX2D() > position.x &&
[8035]115            this->getAbsCoor2D().y < position.y && this->getAbsCoor2D().y + this->getSizeY2D() > position.y);
[7779]116  }
[5391]117
[7919]118  bool GLGuiWidget::focusOverWidget(const GLGuiCursor* const cursor) const
119  {
120    return this->focusOverWidget(cursor->getAbsCoor2D());
121  }
122
[8448]123  void GLGuiWidget::setFrontColor(const Color& frontColor, bool instantaniously)
124  {
125    if (instantaniously)
126    {
127      this->_frontColor = frontColor;
128      if (this->_toFrontColor != NULL)
129      {
130        delete this->_toFrontColor;
131        this->_toFrontColor = NULL;
132      }
133    }
134    else if (!this->_toFrontColor)
135      this->_toFrontColor = new Color(frontColor);
136    else
137      *this->_toFrontColor = frontColor;
138    //this->_frontColor = frontColor;
139    //this->updateFrontColor();
140  };
[8035]141
[8448]142
[8035]143  void GLGuiWidget::setBorderSize(float borderSize)
[7919]144  {
[8115]145    this->_borderLeft = borderSize;
146    this->_borderRight = borderSize;
147    this->_borderTop = borderSize;
148    this->_borderBottom = borderSize;
[8035]149    this->resize();
150  }
151
[8115]152  void GLGuiWidget::setBorderLeft(float borderLeft)
153  {
154    this->_borderLeft = borderLeft;
155    this->resize();
156  }
157  void GLGuiWidget::setBorderRight(float borderRight)
158  {
159    this->_borderRight = borderRight;
160    this->resize();
161  }
162  void GLGuiWidget::setBorderTop(float borderTop)
163  {
164    this->_borderTop = borderTop;
165    this->resize();
166  }
167  void GLGuiWidget::setBorderBottom(float borderBottom)
168  {
169    this->_borderBottom = borderBottom;
170    this->resize();
171  }
[8035]172
[8115]173
174
[8035]175  void GLGuiWidget::resize()
176  {
177    this->backRect().setSize(this->getSize2D());
178    if (this->parent() != NULL)
179      this->parent()->resize();
180  }
181
182
183  void GLGuiWidget::click(const Vector2D& pos)
184  {
[7919]185    assert (!this->_pushed);
186    this->_pushed = true;
187
[8035]188    this->clicking(pos);
[7919]189  }
190
[8035]191  void GLGuiWidget::release(const Vector2D& pos)
[7919]192  {
193    if (this->_pushed)
194    {
[8035]195      this->releasing(pos);
[7919]196      this->_pushed = false;
197    }
198  }
199
200
[8035]201  void GLGuiWidget::clicking(const Vector2D& pos)
[7919]202  {
[8448]203    this->setFrontColor(Color(0, 0, 1));
[7919]204
205  }
206
[8035]207  void GLGuiWidget::releasing(const Vector2D& pos)
[7919]208  {
[8448]209    this->setFrontColor(Color(0,1,0));
[7919]210
211  }
212
213  void GLGuiWidget::receivedFocus()
214  {
[8448]215    this->setFrontColor(Color(0, 1, 0));
[7919]216  }
217
218  void GLGuiWidget::removedFocus()
219  {
[8448]220    this->setFrontColor(Color(1, 0, 0));
[7919]221
222  }
223
224  void GLGuiWidget::destroyed()
[8035]225  {}
226  ;
227
[8448]228
[8035]229  void GLGuiWidget::setWidgetSize(const Vector2D& size)
[7919]230  {
[8035]231    this->setSize2D(size);
232    this->resize();
[7919]233
[8035]234  }
[7919]235
236
[8035]237  void GLGuiWidget::setWidgetSize(float x, float y)
[7779]238  {
[8035]239    this->setWidgetSize(Vector2D(x, y));
240  }
[5391]241
[5392]242
[8035]243
244  void GLGuiWidget::connect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver, Slot executor)
245  {
246    sender->connect(signal, receiver, executor);
[7779]247  }
[5392]248
[8035]249  void GLGuiWidget::connect(Signal& signal, BaseObject* receiver, Slot executor)
[7779]250  {
[8035]251    signal.push_back(SignalConnector(receiver, executor));
[7779]252  }
[5366]253
[5395]254
[7779]255  void GLGuiWidget::show()
256  {
257    this->setVisibility(true);
[8115]258    this->showing();
[7779]259  }
[6287]260
[8035]261
[8312]262
[7779]263  void GLGuiWidget::hide()
264  {
265    this->setVisibility(false);
[8115]266    this->hiding();
[7779]267  }
[6287]268
[8448]269  void GLGuiWidget::tick(float dt)
270  {
271    if (this->_toFrontColor)
272    {
273      this->_frontColor.slerp(*_toFrontColor, dt*3.0);
274      this->updateFrontColor();
275      if (this->_frontColor.dist(*_toFrontColor) < .1)
276      {
277        delete _toFrontColor;
278        _toFrontColor = NULL;
279      }
280    }
281  }
[6431]282
[8448]283
[8035]284  /**
285   * USE THIS FUNCTION ONLY FROM DERIVED CLASS
286   */
[7779]287  void GLGuiWidget::draw() const
288  {
[8035]289    this->backMaterial().select();
290    this->drawRect(this->backRect());
[8448]291    this->backMaterial().unselect();
[7779]292  }
293
[6287]294}
Note: See TracBrowser for help on using the repository browser.