YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
yblit.cpp
浏览该文件的文档.
1 /*
2  © 2011-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 #include "YSLib/Service/YModules.h"
29 #include YFM_YSLib_Service_YBlit
30 
31 using namespace ystdex;
32 
33 namespace YSLib
34 {
35 
36 namespace Drawing
37 {
38 
39 namespace
40 {
41 
43 inline SDst
44 blit_min(SPos s, SPos d)
45 {
46  return max<SPos>(max<SPos>(0, s), s - d);
47 }
48 
49 inline SPos
50 blit_max(SPos s, SPos d, SDst sl, SDst dl, SDst cl)
51 {
52  return min<SPos>(min<SPos>(sl, s + cl), s + dl - d);
53 }
54 
55 } // unnamed namespace;
56 
57 bool
58 BlitBounds(const Point& dp, const Point& sp,
59  const Size& ds, const Size& ss, const Size& sc,
60  SDst& min_x, SDst& min_y, SDst& delta_x, SDst& delta_y)
61 {
62  SPos max_x, max_y;
63 
64  yunseq(min_x = blit_min(sp.X, dp.X), min_y = blit_min(sp.Y, dp.Y),
65  max_x = blit_max(sp.X, dp.X, ss.Width, ds.Width, sc.Width),
66  max_y = blit_max(sp.Y, dp.Y, ss.Height, ds.Height, sc.Height));
67  if(min_x < max_x && min_y < max_y)
68  {
69  yunseq(delta_x = max_x - min_x, delta_y = max_y - min_y);
70  return true;
71  }
72  return false;
73 }
74 
75 
76 void
77 CopyBuffer(const Graphics& dst, const Graphics& src)
78 {
79  YAssertNonnull(dst.GetBufferPtr()), YAssertNonnull(src.GetBufferPtr());
80  YAssert(dst.GetSize() == src.GetSize(), "Source and destination sizes"
81  "are not same.");
82 
83  if(YB_LIKELY(dst.GetBufferPtr() != src.GetBufferPtr()))
84  std::copy_n(src.GetBufferPtr(), GetAreaOf(src.GetSize()),
85  dst.GetBufferPtr());
86 }
87 
88 void
90 {
91  ClearPixel(g.GetBufferPtr(), GetAreaOf(g.GetSize()));
92 }
93 
94 void
95 Fill(const Graphics& g, Color c)
96 {
97  FillPixel<PixelType>(g.GetBufferPtr(), GetAreaOf(g.GetSize()), c);
98 }
99 
100 } // namespace Drawing;
101 
102 } // namespace YSLib;
103 
_tOut ClearPixel(_tOut dst, size_t n) ynothrow
清除指定位置的 n 个连续像素。
Definition: yblit.h:424
YF_API void ClearImage(const Graphics &)
清除图形接口上下文缓冲区。
Definition: yblit.cpp:89
SDst Height
宽和高。
Definition: ygdibase.h:258
yconstfn auto GetAreaOf(const Size &s) ynothrow-> decltype(s.Width *s.Height)
取面积。
Definition: ygdibase.h:404
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:39
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:38
YF_API bool BlitBounds(const Point &, const Point &, const Size &, const Size &, const Size &, SDst &, SDst &, SDst &, SDst &)
贴图边界计算器。
Definition: yblit.cpp:58
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:748
#define YAssertNonnull(_expr)
Definition: cassert.h:81
二维图形接口上下文。
Definition: ygdibase.h:721
YF_API void Fill(const Graphics &, Color)
使用指定颜色填充图形接口上下文缓冲区。
Definition: yblit.cpp:95
c yconstfn g
Definition: ystyle.h:104
#define YB_LIKELY(expr)
Definition: ydef.h:297
YF_API void CopyBuffer(const Graphics &, const Graphics &)
以第一个参数作为目标,复制第二个参数的缓冲区内容。
Definition: yblit.cpp:77
颜色。
Definition: Video.h:339
屏幕区域大小。
Definition: ygdibase.h:249
#define YAssert(_expr, _msg)
Definition: cassert.h:73