YSTest: ygdibase.cpp 源文件

YSTest PreAlpha_b500_20140530 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
ygdibase.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/Core/YModules.h"
29 #include YFM_YSLib_Core_YGDIBase
30 #include YFM_YSLib_Core_YCoreUtilities
31 #include <ystdex/algorithm.hpp>
32
33 namespace YSLib
34 {
35
36 namespace Drawing
37 {
38
39 const Size Size::Invalid(std::numeric_limits<SDst>::lowest(),
40 std::numeric_limits<SDst>::lowest());
41
43 namespace
44 {
45
46 bool
47 RectContainsRaw(const Rect& r, int px, int py) ynothrow
48 {
49 YAssert(r.Width > 0, "Invalid width found."),
50 YAssert(r.Height > 0, "Invalid height found.");
51
52 return IsInInterval<int>(px - r.X, r.Width)
53 && IsInInterval<int>(py - r.Y, r.Height);
54 }
55 inline bool
56 RectContainsRaw(const Rect& r, const Point& pt) ynothrow
57 {
58 return RectContainsRaw(r, pt.X, pt.Y);
59 }
60
61 bool
62 RectContainsStrictRaw(const Rect& r, int px, int py) ynothrow
63 {
64 YAssert(r.Width > 1, "Invalid width found."),
65 YAssert(r.Height > 1, "Invalid height found.");
66 return IsInOpenInterval<int>(px - r.X, r.Width - 1)
67 && IsInOpenInterval<int>(py - r.Y, r.Height - 1);
68 }
69 inline bool
70 RectContainsStrictRaw(const Rect& r, const Point& pt) ynothrow
71 {
72 return RectContainsStrictRaw(r, pt.X, pt.Y);
73 }
74
75 } // unnamed namespace;
76
77 const Rect Rect::Invalid(Size::Invalid);
78
79 bool
80 Rect::Contains(int px, int py) const ynothrow
81 {
82 return !IsUnstrictlyEmpty() && RectContainsRaw(*this, px, py);
83 }
84 bool
85 Rect::Contains(const Rect& r) const ynothrow
86 {
87 return !IsUnstrictlyEmpty() && RectContainsRaw(*this, r.GetPoint())
88 && RectContainsRaw(*this, r.GetPoint() + r.GetSize() - Vec(1, 1));
89 }
90
91 bool
92 Rect::ContainsStrict(int px, int py) const ynothrow
93 {
94 return Width > 1 && Height > 1 && RectContainsStrictRaw(*this, px, py);
95 }
96 bool
97 Rect::ContainsStrict(const Rect& r) const ynothrow
98 {
99 return Width > 1 && Height > 1 && !r.IsUnstrictlyEmpty()
100 && RectContainsStrictRaw(*this, r.GetPoint())
101 && RectContainsStrictRaw(*this, r.GetPoint() + r.GetSize() - Vec(1, 1));
102 }
103
104 Rect&
105 Rect::operator&=(const Rect& r) ynothrow
106 {
107 const SPos x1(max(X, r.X)), x2(min(X + Width, r.X + r.Width)),
108 y1(max(Y, r.Y)), y2(min(Y + Height, r.Y + r.Height));
109
110 return *this = x2 < x1 || y2 < y1 ? Rect() : Rect(x1, y1, x2 - x1, y2 - y1);
111 }
112
113 Rect&
114 Rect::operator|=(const Rect& r) ynothrow
115 {
116 if(!*this)
117 return *this = r;
118 if(!r)
119 return *this;
120
121 const SPos mx(min(X, r.X)), my(min(Y, r.Y));
122
123 return *this = Rect(mx, my, max(X + Width, r.X + r.Width) - mx,
124 max(Y + Height, r.Y + r.Height) - my);
125 }
126
127 Rect
128 operator&(const Rect& a, const Rect& b) ynothrow
129 {
130 return Rect(a) &= b;
131 }
132
133 Rect
134 operator|(const Rect& a, const Rect& b) ynothrow
135 {
136 return Rect(a) |= b;
137 }
138
139
140 const Graphics Graphics::Invalid;
141
142 BitmapPtr
143 Graphics::operator[](size_t r) const ynothrow
144 {
145 YAssertNonnull(pBuffer);
146 YAssert(r < sGraphics.Height, "Access out of range.");
147 return pBuffer + r * sGraphics.Width;
148 }
149
150 BitmapPtr
151 Graphics::at(size_t r) const ythrow(GeneralEvent, std::out_of_range)
152 {
153 if(YB_UNLIKELY(!pBuffer))
154 throw GeneralEvent("Null pointer found.");
155 if(YB_UNLIKELY(r >= sGraphics.Height))
156 throw std::out_of_range("Access out of range.");
157
158 return pBuffer + r * sGraphics.Width;
159 }
160
161 } // namespace Drawing;
162
163 } // namespace YSLib;
164
YSLib::Drawing::Rect::ContainsStrict
bool ContainsStrict(int px, int py) const ynothrow
判断点 (px, py) 是否在矩形内。
Definition: ygdibase.cpp:92
YModules.h
YSLib::Drawing::Rect::Invalid
static const Rect Invalid
无效对象。
Definition: ygdibase.h:423
YSLib::Drawing::Graphics::Invalid
static const Graphics Invalid
无效图形接口上下文。
Definition: ygdibase.h:724
platform::SPos
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:38
YSLib::GeneralEvent
std::runtime_error GeneralEvent
一般运行时异常事件类。
Definition: yexcept.h:51
YB_UNLIKELY
#define YB_UNLIKELY(expr)
分支预测提示。
Definition: ydef.h:298
YSLib::Drawing::Point
GBinaryGroup< SPos > Point
屏幕二维点（直角坐标表示）。
Definition: ygdibase.h:235
YSLib::Drawing::Size::Invalid
static const Size Invalid
无效对象。
Definition: ygdibase.h:256
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
YSLib::Drawing::Rect::Contains
bool Contains(int px, int py) const ynothrow
判断点 (px, py) 是否在矩形内或边上。
Definition: ygdibase.cpp:80
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: ygdibase.h:416
ythrow
#define ythrow(...)
YSLib 动态异常规范：根据是否使用异常规范宏指定或忽略动态异常规范。
Definition: ydef.h:476
YSLib::Drawing::Rect::operator|=
Rect & operator|=(const Rect &) ynothrow
求与另一个屏幕标准矩形的并。
Definition: ygdibase.cpp:114
YAssertNonnull
#define YAssertNonnull(_expr)
Definition: cassert.h:81
YSLib::Drawing::Graphics
二维图形接口上下文。
Definition: ygdibase.h:721
YSLib::Drawing::Y
p1 p1 Y
Definition: ydraw.h:188
YSLib::Drawing::operator&
Rect operator&(const Rect &a, const Rect &b) ynothrow
Definition: ygdibase.cpp:128
algorithm.hpp
泛型算法。
platform::BitmapPtr
PixelType * BitmapPtr
Definition: Video.h:295
YSLib::Drawing::r
bounds & r
Definition: ydraw.h:220
YSLib::Drawing::Width
if(YB_UNLIKELY(r >=sGraphics.Height)) throw std return pBuffer r *sGraphics Width
Definition: ygdibase.cpp:155
YSLib::Drawing::X
p1 X
Definition: ydraw.h:188
YSLib::Drawing::operator|
Rect operator|(const Rect &a, const Rect &b) ynothrow
Definition: ygdibase.cpp:134
YSLib::Drawing::Vec
GBinaryGroup< SPos > Vec
屏幕二维向量（直角坐标表示）。
Definition: ygdibase.h:242
YAssert
#define YAssert(_expr, _msg)
Definition: cassert.h:73