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