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