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