Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/windowing/StarProgressWidget.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
commit6352e8e3196f78388b6c771073f9e03eaa612673 (patch)
treee23772f79a7fbc41bc9108951e9e136857484bf4 /source/windowing/StarProgressWidget.cpp
parent6741a057e5639280d85d0f88ba26f000baa58f61 (diff)
everything everywhere
all at once
Diffstat (limited to 'source/windowing/StarProgressWidget.cpp')
-rw-r--r--source/windowing/StarProgressWidget.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/source/windowing/StarProgressWidget.cpp b/source/windowing/StarProgressWidget.cpp
new file mode 100644
index 0000000..df498f4
--- /dev/null
+++ b/source/windowing/StarProgressWidget.cpp
@@ -0,0 +1,71 @@
+#include "StarProgressWidget.hpp"
+#include "StarLexicalCast.hpp"
+#include "StarInterpolation.hpp"
+
+namespace Star {
+
+ProgressWidget::ProgressWidget(String const& background,
+ String const& overlay,
+ ImageStretchSet const& progressSet,
+ GuiDirection direction)
+ : m_background(background),
+ m_overlay(overlay),
+ m_bar(progressSet),
+ m_direction(direction) {
+
+ m_progressLevel = 0;
+ m_maxLevel = 1;
+
+ if (!m_background.empty())
+ setSize(Vec2I(context()->textureSize(m_background)));
+ else if (!m_overlay.empty())
+ setSize(Vec2I(context()->textureSize(m_overlay)));
+
+ m_color = Color::White;
+}
+
+void ProgressWidget::renderImpl() {
+ float progress = 1;
+ if (m_maxLevel > 0)
+ progress = m_progressLevel / m_maxLevel;
+
+ auto shift = [&](float begin, float end, RectF templ) {
+ RectF result = templ;
+
+ if (m_direction == GuiDirection::Horizontal) {
+ result.min()[0] = lerp(begin, templ.min()[0], templ.max()[0]);
+ result.max()[0] = lerp(end, templ.min()[0], templ.max()[0]);
+ } else {
+ result.min()[1] = lerp(begin, templ.min()[1], templ.max()[1]);
+ result.max()[1] = lerp(end, templ.min()[1], templ.max()[1]);
+ }
+
+ return result;
+ };
+
+ if (!m_background.empty())
+ context()->drawInterfaceQuad(m_background, shift(0, 1, RectF(Vec2F(), Vec2F(size()))), shift(0, 1, RectF(screenBoundRect())));
+
+ context()->drawImageStretchSet(m_bar, shift(0, progress, RectF(screenBoundRect())), m_direction, m_color.toRgba());
+
+ if (!m_overlay.empty())
+ context()->drawInterfaceQuad(m_overlay, shift(0, 1, RectF({}, Vec2F(size()))), shift(0, 1, RectF(screenBoundRect())));
+}
+
+void ProgressWidget::setCurrentProgressLevel(float amount) {
+ m_progressLevel = amount;
+}
+
+void ProgressWidget::setMaxProgressLevel(float amount) {
+ m_maxLevel = amount;
+}
+
+void ProgressWidget::setColor(Color const& color) {
+ m_color = color;
+}
+
+void ProgressWidget::setOverlay(String const& overlay) {
+ m_overlay = overlay;
+}
+
+}