From 892d2c73a831bebc0fc4c618dc75680f84a9f07f Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 18 Jan 2024 02:03:34 -0800 Subject: [PATCH] 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 --- src/v_draw.cpp | 30 ++++++++++++++++++++++++++++++ src/v_draw.hpp | 6 ++++++ 2 files changed, 36 insertions(+) diff --git a/src/v_draw.cpp b/src/v_draw.cpp index bd6aaf8f9..0653e8941 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -219,6 +219,36 @@ void Chain::button_(Button type, int ver, std::optional 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( diff --git a/src/v_draw.hpp b/src/v_draw.hpp index a713b8d15..468695e7e 100644 --- a/src/v_draw.hpp +++ b/src/v_draw.hpp @@ -180,6 +180,10 @@ public: void button(Button type, std::optional press = {}) const { button_(type, 0, press); } void small_button(Button type, std::optional 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