1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#pragma once
#include <type_traits>
#include "Base.h"
namespace cru::platform::graphics {
/**
* \brief Painter is a object to paint on something like window, bitmap and etc.
* \remarks Remember to call EndDraw() when you are done with painting.
*/
struct CRU_PLATFORM_GRAPHICS_API IPainter : virtual IPlatformResource {
virtual Matrix GetTransform() = 0;
virtual void SetTransform(const Matrix& matrix) = 0;
virtual void ConcatTransform(const Matrix& matrix) = 0;
virtual void Clear(const Color& color) = 0;
virtual void DrawLine(const Point& start, const Point& end, IBrush* brush,
float width) = 0;
virtual void StrokeRectangle(const Rect& rectangle, IBrush* brush,
float width) = 0;
virtual void FillRectangle(const Rect& rectangle, IBrush* brush) = 0;
virtual void StrokeEllipse(const Rect& outline_rect, IBrush* brush,
float width) = 0;
virtual void FillEllipse(const Rect& outline_rect, IBrush* brush) = 0;
virtual void StrokeGeometry(IGeometry* geometry, IBrush* brush,
float width) = 0;
virtual void FillGeometry(IGeometry* geometry, IBrush* brush) = 0;
virtual void DrawText(const Point& offset, ITextLayout* text_layout,
IBrush* brush) = 0;
virtual void DrawImage(const Point& offset, IImage* image) = 0;
virtual void PushLayer(const Rect& bounds) = 0;
virtual void PopLayer() = 0;
virtual void PushState() = 0;
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
|