Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: merged the gui back
merged with command:
svn merge -r8114:HEAD https://svn.orxonox.net/orxonox/branches/gui .
→ no conflicts

File size: 4.9 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
71    this->_borderLeft = 1.0;
72    this->_borderRight = 1.0;
73    this->_borderTop = 20.0;
74    this->_borderBottom = 1.0;
75  }
76
77
78  void GLGuiWidget::setParentWidget(GLGuiWidget* parent)
79  {
80    this->_parent = parent;
81
82    if (parent != NULL)
83      parent->addChild2D(this);
84  }
85
86  /** @brief gives focus to this widget */
87  void GLGuiWidget::giveFocus()
88  {
89    if (GLGuiWidget::focused() != NULL)
90      GLGuiWidget::focused()->breakFocus();
91    GLGuiWidget::_focused = this;
92    this->receivedFocus();
93  };
94
95  void GLGuiWidget::breakFocus()
96  {
97    if (GLGuiWidget::_focused == this)
98    {
99      GLGuiWidget::_focused = NULL;
100      this->_pushed = false;
101      this->removedFocus();
102    }
103  };
104
105
106  bool GLGuiWidget::focusOverWidget(const Vector2D& position) const
107  {
108    return (this->getAbsCoor2D().x < position.x && this->getAbsCoor2D().x + this->getSizeX2D() > position.x &&
109            this->getAbsCoor2D().y < position.y && this->getAbsCoor2D().y + this->getSizeY2D() > position.y);
110  }
111
112  bool GLGuiWidget::focusOverWidget(const GLGuiCursor* const cursor) const
113  {
114    return this->focusOverWidget(cursor->getAbsCoor2D());
115  }
116
117
118  void GLGuiWidget::setBorderSize(float borderSize)
119  {
120    this->_borderLeft = borderSize;
121    this->_borderRight = borderSize;
122    this->_borderTop = borderSize;
123    this->_borderBottom = borderSize;
124    this->resize();
125  }
126
127  void GLGuiWidget::setBorderLeft(float borderLeft)
128  {
129    this->_borderLeft = borderLeft;
130    this->resize();
131  }
132  void GLGuiWidget::setBorderRight(float borderRight)
133  {
134    this->_borderRight = borderRight;
135    this->resize();
136  }
137  void GLGuiWidget::setBorderTop(float borderTop)
138  {
139    this->_borderTop = borderTop;
140    this->resize();
141  }
142  void GLGuiWidget::setBorderBottom(float borderBottom)
143  {
144    this->_borderBottom = borderBottom;
145    this->resize();
146  }
147
148
149
150  void GLGuiWidget::resize()
151  {
152    this->backRect().setSize(this->getSize2D());
153    if (this->parent() != NULL)
154      this->parent()->resize();
155  }
156
157
158  void GLGuiWidget::click(const Vector2D& pos)
159  {
160    assert (!this->_pushed);
161    this->_pushed = true;
162
163    this->clicking(pos);
164  }
165
166  void GLGuiWidget::release(const Vector2D& pos)
167  {
168    if (this->_pushed)
169    {
170      this->releasing(pos);
171      this->_pushed = false;
172    }
173  }
174
175
176  void GLGuiWidget::clicking(const Vector2D& pos)
177  {
178    this->frontMaterial().setDiffuse(0, 0, 1);
179
180  }
181
182  void GLGuiWidget::releasing(const Vector2D& pos)
183  {
184    this->frontMaterial().setDiffuse(0,1,0);
185
186  }
187
188  void GLGuiWidget::receivedFocus()
189  {
190    this->frontMaterial().setDiffuse(0, 1, 0);
191  }
192
193  void GLGuiWidget::removedFocus()
194  {
195    this->frontMaterial().setDiffuse(1, 0, 0);
196
197  }
198
199  void GLGuiWidget::destroyed()
200  {}
201  ;
202
203  void GLGuiWidget::setWidgetSize(const Vector2D& size)
204  {
205    this->setSize2D(size);
206    this->resize();
207
208  }
209
210
211  void GLGuiWidget::setWidgetSize(float x, float y)
212  {
213    this->setWidgetSize(Vector2D(x, y));
214  }
215
216
217
218  void GLGuiWidget::connect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver, Slot executor)
219  {
220    sender->connect(signal, receiver, executor);
221  }
222
223  void GLGuiWidget::connect(Signal& signal, BaseObject* receiver, Slot executor)
224  {
225    signal.push_back(SignalConnector(receiver, executor));
226  }
227
228
229  void GLGuiWidget::show()
230  {
231    this->setVisibility(true);
232    this->showing();
233  }
234
235
236  void GLGuiWidget::hide()
237  {
238    this->setVisibility(false);
239    this->hiding();
240  }
241
242
243  /**
244   * USE THIS FUNCTION ONLY FROM DERIVED CLASS
245   */
246  void GLGuiWidget::draw() const
247  {
248    this->backMaterial().select();
249    this->drawRect(this->backRect());
250  }
251
252}
Note: See TracBrowser for help on using the repository browser.