YSTest: ExStyle.cpp 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

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

- 文件列表
- 文件成员

ExStyle.cpp
浏览该文件的文档.
1 /*
2 © 2014-2015 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/UI/YModules.h"
29 #include YFM_YSLib_UI_ExStyle
30 #include YFM_YSLib_UI_YGUI
31 #include YFM_YSLib_Service_YBlit
32 #include YFM_YSLib_UI_Button
33 #include YFM_YSLib_UI_Selector
34 #include <ystdex/cast.hpp>
35
36 namespace YSLib
37 {
38
39 using namespace Drawing;
40
41 namespace UI
42 {
43
44 namespace Styles
45 {
46
47 namespace
48 {
49
51 void
52 RectDrawButton_Aoi(const PaintContext& pc, Size s, Hue base_hue,
53 CursorState cursor_state, bool is_enabled, bool is_focused)
54 {
55 const bool inside(cursor_state != CursorState::Outside);
56 const auto roll([=](bool b, MonoType gr, HSL hsl){
57 return MakeGrayOrColor(Color(hsl.Roll(base_hue)), gr, inside || b);
58 });
59 const auto& g(pc.Target);
60
61 DrawRectRoundCorner(pc, s, is_enabled
62 ? roll(is_focused, 112, {25.640625F, 0.493671F, 0.462891F})
63 : FetchGUIConfiguration().Colors[Styles::Workspace]);
64 if(YB_LIKELY(s.Width > 2 && s.Height > 2))
65 {
66 auto pt(pc.Location);
67 const Rect& bounds(pc.ClipArea);
68
69 yunseq(pt.X += 1, pt.Y += 1, s.Width -= 2, s.Height -= 2);
70 FillRect(g, bounds, {pt, s}, is_enabled ? roll(is_focused, 243,
71 {11.304688F, 0.990431F, 0.591797F}) : MakeGray(244));
72 if(is_enabled)
73 {
74 if(s.Width > 2 && s.Height > 2)
75 {
76 Rect rp(pt.X + 1, pt.Y + 1, s.Width - 2, (s.Height - 2) / 2);
77
78 FillRect(g, bounds, rp,
79 roll({}, 239, {39.132872F, 0.920000F, 0.951172F}));
80 // XXX: Conversion to 'SPos' might be implementation-defined.
81 rp.Y += SPos(rp.Height);
82 if(s.Height % 2 != 0)
83 ++rp.Height;
84 FillRect(g, bounds, rp,
85 roll({}, 214, {29.523438F, 0.969231F, 0.873047F}));
86 }
87 if(cursor_state == CursorState::Pressed)
88 {
89 const Color tc(HSL(165, 0.4F, 0.16F).Roll(base_hue));
90
91 TransformRect(g, bounds & Rect(pt, s),
92 [=](BitmapPtr dst) ynothrowv{
93 const Color d(*dst);
94
95 *dst = Color(d.GetR() ^ tc.GetR(), d.GetG() ^ tc.GetG(),
96 d.GetB() ^ tc.GetB());
97 });
98 }
99 }
100 }
101 }
102
103
105
106 enum SelectorIndex_Aoi
107 {
108 SelectorIndex_Aoi_C1 = 4,
109 SelectorIndex_Aoi_C2 = 8,
110 SelectorIndex_Aoi_C3 = 11,
111 SelectorIndex_Aoi_End = 14
112 };
113
114 enum ControlState : yimpl(size_t)
115 {
116 ControlState_Focused = 0,
117 ControlState_Enabled = 1,
118 ControlState_Locked = 2,
119 ControlState_Ticked = 3
120 };
121
122
123 void
124 RectDrawSelector_Aoi(void(*f)(const PaintContext&, const Size&, const bool[],
125 const Color[], size_t), const PaintContext& pc, Thumb& tmb, bool is_ticked)
126 {
127 const Hue base_hue(tmb.GetHue());
128 const auto roll([=](float h, float s, float l) ynothrow{
129 return Color(HSL(h, s, l).Roll(base_hue));
130 });
131 const Color colors[]{MakeGray(177), MakeGray(143), roll(2.3F, .315F, .486F),
132 roll(25.9F, .519F, .359F), MakeGray(246), MakeGray(244),
133 roll(2.1F, .737F, .925F), roll(20.8F, .743F, .863F),
134 roll(32.7F, .073F, .704F), roll(23.9F, .914F, .725F),
135 roll(25.5F, .905F, .669F), MakeGray(232), roll(20.F, .934F, .88F),
136 roll(20.8F, .923F, .847F)};
137 const bool ctl_states[]{IsFocused(tmb), IsEnabled(tmb),
138 IsFocusedByShell(tmb), is_ticked};
139
140 f(pc, GetSizeOf(tmb), ctl_states, colors,
141 [](CursorState s) ynothrow -> size_t{
142 switch(s)
143 {
144 case CursorState::Outside:
145 return 1;
146 case CursorState::Over:
147 return 2;
148 case CursorState::Pressed:
149 return 3;
150 default:
151 YAssert(false, "Invalid state found.");
152 };
153 return 0;
154 }(tmb.GetCursorState()));
155 }
156
157
158 void
159 RectDrawCheckBox_Aoi(const PaintContext& pc_, CheckBox& cb)
160 {
161 RectDrawSelector_Aoi([](const PaintContext& pc, const Size& s,
162 const bool cst[], const Color ccs[], size_t c_idx){
163 const auto& g(pc.Target);
164 const auto& pt(pc.Location);
165 const Rect& bounds(pc.ClipArea);
166 const Rect r(pt, s);
167 const bool is_enabled(cst[ControlState_Enabled]);
168
169 DrawRect(g, bounds, r, ccs[is_enabled ? c_idx : 0]);
170 // XXX: Minimal size.
171 if(YB_LIKELY(r.Width > 10 && r.Height > 10))
172 {
173 Rect rt(r);
174
175 Diminish(rt);
176 FillRect(g, bounds, rt, ccs[SelectorIndex_Aoi_C1
177 + (cst[ControlState_Locked] || cst[ControlState_Focused]
178 ? 2 : is_enabled ? c_idx : 0)]);
179 if(is_enabled)
180 {
181 --c_idx;
182 Diminish(rt);
183 DrawRect(g, bounds, rt, ccs[SelectorIndex_Aoi_C2 + c_idx]);
184 Diminish(rt);
185 FillRect(g, bounds, rt, ccs[SelectorIndex_Aoi_C3 + c_idx]);
186 }
187 }
188 if(cst[ControlState_Ticked])
189 DrawTick(g, bounds, r, is_enabled ? Color(4, 34, 113)
190 : MakeGray(190), is_enabled ? Color(108, 166, 208)
191 : MakeGray(199));
192 }, pc_, cb, cb.IsTicked());
193 }
194
195 void
196 RectDrawRadioBox_Aoi(const PaintContext& pc_, RadioBox& rb)
197 {
198 RectDrawSelector_Aoi([](const PaintContext& pc, const Size& s,
199 const bool cst[], const Color ccs[], size_t c_idx){
200 const auto& g(pc.Target);
201 const SDst rad(min(s.Width / 2, s.Height / 2));
202 const auto pt(pc.Location + Size(rad, rad));
203 const Rect& bounds(pc.ClipArea);
204 const Rect r(pc.Location, s);
205 const bool is_enabled(cst[ControlState_Enabled]);
206
207 DrawCircle(g, bounds, pt, rad, ccs[is_enabled ? c_idx : 0]);
208 // XXX: Minimal size.
209 if(YB_LIKELY(r.Width > 10 && r.Height > 10))
210 {
211 SDst radt(rad);
212
213 FillCircle(g, bounds, pt, --radt, ccs[SelectorIndex_Aoi_C1
214 + (cst[ControlState_Locked] || cst[ControlState_Focused]
215 ? 2 : is_enabled ? c_idx : 0)]);
216 if(is_enabled)
217 {
218 --c_idx;
219 DrawCircle(g, bounds, pt, --radt,
220 ccs[SelectorIndex_Aoi_C2 + c_idx]);
221 DrawCircle(g, bounds, pt, --radt,
222 ccs[SelectorIndex_Aoi_C3 + c_idx]);
223 }
224 }
225 if(cst[ControlState_Ticked])
226 FillCircle(g, bounds, pt, rad - 2, is_enabled ? Color(11, 130, 199)
227 : MakeGray(190));
228 }, pc_, rb, rb.IsSelected());
229 }
231
232 } // unnamed namespace;
233
234
235 void
236 InitExStyles()
237 {
238 YTraceDe(Notice, "Initializing extra styles ...");
239
240 HandlerTable ht;
241
242 YTraceDe(Informative, "Adding Thumb style 'Aoi'...");
243 AddHandlers<Thumb>(ht, {{Thumb::ThumbBackground,
244 [](PaintEventArgs&& e){
245 const auto&
246 tmb(ystdex::polymorphic_downcast<Thumb&>(e.GetSender()));
247
248 RectDrawButton_Aoi(e, GetSizeOf(tmb), tmb.GetHue(),
249 tmb.GetCursorState(), IsEnabled(tmb), IsFocused(tmb));
250 }
251 }}),
252 YTraceDe(Informative, "Adding CheckBox style 'Aoi'...");
253 AddHandlers<CheckBox>(ht, {{CheckBox::CheckBoxBackground,
254 [](PaintEventArgs&& e){
255 RectDrawCheckBox_Aoi(e,
256 ystdex::polymorphic_downcast<CheckBox&>(e.GetSender()));
257 }
258 }}),
259 YTraceDe(Informative, "Adding RadioBox style 'Aoi'...");
260 AddHandlers<RadioBox>(ht, {{CheckBox::CheckBoxBackground,
261 [](PaintEventArgs&& e){
262 RectDrawRadioBox_Aoi(e,
263 ystdex::polymorphic_downcast<RadioBox&>(e.GetSender()));
264 }
265 }});
266 YTraceDe(Notice, "Adding style 'Aoi'...");
267 FetchGUIConfiguration().Styles.Add("Aoi", std::move(ht));
268 YTraceDe(Notice, "Extra style(s) initialized successfully.");
269 }
270
271 } // namespace Styles;
272
273 } // namespace UI;
274
275 } // namespace YSLib;
276
YSLib::Drawing::GGraphics::Height
const SizeType sGraphics Height
Definition: YGraphics.h:136
YTraceDe
#define YTraceDe(...)
YCLib 默认调试跟踪。
Definition: Debug.h:313
NPL::dst
YF_API const char src const string const char * dst
Definition: Dependency.h:95
YSLib::UI::FetchGUIConfiguration
GUIConfiguration & FetchGUIConfiguration()
Definition: YGUI.cpp:519
YSLib::UI::CheckBox::CheckBoxBackground
Definition: Selector.h:137
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
platform::MonoType
octet MonoType
Definition: Video.h:252
cast.hpp
C++ 转换模板。
UI
YSLib::UI::IsFocused
YF_API bool IsFocused(const IWidget &)
判断部件是否取得焦点。
Definition: YFocus.cpp:38
YSLib::Drawing::BitmapPtr
Pixel * BitmapPtr
Definition: YGraphics.h:42
YSLib::Drawing::r
The boundary is out of the const Graphics const Rect const Point const Point Color c const Rect const Rect & r
Definition: YDraw.h:174
CHRLib::f
f(d, s)
YSLib::Drawing::Color
The boundary is out of the const Rect SDst SPos SPos SPos Color
Definition: YDraw.h:127
YSLib::Drawing::DrawTick
YF_API void DrawTick(const Graphics &, const Rect &, const Rect &, Color, Color)
Definition: YStyle.cpp:257
YSLib::UI::Styles::InitExStyles
YF_API void InitExStyles()
初始化扩展样式。
Definition: ExStyle.cpp:236
YSLib::UI::Styles::Workspace
应用程序工作区背景。
Definition: YStyle.h:314
YSLib::YAssert
YAssert(!(v< Deref(a)),"Value less than lower bound found.")
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:1022
YSLib::Drawing::FillRect
c YF_API void FillRect(const Graphics &g, const Rect &r, Color c)
填充标准矩形。
Definition: YDraw.cpp:150
YSLib::UI::CursorState
CursorState
指针设备光标相对控件的状态。
Definition: YControl.h:344
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
YSLib::Drawing::g
The boundary is out of the const Graphics & g
Definition: YDraw.h:161
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:140
Drawing
ystdex::min
const _type & min(const _type &a, const _type &b, _fComp comp=less< _type >())
取较小的元素。
Definition: algorithm.hpp:527
YSLib::yimpl
YF_API yimpl(GUIApplication &) FetchGlobalInstance()
取全局应用程序实例。
platform::SPos
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:43
YSLib::UI::Thumb::ThumbBackground
Definition: Button.h:55
YSLib::UI::PaintEventArgs
部件绘制参数。
Definition: YWidgetEvent.h:323
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
platform::Descriptions::Notice
Definition: YCommon.h:168
ynothrowv
#define ynothrowv
YSLib 无异常抛出保证验证：有条件地使用无异常抛出规范。
Definition: ydef.h:786
YSLib::UI::Styles::HandlerTable
unordered_map< Key, Handler, ystdex::combined_hash< Key >> HandlerTable
样式处理器表。
Definition: YStyle.h:383
YModules.h
CHRLib::e
const char const char * e
Definition: CharacterProcessing.h:109
YSLib::Drawing::DrawRect
void DrawRect(const Graphics &g, const Rect &bounds, const Rect &r, Color c)
Definition: YDraw.cpp:136
YSLib::Drawing::DrawCircle
bounds c YF_API void DrawCircle(const Graphics &g, const Rect &bounds, const Point &, SDst, Color)
描画圆形。
Definition: YDraw.cpp:180
platform::Descriptions::Informative
Definition: YCommon.h:169
YSLib::Drawing::bounds
The boundary is out of the const Rect & bounds
Definition: YDraw.h:127
YSLib::Drawing::DrawRectRoundCorner
YF_API void DrawRectRoundCorner(const PaintContext &pc, const Size &s, Color)
绘制部件边框用空心标准矩形。
Definition: YStyle.cpp:42
CHRLib::d
_tDst * d
Definition: CharacterProcessing.h:139
YB_LIKELY
#define YB_LIKELY(_expr)
Definition: ydef.h:463
YSLib::UI::GetSizeOf
pt pt Y const IWidget &wgt const IWidget &wgt GetSizeOf
无效化：使相对部件的子部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: YWidget.h:161
YSLib::Drawing::TransformRect
bool TransformRect(const Graphics &g, const Point &pt, const Size &s, _fTransformPixel tp)
以像素为单位变换标准矩形。
Definition: YBlit.h:571
YSLib::UI::CursorState::Pressed
YSLib::Drawing::FillCircle
YF_API void FillCircle(const Graphics &g, const Rect &bounds, const Point &, SDst, Color)
填充圆形。
Definition: YDraw.cpp:202