Use a proper ProgressBar in UpdateActivity

Can't have the update window not use my fancy clip rect progress bars, see 04455ada1c.
This commit is contained in:
Tamás Bálint Misius 2023-10-25 22:20:05 +02:00
parent e2743a2be1
commit eb29915243
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
2 changed files with 11 additions and 38 deletions

View File

@ -3,6 +3,7 @@
#include "Task.h"
#include "gui/interface/Label.h"
#include "gui/interface/ProgressBar.h"
#include "gui/interface/Engine.h"
#include "gui/dialogues/ErrorMessage.h"
#include "gui/Style.h"
@ -32,6 +33,9 @@ TaskWindow::TaskWindow(String title_, Task * task_, bool closeOnDone):
statusLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
AddComponent(statusLabel);
progressBar = new ui::ProgressBar(Position + Vec2{ 1, Size.Y-16 }, Vec2{ Size.X, 17 });
AddComponent(progressBar);
MakeActiveWindow();
task->AddTaskListener(this);
@ -71,6 +75,8 @@ void TaskWindow::NotifyProgress(Task * task)
progressStatus = String::Build(progress, "%");
else
progressStatus = "Please wait...";
progressBar->SetProgress(progress);
progressBar->SetStatus(progressStatus);
}
void TaskWindow::OnTick(float dt)
@ -88,39 +94,4 @@ void TaskWindow::OnDraw()
Graphics * g = GetGraphics();
g->DrawFilledRect(RectSized(Position - Vec2{ 1, 1 }, Size + Vec2{ 2, 2 }), 0x000000_rgb);
g->DrawRect(RectSized(Position, Size), 0xFFFFFF_rgb);
g->DrawLine(Position + Vec2{ 0, Size.Y-17 }, Position + Vec2{ Size.X - 1, Size.Y-17 }, 0xFFFFFF_rgb);
ui::Colour progressBarColour = style::Colour::WarningTitle;
if(progress!=-1)
{
if(progress > 0)
{
if(progress > 100)
progress = 100;
float size = float(Size.X-4)*(float(progress)/100.0f); // TIL...
size = std::min(std::max(size, 0.0f), float(Size.X-4));
g->DrawFilledRect(RectSized(Position + Vec2{ 2, Size.Y-15 }, Vec2{ int(size), 13 }), progressBarColour.NoAlpha());
}
} 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)-int(position)+1;
rsize = 40-size;
}
g->DrawFilledRect(RectSized(Position + Vec2{ 2 + int(position), Size.Y-15 }, Vec2{ size, 13 }), progressBarColour.NoAlpha());
if(rsize)
{
g->DrawFilledRect(RectSized(Position + Vec2{ 2, Size.Y-15 }, Vec2{ rsize, 13 }), progressBarColour.NoAlpha());
}
}
g->BlendText(Position + Vec2{ ((Size.X-(Graphics::TextSize(progressStatus).X - 1))/2), Size.Y-13 }, progressStatus, progress<50 ? 0xFFFFFF_rgb .WithAlpha(255) : 0x000000_rgb .WithAlpha(255));
}
TaskWindow::~TaskWindow() {
delete task;
}

View File

@ -1,21 +1,24 @@
#pragma once
#include "gui/interface/Window.h"
#include "tasks/TaskListener.h"
#include <memory>
namespace ui
{
class Label;
class ProgressBar;
}
class Task;
class TaskWindow: public ui::Window, public TaskListener {
Task * task;
std::unique_ptr<Task> task;
String title;
int progress;
float intermediatePos;
bool done;
bool closeOnDone;
ui::Label * statusLabel;
ui::Label *statusLabel{};
ui::ProgressBar *progressBar{};
String progressStatus;
public:
TaskWindow(String title_, Task * task_, bool closeOnDone = true);
@ -26,5 +29,4 @@ public:
void OnTick(float dt) override;
void OnDraw() override;
void Exit();
virtual ~TaskWindow();
};