Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged gui back to the trunk
merged with command
merge -r8377:HEAD https://svn.orxonox.net/orxonox/branches/gui .

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