Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

EVENTS WORK :)

File size: 4.9 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
[7943]50  GLGuiWidget* GLGuiWidget::_selected = NULL;
[7919]51  GLGuiWidget* GLGuiWidget::_focused = NULL;
52  GLGuiWidget* GLGuiWidget::_inputGrabber = NULL;
[5362]53
[7919]54
55
[7779]56  /**
57   * initializes the GUI-element
58   */
59  void GLGuiWidget::init()
60  {
61    this->setClassID(CL_GLGUI_WIDGET, "GLGuiWidget");
[5392]62
[7919]63    this->_focusable = false;
64    this->_clickable = false;
65    this->_pushed = false;
66
[7779]67    this->setVisibility(GLGUI_WIDGET_DEFAULT_VISIBLE);
[5392]68
[7924]69    this->_backMat.setDiffuse(1.0, 1.0, 1.0);
70    this->_frontMat.setDiffuse(1.0, 0.0, 0.0);
[7936]71    this->_borderSize = 1.0;
[6287]72
[7855]73    this->widgetSignals.resize(SignalCount, SignalConnector());
[7779]74  }
[5392]75
76
[7919]77  /** @brief gives focus to this widget */
78  void GLGuiWidget::giveFocus()
[7779]79  {
[7919]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 &&
[7943]100            this->getAbsCoor2D().y < position.y && this->getAbsCoor2D().y + this->getSizeY2D() > position.y);
[7779]101  }
[5391]102
[7919]103  bool GLGuiWidget::focusOverWidget(const GLGuiCursor* const cursor) const
104  {
105    return this->focusOverWidget(cursor->getAbsCoor2D());
106  }
107
[7925]108
[7936]109  void GLGuiWidget::setBorderSize(float borderSize)
110  {
111    this->_borderSize = borderSize;
112    this->resize();
113  }
114
115
[7925]116  void GLGuiWidget::resize()
117  {
118    this->backRect().setSize(this->getSize2D());
119  }
120
121
[7929]122  void GLGuiWidget::click(const Vector2D& pos)
[7919]123  {
124    assert (!this->_pushed);
125    this->widgetSignals[Signal_click]("none");
126    this->_pushed = true;
127
[7985]128    this->clicking(pos);
[7919]129  }
130
[7929]131  void GLGuiWidget::release(const Vector2D& pos)
[7919]132  {
133    if (this->_pushed)
134    {
135      this->widgetSignals[Signal_release]("none");
136
[7985]137      this->releasing(pos);
[7919]138      this->_pushed = false;
139    }
140  }
141
142
[7985]143  void GLGuiWidget::clicking(const Vector2D& pos)
[7919]144  {
145    this->frontMaterial().setDiffuse(0, 0, 1);
146
147  }
148
[7985]149  void GLGuiWidget::releasing(const Vector2D& pos)
[7919]150  {
[7924]151    this->frontMaterial().setDiffuse(0,1,0);
[7919]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()
[7943]167  {}
168  ;
[7919]169
170
171
172
[7972]173  void GLGuiWidget::connect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver, Slot executor)
174  {
175    sender->connect(signal, receiver, executor);
176  }
177
178  void GLGuiWidget::connect(Signal& signal, BaseObject* receiver, Slot executor)
179  {
180    signal.push_back(SignalConnector(receiver, executor));
181  }
182
183
[7779]184  /**
185   * @brief connects a Signal to the Gui-Elements' Event.
186   * @param sinalType the Type of Signal to set. @see GLGuiSignalType
187   * @param signal the name of the Signal
188   */
[7855]189  void GLGuiWidget::connectSignal(SignalType signalType, BaseObject* object, const Executor* signal)
[7779]190  {
[7855]191    if (signalType >= this->widgetSignals.size())
[7779]192      return;
[5391]193
[7943]194    //    if (this->widgetSignals[signalType] != NULL)
195    //      PRINTF(2)("Already connected a Signal to '%s::%s' type %s... overwriting\n", this->getClassName(), this->getName(), "TEST");
[5392]196
[7855]197    this->widgetSignals[signalType] = SignalConnector(object, signal);
[7779]198  }
[5392]199
[7779]200  /**
201   * @brief removes a Signal from a Gui-ELements' Event
202   * @param signalType the type of Signal to remove.
203   */
[7855]204  void GLGuiWidget::disconnectSignal(SignalType signalType)
[7779]205  {
[7855]206    if (signalType >= this->widgetSignals.size())
[7779]207      return;
[5359]208
[7855]209    this->widgetSignals[signalType] = SignalConnector();
[7779]210  }
[5366]211
[5395]212
[7779]213  void GLGuiWidget::show()
214  {
215    this->setVisibility(true);
216  }
[6287]217
[7925]218
[7779]219  void GLGuiWidget::hide()
220  {
221    this->setVisibility(false);
222  }
[6287]223
[6431]224
[7925]225  /**
226   * USE THIS FUNCTION ONLY FROM DERIVED CLASS
227   */
[7779]228  void GLGuiWidget::draw() const
229  {
[7924]230    this->backMaterial().select();
[7925]231    this->drawRect(this->backRect());
[7779]232  }
233
[6287]234}
Note: See TracBrowser for help on using the repository browser.