Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gl_gui/glgui_widget.cc @ 8015

Last change on this file since 8015 was 7919, checked in by bensch, 19 years ago

orxonox/trunk: merged the gui branche back
merged with command:
https://svn.orxonox.net/orxonox/branches/gui
no conflicts

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