YSTest: YBrush.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

YBrush.h
浏览该文件的文档.
1 /*
2 © 2012-2016 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef YSL_INC_Service_YBrush_h_
29 #define YSL_INC_Service_YBrush_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_Service_YResource
33 #include YFM_YSLib_Core_YEvent // for YSLib::GHEvent;
34 #include YFM_YSLib_Service_YBlend // for Drawing::BlitPixels,
35 // Drawing::Shaders::BlitAlphaPoint;
36
37 namespace YSLib
38 {
39
40 namespace Drawing
41 {
42
58 class YF_API SolidBrush
59 {
60 public:
61 Drawing::Color Color;
62
63 SolidBrush(Drawing::Color c)
64 : Color(c)
65 {}
66
68 void
69 operator()(const PaintContext&) const;
70 };
71
72
79 class YF_API SolidBlendBrush
80 {
81 public:
82 Drawing::Color Color;
83
84 SolidBlendBrush(Drawing::Color c)
85 : Color(c)
86 {}
87
88 void
89 operator()(const PaintContext&) const;
90 };
91
97 class YF_API SolidCompositeBrush
98 {
99 public:
100 Drawing::Color Color;
101
102 SolidCompositeBrush(Drawing::Color c)
103 : Color(c)
104 {}
105
106 void
107 operator()(const PaintContext&) const;
108 };
110
111
118 template<typename... _types>
119 using GBrushUpdater = GHEvent<void(const PaintContext&, _types...)>;
120
121
128 class YF_API ImageBrush
129 {
130 public:
136 GBrushUpdater<const Drawing::Image&, const Point&, const Point&>
137 Update{DefaultUpdate};
138
140 mutable shared_ptr<Drawing::Image> ImagePtr;
142 Point DstOffset{};
144 Point SrcOffset{};
145
146 yconstfn DefDeCtor(ImageBrush)
147 ImageBrush(const shared_ptr<Drawing::Image>& h)
148 : ImagePtr(h)
149 {}
150 ImageBrush(shared_ptr<Drawing::Image>&& h)
151 : ImagePtr(std::move(h))
152 {}
153 DefDeCopyCtor(ImageBrush)
154 DefDeMoveCtor(ImageBrush)
155
156 DefDeCopyAssignment(ImageBrush)
157 DefDeMoveAssignment(ImageBrush)
158
159
164 void
165 operator()(const PaintContext&) const;
166
171 static void
172 DefaultUpdate(const PaintContext&, const Drawing::Image&, const Point&,
173 const Point&);
174 };
175
176
182 template<typename _fPixelShader, bool _bSwapLR = false, bool _bSwapUD = false>
183 void
184 UpdatePixels(_fPixelShader shader, const PaintContext& pc,
185 const Drawing::Image& img, const Point& dst_offset, const Point& src_offset)
186 {
187 const auto& g(pc.Target);
188 const Rect& bounds(pc.ClipArea);
189 const auto& src(img.GetContext());
190
191 Drawing::BlitPixels<_bSwapLR, _bSwapUD>(shader, g.GetBufferPtr(),
192 src.GetBufferPtr(), g.GetSize(), src.GetSize(), bounds.GetPoint(),
193 bounds.GetPoint() + src_offset - dst_offset, bounds.GetSize());
194 }
195
201 template<typename _fPixelShader, bool _bSwapLR = false, bool _bSwapUD = false>
202 void
203 UpdateTranposedPixels(_fPixelShader shader, const PaintContext& pc,
204 const Drawing::Image& img, const Point& dst_offset, const Point& src_offset)
205 {
206 const auto& g(pc.Target);
207 const Rect& bounds(pc.ClipArea);
208 const auto& src(img.GetContext());
209
210 Drawing::BlitPixels<_bSwapLR, _bSwapUD>(shader, g.GetBufferPtr(),
211 ystdex::make_transposed(src.GetBufferPtr(), src.GetWidth(),
212 src.GetHeight(), 0U), g.GetSize(), Transpose(src.GetSize()),
213 bounds.GetPoint(), bounds.GetPoint() + src_offset - dst_offset,
214 bounds.GetSize());
215 }
216
217
225 template<Rotation _vRot = RDeg0,
226 typename _fPixelShader = Shaders::BlitAlphaPoint>
227 void
228 UpdatePixelsWithRotation(_fPixelShader shader, const PaintContext& pc,
229 const Drawing::Image& img, const Point& dst_offset, const Point& src_offset)
230 {
231 using namespace ystdex;
232 using trans_t = ystdex::bool_<_vRot == RDeg90 || _vRot == RDeg270>;
233
234 Drawing::DispatchTranspose(trans_t(), [&](cond_t<trans_t,
235 transposed_iterator<ConstBitmapPtr>, ConstBitmapPtr> src_iter,
236 const Size& ss, const Point& dst_offset_ex){
237 const auto& g(pc.Target);
238 const Rect& bounds(pc.ClipArea);
239
240 Drawing::BlitPixels<_vRot == RDeg180 || _vRot == RDeg270,
241 _vRot == RDeg90 || _vRot == RDeg180>(shader, g.GetBufferPtr(),
242 src_iter, g.GetSize(), ss, bounds.GetPoint(), bounds.GetPoint()
243 + src_offset - (dst_offset + dst_offset_ex), bounds.GetSize());
244 }, img.GetContext());
245 }
246
247
253 template<Rotation _vRot = RDeg0,
254 typename _fPixelShader = Shaders::BlitAlphaPoint>
255 void
256 UpdateRotatedBrush(const PaintContext& pc, const Drawing::Image& img,
257 const Point& dst_offset, const Point& src_offset)
258 {
259 Drawing::UpdatePixelsWithRotation<_vRot, _fPixelShader>(_fPixelShader(),
260 pc, img, dst_offset, src_offset);
261 }
262
263
269 template<typename _fPixelShader = Shaders::BlitAlphaPoint,
270 typename _tImage = Drawing::Image>
271 GBrushUpdater<const _tImage&, const Point&, const Point&>
272 DispatchRotatedBrush(Rotation rot)
273 {
274 switch(rot)
275 {
276 case RDeg0:
277 return UpdateRotatedBrush<RDeg0, _fPixelShader>;
278 break;
279 case RDeg90:
280 return UpdateRotatedBrush<RDeg90, _fPixelShader>;
281 break;
282 case RDeg180:
283 return UpdateRotatedBrush<RDeg180, _fPixelShader>;
284 break;
285 case RDeg270:
286 return UpdateRotatedBrush<RDeg270, _fPixelShader>;
287 default:
288 break;
289 }
290 YAssert(false, "Invalid rotation found.");
291 return {};
292 }
293
294 } // namespace Drawing;
295
296 } // namespace YSLib;
297
298 #endif
299
YSLib::Drawing::UpdatePixelsWithRotation
void UpdatePixelsWithRotation(_fPixelShader shader, const PaintContext &pc, const Drawing::Image &img, const Point &dst_offset, const Point &src_offset)
更新：可能旋转源图像的像素操作。
Definition: YBrush.h:228
YSLib::Drawing::RDeg270
@ RDeg270
Definition: YGDIBase.h:1149
YSLib::Drawing::Color
The boundary is out of the const Rect SDst SPos SPos SPos Color
Definition: YDraw.h:128
YSLib::Drawing::SolidBrush
单色画刷。
Definition: YBrush.h:59
YSLib::Drawing::UpdatePixels
void UpdatePixels(_fPixelShader shader, const PaintContext &pc, const Drawing::Image &img, const Point &dst_offset, const Point &src_offset)
更新：逐像素操作。
Definition: YBrush.h:184
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:536
YSLib::Drawing::SolidBlendBrush::Color
Drawing::Color Color
Definition: YBrush.h:82
YSLib::Drawing::c
The boundary is out of the const Graphics const Rect const Point const Point Color c const Rect const Rect Color c
Definition: YDraw.h:174
YSLib::Drawing::SolidCompositeBrush::Color
Drawing::Color Color
Definition: YBrush.h:100
YSLib::Drawing::DispatchTranspose
void DispatchTranspose(ystdex::false_, _func updater, const ConstGraphics &src)
分派用于着色器更新的可能转置的图像。
Definition: YBlit.h:420
DefDeMoveCtor
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:167
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::Drawing::ImageBrush::ImageBrush
ImageBrush(shared_ptr< Drawing::Image > &&h)
Definition: YBrush.h:150
YSLib::Drawing::RDeg180
@ RDeg180
Definition: YGDIBase.h:1148
ystdex::make_transposed
transposed_iterator< decay_t< _tIter > > make_transposed(_tIter &&i, _tSize w, _tSize h, _tIndex idx)
Definition: iterator.hpp:1083
YSLib::Drawing::g
The boundary is out of the const Graphics & g
Definition: YDraw.h:161
ystdex::bool_
integral_constant< bool, _vInt > bool_
Definition: integral_constant.hpp:93
YSLib::Drawing::SolidBlendBrush::SolidBlendBrush
SolidBlendBrush(Drawing::Color c)
Definition: YBrush.h:84
YSLib::Drawing::SolidBrush::Color
Drawing::Color Color
Definition: YBrush.h:61
YSLib::Drawing::SolidCompositeBrush
单色 Alpha 组合画刷。
Definition: YBrush.h:98
YSLib::YAssert
YAssert(!(v< Deref(a)), "Value less than lower bound found.")
YSLib::Drawing::ImageBrush::ImagePtr
shared_ptr< Drawing::Image > ImagePtr
Definition: YBrush.h:140
YSLib::Drawing::src
src
Definition: YGDI.h:442
YSLib::Drawing::Shaders::BlitAlphaPoint
像素计算：Alpha 混合。
Definition: YBlend.h:81
YSLib::Drawing::UpdateRotatedBrush
void UpdateRotatedBrush(const PaintContext &pc, const Drawing::Image &img, const Point &dst_offset, const Point &src_offset)
使用默认构造的画刷更新：可能旋转源图像的像素操作。
Definition: YBrush.h:256
YSLib::Drawing::Rotation
Rotation
逆时针旋转角度指示输出指向。
Definition: YGDIBase.h:1145
YSLib::GHEvent
标准事件处理器模板。
Definition: YEvent.hpp:59
YSLib::Drawing::BlitPixels
void BlitPixels(_fPixelShader shader, _tOut dst, _tIn src, const Size &ds, const Size &ss, const Point &dp, const Point &sp, const Size &sc)
像素块传输函数模板。
Definition: YBlit.h:296
YSLib::Drawing::ImageBrush::DefDeCtor
yconstfn DefDeCtor(ImageBrush) ImageBrush(const shared_ptr< Drawing
Definition: YBrush.h:146
std
Definition: optional.h:982
YSLib::Drawing::DispatchRotatedBrush
GBrushUpdater< const _tImage &, const Point &, const Point & > DispatchRotatedBrush(Rotation rot)
按指定的源图像旋转方向构造画刷。
Definition: YBrush.h:272
YSLib::Drawing::GBinaryGroup< SPos >
YSLib::Drawing::ImageBrush::DefDeCopyCtor
DefDeCopyCtor(ImageBrush) DefDeMoveCtor(ImageBrush) DefDeCopyAssignment(ImageBrush) DefDeMoveAssignment(ImageBrush) void operator()(const PaintContext &) const
描画：调用图像更新器。
YSLib::Drawing::SolidBlendBrush
单色 Alpha 混合画刷。
Definition: YBrush.h:80
YSLib::Drawing::UpdateTranposedPixels
void UpdateTranposedPixels(_fPixelShader shader, const PaintContext &pc, const Drawing::Image &img, const Point &dst_offset, const Point &src_offset)
更新：转置的逐像素操作。
Definition: YBrush.h:203
YSLib::Drawing::SolidCompositeBrush::SolidCompositeBrush
SolidCompositeBrush(Drawing::Color c)
Definition: YBrush.h:102
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:788
DefDeCopyAssignment
#define DefDeCopyAssignment(_t)
Definition: YBaseMacro.h:186
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
YSLib::Drawing::Transpose
YB_ATTR_nodiscard YB_PURE yconstfn _tBinary Transpose(const _tBinary &obj) ynothrow
转置。
Definition: YGDIBase.h:453
ystdex::cond_t
_t< cond< _tCond, _tThen, _tElse > > cond_t
Definition: meta.hpp:794
YModules.h
YSLib 用户界面模块配置文件。
YSLib::Drawing::RDeg0
@ RDeg0
Definition: YGDIBase.h:1146
YSLib::Drawing::bounds
The boundary is out of the const Rect & bounds
Definition: YDraw.h:127
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
YSLib::Drawing::SolidBrush::SolidBrush
SolidBrush(Drawing::Color c)
Definition: YBrush.h:63
YSLib::Drawing::ConstBitmapPtr
const Pixel * ConstBitmapPtr
Definition: YGraphics.h:44
ystdex::transposed_iterator
下标转置迭代器适配器。
Definition: iterator.hpp:888
YSLib::Drawing::RDeg90
@ RDeg90
Definition: YGDIBase.h:1147
DefDeMoveAssignment
#define DefDeMoveAssignment(_t)
Definition: YBaseMacro.h:191
YSLib::Drawing::ImageBrush
图像画刷。
Definition: YBrush.h:129
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:1073