Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gl/glgui_box.cc @ 10569

Last change on this file since 10569 was 10368, checked in by patrick, 18 years ago

merged the branche playability into the trunk

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