summaryrefslogtreecommitdiff
path: root/src/interface/ProgressBar.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-07-27 19:06:17 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-07-27 19:06:17 (GMT)
commit5befe5c25f8f188e7588de44ab2c8bead22ae999 (patch)
tree643b02af217770c1a3156be03e01442557795760 /src/interface/ProgressBar.cpp
parentf8ca8af387b8611c18ca7c5357efd19c8bc28941 (diff)
downloadpowder-5befe5c25f8f188e7588de44ab2c8bead22ae999.zip
powder-5befe5c25f8f188e7588de44ab2c8bead22ae999.tar.gz
Local file browser + some more interesting things like Progress bar UI component
Diffstat (limited to 'src/interface/ProgressBar.cpp')
-rw-r--r--src/interface/ProgressBar.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/interface/ProgressBar.cpp b/src/interface/ProgressBar.cpp
new file mode 100644
index 0000000..8bc765b
--- /dev/null
+++ b/src/interface/ProgressBar.cpp
@@ -0,0 +1,65 @@
+#include "ProgressBar.h"
+#include "Style.h"
+
+using namespace ui;
+
+ProgressBar::ProgressBar(Point position, Point size):
+ Component(position, size),
+ intermediatePos(0.0f),
+ progressStatus("")
+{
+ progress = 0;
+}
+
+void ProgressBar::SetProgress(int progress)
+{
+ this->progress = progress;
+}
+
+void ProgressBar::SetStatus(std::string status)
+{
+ progressStatus = status;
+}
+
+void ProgressBar::Draw(const Point & screenPos)
+{
+ Graphics * g = ui::Engine::Ref().g;
+
+ ui::Colour progressBarColour = style::Colour::WarningTitle;
+
+ g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 255, 255, 255, 255);
+
+ if(progress!=-1)
+ {
+ if(progress > 0)
+ {
+ float size = float(Size.X-4)*(float(progress)/100.0f); // TIL...
+ size = std::min(std::max(size, 0.0f), float(Size.X-4));
+ g->fillrect(screenPos.X + 2, screenPos.Y + 2, size, Size.Y-4, progressBarColour.Red, progressBarColour.Green, progressBarColour.Blue, 255);
+ }
+ } else {
+ int size = 40, rsize = 0;
+ float position = float(Size.X-4)*(intermediatePos/100.0f);
+ if(position + size - 1 > Size.X-4)
+ {
+ size = (Size.X-4)-position+1;
+ rsize = 40-size;
+ }
+ g->fillrect(screenPos.X + 2 + position, screenPos.Y + 2, size, Size.Y-4, progressBarColour.Red, progressBarColour.Green, progressBarColour.Blue, 255);
+ if(rsize)
+ {
+ g->fillrect(screenPos.X + 2, screenPos.Y + 2, rsize, Size.Y-4, progressBarColour.Red, progressBarColour.Green, progressBarColour.Blue, 255);
+ }
+ }
+ if(progress<50)
+ g->drawtext(screenPos.X + ((Size.X-Graphics::textwidth(progressStatus.c_str()))/2), screenPos.Y + (Size.Y-8)/2, progressStatus, 255, 255, 255, 255);
+ else
+ g->drawtext(screenPos.X + ((Size.X-Graphics::textwidth(progressStatus.c_str()))/2), screenPos.Y + (Size.Y-8)/2, progressStatus, 0, 0, 0, 255);
+}
+
+void ProgressBar::Tick(float dt)
+{
+ intermediatePos += 1.0f*dt;
+ if(intermediatePos>100.0f)
+ intermediatePos = 0.0f;
+} \ No newline at end of file