Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 28, 2006, 11:13:00 AM (18 years ago)
Author:
bensch
Message:

added a fixed positionBox, so that everything can be centered

File:
1 copied

Legend:

Unmodified
Added
Removed
  • branches/proxy/src/lib/gui/gl/glgui_fixedposition_box.cc

    r9541 r9546  
    1616#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI
    1717
    18 #include "glgui_box.h"
     18#include "glgui_fixedposition_box.h"
     19#include "glgui_handler.h"
    1920#include <cassert>
    2021
     
    2425   * standard constructor
    2526  */
    26   GLGuiBox::GLGuiBox (OrxGui::Orientation orientation)
     27  GLGuiFixedpositionBox::GLGuiFixedpositionBox (OrxGui::Position position, OrxGui::Orientation orientation)
     28      GLGuiBox(orientation)
    2729  {
    28     this->init();
    29 
    30     this->setOrientation(orientation);
    3130  }
    3231
     
    3534   * standard deconstructor
    3635  */
    37   GLGuiBox::~GLGuiBox()
     36  GLGuiFixedpositionBox::~GLGuiFixedpositionBox()
    3837  {}
    3938
    40   /**
    41    * initializes the GUI-element
    42    */
    43   void GLGuiBox::init()
     39
     40  void GLGuiFixedpositionBox::setPosition(OrxGui::Position position)
    4441  {
    45     this->setClassID(CL_GLGUI_BOX, "GLGuiBox");
    46   }
    47 
    48   void GLGuiBox::pack(GLGuiWidget* widget)
    49   {
    50     assert (widget != NULL);
    51 
    52     this->children.push_back(widget);
    53     widget->setParentWidget(this);
    54 
    55     this->resize();
     42    this->_position = position;
     43    this->resize;
    5644  }
    5745
    5846
    59   void GLGuiBox::unpack(GLGuiWidget* widget)
     47  void GLGuiFixedpositionBox::resize()
    6048  {
    61     assert(widget != NULL);
     49    GLGuiBox::resize();
    6250
    63     std::vector<GLGuiWidget*>::iterator delWidget = std::find(this->children.begin(), this->children.end(), widget);
    64     if (delWidget != this->children.end())
     51    switch (this->position)
    6552    {
    66       (*delWidget)->setParentWidget(NULL);
    67       this->children.erase(delWidget);
     53      case OrxGui::Center:
     54        this->setAbsCoor2D(GuiHandler::getInstance()->resolution() - this->getSize2D() / 2.0);
     55        break;
     56
    6857    }
    69     this->resize();
    70   }
    71 
    72   void GLGuiBox::clear()
    73   {
    74     this->children.clear();
    75     this->resize();
    76   }
    77 
    78   void GLGuiBox::showAll()
    79   {
    80     std::vector<GLGuiWidget*>::iterator itC = this->children.begin();
    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     }
    89 
    90     this->show();
    91   }
    92 
    93   void GLGuiBox::hideAll()
    94   {
    95     std::vector<GLGuiWidget*>::iterator itC = this->children.begin();
    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     }
    104 
    105     this->hide();
    106   }
    107 
    108   void GLGuiBox::resize()
    109   {
    110     if (orientation() == OrxGui::Vertical)
    111     {
    112       float height = borderTop();
    113       float width = 0.0f;
    114       std::vector<GLGuiWidget*>::iterator widget;
    115 
    116       // find out how big the Widgets are.
    117       for (widget = this->children.begin(); widget != this->children.end(); ++widget)
    118       {
    119         (*widget)->setRelCoor2D(borderLeft(), height);
    120         height += (*widget)->getSizeY2D();
    121         width = fmax(width, (*widget)->getSizeX2D());
    122       }
    123 
    124       width += borderLeft() + borderRight();
    125       height += borderBottom(); /* *2 done further up */
    126 
    127       this->setSize2D(width, height);
    128     }
    129     else
    130     {
    131       float height = borderTop();
    132       float width = 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, borderTop());
    139         height = fmax(height, (*widget)->getSizeY2D());
    140         width += (*widget)->getSizeX2D();
    141       }
    142 
    143       width += borderRight() ;
    144       height += borderBottom(); /* *2 done further up */
    145 
    146       this->setSize2D(width, height);
    147     }
    148     GLGuiWidget::resize();
    149 
    15058    // resize everything.
    15159    //for (widget = this->children.begin(); widget != this->children.end(); ++widget)
     
    15361  }
    15462
    155   /**
    156    * @brief draws the GLGuiBox
    157    */
    158   void GLGuiBox::draw() const
    159   {
    160     this->beginDraw();
    161     GLGuiWidget::draw();
    162     this->endDraw();
    163   }
    16463}
Note: See TracChangeset for help on using the changeset viewer.