Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged the branche playability into the trunk

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