Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: fixed compile errors

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
[8450]26#include <cassert>
[7919]27
[8450]28
[7919]29/// TAKE THIS OUT OF HERE.
30#include "graphics_engine.h"
31
[7779]32namespace OrxGui
[3655]33{
34
[7779]35  /**
36   * standard constructor
37   */
38  GLGuiHandler::GLGuiHandler ()
39  {
40    this->setClassID(CL_GLGUI_HANDLER, "GLGuiHandler");
41    this->setName("GLGuiHandler");
[3655]42
[7868]43
[8448]44    EventHandler::getInstance()->withUNICODE(ES_MENU, true );
[7919]45
[8324]46    this->_cursor = NULL;
[7919]47    for (unsigned int i = 0; i < EV_NUMBER; i++)
48    {
[8312]49      this->subscribeEvent(ES_ALL, i);
[7919]50    }
[7779]51  }
[3655]52
[7779]53  /**
54   *  the singleton reference to this class
55   */
56  GLGuiHandler* GLGuiHandler::singletonRef = NULL;
[5388]57
[7779]58  /**
59     @brief standard deconstructor
60   */
61  GLGuiHandler::~GLGuiHandler ()
62  {
63    GLGuiHandler::singletonRef = NULL;
64  }
[5388]65
[7919]66  void GLGuiHandler::activateCursor()
67  {
[8324]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()));
[7919]72  }
73
74  void GLGuiHandler::deactivateCursor(bool deleteCursor)
75  {
[8324]76    if (this->_cursor)
[7919]77    {
78      if (deleteCursor)
[8324]79        delete this->_cursor;
80      this->_cursor = NULL;
[7919]81    }
82  }
83
84
[7779]85  void GLGuiHandler::activate()
86  {
87    EventHandler::getInstance()->pushState(ES_MENU);
[5388]88
[7919]89
90
[7779]91  }
[5388]92
[7779]93  void GLGuiHandler::deactivate()
94  {
95    EventHandler::getInstance()->popState();
[5388]96
[7919]97
[7779]98  }
[5388]99
100
[7779]101  void GLGuiHandler::process(const Event &event)
102  {
[7919]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())
[8035]111            {
[8324]112              Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y);
[8035]113              GLGuiWidget::focused()->click(cursorPos - GLGuiWidget::focused()->getAbsCoor2D());
114            }
[7919]115          }
116          else
117          {
118            if (GLGuiWidget::focused()->clickable())
[8035]119            {
[8324]120              Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y);
[8035]121              GLGuiWidget::focused()->release(cursorPos - GLGuiWidget::focused()->getAbsCoor2D());
122            }
[7919]123          }
124        }
125        break;
126      case EV_LEAVE_STATE:
127        if (GLGuiWidget::focused() != NULL)
128          GLGuiWidget::focused()->breakFocus();
129        break;
[5388]130
[7919]131      case EV_VIDEO_RESIZE:
[8324]132        if (this->_cursor != NULL)
133          this->_cursor->setMaxBorders(Vector2D(event.resize.w, event.resize.h));
[7919]134        break;
135    }
[5388]136
[7919]137
138
139    if (GLGuiWidget::focused())
140    {
141      GLGuiWidget::focused()->processEvent(event);
142    }
143
144
145
[7779]146  }
[5406]147
[8035]148
149  Vector2D GLGuiHandler::cursorPositionOverFocusedWidget() const
150  {
[8324]151    return (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(0,0);
[8035]152  }
153
154  const Vector2D& GLGuiHandler::cursorPositionAbs() const
155  {
[8324]156    if (this->_cursor)
157      return this->_cursor->getAbsCoor2D();
[8035]158    else
159      return Vector2D::nullVector();
160  }
161  Vector2D GLGuiHandler::cursorPositionRel(const GLGuiWidget* const widget) const
162  {
163    assert (widget != NULL);
[8324]164    if (this->_cursor)
165      return  this->_cursor->getAbsCoor2D() - widget->getAbsCoor2D();
[8035]166    else
167      return Vector2D::nullVector();
168  }
169
170
[7779]171  void GLGuiHandler::draw()
172  {
[7919]173    //    GLGuiMainWidget::getInstance()->draw2D(E2D_LAYER_TOP);
[7779]174  }
[5406]175
176
[7779]177  void GLGuiHandler::tick(float dt)
178  {
[7919]179
180    // CHECK THE COLLISIONS.
181    const std::list<BaseObject*>* objects = ClassList::getList(CL_GLGUI_WIDGET);
182
[8324]183    if (objects != NULL && this->_cursor != NULL)
[7919]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() &&
[8324]191            widget->focusOverWidget(this->_cursor))
[7919]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    }
[7779]204  }
[5406]205}
Note: See TracBrowser for help on using the repository browser.