Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/lib/gui/gl_gui/glgui_handler.cc @ 7892

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

orxonox/trunk: saver delete events

File size: 2.8 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
27namespace OrxGui
28{
29
30  /**
31   * standard constructor
32   */
33  GLGuiHandler::GLGuiHandler ()
34  {
35    this->setClassID(CL_GLGUI_HANDLER, "GLGuiHandler");
36    this->setName("GLGuiHandler");
37
38
39    this->cursor = NULL;
40    for (unsigned int i = 0; i < EV_NUMBER; i++)
41    {
42      this->subscribeEvent(ES_MENU, i);
43    }
44
45  }
46
47  /**
48   *  the singleton reference to this class
49   */
50  GLGuiHandler* GLGuiHandler::singletonRef = NULL;
51
52  /**
53     @brief standard deconstructor
54   */
55  GLGuiHandler::~GLGuiHandler ()
56  {
57    GLGuiHandler::singletonRef = NULL;
58  }
59
60  void GLGuiHandler::activateCursor()
61  {
62    this->cursor = new GLGuiCursor();
63    this->cursor->show();
64  }
65
66  void GLGuiHandler::deactivateCursor(bool deleteCursor)
67  {
68    if (this->cursor)
69    {
70      if (deleteCursor)
71        delete this->cursor;
72      this->cursor = NULL;
73    }
74  }
75
76
77  void GLGuiHandler::activate()
78  {
79    EventHandler::getInstance()->pushState(ES_MENU);
80
81  }
82
83  void GLGuiHandler::deactivate()
84  {
85    EventHandler::getInstance()->popState();
86
87  }
88
89
90  void GLGuiHandler::process(const Event &event)
91  {
92    if (event.type == EV_MOUSE_BUTTON_LEFT)
93    {
94
95      if (GLGuiWidget::focused() != NULL)
96      {
97        if (event.bPressed)
98        {
99          GLGuiWidget::focused()->click();
100        }
101        else
102          GLGuiWidget::focused()->release();
103      }
104    }
105
106  }
107
108  void GLGuiHandler::draw()
109  {
110//    GLGuiMainWidget::getInstance()->draw2D(E2D_LAYER_TOP);
111  }
112
113
114  void GLGuiHandler::tick(float dt)
115  {
116
117    // CHECK THE COLLISIONS.
118    const std::list<BaseObject*>* objects = ClassList::getList(CL_GLGUI_WIDGET);
119
120    if (objects != NULL && this->cursor != NULL)
121    {
122      for (std::list<BaseObject*>::const_iterator it = objects->begin(); it != objects->end(); it++)
123      {
124        GLGuiWidget* widget = dynamic_cast<GLGuiWidget*>(*it);
125
126        if (widget->isVisible() &&
127            widget->focusable() &&
128            widget->focusOverWidget(this->cursor))
129        {
130          // receiving Focus
131          if (GLGuiWidget::focused() != widget)
132          {
133            widget->giveFocus();
134          }
135          return ;
136        }
137      }
138      if (GLGuiWidget::focused() != NULL)
139        GLGuiWidget::focused()->breakFocus();
140    }
141  }
142}
Note: See TracBrowser for help on using the repository browser.