| 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 | |
|---|
| 20 | namespace 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 | this->addChild2D(widget); |
|---|
| 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 | this->children.erase(delWidget); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | void GLGuiBox::clear() |
|---|
| 68 | { |
|---|
| 69 | this->children.clear(); |
|---|
| 70 | this->resize(); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | void GLGuiBox::showAll() |
|---|
| 74 | { |
|---|
| 75 | std::vector<GLGuiWidget*>::iterator itC = this->children.begin(); |
|---|
| 76 | while (itC != this->children.end()) |
|---|
| 77 | { |
|---|
| 78 | if ((*itC)->isA(CL_GLGUI_CONTAINER)) |
|---|
| 79 | static_cast<GLGuiContainer*>(*itC)->showAll(); |
|---|
| 80 | else |
|---|
| 81 | (*itC)->show(); |
|---|
| 82 | itC++; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | this->show(); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | void GLGuiBox::hideAll() |
|---|
| 89 | { |
|---|
| 90 | std::vector<GLGuiWidget*>::iterator itC = this->children.begin(); |
|---|
| 91 | while (itC != this->children.end()) |
|---|
| 92 | { |
|---|
| 93 | if ((*itC)->isA(CL_GLGUI_CONTAINER)) |
|---|
| 94 | static_cast<GLGuiContainer*>(*itC)->hideAll(); |
|---|
| 95 | else |
|---|
| 96 | (*itC)->hide(); |
|---|
| 97 | itC++; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | this->hide(); |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | void GLGuiBox::resize() |
|---|
| 104 | { |
|---|
| 105 | float height = this->borderSize(); |
|---|
| 106 | float width = 0.0f; |
|---|
| 107 | std::vector<GLGuiWidget*>::iterator widget; |
|---|
| 108 | |
|---|
| 109 | // find out how big the Widgets are. |
|---|
| 110 | for (widget = this->children.begin(); widget != this->children.end(); ++widget) |
|---|
| 111 | { |
|---|
| 112 | (*widget)->setRelCoor2D(this->borderSize(), height); |
|---|
| 113 | height += (*widget)->getSizeY2D(); |
|---|
| 114 | width = fmax(width, (*widget)->getSizeX2D()); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | width += this->borderSize() * 2.0; |
|---|
| 118 | height += this->borderSize(); /* *2 done further up */ |
|---|
| 119 | |
|---|
| 120 | printf("%f %f\n", width, height); |
|---|
| 121 | this->setSize2D(width, height); |
|---|
| 122 | GLGuiWidget::resize(); |
|---|
| 123 | // resize everything. |
|---|
| 124 | //for (widget = this->children.begin(); widget != this->children.end(); ++widget) |
|---|
| 125 | //{} |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | /** |
|---|
| 129 | * @brief draws the GLGuiBox |
|---|
| 130 | */ |
|---|
| 131 | void GLGuiBox::draw() const |
|---|
| 132 | { |
|---|
| 133 | this->beginDraw(); |
|---|
| 134 | GLGuiWidget::draw(); |
|---|
| 135 | this->endDraw(); |
|---|
| 136 | } |
|---|
| 137 | } |
|---|