Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8457 was 8450, checked in by bensch, 18 years ago

orxonox/trunk: fixed compile errors

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