aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform/graphics/util/Painter.hpp
blob: af3a199746d0130bcd8840e89a44b1a3b0963bdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#pragma once
#include "../Painter.hpp"

#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->SetTransform(old * matrix);
  action(painter);
  painter->SetTransform(old);
}
}  // namespace cru::platform::graphics::util