Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gl_gui/glgui_handler.cc @ 7933

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

orxonox/trunk: merged the gui branche back
merged with command:
https://svn.orxonox.net/orxonox/branches/gui
no conflicts

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