]> git.localhorst.tv Git - space.git/commitdiff
simple dual gauge (vertical)
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 27 Dec 2013 17:32:55 +0000 (18:32 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 27 Dec 2013 17:32:55 +0000 (18:32 +0100)
src/ui/DualGauge.cpp [new file with mode: 0644]
src/ui/DualGauge.h [new file with mode: 0644]

diff --git a/src/ui/DualGauge.cpp b/src/ui/DualGauge.cpp
new file mode 100644 (file)
index 0000000..55f9528
--- /dev/null
@@ -0,0 +1,32 @@
+#include "DualGauge.h"
+
+#include "../graphics/Canvas.h"
+
+#include <algorithm>
+#include <cmath>
+
+
+namespace space {
+
+void DualGauge::Render(Canvas &canv, float val) const {
+       canv.SetColor(borderCol);
+       canv.OutlineRect(pos, size);
+
+       canv.SetColor(bgCol);
+       canv.FillRect(bgPos, bgSize);
+
+       if (val == 0) return;
+
+       Vector<int> vSize(valSize.x, valSize.y * std::abs(val));
+
+       if (val > 0) {
+               Vector<int> vPos(valPos.x, valPos.y - vSize.y);
+               canv.SetColor(posCol);
+               canv.FillRect(vPos, vSize);
+       } else {
+               canv.SetColor(negCol);
+               canv.FillRect(valPos, vSize);
+       }
+}
+
+}
diff --git a/src/ui/DualGauge.h b/src/ui/DualGauge.h
new file mode 100644 (file)
index 0000000..9aa30e3
--- /dev/null
@@ -0,0 +1,48 @@
+#ifndef SPACE_DUALGAUGE_H_
+#define SPACE_DUALGAUGE_H_
+
+#include "../graphics/Color.h"
+#include "../graphics/Vector.h"
+
+
+namespace space {
+
+class Canvas;
+
+class DualGauge {
+
+public:
+       constexpr DualGauge(
+               Vector<int> size,
+               Vector<int> pos,
+               Color borderCol,
+               Color bgCol,
+               Color posCol,
+               Color negCol)
+       : pos(pos), size(size)
+       , bgPos(pos + Vector<int>(1, 1)), bgSize(size - Vector<int>(2, 2))
+       , valPos(pos.x + 2, pos.y + 2 + (size.y - 4) / 2)
+       , valSize(size.x - 4, (size.y - 4) / 2)
+       , borderCol(borderCol), bgCol(bgCol)
+       , posCol(posCol), negCol(negCol) { }
+
+public:
+       void Render(Canvas &, float value) const;
+
+private:
+       Vector<int> pos;
+       Vector<int> size;
+       Vector<int> bgPos;
+       Vector<int> bgSize;
+       Vector<int> valPos;
+       Vector<int> valSize;
+       Color borderCol;
+       Color bgCol;
+       Color posCol;
+       Color negCol;
+
+};
+
+}
+
+#endif