aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform/graph/util/painter_util.hpp
blob: 71e125c39c7d77617efaa9912eb4c53ef98a03d3 (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::graph::util {
template <typename Fn>
inline 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::util