Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

gui: removed the grab-event, and using Rect now

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