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_box.h" |
---|
19 | #include <cassert> |
---|
20 | #include <iostream> |
---|
21 | #include "debug.h" |
---|
22 | #include "network_log.h" |
---|
23 | |
---|
24 | namespace OrxGui |
---|
25 | { |
---|
26 | ObjectListDefinition(GLGuiBox); |
---|
27 | /** |
---|
28 | * standard constructor |
---|
29 | */ |
---|
30 | GLGuiBox::GLGuiBox (OrxGui::Orientation orientation) |
---|
31 | { |
---|
32 | this->init(); |
---|
33 | |
---|
34 | this->setOrientation(orientation); |
---|
35 | } |
---|
36 | |
---|
37 | |
---|
38 | /** |
---|
39 | * standard deconstructor |
---|
40 | */ |
---|
41 | GLGuiBox::~GLGuiBox() |
---|
42 | { |
---|
43 | // unpack all the widgets. |
---|
44 | while(!this->_children.empty()) |
---|
45 | { |
---|
46 | /// not deleting children here. |
---|
47 | this->_children.front()->setParentWidget(NULL); |
---|
48 | this->_children.pop_front(); |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | /** |
---|
53 | * initializes the GUI-element |
---|
54 | */ |
---|
55 | void GLGuiBox::init() |
---|
56 | { |
---|
57 | this->registerObject(this, GLGuiBox::_objectList); |
---|
58 | } |
---|
59 | |
---|
60 | void GLGuiBox::pack(GLGuiWidget* widget) |
---|
61 | { |
---|
62 | assert (widget != NULL); |
---|
63 | this->_children.push_back(widget); |
---|
64 | |
---|
65 | this->packing(widget); |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | void GLGuiBox::pack(GLGuiWidget* widget, std::list<GLGuiWidget*>::iterator pos) |
---|
70 | { |
---|
71 | this->_children.insert(pos, widget); |
---|
72 | this->packing(widget); |
---|
73 | } |
---|
74 | |
---|
75 | void GLGuiBox::pack(GLGuiWidget* widget, unsigned int position) |
---|
76 | { |
---|
77 | if (this->_children.empty()) |
---|
78 | this->pack(widget); |
---|
79 | |
---|
80 | unsigned int pos = 0; |
---|
81 | std::list<GLGuiWidget*>::iterator it = this->_children.begin(); |
---|
82 | |
---|
83 | for (; pos < position; ++pos) |
---|
84 | { |
---|
85 | if (this->_children.end() == ++it) |
---|
86 | { |
---|
87 | PRINTF(2)("Reached end of packing list, without getting to the designated position %d (i am at %d)\n", position, pos); |
---|
88 | this->pack(widget); |
---|
89 | } |
---|
90 | } |
---|
91 | this->_children.insert(it, widget); |
---|
92 | this->packing(widget); |
---|
93 | } |
---|
94 | |
---|
95 | void GLGuiBox::pack(GLGuiWidget* widget, const GLGuiWidget* widgetPointer) |
---|
96 | { |
---|
97 | assert (widget != NULL && widgetPointer != NULL); |
---|
98 | |
---|
99 | std::list<GLGuiWidget*>::iterator it = this->_children.begin(); |
---|
100 | for (; it != this->_children.end(); ++it) |
---|
101 | { |
---|
102 | if (widgetPointer == *it) |
---|
103 | { |
---|
104 | this->_children.insert(it, widget); |
---|
105 | this->packing(widget); |
---|
106 | return; |
---|
107 | } |
---|
108 | } |
---|
109 | PRINTF(2)("WidgetPointer %p not found, inserting at the end\n", widgetPointer); |
---|
110 | this->pack(widget); |
---|
111 | } |
---|
112 | |
---|
113 | void GLGuiBox::packFront(GLGuiWidget* widget) |
---|
114 | { |
---|
115 | this->_children.push_front(widget); |
---|
116 | this->packing(widget); |
---|
117 | } |
---|
118 | |
---|
119 | void GLGuiBox::packBack(GLGuiWidget* widget) |
---|
120 | { |
---|
121 | this->pack(widget); |
---|
122 | } |
---|
123 | |
---|
124 | void GLGuiBox::packing(GLGuiWidget* widget) |
---|
125 | { |
---|
126 | widget->setParentWidget(this); |
---|
127 | this->resize(); |
---|
128 | } |
---|
129 | |
---|
130 | void GLGuiBox::unpack(GLGuiWidget* widget) |
---|
131 | { |
---|
132 | assert(widget != NULL); |
---|
133 | |
---|
134 | std::list<GLGuiWidget*>::iterator delWidget = std::find(this->_children.begin(), this->_children.end(), widget); |
---|
135 | if (delWidget != this->_children.end()) |
---|
136 | { |
---|
137 | (*delWidget)->setParentWidget(NULL); |
---|
138 | this->_children.erase(delWidget); |
---|
139 | } |
---|
140 | this->resize(); |
---|
141 | } |
---|
142 | |
---|
143 | void GLGuiBox::clear() |
---|
144 | { |
---|
145 | this->_children.clear(); |
---|
146 | this->resize(); |
---|
147 | } |
---|
148 | |
---|
149 | void GLGuiBox::showAll() |
---|
150 | { |
---|
151 | std::list<GLGuiWidget*>::iterator itC = this->_children.begin(); |
---|
152 | while (itC != this->_children.end()) |
---|
153 | { |
---|
154 | if ((*itC)->isA(GLGuiContainer::staticClassID())) |
---|
155 | static_cast<GLGuiContainer*>(*itC)->showAll(); |
---|
156 | else |
---|
157 | (*itC)->show(); |
---|
158 | itC++; |
---|
159 | } |
---|
160 | |
---|
161 | this->show(); |
---|
162 | } |
---|
163 | |
---|
164 | void GLGuiBox::hideAll() |
---|
165 | { |
---|
166 | std::list<GLGuiWidget*>::iterator itC = this->_children.begin(); |
---|
167 | while (itC != this->_children.end()) |
---|
168 | { |
---|
169 | if ((*itC)->isA(GLGuiContainer::staticClassID())) |
---|
170 | static_cast<GLGuiContainer*>(*itC)->hideAll(); |
---|
171 | else |
---|
172 | (*itC)->hide(); |
---|
173 | itC++; |
---|
174 | } |
---|
175 | |
---|
176 | this->hide(); |
---|
177 | } |
---|
178 | |
---|
179 | void GLGuiBox::resize() |
---|
180 | { |
---|
181 | if (this->orientation() == OrxGui::Vertical) |
---|
182 | { |
---|
183 | float height = borderTop(); |
---|
184 | float width = 0.0f; |
---|
185 | std::list<GLGuiWidget*>::iterator widget; |
---|
186 | |
---|
187 | // find out how big the Widgets are. |
---|
188 | for (widget = this->_children.begin(); widget != this->_children.end(); ++widget) |
---|
189 | { |
---|
190 | float radDir = (*widget)->getAbsDir2D() * 2 * M_PI / 360; |
---|
191 | float realSizeX = fabsf((*widget)->getSizeX2D() * cosf(radDir)) + fabsf((*widget)->getSizeY2D() * sinf(radDir)); |
---|
192 | float realSizeY = fabsf((*widget)->getSizeX2D() * sinf(radDir)) + fabsf((*widget)->getSizeY2D() * cosf(radDir)); |
---|
193 | |
---|
194 | (*widget)->setRelCoor2D(borderLeft(), height + borderTop()); |
---|
195 | height += realSizeY; |
---|
196 | width = fmax(width, realSizeX); |
---|
197 | } |
---|
198 | |
---|
199 | width += borderLeft() + borderRight(); |
---|
200 | height += borderBottom(); /* *2 done further up */ |
---|
201 | |
---|
202 | this->setSize2D(width, height); |
---|
203 | } |
---|
204 | else |
---|
205 | { |
---|
206 | float height = borderTop(); |
---|
207 | float width = borderLeft(); |
---|
208 | std::list<GLGuiWidget*>::iterator widget; |
---|
209 | |
---|
210 | // find out how big the Widgets are. |
---|
211 | for (widget = this->_children.begin(); widget != this->_children.end(); ++widget) |
---|
212 | { |
---|
213 | float radDir = (*widget)->getAbsDir2D() * 2 * M_PI / 360; |
---|
214 | //std::cout << "size X: " << (*widget)->getSizeX2D() << "size Y: " << (*widget)->getSizeY2D() << '\n'; |
---|
215 | float realSizeX = fabsf((*widget)->getSizeX2D() * cosf(radDir)) + fabsf((*widget)->getSizeY2D() * sinf(radDir)); |
---|
216 | float realSizeY = fabsf((*widget)->getSizeX2D() * sinf(radDir)) + fabsf((*widget)->getSizeY2D() * cosf(radDir)); |
---|
217 | |
---|
218 | (*widget)->setRelCoor2D(width, borderTop()); |
---|
219 | height = fmax(height, realSizeY); |
---|
220 | width += realSizeX; |
---|
221 | } |
---|
222 | |
---|
223 | width += borderRight() ; |
---|
224 | height += borderBottom(); /* *2 done further up */ |
---|
225 | |
---|
226 | this->setSize2D(width, height); |
---|
227 | } |
---|
228 | GLGuiWidget::resize(); |
---|
229 | |
---|
230 | // resize everything. |
---|
231 | //for (widget = this->_children.begin(); widget != this->_children.end(); ++widget) |
---|
232 | //{} |
---|
233 | } |
---|
234 | |
---|
235 | /** |
---|
236 | * @brief draws the GLGuiBox |
---|
237 | */ |
---|
238 | void GLGuiBox::draw() const |
---|
239 | { |
---|
240 | this->beginDraw(); |
---|
241 | GLGuiWidget::draw(); |
---|
242 | this->endDraw(); |
---|
243 | } |
---|
244 | } |
---|