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 
47 {
48  /*
49  \brief 空白距离:左、右、上、下。
50  \since build 365
51  */
52  SPos Left, Right, Top, Bottom;
53 
58  yconstfn
60  : Padding(0, 0, 0, 0)
61  {}
66  yconstfn
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 
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 }
99 operator+(const Rect&, const Padding&);
101 
102 
106 inline SDst
108 {
109  return max<SPos>(0, m.Left) + max<SPos>(0, m.Right);
110 }
111 
115 inline SDst
117 {
118  return max<SPos>(0, m.Top) + max<SPos>(0, m.Bottom);
119 }
120 
121 
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 
149 ClipBounds(Rect&, const Rect&);
150 
160 ClipMargin(PaintContext&, const Padding&, const Size&);
161 
162 
167 class YF_API BasicImage : protected Graphics,
168  implements IImage
169 {
170 public:
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 
202 {
203 public:
217  CompactPixmap(unique_ptr<PixelType[]>, const Size&) ynothrow;
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  */
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:
304  : CompactPixmap(), pBufferAlpha()
305  {}
314  CompactPixmapEx(CompactPixmapEx&&) ynothrow;
318  ~CompactPixmapEx() override
319  {
320  delete[] pBufferAlpha;
321  }
322 
323  /*
324  \brief 复制赋值:使用复制构造函数和交换函数。
325  \since build 296
326  */
329  {
330  CompactPixmapEx(buf).swap(*this);
331  return *this;
332  }
333  /*
334  \brief 转移赋值:使用转移构造函数和交换函数。
335  */
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 
bool Clip(Rect &x, const Rect &y)
剪切操作:取标准矩形交集并判断是否严格非空。
Definition: ygdi.h:134
yconstfn Padding(SPos l, SPos r, SPos t, SPos b)
构造:使用 4 个边距。
Definition: ygdi.h:67
标准矩形像素图缓冲区。
Definition: ygdi.h:201
#define ImplRet(...)
Definition: YBaseMacro.h:97
YF_API Padding FetchMargin(const Rect &, const Size &)
取内边界相对于外边界的边距。
Definition: ygdi.cpp:51
DefDeCtor(BasicImage) BasicImage(const Graphics &g)
Definition: ygdi.h:171
#define implements
Definition: YBaseMacro.h:272
SizeOfBufferAlpha
Definition: ygdi.h:352
SDst GetVerticalOf(const Padding &m)
取竖直边距和。
Definition: ygdi.h:116
yconstfn Padding operator+(const Padding &x, const Padding &y)
加法:对应分量调用 operator+ 。
Definition: ygdi.h:89
#define DefDeCtor(_t)
Definition: YBaseMacro.h:131
#define YF_API
Definition: Platform.h:64
CompactPixmapEx()
使用 8 位 Alpha 扩展的标准矩形像素图缓冲区。
Definition: ygdi.h:303
YF_API void ClearImage(const Graphics &)
清除图形接口上下文缓冲区。
Definition: yblit.cpp:89
SDst GetHorizontalOf(const Padding &m)
取水平边距和。
Definition: ygdi.h:107
yconstfn auto GetAreaOf(const Size &s) ynothrow-> decltype(s.Width *s.Height)
取面积。
Definition: ygdibase.h:404
YF_API Point ClipBounds(Rect &, const Rect &)
根据指定源的边界优化绘制上下文的剪切区域。
Definition: ygdi.cpp:59
yconstfn Padding()
默认构造:使用零边距。
Definition: ygdi.h:59
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:39
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:38
使用 Graphics 定义的基本图像。
Definition: ygdi.h:167
#define ImplI(...)
Definition: YBaseMacro.h:308
Padding & operator+=(const Padding &m)
加法赋值:对应分量调用 operator+= 。
Definition: ygdi.h:75
CompactPixmapEx & operator=(const CompactPixmapEx &buf)
Definition: ygdi.h:328
CompactPixmapEx(ConstBitmapPtr, SDst, SDst)
构造:使用指定位图指针和大小。
void swap(any &x, any &y)
交换对象。
Definition: any.h:729
sizeof(AlphaType)*GetAreaOf(GetSize())) using CompactPixmap void SetSize(const Size &) override
重新设置缓冲区大小。
GBinaryGroup< SPos > Point
屏幕二维点(直角坐标表示)。
Definition: ygdibase.h:235
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:748
#define ImplExpr(...)
Definition: YBaseMacro.h:93
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
DefClone(const override, CompactPixmapEx) void swap(CompactPixmapEx &buf) ynothrow
Definition: ygdi.h:371
屏幕标准矩形:表示屏幕矩形区域。
Definition: ygdibase.h:416
#define DefSetter(_t, _n, _m)
Definition: YBaseMacro.h:188
yconstfn GBinaryGroup< _type > operator+(const GBinaryGroup< _type > &a, const GBinaryGroup< _type > &b) ynothrow
加法:屏幕二元组。
Definition: ygdibase.h:203
二维图形接口上下文。
Definition: ygdibase.h:721
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:463
Rotation
逆时针旋转角度指示输出指向。
Definition: ygdibase.h:868
YF_API Point ClipMargin(PaintContext &, const Padding &, const Size &)
根据指定边距和源的大小优化绘制上下文的剪切区域。
Definition: ygdi.cpp:68
空白样式。
Definition: ygdi.h:46
PixelType * BitmapPtr
Definition: Video.h:295
YF_API bool CopyTo(BitmapPtr, const CompactPixmapEx &, const Size &, const Point &, const Point &, const Size &, Rotation=RDeg0)
位图缓冲区向指针指定的缓冲区复制。
Definition: ygdi.cpp:234
bounds & r
Definition: ydraw.h:220
PDefH(void, DrawLineSeg, const Graphics &g, const Rect &bounds, const Point &p1, const Point &p2, Color c) ImplExpr(DrawLineSeg(g
c yconstfn g
Definition: ystyle.h:104
DefGetter(const ynothrow, AlphaType *, BufferAlphaPtr, pBufferAlpha) DefGetter(const ynothrow
取 Alpha 缓冲区的指针。
const PixelType * ConstBitmapPtr
Definition: Video.h:296
屏幕区域大小。
Definition: ygdibase.h:249
ystdex::octet AlphaType
Definition: Video.h:186
YF_API bool BlitTo(BitmapPtr, const CompactPixmapEx &, const Size &, const Point &, const Point &, const Size &, Rotation=RDeg0)
贴图:位图缓冲区向指针指定的缓冲区以贴图算法复制。
Definition: ygdi.cpp:253