srb2::Draw: add sticker and small_sticker methods

- Can be aligned to place a wing on only the left or right
  sides, or both
- Width is adjustable
- Custom sticker support
This commit is contained in:
James R 2024-01-18 02:03:34 -08:00
parent 6347afb63f
commit 892d2c73a8
2 changed files with 36 additions and 0 deletions

View file

@ -219,6 +219,36 @@ void Chain::button_(Button type, int ver, std::optional<bool> press) const
}
}
void Chain::sticker(patch_t* end_graphic, UINT8 color) const
{
const auto _ = Clipper(*this);
INT32 x = x_;
INT32 y = y_;
INT32 width = width_;
INT32 flags = flags_ | V_FLIP;
auto fill = [&](int x, int width) { V_DrawFill(x, y, width, SHORT(end_graphic->height), color | (flags_ & ~0xFF)); };
if (align_ == Align::kRight)
{
width = -(width);
flags ^= V_FLIP;
fill(x + width, -(width));
}
else
{
fill(x, width);
}
V_DrawScaledPatch(x + width, y, flags, end_graphic);
if (align_ == Align::kCenter)
{
V_DrawScaledPatch(x, y, flags ^ V_FLIP, end_graphic);
}
}
Chain::Clipper::Clipper(const Chain& chain)
{
V_SetClipRect(

View file

@ -180,6 +180,10 @@ public:
void button(Button type, std::optional<bool> press = {}) const { button_(type, 0, press); }
void small_button(Button type, std::optional<bool> press = {}) const { button_(type, 1, press); }
void sticker(patch_t* end_graphic, UINT8 color) const;
void sticker() const { sticker(Draw::cache_patch("K_STIKEN"), 24); }
void small_sticker() const { sticker(Draw::cache_patch("K_STIKE2"), 24); }
private:
constexpr Chain() {}
explicit Chain(float x, float y) : x_(x), y_(y) {}
@ -261,6 +265,8 @@ public:
VOID_METHOD(fill);
VOID_METHOD(button);
VOID_METHOD(small_button);
VOID_METHOD(sticker);
VOID_METHOD(small_sticker);
#undef VOID_METHOD