--- /dev/null
+#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);
+ }
+}
+
+}
--- /dev/null
+#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