Kiwano Engine v1.3.x
RenderContextImpl.h
1// Copyright (c) 2016-2019 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/render/RenderContext.h>
23#include <kiwano/render/DirectX/TextRenderer.h>
24
25namespace kiwano
26{
27namespace graphics
28{
29namespace directx
30{
31
32class KGE_API RenderContextImpl : public RenderContext
33{
34public:
36
37 virtual ~RenderContextImpl();
38
39 virtual HRESULT CreateDeviceResources(ComPtr<ID2D1Factory> factory, ComPtr<ID2D1DeviceContext> ctx);
40
41 void BeginDraw() override;
42
43 void EndDraw() override;
44
45 void DrawImage(const Image& image, const Rect* src_rect) override;
46
47 void CreateBitmap(Bitmap& bitmap, const PixelSize& size) override;
48
49 void DrawBitmap(const Bitmap& bitmap, const Rect* src_rect, const Rect* dest_rect) override;
50
51 void DrawTextLayout(const TextLayout& layout, const Point& offset, RefPtr<Brush> outline_brush) override;
52
53 void DrawShape(const Shape& shape) override;
54
55 void DrawLine(const Point& point1, const Point& point2) override;
56
57 void DrawRectangle(const Rect& rect) override;
58
59 void DrawRoundedRectangle(const Rect& rect, const Vec2& radius) override;
60
61 void DrawEllipse(const Point& center, const Vec2& radius) override;
62
63 void FillShape(const Shape& shape) override;
64
65 void FillRectangle(const Rect& rect) override;
66
67 void FillRoundedRectangle(const Rect& rect, const Vec2& radius) override;
68
69 void FillEllipse(const Point& center, const Vec2& radius) override;
70
71 void PushClipRect(const Rect& clip_rect) override;
72
73 void PopClipRect() override;
74
75 void PushLayer(Layer& layer) override;
76
77 void PopLayer() override;
78
79 void Clear() override;
80
81 void Clear(const Color& clear_color) override;
82
83 Size GetSize() const override;
84
85 void SetCurrentBrush(RefPtr<Brush> brush) override;
86
87 void SetCurrentStrokeStyle(RefPtr<StrokeStyle> stroke_style) override;
88
89 Matrix3x2 GetTransform() const override;
90
91 void SetTransform(const Matrix3x2& matrix) override;
92
93 void SetBlendMode(BlendMode blend) override;
94
95 void SetAntialiasMode(bool enabled) override;
96
97 void SetTextAntialiasMode(TextAntialiasMode mode) override;
98
99 bool CheckVisibility(const Rect& bounds, const Matrix3x2& transform) override;
100
101 void Resize(const Size& size) override;
102
103 RefPtr<Image> GetTarget() const override;
104
105 void SetTarget(const Image& target) override;
106
107protected:
108 void DiscardDeviceResources();
109
110 void SaveDrawingState();
111
112 void RestoreDrawingState();
113
114protected:
115 ComPtr<ITextRenderer> text_renderer_;
116 ComPtr<ID2D1DeviceContext> device_ctx_;
117 ComPtr<ID2D1DrawingStateBlock> drawing_state_;
118};
119
121{
122public:
123 HRESULT CreateDeviceResources(ComPtr<ID2D1Factory> factory, ComPtr<ID2D1DeviceContext> ctx) override;
124
125 RefPtr<Image> GetTarget() const override;
126
127 void SetTarget(const Image& target) override;
128
129 void BeginDraw() override;
130
131 void EndDraw() override;
132
133private:
134 ComPtr<ID2D1CommandList> cmd_list_;
135 ComPtr<ID2D1Image> original_target_;
136};
137
138} // namespace directx
139} // namespace graphics
140} // namespace kiwano
位图
Definition: Bitmap.h:95
Definition: Color.h:41
图像(位图或矢量图)
Definition: Bitmap.h:64
图层
Definition: Layer.h:37
引用计数智能指针
Definition: RefBasePtr.hpp:35
渲染上下文
Definition: RenderContext.h:62
形状
Definition: Shape.h:38
文本布局
Definition: TextLayout.h:37
Definition: RenderContextImpl.h:33
TextAntialiasMode
文字抗锯齿模式
Definition: RenderContext.h:40
BlendMode
混合模式
Definition: RenderContext.h:50