YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ystyle.h
浏览该文件的文档.
1 /*
2  © 2010-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_UI_ystyle_h_
29 #define YSL_INC_UI_ystyle_h_ 1
30 
31 #include "YModules.h"
32 #include YFM_YSLib_UI_YComponent
33 #include YFM_YSLib_Service_YDraw
34 #include <ystdex/rational.hpp>
35 #include <typeindex>
36 
37 namespace YSLib
38 {
39 
40 namespace Drawing
41 {
42 
44 
45 
51 YF_API void
52 DrawRectRoundCorner(const PaintContext& pc, const Size& s, Color);
53 
54 
59 YF_API void
60 RectDrawArrow(const PaintContext&, SDst, Rotation = RDeg0,
62 
67 YF_API void
68 DrawArrow(const Graphics&, const Rect&, SDst = 4, Rotation = RDeg0,
70 
77 YF_API void
78 DrawCross(const Graphics&, const Rect&, const Rect&, Color);
79 
80 /*
81 \brief 在指定图形接口上下文中使用指定颜色描画对勾(“√”)。
82 \note 第二个参数指定边界;绘制的图形顶点为第三个参数指定的矩形的顶点或边的中点。
83 \note 若指定的矩形不满足长和宽都大于 8 则忽略。
84 \since build 480
85 */
87 YF_API void
89 DrawTick(const Graphics&, const Rect&, const Rect&, Color, Color);
91 inline PDefH(void, DrawTick, const Graphics& g, const Rect& bounds,
92  const Rect& r, Color c)
93  ImplExpr(DrawTick(g, bounds, r, c, c))
95 
96 
97 
98 //平台无关色彩系统类型和转换。
99 
101 
102 yconstfn PDefH(Color, MakeGray, MonoType g)
104  ImplRet(Color(g, g, g))
105 
107 yconstfn PDefH(Color, MakeGrayOrColor, Color c, MonoType g, bool colored)
108  ImplRet(colored ? c : Color(g, g, g))
110 
111 
117 using Hue = ystdex::fixed_point<u16, 9>;
118 
119 
124 struct hsl_t
125 {
131  Hue h;
137  float s, l;
138 };
139 
147 
155 
156 
163 RollColor(hsl_t, Hue);
164 
165 } // namespace Drawing;
166 
167 namespace UI
168 {
169 
170 namespace Styles
171 {
172 
177 enum Area
178 {
179  //背景和填充区域。
180  Null = 0,
181  Desktop = 1,
182  Window = 2,
183  Panel = 3,
184  Track = 4,
185  Workspace = 5,
186  Shadow = 6,
188  Light = 8,
189  Frame = 9,
190  Highlight = 10,
191  BorderFill = 11,
194  ActiveTitle = 14,
196 
197  //前景和文本。
200  PanelText = 18,
201  GrayText = 19,
202  TitleText = 20,
205 
206  EndArea = 24
207 };
208 
209 
215 {
216 public:
217  using ItemType = Drawing::Color; //项目类型。
218  using ColorListType = vector<ItemType>; //颜色组类型。
219 
220 private:
221  ColorListType colors; //颜色组。
222 // Drawing::Color colors[EndArea];
223 
224 public:
229  Palette();
230 
234  PDefHOp(Drawing::Color&, [], size_t s)
235  ImplRet(colors[s])
236 
237  DefGetter(const ynothrow, const ColorListType&, List, colors)
238  DefGetter(ynothrow, ColorListType&, List, colors)
242  pair<Drawing::Color, Drawing::Color>
243  GetPair(ColorListType::size_type, ColorListType::size_type) const;
244 };
245 
246 
248 
249 using StyleItem = size_t;
251 
253 using Key = pair<std::type_index, StyleItem>;
254 
256 using Handler = std::function<void(PaintEventArgs&&)>;
257 
259 using HandlerTable = unordered_map<Key, Handler, ystdex::combined_hash<Key>>;
260 
262 using VisualStyle = pair<string, HandlerTable>;
263 
264 
273 template<typename _tIn>
274 void
275 AddHandlers(HandlerTable& table, std::type_index idx, _tIn first, _tIn last)
276 {
277  for(; first != last; ++first)
278  {
279  auto&& ref(*first);
280 
281  table.emplace(Key(idx, get<0U>(ref)), get<1U>(ref));
282  }
283 }
284 template<typename _type, typename _tIn>
285 inline void
286 AddHandlers(HandlerTable& table, _tIn first, _tIn last)
287 {
288  Styles::AddHandlers(table, typeid(_type), first, last);
289 }
290 inline PDefH(void, AddHandlers, HandlerTable& table, std::type_index idx,
291  std::initializer_list<pair<StyleItem, Handler>> il)
292  ImplExpr(Styles::AddHandlers(table, idx, il.begin(), il.end()))
293 template<typename _type>
294 inline void
296  std::initializer_list<pair<StyleItem, Handler>> il)
297 {
298  Styles::AddHandlers(table, typeid(_type), il);
299 }
301 
302 template<typename _tRange>
303 inline void
304 AddHandlers(HandlerTable& table, std::type_index idx, _tRange&& c)
305 {
306  // XXX: Consider std::make_move_iterator.
307  Styles::AddHandlers(table, idx, begin(yforward(c)), end(yforward(c)));
308 }
309 template<typename _type, typename _tRange>
310 inline void
311 AddHandlers(HandlerTable& table, _tRange&& c)
312 {
313  Styles::AddHandlers(table, typeid(_type), yforward(c));
314 }
316 
317 
318 
324 {
325 private:
327 
328 public:
329  Painter(const Key& k)
330  : key(k)
331  {}
332  template<typename _type1, typename _type2>
333  Painter(_type1&& arg1, _type2&& arg2)
334  : key(yforward(arg1), yforward(arg2))
335  {}
338 
341 
342  DefGetter(const ynothrow, StyleItem, Item, key.second)
343  DefGetter(const ynothrow, const Key&, Key, key)
344  DefGetter(const ynothrow, std::type_index, TypeIndex, key.first)
345 
346  void
347  operator()(PaintEventArgs&&) const;
348 };
349 
350 
355 class YF_API StyleMap : private noncopyable, private map<string, HandlerTable>
356 {
357 public:
358  using MapType = map<string, HandlerTable>;
359  using MapType::const_iterator;
360  using MapType::iterator;
361 
362 private:
363  const_iterator current;
364 
365 public:
367  : MapType({{}}), current(cbegin())
368  {}
369  template<typename... _tParams>
370  StyleMap(_tParams&&... args)
371  : MapType({{}, yforward(args)...}), current(cbegin())
372  {}
373 
375  DefGetter(const ynothrow, const_iterator, Current, current)
376 
377  template<typename... _tParams>
378  void
379  Add(_tParams&&... args)
380  {
381  emplace(yforward(args)...);
382  }
383 
385  void
386  Remove(const string&);
387 
388  PDefH(void, Paint, const Styles::Painter& painter,
389  PaintEventArgs&& e)
390  ImplExpr(PaintAsStyle(painter.GetKey(), std::move(e)))
391 
392  void
393  PaintAsStyle(const Key&, PaintEventArgs&&);
394 
395  void
396  Switch(const string&);
397 
398  using MapType::at;
399 
400  using MapType::cbegin;
401 
402  using MapType::cend;
403 
404  using MapType::crbegin;
405 
406  using MapType::crend;
407 
408  using MapType::empty;
409 
410  using MapType::find;
411 
412  using MapType::lower_bound;
413 
414  using MapType::size;
415 
416  using MapType::upper_bound;
417 };
418 
419 
424 YF_API HandlerTable&
425 FetchDefault();
427 
428 } // namespace Styles;
429 
430 } // namespace UI;
431 
432 } // namespace YSLib;
433 
434 #endif
435 
size_t StyleItem
标识样式渲染项的类型。
Definition: ystyle.h:250
YF_API HandlerTable & FetchDefault()
取默认样式处理器表。
Definition: ystyle.cpp:346
DefGetter(const ynothrow, const_iterator, Current, current) template< typename..._tParams > void Add(_tParams &&...args)
Definition: ystyle.h:375
容器阴影背景。
Definition: ystyle.h:187
YF_API void DrawCross(const Graphics &, const Rect &, const Rect &, Color)
在指定图形接口上下文中使用指定颜色描画交叉直线段(“×”)。
Definition: ystyle.cpp:125
const_iterator current
Definition: ystyle.h:363
static auto first(const _tIterator &i) -> decltype((i->first))
Definition: iterator.hpp:759
PDefH(void, AddHandlers, HandlerTable &table, std::type_index idx, std::initializer_list< pair< StyleItem, Handler >> il) ImplExpr(Styles
Definition: ystyle.h:290
#define ImplRet(...)
Definition: YBaseMacro.h:97
float s
饱和度和亮度。
Definition: ystyle.h:137
yconstfn const string _tParams && args
Definition: Loader.h:111
#define DefDeCopyCtor(_t)
Definition: YBaseMacro.h:136
部件绘制参数。
Definition: ywgtevt.h:276
#define YF_API
Definition: Platform.h:64
Hue h
色调。
Definition: ystyle.h:131
std::function< void(PaintEventArgs &&)> Handler
样式处理器。
Definition: ystyle.h:256
阴影背景。
Definition: ystyle.h:186
不活动边框背景。
Definition: ystyle.h:193
面板。
Definition: ypanel.h:45
窗口。
Definition: ywindow.h:44
YF_API void DrawRectRoundCorner(const PaintContext &pc, const Size &s, Color)
绘制部件边框用空心标准矩形。
Definition: ystyle.cpp:42
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:39
Painter(const Key &k)
Definition: ystyle.h:329
Painter(_type1 &&arg1, _type2 &&arg2)
Definition: ystyle.h:333
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:722
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:180
map< VisualEvent, MappedType > MapType
映射表类型。
Definition: ywgtevt.h:426
YF_API void DrawTick(const Graphics &, const Rect &, const Rect &, Color, Color)
Definition: ystyle.cpp:138
活动标题背景。
Definition: ystyle.h:194
样式映射。
Definition: ystyle.h:355
不可复制对象:禁止派生类调用默认原型的复制构造函数和复制赋值操作符。
Definition: utility.hpp:75
hsl_t ColorToHSL(Color c)
Definition: ystyle.cpp:161
void AddHandlers(HandlerTable &table, std::type_index idx, _tIn first, _tIn last)
向样式处理器表添加指定类型的处理器。
Definition: ystyle.h:275
#define ImplExpr(...)
Definition: YBaseMacro.h:93
map< string, HandlerTable > MapType
Definition: ystyle.h:358
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
unordered_map< Key, Handler, ystdex::combined_hash< Key >> HandlerTable
样式处理器表。
Definition: ystyle.h:259
明亮背景。
Definition: ystyle.h:188
ystdex::octet MonoType
Definition: Video.h:185
桌面。
Definition: ydesktop.h:46
带样式的绘制处理函数。
Definition: ystyle.h:323
高亮背景。
Definition: ystyle.h:190
Area
样式区域类型。
Definition: ystyle.h:177
pair< string, HandlerTable > VisualStyle
视觉样式。
Definition: ystyle.h:262
默认调色板。
Definition: ystyle.h:214
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:463
ColorListType colors
Definition: ystyle.h:221
应用程序工作区背景。
Definition: ystyle.h:185
Rotation
逆时针旋转角度指示输出指向。
Definition: ygdibase.h:868
Color
控制台颜色枚举。
Definition: Video.h:458
空(屏幕背景)。
Definition: ystyle.h:180
const IWidget &wgt ImplRet(wgt.GetView().IsVisible()) bool YF_API Contains(const IWidget &
判断点是否在部件的可视区域内。
StyleMap(_tParams &&...args)
Definition: ystyle.h:370
按指定颜色或分量选取彩色或灰度色。
Definition: ystyle.h:124
#define DefDeMoveAssignment(_t)
Definition: YBaseMacro.h:159
活动边框背景。
Definition: ystyle.h:192
YF_API void DrawArrow(const Graphics &, const Rect &, SDst=4, Rotation=RDeg0, Color=ColorSpace::Black)
在指定图形接口上下文上描画箭头。
Definition: ystyle.cpp:100
Selected const shared_ptr< ListType > const pair< Color, Color > & DefDeMoveCtor(TextList) DefPredMem(const ynothrow
Color HSLToColor(hsl_t c)
Definition: ystyle.cpp:200
bounds & r
Definition: ydraw.h:220
YF_API void RectDrawArrow(const PaintContext &, SDst, Rotation=RDeg0, Color=ColorSpace::Black)
在指定上下文的矩形中画箭头。
Definition: ystyle.cpp:68
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
边框填充。
Definition: ystyle.h:191
YF_API Color RollColor(hsl_t, Hue)
色调偏移。
Definition: ystyle.cpp:238
std::uint16_t u16
Definition: yadaptor.h:68
滚动条背景。
Definition: ystyle.h:184
颜色。
Definition: Video.h:339
static auto second(const _tIterator &i) -> decltype((i->second))
Definition: iterator.hpp:765
有理数运算。
不活动标题背景。
Definition: ystyle.h:195
#define DefDeCopyAssignment(_t)
Definition: YBaseMacro.h:154
vector< ItemType > ColorListType
Definition: ystyle.h:218
pair< std::type_index, StyleItem > Key
标识查找样式的键。
Definition: ystyle.h:253
框架背景。
Definition: ystyle.h:189