Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

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

File size: 5.3 KB
RevLine 
[4744]1/*
[1853]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.
[1855]10
11   ### File Specific:
[5360]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[5360]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI
[1853]17
[5364]18#include "glgui_box.h"
[8450]19#include <cassert>
[9656]20#include "debug.h"
[1853]21
[7779]22namespace OrxGui
[3365]23{
[7779]24  /**
25   * standard constructor
26  */
[8035]27  GLGuiBox::GLGuiBox (OrxGui::Orientation orientation)
[7779]28  {
29    this->init();
[4320]30
[8035]31    this->setOrientation(orientation);
[7779]32  }
[1853]33
34
[7779]35  /**
36   * standard deconstructor
37  */
38  GLGuiBox::~GLGuiBox()
[9656]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  }
[5360]48
[7779]49  /**
50   * initializes the GUI-element
51   */
52  void GLGuiBox::init()
[5393]53  {
[7779]54    this->setClassID(CL_GLGUI_BOX, "GLGuiBox");
[5393]55  }
[7779]56
57  void GLGuiBox::pack(GLGuiWidget* widget)
[5393]58  {
[8035]59    assert (widget != NULL);
[9656]60    this->_children.push_back(widget);
[7779]61
[9656]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  {
[8035]123    widget->setParentWidget(this);
124    this->resize();
[5393]125  }
126
[7779]127  void GLGuiBox::unpack(GLGuiWidget* widget)
[5393]128  {
[9110]129    assert(widget != NULL);
[8035]130
[9656]131    std::list<GLGuiWidget*>::iterator delWidget = std::find(this->_children.begin(), this->_children.end(), widget);
132    if (delWidget != this->_children.end())
[7779]133    {
[8035]134      (*delWidget)->setParentWidget(NULL);
[9656]135      this->_children.erase(delWidget);
[7779]136    }
[8035]137    this->resize();
[5393]138  }
139
[8035]140  void GLGuiBox::clear()
141  {
[9656]142    this->_children.clear();
[8035]143    this->resize();
144  }
145
[7779]146  void GLGuiBox::showAll()
147  {
[9656]148    std::list<GLGuiWidget*>::iterator itC = this->_children.begin();
149    while (itC != this->_children.end())
[7779]150    {
151      if ((*itC)->isA(CL_GLGUI_CONTAINER))
152        static_cast<GLGuiContainer*>(*itC)->showAll();
153      else
154        (*itC)->show();
155      itC++;
156    }
[5393]157
[7779]158    this->show();
[5393]159  }
160
[7779]161  void GLGuiBox::hideAll()
162  {
[9656]163    std::list<GLGuiWidget*>::iterator itC = this->_children.begin();
164    while (itC != this->_children.end())
[7779]165    {
166      if ((*itC)->isA(CL_GLGUI_CONTAINER))
167        static_cast<GLGuiContainer*>(*itC)->hideAll();
168      else
169        (*itC)->hide();
170      itC++;
171    }
[5393]172
[7779]173    this->hide();
174  }
[5393]175
[8035]176  void GLGuiBox::resize()
177  {
178    if (orientation() == OrxGui::Vertical)
179    {
[8619]180      float height = borderTop();
[8035]181      float width = 0.0f;
[9656]182      std::list<GLGuiWidget*>::iterator widget;
[5360]183
[8035]184      // find out how big the Widgets are.
[9656]185      for (widget = this->_children.begin(); widget != this->_children.end(); ++widget)
[8035]186      {
[8619]187        (*widget)->setRelCoor2D(borderLeft(), height);
[8035]188        height += (*widget)->getSizeY2D();
189        width = fmax(width, (*widget)->getSizeX2D());
190      }
191
[8619]192      width += borderLeft() + borderRight();
193      height += borderBottom(); /* *2 done further up */
[8035]194
195      this->setSize2D(width, height);
196    }
197    else
198    {
[8619]199      float height = borderTop();
200      float width = borderLeft();
[9656]201      std::list<GLGuiWidget*>::iterator widget;
[8035]202
203      // find out how big the Widgets are.
[9656]204      for (widget = this->_children.begin(); widget != this->_children.end(); ++widget)
[8035]205      {
[8619]206        (*widget)->setRelCoor2D(width, borderTop());
[8035]207        height = fmax(height, (*widget)->getSizeY2D());
208        width += (*widget)->getSizeX2D();
209      }
210
[8619]211      width += borderRight() ;
212      height += borderBottom(); /* *2 done further up */
[8035]213
214      this->setSize2D(width, height);
215    }
216    GLGuiWidget::resize();
217
218    // resize everything.
[9656]219    //for (widget = this->_children.begin(); widget != this->_children.end(); ++widget)
[8035]220    //{}
221  }
222
[7779]223  /**
[8035]224   * @brief draws the GLGuiBox
[7779]225   */
226  void GLGuiBox::draw() const
227  {
[8035]228    this->beginDraw();
229    GLGuiWidget::draw();
230    this->endDraw();
[7779]231  }
[5360]232}
Note: See TracBrowser for help on using the repository browser.