Use clip rects to draw progress bar content
This commit is contained in:
parent
5e15d02eb8
commit
04455ada1c
@ -14,7 +14,7 @@ class VideoBuffer: public RasterDrawMethods<VideoBuffer>
|
||||
{
|
||||
PlaneAdapter<std::vector<pixel>> video;
|
||||
|
||||
Rect<int> getClipRect() const
|
||||
Rect<int> GetClipRect() const
|
||||
{
|
||||
return video.Size().OriginRect();
|
||||
}
|
||||
@ -58,11 +58,6 @@ class Graphics: public RasterDrawMethods<Graphics>
|
||||
PlaneAdapter<std::array<pixel, WINDOW.X * WINDOW.Y>, WINDOW.X, WINDOW.Y> video;
|
||||
Rect<int> clipRect = video.Size().OriginRect();
|
||||
|
||||
Rect<int> getClipRect() const
|
||||
{
|
||||
return clipRect;
|
||||
}
|
||||
|
||||
friend struct RasterDrawMethods<Graphics>;
|
||||
|
||||
public:
|
||||
@ -99,4 +94,9 @@ public:
|
||||
Graphics();
|
||||
|
||||
void SwapClipRect(Rect<int> &);
|
||||
|
||||
Rect<int> GetClipRect() const
|
||||
{
|
||||
return clipRect;
|
||||
}
|
||||
};
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include "Graphics.h"
|
||||
#include "RasterDrawMethods.h"
|
||||
|
||||
#define clipRect() (static_cast<Derived const &>(*this).getClipRect())
|
||||
#define clipRect() (static_cast<Derived const &>(*this).GetClipRect())
|
||||
|
||||
template<typename Derived, typename V>
|
||||
static inline void drawPixelUnchecked(RasterDrawMethods<Derived> &self, V Derived::*video, Vec2<int> pos, RGB<uint8_t> colour)
|
||||
|
@ -42,7 +42,7 @@ class Renderer: public RasterDrawMethods<Renderer>
|
||||
std::array<pixel, WINDOW.X * RES.Y> persistentVideo;
|
||||
Video warpVideo;
|
||||
|
||||
Rect<int> getClipRect() const
|
||||
Rect<int> GetClipRect() const
|
||||
{
|
||||
return video.Size().OriginRect();
|
||||
}
|
||||
|
@ -40,39 +40,37 @@ String ProgressBar::GetStatus()
|
||||
return progressStatus;
|
||||
}
|
||||
|
||||
void ProgressBar::Draw(const Point & screenPos)
|
||||
void ProgressBar::Draw(const Point &screenPos)
|
||||
{
|
||||
Graphics * g = GetGraphics();
|
||||
|
||||
ui::Colour progressBarColour = style::Colour::WarningTitle;
|
||||
|
||||
Graphics *g = GetGraphics();
|
||||
g->DrawRect(RectSized(screenPos, Size), 0xFFFFFF_rgb);
|
||||
|
||||
if(progress!=-1)
|
||||
auto inner = RectSized(screenPos + Vec2{ 2, 2 }, Size - Vec2{ 4, 4 });
|
||||
auto drawContent = [this, screenPos, g, inner](int beginX, int endX, ui::Colour bgColour, ui::Colour textColour) {
|
||||
auto clip = RectSized(inner.TopLeft + Vec2{ beginX, 0 }, Vec2{ endX - beginX, inner.Size().Y }) & g->GetClipRect();
|
||||
g->SwapClipRect(clip);
|
||||
if (bgColour.Alpha)
|
||||
{
|
||||
g->DrawFilledRect(inner, bgColour.NoAlpha());
|
||||
}
|
||||
g->BlendText(screenPos + Vec2{
|
||||
(Size.X - (Graphics::TextSize(progressStatus).X - 1)) / 2,
|
||||
(Size.Y - 8) / 2
|
||||
}, progressStatus, textColour);
|
||||
g->SwapClipRect(clip);
|
||||
};
|
||||
drawContent(0, inner.Size().X, 0x000000_rgb .WithAlpha(0), 0xFFFFFF_rgb .WithAlpha(255));
|
||||
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(screenPos + Vec2{ 2, 2 }, Vec2{ int(size), Size.Y-4 }), 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 = int((Size.X-4)-position+1);
|
||||
rsize = 40-size;
|
||||
}
|
||||
g->DrawFilledRect(RectSized(screenPos + Vec2{ 2 + int(position), 2 }, Vec2{ size, Size.Y-4 }), progressBarColour.NoAlpha());
|
||||
if(rsize)
|
||||
{
|
||||
g->DrawFilledRect(RectSized(screenPos + Vec2{ 2, 2 }, Vec2{ rsize, Size.Y-4 }), progressBarColour.NoAlpha());
|
||||
}
|
||||
constexpr auto size = 40;
|
||||
auto pos = int(inner.Size().X * intermediatePos / 100);
|
||||
drawContent(pos, pos + size, style::Colour::WarningTitle, 0x000000_rgb .WithAlpha(255));
|
||||
pos -= inner.Size().X;
|
||||
drawContent(pos, pos + size, style::Colour::WarningTitle, 0x000000_rgb .WithAlpha(255));
|
||||
}
|
||||
else
|
||||
{
|
||||
drawContent(0, inner.Size().X * progress / 100, style::Colour::WarningTitle, 0x000000_rgb .WithAlpha(255));
|
||||
}
|
||||
g->BlendText(screenPos + Vec2{ ((Size.X-(Graphics::TextSize(progressStatus).X - 1))/2), (Size.Y-8)/2 }, progressStatus, progress<50 ? 0xFFFFFF_rgb .WithAlpha(255) : 0x000000_rgb .WithAlpha(255));
|
||||
}
|
||||
|
||||
void ProgressBar::Tick(float dt)
|
||||
|
Loading…
Reference in New Issue
Block a user