aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform/painter_util.hpp
blob: 5711d099312a1cb8db0e649944b6b0828019294e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#pragma once
#include "painter.hpp"

#include <functional>
#include <type_traits>

namespace cru::platform::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