Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9729 was 9656, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy bache back with no conflicts

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