YSTest: ygdi.h 源文件

YSTest PreAlpha_b500_20140530 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
ygdi.h
浏览该文件的文档.
1 /*
2 © 2009-2014 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_YGDIBase
33
34 namespace YSLib
35 {
36
37 namespace Drawing
38 {
39
40 // GDI 逻辑对象。
41
46 struct YF_API Padding
47 {
48 /*
49 \brief 空白距离：左、右、上、下。
50 \since build 365
51 */
52 SPos Left, Right, Top, Bottom;
53
58 yconstfn
59 Padding()
60 : Padding(0, 0, 0, 0)
61 {}
66 yconstfn
67 Padding(SPos l, SPos r, SPos t, SPos b)
68 : Left(l), Right(r), Top(t), Bottom(b)
69 {}
70
74 Padding&
75 operator+=(const Padding& m)
76 {
77 yunseq(Left += m.Left, Right += m.Right, Top += m.Top,
78 Bottom += m.Bottom);
79 return *this;
80 }
81 };
82
84
85
88 yconstfn Padding
89 operator+(const Padding& x, const Padding& y)
90 {
91 return Padding(x.Left + y.Left, x.Right + y.Right, x.Top + y.Top,
92 x.Bottom + y.Bottom);
93 }
98 YF_API Rect
99 operator+(const Rect&, const Padding&);
101
102
106 inline SDst
107 GetHorizontalOf(const Padding& m)
108 {
109 return max<SPos>(0, m.Left) + max<SPos>(0, m.Right);
110 }
111
115 inline SDst
116 GetVerticalOf(const Padding& m)
117 {
118 return max<SPos>(0, m.Top) + max<SPos>(0, m.Bottom);
119 }
120
121
125 YF_API Padding
126 FetchMargin(const Rect&, const Size&);
127
128
133 inline bool
134 Clip(Rect& x, const Rect& y)
135 {
136 x &= y;
137 return !x.IsUnstrictlyEmpty();
138 }
139
148 YF_API Point
149 ClipBounds(Rect&, const Rect&);
150
159 YF_API Point
160 ClipMargin(PaintContext&, const Padding&, const Size&);
161
162
167 class YF_API BasicImage : protected Graphics,
168 implements IImage
169 {
170 public:
171 DefDeCtor(BasicImage)
172 BasicImage(const Graphics& g)
173 : Graphics(g)
174 {}
175
176 using Graphics::operator!;
177
178 using Graphics::operator bool;
179
180 using Graphics::GetBufferPtr;
181 using Graphics::GetHeight;
182 using Graphics::GetWidth;
183 using Graphics::GetSize;
184 ImplI(IImage) DefGetter(const ynothrow override, const Graphics&, Context,
185 *this)
186
188 ImplI(IImage) DefClone(const override, BasicImage)
189
190 ImplI(IImage) DefSetter(const Size&, Size, sGraphics)
191 };
192
193
201 class YF_API CompactPixmap : public BasicImage
202 {
203 public:
208 DefDeCtor(CompactPixmap)
212 CompactPixmap(ConstBitmapPtr, SDst, SDst);
217 CompactPixmap(unique_ptr<PixelType[]>, const Size&) ynothrow;
218 CompactPixmap(const CompactPixmap&);
222 CompactPixmap(CompactPixmap&&) ynothrow;
226 ~CompactPixmap() override
227 {
228 delete[] pBuffer;
229 }
230
231 /*
232 \brief 统一赋值：使用值参数和交换函数进行复制或转移赋值。
233 \since build 476
234 */
235 PDefHOp(CompactPixmap&, =, CompactPixmap msg) ynothrow
236 ImplRet(msg.swap(*this), *this)
237
243 void
244 SetContent(ConstBitmapPtr, SDst, SDst);
245 PDefH(void, SetSize, SDst w, SDst h)
246 ImplExpr(SetSize(Size(w, h)))
253 void
254 SetSize(const Size&) override;
258 void
259 SetSizeSwap();
260
264 virtual void
265 ClearImage() const;
266
267 virtual DefClone(const, CompactPixmap)
268
269 /*
270 \brief 交换。
271 */
272 PDefH(void, swap, CompactPixmap& buf) ynothrow
273 ImplExpr(std::swap<Graphics>(*this, buf))
274 };
275
280 inline DefSwap(ynothrow, CompactPixmap)
281
282
289 class YF_API CompactPixmapEx : public CompactPixmap
290 {
291 protected:
296 AlphaType* pBufferAlpha;
297
298 public:
303 CompactPixmapEx()
304 : CompactPixmap(), pBufferAlpha()
305 {}
309 CompactPixmapEx(ConstBitmapPtr, SDst, SDst);
310 CompactPixmapEx(const CompactPixmapEx&);
314 CompactPixmapEx(CompactPixmapEx&&) ynothrow;
318 ~CompactPixmapEx() override
319 {
320 delete[] pBufferAlpha;
321 }
322
323 /*
324 \brief 复制赋值：使用复制构造函数和交换函数。
325 \since build 296
326 */
327 CompactPixmapEx&
328 operator=(const CompactPixmapEx& buf)
329 {
330 CompactPixmapEx(buf).swap(*this);
331 return *this;
332 }
333 /*
334 \brief 转移赋值：使用转移构造函数和交换函数。
335 */
336 CompactPixmapEx&
337 operator=(CompactPixmapEx&& buf) ynothrow
338 {
339 swap(buf);
340 return *this;
341 }
342
347 DefGetter(const ynothrow, AlphaType*, BufferAlphaPtr, pBufferAlpha)
352 DefGetter(const ynothrow, size_t, SizeOfBufferAlpha,
353 sizeof(AlphaType) * GetAreaOf(GetSize()))
354
355 using CompactPixmap::SetSize;
362 void
363 SetSize(const Size&) override;
364
368 void
369 ClearImage() const override;
370
371 DefClone(const override, CompactPixmapEx)
372
373 /*
374 \brief 交换。
375 */
376 void
377 swap(CompactPixmapEx& buf) ynothrow
378 {
379 std::swap<CompactPixmap>(*this, buf),
380 std::swap(pBufferAlpha, buf.pBufferAlpha);
381 }
382 };
383
388 inline DefSwap(ynothrow, CompactPixmapEx)
389
390
391
398 YF_API bool
399 CopyTo(BitmapPtr, const Graphics&, const Size&, const Point&, const Point&,
400 const Size&, Rotation = RDeg0);
408 YF_API bool
409 CopyTo(BitmapPtr, const CompactPixmapEx&, const Size&,
410 const Point&, const Point&, const Size&, Rotation = RDeg0);
419 inline bool
420 CopyTo(const Graphics& dst, const Graphics& src,
421 const Point& dp = {}, const Point& sp = {}, Rotation rot = RDeg0)
422 {
423 return CopyTo(dst.GetBufferPtr(), src, dst.GetSize(),
424 dp, sp, src.GetSize(), rot);
425 }
433 inline bool
434 CopyTo(const Graphics& dst, const CompactPixmapEx& src,
435 const Point& dp = {}, const Point& sp = {}, Rotation rot = RDeg0)
436 {
437 return CopyTo(dst.GetBufferPtr(), src, dst.GetSize(),
438 dp, sp, src.GetSize(), rot);
439 }
440
448 YF_API bool
449 BlitTo(BitmapPtr, const CompactPixmapEx&, const Size&,
450 const Point&, const Point&, const Size&, Rotation = RDeg0);
458 inline bool
459 BlitTo(const Graphics& dst, const CompactPixmapEx& src,
460 const Point& dp = {}, const Point& sp = {}, Rotation rot = RDeg0)
461 {
462 return BlitTo(dst.GetBufferPtr(), src, dst.GetSize(),
463 dp, sp, src.GetSize(), rot);
464 }
465
466 } // namespace Drawing;
467
468 } // namespace YSLib;
469
470 #endif
471
YSLib::UI::BorderArea::Right
YSLib::Drawing::Clip
bool Clip(Rect &x, const Rect &y)
剪切操作：取标准矩形交集并判断是否严格非空。
Definition: ygdi.h:134
YSLib::Drawing::Padding::Padding
yconstfn Padding(SPos l, SPos r, SPos t, SPos b)
构造：使用 4 个边距。
Definition: ygdi.h:67
YSLib::Drawing::CompactPixmap
标准矩形像素图缓冲区。
Definition: ygdi.h:201
ImplRet
#define ImplRet(...)
Definition: YBaseMacro.h:97
YSLib::Drawing::FetchMargin
YF_API Padding FetchMargin(const Rect &, const Size &)
取内边界相对于外边界的边距。
Definition: ygdi.cpp:51
YSLib::Drawing::BasicImage::DefDeCtor
DefDeCtor(BasicImage) BasicImage(const Graphics &g)
Definition: ygdi.h:171
implements
#define implements
Definition: YBaseMacro.h:272
YSLib::Drawing::SizeOfBufferAlpha
SizeOfBufferAlpha
Definition: ygdi.h:352
YSLib::Drawing::GetVerticalOf
SDst GetVerticalOf(const Padding &m)
取竖直边距和。
Definition: ygdi.h:116
YSLib::Drawing::Padding::operator+
yconstfn Padding operator+(const Padding &x, const Padding &y)
加法：对应分量调用 operator+ 。
Definition: ygdi.h:89
DefDeCtor
#define DefDeCtor(_t)
Definition: YBaseMacro.h:131
platform_ex::Windows::l
l
Definition: MinGW32.cpp:50
YF_API
#define YF_API
Definition: Platform.h:64
YSLib::Drawing::CompactPixmap::CompactPixmapEx
CompactPixmapEx()
使用 8 位 Alpha 扩展的标准矩形像素图缓冲区。
Definition: ygdi.h:303
YSLib::Drawing::ClearImage
YF_API void ClearImage(const Graphics &)
清除图形接口上下文缓冲区。
Definition: yblit.cpp:89
YSLib::Drawing::Padding::GetHorizontalOf
SDst GetHorizontalOf(const Padding &m)
取水平边距和。
Definition: ygdi.h:107
YSLib::Drawing::GetAreaOf
yconstfn auto GetAreaOf(const Size &s) ynothrow-> decltype(s.Width *s.Height)
取面积。
Definition: ygdibase.h:404
YSLib::Drawing::ClipBounds
YF_API Point ClipBounds(Rect &, const Rect &)
根据指定源的边界优化绘制上下文的剪切区域。
Definition: ygdi.cpp:59
YSLib::Drawing::Padding::Padding
yconstfn Padding()
默认构造：使用零边距。
Definition: ygdi.h:59
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:39
platform::SPos
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:38
YSLib::Drawing::BasicImage
使用 Graphics 定义的基本图像。
Definition: ygdi.h:167
ImplI
#define ImplI(...)
Definition: YBaseMacro.h:308
YSLib::Drawing::Padding::operator+=
Padding & operator+=(const Padding &m)
加法赋值：对应分量调用 operator+= 。
Definition: ygdi.h:75
YSLib::Drawing::operator=
CompactPixmapEx & operator=(const CompactPixmapEx &buf)
Definition: ygdi.h:328
YSLib::Drawing::CompactPixmapEx
CompactPixmapEx(ConstBitmapPtr, SDst, SDst)
构造：使用指定位图指针和大小。
ystdex::swap
void swap(any &x, any &y)
交换对象。
Definition: any.h:729
YSLib::Drawing::Padding::Right
SPos Right
Definition: ygdi.h:52
YSLib::Drawing::SetSize
sizeof(AlphaType)*GetAreaOf(GetSize())) using CompactPixmap void SetSize(const Size &) override
重新设置缓冲区大小。
YSLib::Drawing::Point
GBinaryGroup< SPos > Point
屏幕二维点（直角坐标表示）。
Definition: ygdibase.h:235
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:748
ImplExpr
#define ImplExpr(...)
Definition: YBaseMacro.h:93
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
YSLib::Drawing::DefClone
DefClone(const override, CompactPixmapEx) void swap(CompactPixmapEx &buf) ynothrow
Definition: ygdi.h:371
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: ygdibase.h:416
DefSetter
#define DefSetter(_t, _n, _m)
Definition: YBaseMacro.h:188
YSLib::Drawing::GBinaryGroup< SPos >
YSLib::Drawing::operator+
yconstfn GBinaryGroup< _type > operator+(const GBinaryGroup< _type > &a, const GBinaryGroup< _type > &b) ynothrow
加法：屏幕二元组。
Definition: ygdibase.h:203
YSLib::Drawing::Padding::Top
SPos Top
Definition: ygdi.h:52
YSLib::Drawing::Graphics
二维图形接口上下文。
Definition: ygdibase.h:721
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:463
YSLib::Drawing::Padding::Left
SPos Left
Definition: ygdi.h:52
YSLib::Drawing::RDeg0
Definition: ygdibase.h:870
Rotation
Rotation
逆时针旋转角度指示输出指向。
Definition: ygdibase.h:868
YSLib::UI::BorderArea::Left
YSLib::Drawing::ClipMargin
YF_API Point ClipMargin(PaintContext &, const Padding &, const Size &)
根据指定边距和源的大小优化绘制上下文的剪切区域。
Definition: ygdi.cpp:68
YSLib::Drawing::Padding
空白样式。
Definition: ygdi.h:46
YSLib::Drawing::Padding::Bottom
SPos Bottom
Definition: ygdi.h:52
platform::BitmapPtr
PixelType * BitmapPtr
Definition: Video.h:295
YSLib::Drawing::CopyTo
YF_API bool CopyTo(BitmapPtr, const CompactPixmapEx &, const Size &, const Point &, const Point &, const Size &, Rotation=RDeg0)
位图缓冲区向指针指定的缓冲区复制。
Definition: ygdi.cpp:234
YSLib::Drawing::r
bounds & r
Definition: ydraw.h:220
YSLib::Drawing::PDefH
PDefH(void, DrawLineSeg, const Graphics &g, const Rect &bounds, const Point &p1, const Point &p2, Color c) ImplExpr(DrawLineSeg(g
YSLib::Drawing::g
c yconstfn g
Definition: ystyle.h:104
YSLib::Drawing::DefGetter
DefGetter(const ynothrow, AlphaType *, BufferAlphaPtr, pBufferAlpha) DefGetter(const ynothrow
取 Alpha 缓冲区的指针。
YModules.h
platform::ConstBitmapPtr
const PixelType * ConstBitmapPtr
Definition: Video.h:296
YSLib::Drawing::Size
屏幕区域大小。
Definition: ygdibase.h:249
platform::AlphaType
ystdex::octet AlphaType
Definition: Video.h:186
YSLib::Drawing::BlitTo
YF_API bool BlitTo(BitmapPtr, const CompactPixmapEx &, const Size &, const Point &, const Point &, const Size &, Rotation=RDeg0)
贴图：位图缓冲区向指针指定的缓冲区以贴图算法复制。
Definition: ygdi.cpp:253