Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gl/glgui_handler.cc @ 8619

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

orxonox/trunk: fixed compile errors

File size: 4.6 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_handler.h"
19#include "event_handler.h"
20
21#include "glgui_mainwidget.h"
22#include "glgui_cursor.h"
23
24#include "class_list.h"
25
26#include <cassert>
27
28
29/// TAKE THIS OUT OF HERE.
30#include "graphics_engine.h"
31
32namespace OrxGui
33{
34
35  /**
36   * standard constructor
37   */
38  GLGuiHandler::GLGuiHandler ()
39  {
40    this->setClassID(CL_GLGUI_HANDLER, "GLGuiHandler");
41    this->setName("GLGuiHandler");
42
43
44    EventHandler::getInstance()->withUNICODE(ES_MENU, true );
45
46    this->_cursor = NULL;
47    for (unsigned int i = 0; i < EV_NUMBER; i++)
48    {
49      this->subscribeEvent(ES_ALL, i);
50    }
51  }
52
53  /**
54   *  the singleton reference to this class
55   */
56  GLGuiHandler* GLGuiHandler::singletonRef = NULL;
57
58  /**
59     @brief standard deconstructor
60   */
61  GLGuiHandler::~GLGuiHandler ()
62  {
63    GLGuiHandler::singletonRef = NULL;
64  }
65
66  void GLGuiHandler::activateCursor()
67  {
68    if (this->_cursor == NULL)
69      this->_cursor = new GLGuiCursor();
70    this->_cursor->show();
71    this->_cursor->setMaxBorders(Vector2D(GraphicsEngine::getInstance()->getResolutionX(), GraphicsEngine::getInstance()->getResolutionY()));
72  }
73
74  void GLGuiHandler::deactivateCursor(bool deleteCursor)
75  {
76    if (this->_cursor)
77    {
78      if (deleteCursor)
79        delete this->_cursor;
80      this->_cursor = NULL;
81    }
82  }
83
84
85  void GLGuiHandler::activate()
86  {
87    EventHandler::getInstance()->pushState(ES_MENU);
88
89
90
91  }
92
93  void GLGuiHandler::deactivate()
94  {
95    EventHandler::getInstance()->popState();
96
97
98  }
99
100
101  void GLGuiHandler::process(const Event &event)
102  {
103    switch (event.type)
104    {
105      case  EV_MOUSE_BUTTON_LEFT:
106        if (GLGuiWidget::focused() != NULL)
107        {
108          if (event.bPressed)
109          {
110            if (GLGuiWidget::focused()->clickable())
111            {
112              Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y);
113              GLGuiWidget::focused()->click(cursorPos - GLGuiWidget::focused()->getAbsCoor2D());
114            }
115          }
116          else
117          {
118            if (GLGuiWidget::focused()->clickable())
119            {
120              Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y);
121              GLGuiWidget::focused()->release(cursorPos - GLGuiWidget::focused()->getAbsCoor2D());
122            }
123          }
124        }
125        break;
126      case EV_LEAVE_STATE:
127        if (GLGuiWidget::focused() != NULL)
128          GLGuiWidget::focused()->breakFocus();
129        break;
130
131      case EV_VIDEO_RESIZE:
132        if (this->_cursor != NULL)
133          this->_cursor->setMaxBorders(Vector2D(event.resize.w, event.resize.h));
134        break;
135    }
136
137
138
139    if (GLGuiWidget::focused())
140    {
141      GLGuiWidget::focused()->processEvent(event);
142    }
143
144
145
146  }
147
148
149  Vector2D GLGuiHandler::cursorPositionOverFocusedWidget() const
150  {
151    return (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(0,0);
152  }
153
154  const Vector2D& GLGuiHandler::cursorPositionAbs() const
155  {
156    if (this->_cursor)
157      return this->_cursor->getAbsCoor2D();
158    else
159      return Vector2D::nullVector();
160  }
161  Vector2D GLGuiHandler::cursorPositionRel(const GLGuiWidget* const widget) const
162  {
163    assert (widget != NULL);
164    if (this->_cursor)
165      return  this->_cursor->getAbsCoor2D() - widget->getAbsCoor2D();
166    else
167      return Vector2D::nullVector();
168  }
169
170
171  void GLGuiHandler::draw()
172  {
173    //    GLGuiMainWidget::getInstance()->draw2D(E2D_LAYER_TOP);
174  }
175
176
177  void GLGuiHandler::tick(float dt)
178  {
179
180    // CHECK THE COLLISIONS.
181    const std::list<BaseObject*>* objects = ClassList::getList(CL_GLGUI_WIDGET);
182
183    if (objects != NULL && this->_cursor != NULL)
184    {
185      for (std::list<BaseObject*>::const_iterator it = objects->begin(); it != objects->end(); it++)
186      {
187        GLGuiWidget* widget = dynamic_cast<GLGuiWidget*>(*it);
188
189        if (widget->isVisible() &&
190            widget->focusable() &&
191            widget->focusOverWidget(this->_cursor))
192        {
193          // receiving Focus
194          if (GLGuiWidget::focused() != widget)
195          {
196            widget->giveFocus();
197          }
198          return ;
199        }
200      }
201      if (GLGuiWidget::focused() != NULL)
202        GLGuiWidget::focused()->breakFocus();
203    }
204  }
205}
Note: See TracBrowser for help on using the repository browser.