aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform/graph/painter_util.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/platform/graph/painter_util.hpp')
-rw-r--r--include/cru/platform/graph/painter_util.hpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/include/cru/platform/graph/painter_util.hpp b/include/cru/platform/graph/painter_util.hpp
new file mode 100644
index 00000000..c137e8cb
--- /dev/null
+++ b/include/cru/platform/graph/painter_util.hpp
@@ -0,0 +1,18 @@
+#pragma once
+#include "painter.hpp"
+
+#include <functional>
+#include <type_traits>
+
+namespace cru::platform::graph::util {
+template <typename Fn>
+inline void WithTransform(Painter* painter, const Matrix& matrix,
+ const Fn& action) {
+ static_assert(std::is_invocable_v<decltype(action), Painter*>,
+ "Action must can be be invoked with painter.");
+ const auto old = painter->GetTransform();
+ painter->SetTransform(old * matrix);
+ action(painter);
+ painter->SetTransform(old);
+}
+} // namespace cru::platform::util