Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/water/src/lib/gui/gl_gui/glgui_widget.cc @ 8080

Last change on this file since 8080 was 8035, checked in by bensch, 19 years ago

gui: merged the gui back to the trunk

File size: 4.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 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
26namespace OrxGui
27{
28
29  /**
30   * @brief standard constructor
31  */
32  GLGuiWidget::GLGuiWidget (GLGuiWidget* parent)
33  {
34    this->init();
35
36    this->setParentWidget(parent);
37  }
38
39
40  /**
41   * @brief standard deconstructor
42   */
43  GLGuiWidget::~GLGuiWidget()
44  {
45    if (this == GLGuiWidget::_focused)
46      GLGuiWidget::_focused = NULL;
47  }
48
49  GLGuiWidget* GLGuiWidget::_selected = NULL;
50  GLGuiWidget* GLGuiWidget::_focused = NULL;
51  GLGuiWidget* GLGuiWidget::_inputGrabber = NULL;
52
53
54
55  /**
56   * initializes the GUI-element
57   */
58  void GLGuiWidget::init()
59  {
60    this->setClassID(CL_GLGUI_WIDGET, "GLGuiWidget");
61
62    this->_focusable = false;
63    this->_clickable = false;
64    this->_pushed = false;
65
66    this->setVisibility(GLGUI_WIDGET_DEFAULT_VISIBLE);
67
68    this->_backMat.setDiffuse(1.0, 1.0, 1.0);
69    this->_frontMat.setDiffuse(1.0, 0.0, 0.0);
70    this->_borderSize = 1.0;
71  }
72
73
74  void GLGuiWidget::setParentWidget(GLGuiWidget* parent)
75  {
76    this->_parent = parent;
77
78    if (parent != NULL)
79      parent->addChild2D(this);
80  }
81
82  /** @brief gives focus to this widget */
83  void GLGuiWidget::giveFocus()
84  {
85    if (GLGuiWidget::focused() != NULL)
86      GLGuiWidget::focused()->breakFocus();
87    GLGuiWidget::_focused = this;
88    this->receivedFocus();
89  };
90
91  void GLGuiWidget::breakFocus()
92  {
93    if (GLGuiWidget::_focused == this)
94    {
95      GLGuiWidget::_focused = NULL;
96      this->_pushed = false;
97      this->removedFocus();
98    }
99  };
100
101
102  bool GLGuiWidget::focusOverWidget(const Vector2D& position) const
103  {
104    return (this->getAbsCoor2D().x < position.x && this->getAbsCoor2D().x + this->getSizeX2D() > position.x &&
105            this->getAbsCoor2D().y < position.y && this->getAbsCoor2D().y + this->getSizeY2D() > position.y);
106  }
107
108  bool GLGuiWidget::focusOverWidget(const GLGuiCursor* const cursor) const
109  {
110    return this->focusOverWidget(cursor->getAbsCoor2D());
111  }
112
113
114  void GLGuiWidget::setBorderSize(float borderSize)
115  {
116    this->_borderSize = borderSize;
117    this->resize();
118  }
119
120
121  void GLGuiWidget::resize()
122  {
123    this->backRect().setSize(this->getSize2D());
124    if (this->parent() != NULL)
125      this->parent()->resize();
126  }
127
128
129  void GLGuiWidget::click(const Vector2D& pos)
130  {
131    assert (!this->_pushed);
132    this->_pushed = true;
133
134    this->clicking(pos);
135  }
136
137  void GLGuiWidget::release(const Vector2D& pos)
138  {
139    if (this->_pushed)
140    {
141      this->releasing(pos);
142      this->_pushed = false;
143    }
144  }
145
146
147  void GLGuiWidget::clicking(const Vector2D& pos)
148  {
149    this->frontMaterial().setDiffuse(0, 0, 1);
150
151  }
152
153  void GLGuiWidget::releasing(const Vector2D& pos)
154  {
155    this->frontMaterial().setDiffuse(0,1,0);
156
157  }
158
159  void GLGuiWidget::receivedFocus()
160  {
161    this->frontMaterial().setDiffuse(0, 1, 0);
162  }
163
164  void GLGuiWidget::removedFocus()
165  {
166    this->frontMaterial().setDiffuse(1, 0, 0);
167
168  }
169
170  void GLGuiWidget::destroyed()
171  {}
172  ;
173
174  void GLGuiWidget::setWidgetSize(const Vector2D& size)
175  {
176    this->setSize2D(size);
177    this->resize();
178
179  }
180
181
182  void GLGuiWidget::setWidgetSize(float x, float y)
183  {
184    this->setWidgetSize(Vector2D(x, y));
185  }
186
187
188
189  void GLGuiWidget::connect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver, Slot executor)
190  {
191    sender->connect(signal, receiver, executor);
192  }
193
194  void GLGuiWidget::connect(Signal& signal, BaseObject* receiver, Slot executor)
195  {
196    signal.push_back(SignalConnector(receiver, executor));
197  }
198
199
200  void GLGuiWidget::show()
201  {
202    this->setVisibility(true);
203  }
204
205
206  void GLGuiWidget::hide()
207  {
208    this->setVisibility(false);
209  }
210
211
212  /**
213   * USE THIS FUNCTION ONLY FROM DERIVED CLASS
214   */
215  void GLGuiWidget::draw() const
216  {
217    this->backMaterial().select();
218    this->drawRect(this->backRect());
219  }
220
221}
Note: See TracBrowser for help on using the repository browser.