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