From: Daniel Karbach Date: Fri, 27 Dec 2013 17:32:55 +0000 (+0100) Subject: simple dual gauge (vertical) X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=1cb5ed22d7772abe6f9893be90f26f46dbde39f7;p=space.git simple dual gauge (vertical) --- diff --git a/src/ui/DualGauge.cpp b/src/ui/DualGauge.cpp new file mode 100644 index 0000000..55f9528 --- /dev/null +++ b/src/ui/DualGauge.cpp @@ -0,0 +1,32 @@ +#include "DualGauge.h" + +#include "../graphics/Canvas.h" + +#include +#include + + +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 vSize(valSize.x, valSize.y * std::abs(val)); + + if (val > 0) { + Vector 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 index 0000000..9aa30e3 --- /dev/null +++ b/src/ui/DualGauge.h @@ -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 size, + Vector pos, + Color borderCol, + Color bgCol, + Color posCol, + Color negCol) + : pos(pos), size(size) + , bgPos(pos + Vector(1, 1)), bgSize(size - Vector(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 pos; + Vector size; + Vector bgPos; + Vector bgSize; + Vector valPos; + Vector valSize; + Color borderCol; + Color bgCol; + Color posCol; + Color negCol; + +}; + +} + +#endif