Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

gui: selected introduced

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