[10107] | 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_ |
---|
| 17 | |
---|
| 18 | #include "glgui_energywidgetvertical.h" |
---|
| 19 | |
---|
| 20 | #include "multi_type.h" |
---|
[10194] | 21 | #include <iostream> |
---|
| 22 | #include "math.h" |
---|
[10200] | 23 | #include "glgui_image.h" |
---|
[10107] | 24 | |
---|
| 25 | namespace OrxGui |
---|
| 26 | { |
---|
| 27 | /** |
---|
| 28 | * @brief standard constructor |
---|
| 29 | */ |
---|
| 30 | GLGuiEnergyWidgetVertical::GLGuiEnergyWidgetVertical () |
---|
| 31 | { |
---|
[10301] | 32 | this->_bar = new GLGuiBar(); |
---|
| 33 | this->_valueText = new GLGuiText(); |
---|
| 34 | this->_image = new GLGuiImage(); |
---|
[10234] | 35 | |
---|
| 36 | this->setAbsDir2D(270); |
---|
| 37 | this->setBackgroundTexture(Texture()); |
---|
| 38 | this->setBackgroundColor(Color(1,1,1,0)); |
---|
| 39 | this->setBorderTop(10); |
---|
| 40 | this->setBorderLeft(10); |
---|
| 41 | this->setBorderRight(10); |
---|
| 42 | this->setBorderBottom(10); |
---|
| 43 | this->setWidgetSize(120,50); |
---|
| 44 | |
---|
[10301] | 45 | this->_bar->setParent2D(this); |
---|
| 46 | this->_bar->setBackgroundTexture(Texture()); |
---|
| 47 | this->_bar->setBackgroundColor(Color(0,0,0,0)); |
---|
[10421] | 48 | this->_bar->setForegroundTexture("textures/gui/gui_element_background_faded.png"); |
---|
[10301] | 49 | this->_bar->setForegroundColor(Color::green); |
---|
| 50 | this->_bar->setChangedValueColor(Color(1,0,0,0.2)); |
---|
| 51 | this->_bar->setBorderTop(0); |
---|
| 52 | this->_bar->setBorderLeft(0); |
---|
| 53 | this->_bar->setBorderRight(0); |
---|
| 54 | this->_bar->setBorderBottom(0); |
---|
| 55 | this->_bar->setWidgetSize(100,30); |
---|
[10234] | 56 | //this->_bar.setRelCoor2D(borderLeft(), 0); |
---|
[10301] | 57 | this->_bar->setRelCoor2D(0,0); |
---|
[10234] | 58 | |
---|
[10301] | 59 | this->_image->setParent2D(this); |
---|
| 60 | this->_image->setBorderTop(0); |
---|
| 61 | this->_image->setBorderLeft(0); |
---|
| 62 | this->_image->setBorderRight(0); |
---|
| 63 | this->_image->setBorderBottom(0); |
---|
| 64 | this->_image->setWidgetSize(30,30); |
---|
| 65 | this->_image->setForegroundColor(Color(1,1,1,0.6)); |
---|
[10516] | 66 | this->_image->setBackgroundTexture(Texture()); |
---|
[10301] | 67 | this->_image->setBackgroundColor(Color(1,1,1,0)); |
---|
[10600] | 68 | // this->_image->loadImageFromFile("textures/evil-flower.png"); |
---|
[10234] | 69 | //this->_image.setRelCoor2D(borderLeft(), borderTop() + this->_bar.getSizeX2D()); |
---|
[10301] | 70 | this->_image->setRelCoor2D(0,0); |
---|
| 71 | this->_image->setRelDir2D(90); |
---|
| 72 | this->_image->setVisibility(true); |
---|
[10234] | 73 | |
---|
[10301] | 74 | |
---|
| 75 | this->_valueText->setParent2D(this->_bar); |
---|
| 76 | this->_valueText->setWidgetSize(100,20); |
---|
[10234] | 77 | //this->_valueText.setRelCoor2D(borderLeft(), borderTop() + this->_bar.getSizeX2D()); |
---|
[10301] | 78 | this->_valueText->setAbsCoor2D(-15,-20); |
---|
| 79 | this->_valueText->setChangedTextColor(Color::white); |
---|
| 80 | this->_valueText->setForegroundColor(Color::white); |
---|
| 81 | this->_valueText->setBackgroundTexture(Texture()); |
---|
| 82 | this->_valueText->setBackgroundColor(Color(0,0,0,0)); |
---|
[10107] | 83 | } |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | /** |
---|
| 87 | * @brief standard deconstructor |
---|
| 88 | */ |
---|
| 89 | GLGuiEnergyWidgetVertical::~GLGuiEnergyWidgetVertical () |
---|
| 90 | { |
---|
[10332] | 91 | |
---|
[10301] | 92 | if ( this->_valueText ) |
---|
| 93 | { |
---|
| 94 | delete this->_valueText; |
---|
| 95 | this->_valueText = NULL; |
---|
| 96 | } |
---|
[10421] | 97 | |
---|
[10301] | 98 | if ( this->_image ) |
---|
| 99 | { |
---|
| 100 | delete this->_image; |
---|
| 101 | this->_image = NULL; |
---|
| 102 | } |
---|
[10421] | 103 | |
---|
[10332] | 104 | /* |
---|
| 105 | if ( this->_bar ) |
---|
| 106 | { |
---|
| 107 | delete this->_bar; |
---|
| 108 | this->_bar = NULL; |
---|
| 109 | } |
---|
| 110 | */ |
---|
[10107] | 111 | } |
---|
| 112 | |
---|
| 113 | void GLGuiEnergyWidgetVertical::setMaximum(float max) |
---|
| 114 | { |
---|
[10301] | 115 | this->_bar->setMaximum(max); |
---|
[10107] | 116 | } |
---|
| 117 | |
---|
| 118 | void GLGuiEnergyWidgetVertical::setValue(float value) |
---|
| 119 | { |
---|
| 120 | MultiType val(value); |
---|
[10200] | 121 | //MultiType val(200.00); |
---|
[10107] | 122 | val.setType(MT_INT); |
---|
| 123 | |
---|
| 124 | |
---|
[10301] | 125 | this->_bar->setValue(value); |
---|
| 126 | this->_bar->setForegroundColor(Color::slerpHSVColor(Color::red, Color::green, value/this->_bar->maximum())); |
---|
[10233] | 127 | //this->_bar.setFrontColor(Color(1,1,1,1), true); |
---|
[10301] | 128 | this->_valueText->setText(val.getString()); |
---|
[10194] | 129 | //this->_valueText.setText("asdfas"); |
---|
[10107] | 130 | } |
---|
| 131 | |
---|
[10200] | 132 | void GLGuiEnergyWidgetVertical::setDisplayedImage(const std::string& imageName) |
---|
| 133 | { |
---|
[10301] | 134 | this->_image->loadImageFromFile(imageName); |
---|
[10200] | 135 | } |
---|
| 136 | |
---|
[10107] | 137 | void GLGuiEnergyWidgetVertical::resize() |
---|
| 138 | { |
---|
[10234] | 139 | Vector2D widgetSize = this->getSize2D(); |
---|
| 140 | |
---|
| 141 | this->setBorderTop(widgetSize.y * 0.1); |
---|
| 142 | this->setBorderBottom(widgetSize.y * 0.1); |
---|
| 143 | this->setBorderLeft(widgetSize.x * 0.2); |
---|
| 144 | this->setBorderRight(widgetSize.x * 0.2); |
---|
[10421] | 145 | |
---|
[10301] | 146 | this->_bar->setWidgetSize(widgetSize.x * 0.8, widgetSize.y * 0.6); |
---|
| 147 | this->_image->setWidgetSize(widgetSize.y * 0.6, widgetSize.y * 0.6); |
---|
| 148 | this->_valueText->setWidgetSize(widgetSize.x* 0.8, widgetSize.y * 0.4); |
---|
[10107] | 149 | } |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | void GLGuiEnergyWidgetVertical::showing() |
---|
| 153 | { |
---|
[10421] | 154 | |
---|
[10301] | 155 | this->_bar->show(); |
---|
| 156 | this->_image->show(); |
---|
| 157 | this->_valueText->show(); |
---|
[10107] | 158 | } |
---|
| 159 | |
---|
| 160 | void GLGuiEnergyWidgetVertical::hiding() |
---|
| 161 | { |
---|
[10301] | 162 | this->_image->hide(); |
---|
| 163 | this->_valueText->hide(); |
---|
| 164 | this->_bar->hide(); |
---|
[10107] | 165 | } |
---|
| 166 | } |
---|