Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

gui: borders should work… testing

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  /**
[8035]30   * @brief standard constructor
[7779]31  */
[8035]32  GLGuiWidget::GLGuiWidget (GLGuiWidget* parent)
[7779]33  {
34    this->init();
[8035]35
36    this->setParentWidget(parent);
[7779]37  }
[1853]38
[5359]39
[7779]40  /**
[8035]41   * @brief standard deconstructor
[7779]42   */
43  GLGuiWidget::~GLGuiWidget()
44  {
[7919]45    if (this == GLGuiWidget::_focused)
46      GLGuiWidget::_focused = NULL;
[7779]47  }
[5359]48
[8035]49  GLGuiWidget* GLGuiWidget::_selected = NULL;
[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
[8035]68    this->_backMat.setDiffuse(1.0, 1.0, 1.0);
69    this->_frontMat.setDiffuse(1.0, 0.0, 0.0);
[8115]70
[8116]71    this->_borderLeft = 10.0;
[8115]72    this->_borderRight = 1.0;
73    this->_borderTop = 1.0;
74    this->_borderBottom = 1.0;
[8035]75  }
[6287]76
[8035]77
78  void GLGuiWidget::setParentWidget(GLGuiWidget* parent)
79  {
80    this->_parent = parent;
81
82    if (parent != NULL)
83      parent->addChild2D(this);
[7779]84  }
[5392]85
[7919]86  /** @brief gives focus to this widget */
87  void GLGuiWidget::giveFocus()
[7779]88  {
[7919]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 &&
[8035]109            this->getAbsCoor2D().y < position.y && this->getAbsCoor2D().y + this->getSizeY2D() > position.y);
[7779]110  }
[5391]111
[7919]112  bool GLGuiWidget::focusOverWidget(const GLGuiCursor* const cursor) const
113  {
114    return this->focusOverWidget(cursor->getAbsCoor2D());
115  }
116
[8035]117
118  void GLGuiWidget::setBorderSize(float borderSize)
[7919]119  {
[8115]120    this->_borderLeft = borderSize;
121    this->_borderRight = borderSize;
122    this->_borderTop = borderSize;
123    this->_borderBottom = borderSize;
[8035]124    this->resize();
125  }
126
[8115]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  }
[8035]147
[8115]148
149
[8035]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  {
[7919]160    assert (!this->_pushed);
161    this->_pushed = true;
162
[8035]163    this->clicking(pos);
[7919]164  }
165
[8035]166  void GLGuiWidget::release(const Vector2D& pos)
[7919]167  {
168    if (this->_pushed)
169    {
[8035]170      this->releasing(pos);
[7919]171      this->_pushed = false;
172    }
173  }
174
175
[8035]176  void GLGuiWidget::clicking(const Vector2D& pos)
[7919]177  {
178    this->frontMaterial().setDiffuse(0, 0, 1);
179
180  }
181
[8035]182  void GLGuiWidget::releasing(const Vector2D& pos)
[7919]183  {
[8035]184    this->frontMaterial().setDiffuse(0,1,0);
[7919]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()
[8035]200  {}
201  ;
202
203  void GLGuiWidget::setWidgetSize(const Vector2D& size)
[7919]204  {
[8035]205    this->setSize2D(size);
206    this->resize();
[7919]207
[8035]208  }
[7919]209
210
[8035]211  void GLGuiWidget::setWidgetSize(float x, float y)
[7779]212  {
[8035]213    this->setWidgetSize(Vector2D(x, y));
214  }
[5391]215
[5392]216
[8035]217
218  void GLGuiWidget::connect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver, Slot executor)
219  {
220    sender->connect(signal, receiver, executor);
[7779]221  }
[5392]222
[8035]223  void GLGuiWidget::connect(Signal& signal, BaseObject* receiver, Slot executor)
[7779]224  {
[8035]225    signal.push_back(SignalConnector(receiver, executor));
[7779]226  }
[5366]227
[5395]228
[7779]229  void GLGuiWidget::show()
230  {
231    this->setVisibility(true);
[8115]232    this->showing();
[7779]233  }
[6287]234
[8035]235
[7779]236  void GLGuiWidget::hide()
237  {
238    this->setVisibility(false);
[8115]239    this->hiding();
[7779]240  }
[6287]241
[6431]242
[8035]243  /**
244   * USE THIS FUNCTION ONLY FROM DERIVED CLASS
245   */
[7779]246  void GLGuiWidget::draw() const
247  {
[8035]248    this->backMaterial().select();
249    this->drawRect(this->backRect());
[7779]250  }
251
[6287]252}
Note: See TracBrowser for help on using the repository browser.