YSTest: YGDI.h 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

YGDI.h
浏览该文件的文档.
1 /*
2 © 2009-2017 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_YGDI_h_
29 #define YSL_INC_Service_YGDI_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_Core_YGraphics
33
34 namespace YSLib
35 {
36
37 namespace Drawing
38 {
39
40 // GDI 逻辑对象。
41
46 struct YF_API Padding
47 {
52 SPos Left = 0, Right = 0, Top = 0, Bottom = 0;
53
58 DefDeCtor(Padding)
63 explicit yconstfn
64 Padding(SPos x)
65 : Padding(x, x, x, x)
66 {}
71 yconstfn
72 Padding(SPos l, SPos r, SPos t, SPos b)
73 : Left(l), Right(r), Top(t), Bottom(b)
74 {}
75
79 PDefHOp(Padding&, +=, const Padding& m)
80 ImplRet(yunseq(Left += m.Left, Right += m.Right, Top += m.Top,
81 Bottom += m.Bottom), *this)
82
87 PDefHOp(Padding&, -=, const Padding& m)
88 ImplRet(yunseq(Left -= m.Left, Right -= m.Right, Top -= m.Top,
89 Bottom -= m.Bottom), *this)
90
95 PDefHOp(Padding&, *=, size_t n)
96 // XXX: Conversion to 'SPos' might be implementation-defined.
97 ImplRet(yunseq(Left *= SPos(n), Right *= SPos(n), Top *= SPos(n),
98 Bottom *= SPos(n)), *this)
99 };
100
102
103
107 yconstfn PDefHOp(Padding, -, const Padding& x)
108 ImplRet(Padding(-x.Left, -x.Right, -x.Top, -x.Bottom))
109
113 yconstfn PDefHOp(Padding, +, const Padding& x, const Padding& y)
114 ImplRet(Padding(x.Left + y.Left, x.Right + y.Right, x.Top + y.Top,
115 x.Bottom + y.Bottom))
116
121 yconstfn PDefHOp(Padding, -, const Padding& x, const Padding& y)
122 ImplRet(Padding(x.Left - y.Left, x.Right - y.Right, x.Top - y.Top,
123 x.Bottom - y.Bottom))
124
129 yconstfn PDefHOp(Padding, *, const Padding& x, size_t n)
130 ImplRet(Padding(SPos(x.Left * ptrdiff_t(n)), SPos(x.Right * ptrdiff_t(n)),
131 SPos(x.Top * ptrdiff_t(n)), SPos(x.Bottom * ptrdiff_t(n))))
132
137 YF_API Rect
138 operator+(const Rect&, const Padding&);
139
145 inline PDefHOp(Rect, -, const Rect& r, const Padding& m)
146 ImplRet(r + -m)
148
149
153 inline PDefH(SDst, GetHorizontalOf, const Padding& m)
154 ImplRet(SDst(max<SPos>(0, m.Left) + max<SPos>(0, m.Right)))
155
159 inline PDefH(SDst, GetVerticalOf, const Padding& m)
160 ImplRet(SDst(max<SPos>(0, m.Top) + max<SPos>(0, m.Bottom)))
161
162
166 YF_API Padding
167 FetchMargin(const Rect&, const Size&);
168
169
174 inline PDefH(bool, Clip, Rect& x, const Rect& y)
175 ImplRet(x &= y, !x.IsUnstrictlyEmpty())
176
185 YF_API Point
186 ClipBounds(Rect&, const Rect&);
187
196 YF_API Point
197 ClipMargin(PaintContext&, const Padding&, const Size&);
198
199
204 class YF_API BasicImage : protected Graphics, implements IImage
205 {
206 public:
207 DefDeCtor(BasicImage)
208 BasicImage(const Graphics& g)
209 : Graphics(g)
210 {}
212 DefDeCopyCtor(BasicImage)
217 ~BasicImage() override;
218
219 using Graphics::operator!;
220
221 using Graphics::operator bool;
222
223 using Graphics::GetBufferPtr;
224 using Graphics::GetHeight;
225 using Graphics::GetWidth;
226 using Graphics::GetSize;
228 DefGetter(const ynothrow ImplI(IImage), Graphics, Context, *this)
229
230
231 DefClone(const ImplI(IImage), BasicImage)
232
233 DefSetter(ImplI(IImage), const Size&, Size, sGraphics)
234 };
235
236
243 class YF_API CompactPixmap
244 : private GGraphics<unique_ptr<Pixel[]>>, implements IImage
245 {
246 private:
248
249 using BaseType = GGraphics<unique_ptr<Pixel[]>>;
250
251 protected:
252 using BaseType::pBuffer;
253 using BaseType::sGraphics;
255
256 public:
261 DefDeCtor(CompactPixmap)
265 CompactPixmap(ConstBitmapPtr, SDst, SDst);
270 CompactPixmap(unique_ptr<Pixel[]>, const Size&) ynothrow;
271 CompactPixmap(const CompactPixmap&);
272 DefDeMoveCtor(CompactPixmap)
273
275
276 PDefHOp(CompactPixmap&, =, const CompactPixmap& buf)
278 ImplRet(ystdex::copy_and_swap(*this, buf))
279 DefDeMoveAssignment(CompactPixmap)
281
283
284 using BaseType::operator!;
285
286 using BaseType::operator bool;
287
288 DefGetter(const ynothrow, BitmapPtr, BufferPtr,
289 BaseType::GetBufferPtr().get())
290 using BaseType::GetBufferPtr;
291 using BaseType::GetHeight;
292 using BaseType::GetWidth;
293 using BaseType::GetSize;
294 DefGetter(const ynothrow ImplI(IImage), Graphics, Context,
295 Graphics(GetBufferPtr(), GetSize()))
297
303 void
304 SetContent(ConstBitmapPtr, SDst, SDst);
305 PDefH(void, SetSize, SDst w, SDst h)
306 ImplExpr(SetSize({w, h}))
313 void
314 SetSize(const Size&) override;
318 void
319 SetSizeSwap();
320
324 virtual void
325 ClearImage() const;
326
327 DefClone(const ImplI(IImage), CompactPixmap)
328
329
333 friend PDefH(void, swap, CompactPixmap& x, CompactPixmap& y) ynothrow
334 ImplExpr(std::swap<BaseType>(x, y))
335 };
336
341 static_assert(ystdex::is_nothrow_moveable<CompactPixmap>(),
342 "Postcondition failed.");
343
344
350 class YF_API CompactPixmapEx : public CompactPixmap
351 {
352 protected:
357 unique_ptr<AlphaType[]> pBufferAlpha;
358
359 public:
360 DefDeCtor(CompactPixmapEx)
364 CompactPixmapEx(ConstBitmapPtr, SDst, SDst);
365 CompactPixmapEx(const CompactPixmapEx&);
366 DefDeMoveCtor(CompactPixmapEx)
367
369
370 PDefHOp(CompactPixmapEx&, =, const CompactPixmapEx& buf)
372 ImplRet(ystdex::copy_and_swap(*this, buf))
373 DefDeMoveAssignment(CompactPixmapEx)
375
380 DefGetter(const ynothrow, AlphaType*, BufferAlphaPtr, pBufferAlpha.get())
385 DefGetter(const ynothrow, size_t, SizeOfBufferAlpha,
386 sizeof(AlphaType) * size_t(GetAreaOf(GetSize())))
387
388 using CompactPixmap::SetSize;
395 void
396 SetSize(const Size&) override;
397
401 void
402 ClearImage() const override;
403
404 DefClone(const override, CompactPixmapEx)
405
410 PDefH(void, swap, CompactPixmapEx& x, CompactPixmapEx& y) ynothrow
411 ImplExpr(std::swap<CompactPixmap>(x, y),
412 std::swap(x.pBufferAlpha, y.pBufferAlpha))
413 };
414
419 static_assert(ystdex::is_nothrow_moveable<CompactPixmapEx>(),
420 "Postcondition failed.");
421
422
431 YF_API bool
432 CopyTo(BitmapPtr, const ConstGraphics&, const Size&, const Point&, const Point&,
433 const Size&, Rotation = RDeg0);
441 YF_API bool
442 CopyTo(BitmapPtr, const CompactPixmapEx&, const Size&,
443 const Point&, const Point&, const Size&, Rotation = RDeg0);
452 inline PDefH(bool, CopyTo, const Graphics& dst, const ConstGraphics& src,
453 const Point& dp = {}, const Point& sp = {}, Rotation rot = RDeg0)
454 ImplRet(CopyTo(dst.GetBufferPtr(), src, dst.GetSize(), dp, sp,
455 src.GetSize(), rot))
463 inline PDefH(bool, CopyTo, const Graphics& dst, const CompactPixmapEx& src,
464 const Point& dp = {}, const Point& sp = {}, Rotation rot = RDeg0)
465 ImplRet(CopyTo(dst.GetBufferPtr(), src, dst.GetSize(), dp, sp,
466 src.GetSize(), rot))
467
475 YF_API bool
476 BlitTo(BitmapPtr, const CompactPixmapEx&, const Size&,
477 const Point&, const Point&, const Size&, Rotation = RDeg0);
485 inline PDefH(bool, BlitTo, const Graphics& dst, const CompactPixmapEx& src,
486 const Point& dp = {}, const Point& sp = {}, Rotation rot = RDeg0)
487 ImplRet(BlitTo(dst.GetBufferPtr(), src, dst.GetSize(), dp, sp,
488 src.GetSize(), rot))
489
490 } // namespace Drawing;
491
492 } // namespace YSLib;
493
494 #endif
495
YSLib::Drawing::GetHeight
tr GetHeight())) inline PDefH(void
按字体高度和行距调整文本区域的底边距。
YSLib::Drawing::CompactPixmapEx
使用 8 位 Alpha 扩展的标准矩形像素图缓冲区。
Definition: YGDI.h:350
NPL::dst
YF_API const char src const string const char * dst
Definition: Dependency.h:95
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:680
YSLib::Drawing::ClipMargin
Point ClipMargin(PaintContext &pc, const Padding &m, const Size &ss)
Definition: YGDI.cpp:69
YSLib::Drawing::BasicImage
使用 Graphics 定义的基本图像。
Definition: YGDI.h:204
YModules.h
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::Drawing::Padding::DefDeCtor
DefDeCtor(Padding) explicit yconstfn Padding(SPos x)
默认构造：使用零边距。
Definition: YGDI.h:58
YSLib::Drawing::GGraphics
二维图形接口上下文模板。
Definition: YGraphics.h:62
YSLib::UI::y
SPos SPos y
Definition: YWidget.cpp:44
YSLib::Drawing::BitmapPtr
Pixel * BitmapPtr
Definition: YGraphics.h:42
YSLib::Drawing::r
The boundary is out of the const Graphics const Rect const Point const Point Color c const Rect const Rect & r
Definition: YDraw.h:174
YSLib::Drawing::CompactPixmap
标准矩形像素图缓冲区。
Definition: YGDI.h:243
platform::bool
std::FILE *fp bool
Definition: FileIO.h:1280
DefDeMoveCtor
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:167
ImplI
#define ImplI(...)
Definition: YBaseMacro.h:388
YSLib::Text::buf
const char * buf
Definition: TextFile.h:81
ystdex::max
const _type & max(const _type &a, const _type &b, _fComp comp=less< _type >())
取较大的元素。
Definition: algorithm.hpp:549
DefClone
#define DefClone(_q, _t)
动态复制。
Definition: YBaseMacro.h:294
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:1022
platform::AlphaType
octet AlphaType
Definition: Video.h:253
YSLib::Drawing::FetchMargin
Padding FetchMargin(const Rect &r, const Size &s)
Definition: YGDI.cpp:51
YSLib::Drawing::Padding::src
dst src rot src
Definition: YGDI.h:465
YSLib::Drawing::CompactPixmapEx::pBufferAlpha
unique_ptr< AlphaType[]> pBufferAlpha
Alpha 缓冲区指针。
Definition: YGDI.h:357
DefDeMoveAssignment
#define DefDeMoveAssignment(_t)
Definition: YBaseMacro.h:191
DefDeCtor
#define DefDeCtor(_t)
简单通用成员函数定义。
Definition: YBaseMacro.h:157
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
YSLib::Drawing::x
The boundary is out of the const Rect SDst SPos x
Definition: YDraw.h:127
YSLib::Drawing::w
The boundary is out of the const Rect SDst w
Definition: YDraw.h:127
YSLib::Drawing::g
The boundary is out of the const Graphics & g
Definition: YDraw.h:161
ystdex
特性测试宏。
Definition: ydef.h:822
YSLib::Drawing::ImplExpr
tr TextRegion &tr ImplExpr(tr.Margin.Bottom=SPos(FetchResizedBottomMargin(tr))) YF_API SDst FetchCharWidth(const Font &
取指定的字符使用指定字体的显示宽度。
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::Drawing::ClearImage
YF_API void ClearImage(const Graphics &)
清除图形接口上下文缓冲区。
Definition: YBlit.cpp:88
Drawing
platform::SPos
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:43
YSLib::Drawing::Rotation
Rotation
逆时针旋转角度指示输出指向。
Definition: YGDIBase.h:895
YSLib::Drawing::CopyTo
bool CopyTo(BitmapPtr dst, const ConstGraphics &g, const Size &ds, const Point &dp, const Point &sp, const Size &sc, Rotation rot)
Definition: YGDI.cpp:203
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
YSLib::Drawing::BlitTo
bool BlitTo(BitmapPtr dst, const CompactPixmapEx &buf, const Size &ds, const Point &dp, const Point &sp, const Size &sc, Rotation rot)
Definition: YGDI.cpp:238
YSLib::Drawing::GBinaryGroup< SPos >
DefSetter
#define DefSetter(_q, _t, _n, _m)
Definition: YBaseMacro.h:252
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:540
YSLib::Drawing::Padding
空白样式。
Definition: YGDI.h:46
std
Definition: memory.hpp:1183
YSLib::Drawing::BasicImage::DefDeCtor
DefDeCtor(BasicImage) BasicImage(const Graphics &g)
Definition: YGDI.h:207
YSLib::ImplRet
ImplRet(FetchGlobalInstance().GetGUIHostRef()) YF_API void Execute(GUIApplication &
执行程序主消息循环。
YSLib::Drawing::ClipBounds
Point ClipBounds(Rect &clip, const Rect &bounds)
Definition: YGDI.cpp:60
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
YSLib::Drawing::Padding::Padding
yconstfn Padding(SPos l, SPos r, SPos t, SPos b)
构造：使用 4 个边距。
Definition: YGDI.h:72
DefDeCopyCtor
#define DefDeCopyCtor(_t)
Definition: YBaseMacro.h:162
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:293
implements
#define implements
Definition: YBaseMacro.h:352
ystdex::copy_and_swap
_type & copy_and_swap(_type &obj, const _type2 &new_val)
复制后交换。
Definition: utility.hpp:170
YSLib::Drawing::RDeg0
Definition: YGDIBase.h:897
YSLib::Drawing::PDefH
yconstfn PDefH(Size, Transpose, const Size &s) ynothrow ImplRet(
转置。
Definition: YGDIBase.h:516
YSLib::Drawing::ConstBitmapPtr
const Pixel * ConstBitmapPtr
Definition: YGraphics.h:44
YSLib::Drawing::Padding::src
src
Definition: YGDI.h:454
YSLib::swap
void swap(ValueNode &x, ValueNode &y) ynothrow
Definition: ValueNode.cpp:73
ystdex::details::get
get())
Definition: cast.hpp:102