YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ydraw.h
浏览该文件的文档.
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 #ifndef YSL_INC_Service_ydraw_h_
29 #define YSL_INC_Service_ydraw_h_ 1
30 
31 #include "YModules.h"
32 #include YFM_YSLib_Core_YGDIBase
33 
34 namespace YSLib
35 {
36 
37 namespace Drawing
38 {
39 
63 inline void
65 {
66  YAssertNonnull(dst);
67  dst[y * w + x] = c;
68 }
74 inline void
75 PutPixel(const Graphics& g, SPos x, SPos y, Color c)
76 {
77  YAssert(Rect(g.GetSize()).Contains(x, y),
78  "The pixel is out of the buffer.");
79  PutPixel(g.GetBufferPtr(), g.GetWidth(), x, y, c);
80 }
81 
87 inline void
89 PlotPixel(BitmapPtr dst, const Rect& bounds, SDst w, SPos x, SPos y, Color c)
90 {
91  if(bounds.Contains(x, y))
92  PutPixel(dst, w, x, y, c);
93 }
94 
96 
97 inline void
98 DrawPoint(const Graphics& g, const Rect& bounds, SPos x, SPos y, Color c)
99 {
100  YAssert(bounds.IsUnstrictlyEmpty() || Rect(g.GetSize()).Contains(bounds),
101  "The boundary is out of the buffer.");
102  PlotPixel(g.GetBufferPtr(), bounds, g.GetWidth(), x, y, c);
103 }
104 inline void
105 DrawPoint(const Graphics& g, const Rect& bounds, const Point& pt, Color c)
106 {
107  DrawPoint(g, bounds, pt.X, pt.Y, c);
108 }
110 
111 
117 YF_API void
118 PlotHLineSeg(BitmapPtr dst, const Rect& bounds, SDst w, SPos y, SPos x1,
119  SPos x2, Color);
120 
127 inline void
128 DrawHLineSeg(const Graphics& g, const Rect& bounds, SPos y, SPos x1, SPos x2,
129  Color c)
130 {
131  YAssert(bool(g), "Invalid graphics context found."),
132  YAssert(bounds.IsUnstrictlyEmpty() || Rect(g.GetSize()).Contains(bounds),
133  "The boundary is out of the buffer.");
134  PlotHLineSeg(g.GetBufferPtr(), bounds, g.GetWidth(), y, x1, x2, c);
135 }
136 
142 YF_API void
143 PlotVLineSeg(BitmapPtr dst, const Rect& bounds, SDst w, SPos x, SPos y1,
144  SPos y2, Color);
145 
152 inline void
153 DrawVLineSeg(const Graphics& g, const Rect& bounds, SPos x, SPos y1, SPos y2,
154  Color c)
155 {
156  YAssert(bool(g), "Invalid graphics context found."),
157  YAssert(bounds.IsUnstrictlyEmpty() || Rect(g.GetSize()).Contains(bounds),
158  "The boundary is out of the buffer.");
159  PlotVLineSeg(g.GetBufferPtr(), bounds, g.GetWidth(), x, y1, y2, c);
160 }
161 
167 YF_API void
168 PlotLineSeg(BitmapPtr dst, const Rect& bounds, SDst w, SPos x1, SPos y1,
169  SPos x2, SPos y2, Color);
170 
172 
173 /*
174 \pre 断言: <tt>bool(g)</tt> 。
175 \pre 断言: bounds 在 g 指定的边界内。
176 */
177 inline void
178 DrawLineSeg(const Graphics& g, const Rect& bounds, SPos x1, SPos y1, SPos x2,
179  SPos y2, Color c)
180 {
181  YAssert(bool(g), "Invalid graphics context found."),
182  YAssert(bounds.IsUnstrictlyEmpty() || Rect(g.GetSize()).Contains(bounds),
183  "The boundary is out of the buffer.");
184  PlotLineSeg(g.GetBufferPtr(), bounds, g.GetWidth(), x1, y1, x2, y2, c);
185 }
186 inline PDefH(void, DrawLineSeg, const Graphics& g, const Rect& bounds,
187  const Point& p1, const Point& p2, Color c)
188  ImplExpr(DrawLineSeg(g, bounds, p1.X, p1.Y, p2.X, p2.Y, c))
190 
191 
197 YF_API void
199 DrawRect(const Graphics& g, const Rect& bounds, const Point& pt,
200  const Size& s, Color c);
202 inline void
203 DrawRect(const Graphics& g, const Rect& bounds, const Rect& r, Color c)
204 {
205  DrawRect(g, bounds, r.GetPoint(), r.GetSize(), c);
206 }
208 
214 
216 YF_API void
217 FillRect(const Graphics& g, const Rect&, Color c);
218 inline PDefH(void, FillRect, const Graphics& g, const Rect& bounds,
219  const Rect& r, Color c)
220  ImplExpr(FillRect(g, bounds & r, c))
222 
223 
224 
226 
227 YF_API void
229 DrawCircle(const Graphics&, const Rect&, const Point&, SDst, Color c);
230 
232 YF_API void
233 FillCircle(const Graphics&, const Rect&, const Point&, SDst, Color c);
235 
236 
238 template<typename _tIn>
239 void
240 DrawPolygon(Graphics& g, const Rect& bounds, _tIn first, _tIn last, Color c)
241 {
242  if(YB_LIKELY(first != last))
243  {
245  const _tIn old(first);
246  _tIn mid(first);
247 
248  ++mid;
249  while(mid != last)
250  {
251  YAssert(!is_undereferenceable(first), "Invalid iterator found.");
252  YAssert(!is_undereferenceable(mid), "Invalid iterator found.");
253 
254  DrawLineSeg(g, bounds, *first, *mid, c);
255  yunseq(++first, ++mid);
256  }
257  YAssert(!is_undereferenceable(first), "Invalid iterator found.");
258  YAssert(!is_undereferenceable(old), "Invalid iterator found.");
259  DrawLineSeg(g, bounds, *first, *old, c);
260  }
261 }
263 
264 } // namespace Drawing;
265 
266 } // namespace YSLib;
267 
268 #endif
269 
void DrawVLineSeg(const Graphics &g, const Rect &bounds, SPos x, SPos y1, SPos y2, Color c)
描画竖直线段。
Definition: ydraw.h:153
static auto first(const _tIterator &i) -> decltype((i->first))
Definition: iterator.hpp:759
YF_API void FillCircle(const Graphics &, const Rect &, const Point &, SDst, Color c)
填充圆形。
Definition: ydraw.cpp:195
YF_API void FillRect(const Graphics &g, const Rect &, Color c)
填充标准矩形。
Definition: ydraw.cpp:146
YF_API void PlotLineSeg(BitmapPtr dst, const Rect &bounds, SDst w, SPos x1, SPos y1, SPos x2, SPos y2, Color)
绘制线段:在宽 w 的缓冲区内的区域 bounds 绘制端点为 p1(x1, y1) 和 p2(x2, y2) 的线段。 ...
Definition: ydraw.cpp:83
#define YF_API
Definition: Platform.h:64
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:39
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:38
bounds c YF_API void DrawCircle(const Graphics &, const Rect &, const Point &, SDst, Color c)
描画圆形。
Definition: ydraw.cpp:173
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:748
void DrawLineSeg(const Graphics &g, const Rect &bounds, SPos x1, SPos y1, SPos x2, SPos y2, Color c)
描画线段:在区域 ds 绘制端点为 p1(x1, y1) 和 p2(x2, y2) 的线段。
Definition: ydraw.h:178
#define ImplExpr(...)
Definition: YBaseMacro.h:93
bool Contains(int px, int py) const ynothrow
判断点 (px, py) 是否在矩形内或边上。
Definition: ygdibase.cpp:80
void DrawHLineSeg(const Graphics &g, const Rect &bounds, SPos y, SPos x1, SPos x2, Color c)
描画水平线段。
Definition: ydraw.h:128
屏幕标准矩形:表示屏幕矩形区域。
Definition: ygdibase.h:416
屏幕二元组。
Definition: ygdibase.h:54
void PutPixel(BitmapPtr dst, SDst w, SPos x, SPos y, Color c)
修改指定位置的像素:(x, y) 。
Definition: ydraw.h:64
#define YAssertNonnull(_expr)
Definition: cassert.h:81
二维图形接口上下文。
Definition: ygdibase.h:721
void PlotPixel(BitmapPtr dst, const Rect &bounds, SDst w, SPos x, SPos y, Color c)
绘制指定位置的像素:(x, y) 。
Definition: ydraw.h:89
void DrawPolygon(Graphics &g, const Rect &bounds, _tIn first, _tIn last, Color c)
描画多边形。
Definition: ydraw.h:240
YF_API void PlotVLineSeg(BitmapPtr dst, const Rect &bounds, SDst w, SPos x, SPos y1, SPos y2, Color)
绘制竖直线段:在宽 w 的缓冲区内的区域 bounds 绘制指定竖直水平坐标 x , 竖直坐标 y1 - 1 、 y2 。 ...
Definition: ydraw.cpp:61
p1 p1 Y
Definition: ydraw.h:188
Selected const shared_ptr< ListType > const pair< Color, Color > viewer Contains
Definition: textlist.h:124
void DrawPoint(const Graphics &g, const Rect &bounds, SPos x, SPos y, Color c)
描画点。
Definition: ydraw.h:98
bool is_undereferenceable(const any_input_iterator< _type, _tDifference, _tPointer, _tReference > &i)
PixelType * BitmapPtr
Definition: Video.h:295
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
#define YB_LIKELY(expr)
Definition: ydef.h:297
颜色。
Definition: Video.h:339
屏幕区域大小。
Definition: ygdibase.h:249
p1 p1 p2 p2 c YF_API void DrawRect(const Graphics &g, const Rect &bounds, const Point &pt, const Size &s, Color c)
描画标准矩形。
Definition: ydraw.cpp:131
#define YAssert(_expr, _msg)
Definition: cassert.h:73
YF_API void PlotHLineSeg(BitmapPtr dst, const Rect &bounds, SDst w, SPos y, SPos x1, SPos x2, Color)
绘制水平线段:在宽 w 的缓冲区内的区域 bounds 绘制指定端点水平坐标 x1 、 x2 - 1 ,竖直坐标 y 。 ...
Definition: ydraw.cpp:39