a bit more configurability for the decoration bar
This commit is contained in:
parent
085a7804f9
commit
1526b0dce7
3 changed files with 21 additions and 1 deletions
src
|
@ -277,7 +277,7 @@ public:
|
|||
class CDecoVarBar : public CDecoVar
|
||||
{
|
||||
public:
|
||||
/// function to draw the decorations.
|
||||
CDecoVarBar() : MinValue(0), MaxValue(100), Invert(false) {};
|
||||
virtual void Draw(int x, int y, const CUnitType &type, const CVariable &var) const;
|
||||
|
||||
bool IsVertical; /// if true, vertical bar, else horizontal.
|
||||
|
@ -285,6 +285,9 @@ public:
|
|||
int Height; /// Height of the bar.
|
||||
int Width; /// Width of the bar.
|
||||
bool ShowFullBackground; /// if true, show background like value equal to max.
|
||||
bool Invert; /// if true, invert length
|
||||
int MinValue; /// show only above percent
|
||||
int MaxValue; /// show only below percent
|
||||
char BorderSize; /// Size of the border, 0 for no border.
|
||||
// FIXME color depend of percent (red, Orange, Yellow, Green...)
|
||||
IntColor Color; /// Color of bar.
|
||||
|
|
|
@ -2032,6 +2032,12 @@ static int CclDefineDecorations(lua_State *l)
|
|||
decovarbar->Height = LuaToNumber(l, -1);
|
||||
} else if (!strcmp(key, "Width")) {
|
||||
decovarbar->Width = LuaToNumber(l, -1);
|
||||
} else if (!strcmp(key, "MinValue")) {
|
||||
decovarbar->MinValue = LuaToNumber(l, -1);
|
||||
} else if (!strcmp(key, "MaxValue")) {
|
||||
decovarbar->MaxValue = LuaToNumber(l, -1);
|
||||
} else if (!strcmp(key, "Invert")) {
|
||||
decovarbar->Invert = LuaToBoolean(l, -1);
|
||||
} else if (!strcmp(key, "Orientation")) {
|
||||
key = LuaToString(l, -1);
|
||||
if (!strcmp(key, "horizontal")) {
|
||||
|
|
|
@ -391,6 +391,11 @@ void CDecoVarBar::Draw(int x, int y,
|
|||
const CUnitType &type, const CVariable &var) const
|
||||
{
|
||||
Assert(var.Max);
|
||||
|
||||
int percentage = var.Value * 100 / var.Max;
|
||||
if (MinValue > percentage || MaxValue < percentage) {
|
||||
return;
|
||||
}
|
||||
|
||||
int height = this->Height;
|
||||
if (height == 0) { // Default value
|
||||
|
@ -405,8 +410,14 @@ void CDecoVarBar::Draw(int x, int y,
|
|||
if (this->IsVertical) { // Vertical
|
||||
w = width;
|
||||
h = var.Value * height / var.Max;
|
||||
if (Invert) {
|
||||
h = height - h;
|
||||
}
|
||||
} else {
|
||||
w = var.Value * width / var.Max;
|
||||
if (Invert) {
|
||||
w = width - w;
|
||||
}
|
||||
h = height;
|
||||
}
|
||||
if (this->IsCenteredInX) {
|
||||
|
|
Loading…
Add table
Reference in a new issue