mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-01-17 22:38:38 +01:00
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;
|
PlaneAdapter<std::vector<pixel>> video;
|
||||||
|
|
||||||
Rect<int> getClipRect() const
|
Rect<int> GetClipRect() const
|
||||||
{
|
{
|
||||||
return video.Size().OriginRect();
|
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;
|
PlaneAdapter<std::array<pixel, WINDOW.X * WINDOW.Y>, WINDOW.X, WINDOW.Y> video;
|
||||||
Rect<int> clipRect = video.Size().OriginRect();
|
Rect<int> clipRect = video.Size().OriginRect();
|
||||||
|
|
||||||
Rect<int> getClipRect() const
|
|
||||||
{
|
|
||||||
return clipRect;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend struct RasterDrawMethods<Graphics>;
|
friend struct RasterDrawMethods<Graphics>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -99,4 +94,9 @@ public:
|
|||||||
Graphics();
|
Graphics();
|
||||||
|
|
||||||
void SwapClipRect(Rect<int> &);
|
void SwapClipRect(Rect<int> &);
|
||||||
|
|
||||||
|
Rect<int> GetClipRect() const
|
||||||
|
{
|
||||||
|
return clipRect;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "Graphics.h"
|
#include "Graphics.h"
|
||||||
#include "RasterDrawMethods.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>
|
template<typename Derived, typename V>
|
||||||
static inline void drawPixelUnchecked(RasterDrawMethods<Derived> &self, V Derived::*video, Vec2<int> pos, RGB<uint8_t> colour)
|
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;
|
std::array<pixel, WINDOW.X * RES.Y> persistentVideo;
|
||||||
Video warpVideo;
|
Video warpVideo;
|
||||||
|
|
||||||
Rect<int> getClipRect() const
|
Rect<int> GetClipRect() const
|
||||||
{
|
{
|
||||||
return video.Size().OriginRect();
|
return video.Size().OriginRect();
|
||||||
}
|
}
|
||||||
|
@ -40,39 +40,37 @@ String ProgressBar::GetStatus()
|
|||||||
return progressStatus;
|
return progressStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressBar::Draw(const Point & screenPos)
|
void ProgressBar::Draw(const Point &screenPos)
|
||||||
{
|
{
|
||||||
Graphics * g = GetGraphics();
|
Graphics *g = GetGraphics();
|
||||||
|
|
||||||
ui::Colour progressBarColour = style::Colour::WarningTitle;
|
|
||||||
|
|
||||||
g->DrawRect(RectSized(screenPos, Size), 0xFFFFFF_rgb);
|
g->DrawRect(RectSized(screenPos, Size), 0xFFFFFF_rgb);
|
||||||
|
auto inner = RectSized(screenPos + Vec2{ 2, 2 }, Size - Vec2{ 4, 4 });
|
||||||
if(progress!=-1)
|
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)
|
constexpr auto size = 40;
|
||||||
{
|
auto pos = int(inner.Size().X * intermediatePos / 100);
|
||||||
if(progress > 100)
|
drawContent(pos, pos + size, style::Colour::WarningTitle, 0x000000_rgb .WithAlpha(255));
|
||||||
progress = 100;
|
pos -= inner.Size().X;
|
||||||
float size = float(Size.X-4)*(float(progress)/100.0f); // TIL...
|
drawContent(pos, pos + size, style::Colour::WarningTitle, 0x000000_rgb .WithAlpha(255));
|
||||||
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
|
||||||
}
|
{
|
||||||
} else {
|
drawContent(0, inner.Size().X * progress / 100, style::Colour::WarningTitle, 0x000000_rgb .WithAlpha(255));
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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)
|
void ProgressBar::Tick(float dt)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user