diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-11-03 20:18:23 +0800 |
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-11-03 20:18:23 +0800 |
| commit | a04627baa74b2b6660addeb9853225852634cf34 (patch) | |
| tree | 52f3c247266685204a298cdd11672fcc5287b529 /include/cru | |
| parent | 76746163e04555eb129fc2590ee8b0312fad872c (diff) | |
| download | cru-a04627baa74b2b6660addeb9853225852634cf34.tar.gz cru-a04627baa74b2b6660addeb9853225852634cf34.tar.bz2 cru-a04627baa74b2b6660addeb9853225852634cf34.zip | |
Move WithTransform.
Diffstat (limited to 'include/cru')
| -rw-r--r-- | include/cru/platform/graphics/Painter.h | 11 | ||||
| -rw-r--r-- | include/cru/platform/graphics/util/Painter.h | 18 |
2 files changed, 11 insertions, 18 deletions
diff --git a/include/cru/platform/graphics/Painter.h b/include/cru/platform/graphics/Painter.h index de44c7b4..2e122a08 100644 --- a/include/cru/platform/graphics/Painter.h +++ b/include/cru/platform/graphics/Painter.h @@ -1,4 +1,5 @@ #pragma once +#include <type_traits> #include "Base.h" namespace cru::platform::graphics { @@ -42,5 +43,15 @@ struct CRU_PLATFORM_GRAPHICS_API IPainter : virtual IPlatformResource { virtual void PopState() = 0; virtual void EndDraw() = 0; + + template <typename Fn> + std::enable_if_t<std::is_invocable_v<Fn, IPainter*>> WithTransform( + const Matrix& matrix, const Fn& action) { + const auto old = this->GetTransform(); + this->PushState(); + this->ConcatTransform(matrix); + action(this); + this->PopState(); + } }; } // namespace cru::platform::graphics diff --git a/include/cru/platform/graphics/util/Painter.h b/include/cru/platform/graphics/util/Painter.h deleted file mode 100644 index e36d5c55..00000000 --- a/include/cru/platform/graphics/util/Painter.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include "../Painter.h" - -#include <functional> -#include <type_traits> - -namespace cru::platform::graphics::util { -template <typename Fn> -void WithTransform(IPainter* painter, const Matrix& matrix, const Fn& action) { - static_assert(std::is_invocable_v<decltype(action), IPainter*>, - "Action must can be be invoked with painter."); - const auto old = painter->GetTransform(); - painter->PushState(); - painter->ConcatTransform(matrix); - action(painter); - painter->PopState(); -} -} // namespace cru::platform::graphics::util |
