forked from OpenXcom/OpenXcom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBar.cpp
More file actions
244 lines (219 loc) · 4.46 KB
/
Copy pathBar.cpp
File metadata and controls
244 lines (219 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
* Copyright 2010-2013 OpenXcom Developers.
*
* This file is part of OpenXcom.
*
* OpenXcom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenXcom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Bar.h"
#include <cmath>
#include <SDL.h>
namespace OpenXcom
{
/**
* Sets up a blank bar with the specified size and position.
* @param width Width in pixels.
* @param height Height in pixels.
* @param x X position in pixels.
* @param y Y position in pixels.
*/
Bar::Bar(int width, int height, int x, int y) : Surface(width, height, x, y), _color(0), _color2(0), _scale(0), _max(0), _value(0), _value2(0), _invert(false), _secondOnTop(true)
{
}
/**
*
*/
Bar::~Bar()
{
}
/**
* Changes the color used to draw the border and contents.
* @param color Color value.
*/
void Bar::setColor(Uint8 color)
{
_color = color;
_redraw = true;
}
/**
* Returns the color used to draw the bar.
* @return Color value.
*/
Uint8 Bar::getColor() const
{
return _color;
}
/**
* Changes the color used to draw the second contents.
* @param color Color value.
*/
void Bar::setColor2(Uint8 color)
{
_color2 = color;
_redraw = true;
}
/**
* Returns the second color used to draw the bar.
* @return Color value.
*/
Uint8 Bar::getColor2() const
{
return _color2;
}
/**
* Changes the scale factor used to draw the bar values.
* @param scale Scale in pixels/unit.
*/
void Bar::setScale(double scale)
{
_scale = scale;
_redraw = true;
}
/**
* Returns the scale factor used to draw the bar values.
* @return Scale in pixels/unit.
*/
double Bar::getScale() const
{
return _scale;
}
/**
* Changes the maximum value used to draw the outer border.
* @param max Maximum value.
*/
void Bar::setMax(double max)
{
_max = max;
_redraw = true;
}
/**
* Returns the maximum value used to draw the outer border.
* @return Maximum value.
*/
double Bar::getMax() const
{
return _max;
}
/**
* Changes the value used to draw the inner contents.
* @param value Current value.
*/
void Bar::setValue(double value)
{
_value = value;
_redraw = true;
}
/**
* Returns the value used to draw the inner contents.
* @return Current value.
*/
double Bar::getValue() const
{
return _value;
}
/**
* Changes the value used to draw the second inner contents.
* @param value Current value.
*/
void Bar::setValue2(double value)
{
_value2 = value;
_redraw = true;
}
/**
* Returns the value used to draw the second inner contents.
* @return Current value.
*/
double Bar::getValue2() const
{
return _value2;
}
/**
* Defines whether the second value should be drawn on top. Default this is true.
* @param onTop Second value on top?
*/
void Bar::setSecondValueOnTop(bool onTop)
{
_secondOnTop = onTop;
}
/**
* Enables/disables color inverting. Some bars have
* darker borders and others have lighter borders.
* @param invert Invert setting.
*/
void Bar::setInvert(bool invert)
{
_invert = invert;
_redraw = true;
}
/**
* Draws the bordered bar filled according
* to its values.
*/
void Bar::draw()
{
Surface::draw();
SDL_Rect square;
square.x = 0;
square.y = 0;
square.w = (Uint16)(_scale * _max) + 1;
square.h = getHeight();
if (_invert)
{
drawRect(&square, _color);
}
else
{
drawRect(&square, _color + 4);
}
square.y++;
square.w--;
square.h -= 2;
drawRect(&square, 0);
if (_invert)
{
if (_secondOnTop)
{
square.w = (Uint16)(_scale * _value);
drawRect(&square, _color + 4);
square.w = (Uint16)(_scale * _value2);
drawRect(&square, _color2 + 4);
}
else
{
square.w = (Uint16)(_scale * _value2);
drawRect(&square, _color2 + 4);
square.w = (Uint16)(_scale * _value);
drawRect(&square, _color + 4);
}
}
else
{
if (_secondOnTop)
{
square.w = (Uint16)(_scale * _value);
drawRect(&square, _color);
square.w = (Uint16)(_scale * _value2);
drawRect(&square, _color2);
}
else
{
square.w = (Uint16)(_scale * _value2);
drawRect(&square, _color2);
square.w = (Uint16)(_scale * _value);
drawRect(&square, _color);
}
}
}
}