Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/lib/gui/gl/glgui_box.cc @ 8491

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

remove old bsp branche

File size: 3.7 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
21#include <assert.h>
22
23namespace OrxGui
24{
25  /**
26   * standard constructor
27  */
28  GLGuiBox::GLGuiBox (OrxGui::Orientation orientation)
29  {
30    this->init();
31
32    this->setOrientation(orientation);
33  }
34
35
36  /**
37   * standard deconstructor
38  */
39  GLGuiBox::~GLGuiBox()
40  {}
41
42  /**
43   * initializes the GUI-element
44   */
45  void GLGuiBox::init()
46  {
47    this->setClassID(CL_GLGUI_BOX, "GLGuiBox");
48  }
49
50  void GLGuiBox::pack(GLGuiWidget* widget)
51  {
52    assert (widget != NULL);
53
54    this->children.push_back(widget);
55    widget->setParentWidget(this);
56
57    this->resize();
58  }
59
60
61  void GLGuiBox::unpack(GLGuiWidget* widget)
62  {
63    assert(widget == NULL);
64
65    std::vector<GLGuiWidget*>::iterator delWidget = std::find(this->children.begin(), this->children.end(), widget);
66    if (delWidget != this->children.end())
67    {
68      (*delWidget)->setParentWidget(NULL);
69      this->children.erase(delWidget);
70    }
71    this->resize();
72  }
73
74  void GLGuiBox::clear()
75  {
76    this->children.clear();
77    this->resize();
78  }
79
80  void GLGuiBox::showAll()
81  {
82    std::vector<GLGuiWidget*>::iterator itC = this->children.begin();
83    while (itC != this->children.end())
84    {
85      if ((*itC)->isA(CL_GLGUI_CONTAINER))
86        static_cast<GLGuiContainer*>(*itC)->showAll();
87      else
88        (*itC)->show();
89      itC++;
90    }
91
92    this->show();
93  }
94
95  void GLGuiBox::hideAll()
96  {
97    std::vector<GLGuiWidget*>::iterator itC = this->children.begin();
98    while (itC != this->children.end())
99    {
100      if ((*itC)->isA(CL_GLGUI_CONTAINER))
101        static_cast<GLGuiContainer*>(*itC)->hideAll();
102      else
103        (*itC)->hide();
104      itC++;
105    }
106
107    this->hide();
108  }
109
110  void GLGuiBox::resize()
111  {
112    if (orientation() == OrxGui::Vertical)
113    {
114      float height = this->borderTop();
115      float width = 0.0f;
116      std::vector<GLGuiWidget*>::iterator widget;
117
118      // find out how big the Widgets are.
119      for (widget = this->children.begin(); widget != this->children.end(); ++widget)
120      {
121        (*widget)->setRelCoor2D(this->borderLeft(), height);
122        height += (*widget)->getSizeY2D();
123        width = fmax(width, (*widget)->getSizeX2D());
124      }
125
126      width += this->borderLeft() + this->borderRight();
127      height += this->borderBottom(); /* *2 done further up */
128
129      printf("%f %f\n", width, height);
130      this->setSize2D(width, height);
131    }
132    else
133    {
134      float height = this->borderTop();
135      float width = this->borderLeft();
136      std::vector<GLGuiWidget*>::iterator widget;
137
138      // find out how big the Widgets are.
139      for (widget = this->children.begin(); widget != this->children.end(); ++widget)
140      {
141        (*widget)->setRelCoor2D(width, this->borderTop());
142        height = fmax(height, (*widget)->getSizeY2D());
143        width += (*widget)->getSizeX2D();
144      }
145
146      width += this->borderRight() ;
147      height += this->borderBottom(); /* *2 done further up */
148
149      printf("%f %f\n", width, height);
150      this->setSize2D(width, height);
151    }
152    GLGuiWidget::resize();
153
154    // resize everything.
155    //for (widget = this->children.begin(); widget != this->children.end(); ++widget)
156    //{}
157  }
158
159  /**
160   * @brief draws the GLGuiBox
161   */
162  void GLGuiBox::draw() const
163  {
164    this->beginDraw();
165    GLGuiWidget::draw();
166    this->endDraw();
167  }
168}
Note: See TracBrowser for help on using the repository browser.