Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10317 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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