Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8300 was 8145, checked in by bensch, 19 years ago

trunk: merged the gui back
merged with command:
svn merge -r8114:HEAD https://svn.orxonox.net/orxonox/branches/gui .
→ no conflicts

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