YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ygdi.h
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2009 - 2013.
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 "../Core/ygdibase.h"
32 
34 
35 YSL_BEGIN_NAMESPACE(Drawing)
36 
37 // GDI 逻辑对象。
38 
39 
44 {
45  /*
46  \brief 空白距离:左、右、上、下。
47  \since build 365
48  */
49  SPos Left, Right, Top, Bottom;
50 
55  yconstfn
56  Padding()
57  : Padding(0, 0, 0, 0)
58  {}
63  yconstfn
64  Padding(SPos l, SPos r, SPos t, SPos b)
65  : Left(l), Right(r), Top(t), Bottom(b)
66  {}
67 
71  Padding&
72  operator+=(const Padding& m)
73  {
74  yunseq(Left += m.Left, Right += m.Right, Top += m.Top,
75  Bottom += m.Bottom);
76  return *this;
77  }
78 };
79 
83 yconstfn Padding
84 operator+(const Padding& x, const Padding& y)
85 {
86  return Padding(x.Left + y.Left, x.Right + y.Right, x.Top + y.Top,
87  x.Bottom + y.Bottom);
88 }
93 YF_API Rect
94 operator+(const Rect&, const Padding&);
95 
96 
100 inline SDst
102 {
103  return max<SPos>(0, m.Left) + max<SPos>(0, m.Right);
104 }
105 
109 inline SDst
111 {
112  return max<SPos>(0, m.Top) + max<SPos>(0, m.Bottom);
113 }
114 
115 
119 YF_API Padding
120 FetchMargin(const Rect&, const Size&);
121 
122 
127 inline bool
128 Clip(Rect& x, const Rect& y)
129 {
130  x &= y;
131  return !x.IsUnstrictlyEmpty();
132 }
133 
143 ClipBounds(Rect&, const Rect&);
144 
154 ClipMargin(PaintContext&, const Padding&, const Size&);
155 
156 
162 class YF_API BitmapBuffer : protected Graphics
163 {
164 public:
174  BitmapBuffer(const BitmapBuffer&);
183  virtual
185  {
186  ydelete_array(pBuffer);
187  }
188 
189  /*
190  \brief 复制赋值:使用复制构造函数和交换函数。
191  \since build 296
192  */
193  BitmapBuffer&
194  operator=(const BitmapBuffer& buf)
195  {
196  BitmapBuffer(buf).Swap(*this);
197  return *this;
198  }
199  /*
200  \brief 转移赋值:使用转移构造函数和交换函数。
201  \since build 296
202  */
203  BitmapBuffer&
204  operator=(BitmapBuffer&& buf) ynothrow
205  {
206  Swap(buf);
207  return *this;
208  }
209 
211 
212  using Graphics::operator!;
213 
214  using Graphics::operator bool;
216 
218 
220  using Graphics::GetHeight;
221  using Graphics::GetWidth;
222  using Graphics::GetSize;
224  DefGetter(const ynothrow, const Graphics&, Context, *this)
226 
232  void
233  SetContent(ConstBitmapPtr, SDst, SDst);
239  virtual void
240  SetSize(SDst, SDst);
244  void
245  SetSizeSwap();
246 
250  virtual void
251  ClearImage() const;
252 
253  virtual DefClone(const, BitmapBuffer, Clone)
254 
255  /*
256  \brief 交换。
257  \since build 296
258  */
259  void
260  Swap(BitmapBuffer& buf) ynothrow
261  {
262  std::swap<Graphics>(*this, buf);
263  }
264 };
265 
266 
273 {
274 protected:
276 
277 public:
283  : BitmapBuffer(), pBufferAlpha()
284  {}
298  ~BitmapBufferEx() override
299  {
300  ydelete_array(pBufferAlpha);
301  }
302 
303  /*
304  \brief 复制赋值:使用复制构造函数和交换函数。
305  \since build 296
306  */
309  {
310  BitmapBufferEx(buf).Swap(*this);
311  return *this;
312  }
313  /*
314  \brief 转移赋值:使用转移构造函数和交换函数。
315  \since build 296
316  */
319  {
320  Swap(buf);
321  return *this;
322  }
323 
324  DefGetter(const ynothrow, u8*, BufferAlphaPtr, pBufferAlpha) \
326  DefGetter(const ynothrow, size_t, SizeOfBufferAlpha, sizeof(u8)
328 
334  void
335  SetSize(SDst, SDst) override;
336 
340  void
341  ClearImage() const override;
342 
343  DefClone(const override, BitmapBufferEx, Clone)
344 
345  /*
346  \brief 交换。
347  \since build 296
348  */
349  void
350  Swap(BitmapBufferEx& buf) ynothrow
351  {
352  std::swap<BitmapBuffer>(*this, buf),
353  std::swap(pBufferAlpha, buf.pBufferAlpha);
354  }
355 };
356 
357 
365 YF_API bool
366 CopyTo(BitmapPtr, const Graphics&, const Size&, const Point&, const Point&,
367  const Size&, Rotation = RDeg0);
374 YF_API bool
375 CopyTo(BitmapPtr, const BitmapBufferEx&, const Size&,
376  const Point&, const Point&, const Size&, Rotation = RDeg0);
385 inline bool
386 CopyTo(const Graphics& dst, const Graphics& src,
387  const Point& dp = {}, const Point& sp = {}, Rotation rot = RDeg0)
388 {
389  return CopyTo(dst.GetBufferPtr(), src, dst.GetSize(),
390  dp, sp, src.GetSize(), rot);
391 }
399 inline bool
400 CopyTo(const Graphics& dst, const BitmapBufferEx& src,
401  const Point& dp = {}, const Point& sp = {}, Rotation rot = RDeg0)
402 {
403  return CopyTo(dst.GetBufferPtr(), src, dst.GetSize(),
404  dp, sp, src.GetSize(), rot);
405 }
406 
413 YF_API bool
414 BlitTo(BitmapPtr, const BitmapBufferEx&, const Size&,
415  const Point&, const Point&, const Size&, Rotation = RDeg0);
423 inline bool
424 BlitTo(const Graphics& dst, const BitmapBufferEx& src,
425  const Point& dp = {}, const Point& sp = {}, Rotation rot = RDeg0)
426 {
427  return BlitTo(dst.GetBufferPtr(), src, dst.GetSize(),
428  dp, sp, src.GetSize(), rot);
429 }
430 
431 YSL_END_NAMESPACE(Drawing)
432 
433 YSL_END
434 
435 #endif
436