YSTest: Border.cpp 源文件

YSTest PreAlpha_b500_20140530 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
Border.cpp
浏览该文件的文档.
1 /*
2 © 2013-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/UI/YModules.h"
29 #include YFM_YSLib_UI_Border
30 #include YFM_YSLib_Service_YDraw
31 #include YFM_YSLib_UI_YGUI
32 #include YFM_YSLib_UI_YControl
33
34 namespace YSLib
35 {
36
37 using namespace Drawing;
38
39 namespace UI
40 {
41
42 BorderStyle::BorderStyle()
43 : ActiveColor(FetchGUIState().Colors[Styles::ActiveBorder]),
44 InactiveColor(FetchGUIState().Colors[Styles::InactiveBorder])
45 {}
46
47
48 void
49 BorderBrush::operator()(PaintEventArgs&& e)
50 {
51 auto& sender(e.GetSender());
52
53 DrawRect(e.Target, e.ClipArea, e.Location, GetSizeOf(sender),
54 IsFocused(sender) ? Style.ActiveColor : Style.InactiveColor);
55 }
56
57
58 BorderResizer::Area
59 BorderResizer::CheckArea(const Point& pt)
60 {
61 const auto comp([](SPos q, SPos left, SPos left2){
62 if(q >= 0)
63 {
64 const SPos a[]{SPos(), left, left2};
65 const auto n(SwitchInterval(q, a, 3));
66
67 if(n < 3)
68 return BorderArea(n);
69 }
70 return BorderArea::Center;
71 });
72 const Size& size(GetSizeOf(widget));
73
74 return {comp(pt.X, Margin.Left, size.Width - GetHorizontalOf(Margin)),
75 comp(pt.Y, Margin.Top, size.Height - GetVerticalOf(Margin))};
76 }
77
78 void
79 BorderResizer::Wrap()
80 {
81 auto& controller(widget.get().GetController());
82
83 yunseq(
84 FetchEvent<TouchDown>(controller).Add([this](CursorEventArgs&& e){
85 yunseq(orig_loc = FetchGUIState().CursorLocation,
86 locked_bounds = GetBoundsOf(widget), focused = CheckArea(e));
87 }, 0xE0),
88 FetchEvent<TouchHeld>(controller).Add([this](CursorEventArgs&& e){
89 if(e.Strategy == RoutedEventArgs::Direct
90 && focused != Area(BorderArea::Center, BorderArea::Center))
91 {
92 auto& st(FetchGUIState());
93
94 if(st.CheckDraggingOffset())
95 {
96 const auto offset(st.CursorLocation - orig_loc);
97 auto bounds(locked_bounds);
98
99 switch(focused.first)
100 {
101 case BorderArea::Left:
102 bounds.Width = max<SPos>(MinSize.Width,
103 locked_bounds.Width - offset.X);
104 bounds.X += locked_bounds.Width - bounds.Width;
105 break;
106 case BorderArea::Right:
107 bounds.Width = max<SPos>(MinSize.Width,
108 locked_bounds.Width + offset.X);
109 break;
110 default:
111 ;
112 }
113 switch(focused.second)
114 {
115 case BorderArea::Up:
116 bounds.Height = max<SPos>(MinSize.Height,
117 locked_bounds.Height - offset.Y);
118 bounds.Y += locked_bounds.Height - bounds.Height;
119 break;
120 case BorderArea::Down:
121 bounds.Height = max<SPos>(MinSize.Height,
122 locked_bounds.Height + offset.Y);
123 break;
124 default:
125 ;
126 }
127
128 YTraceDe(Notice, "BorderResizer: new bounds = %s.",
129 to_string(bounds).c_str());
130
131 InvalidateParent(widget);
132
133 if(HostMode)
134 {
135 const auto&
136 off(bounds.GetPoint() - locked_bounds.GetPoint());
137
138 SetBoundsOf(widget, bounds);
139
140 const auto& nloc(FetchGUIState().CursorLocation - off);
141
142 if(bounds.Width != MinSize.Width)
143 orig_loc.X = nloc.X;
144 if(bounds.Height != MinSize.Height)
145 orig_loc.Y = nloc.Y;
146 locked_bounds = GetBoundsOf(widget);
147 locked_bounds.GetPointRef() -= off;
148 }
149 else
150 SetBoundsOf(widget, bounds);
151 }
152 e.Handled = true;
153 // XXX: Paint context target invalidated.
154 }
155 }, 0xE0),
156 FetchEvent<Click>(controller).Add([this](CursorEventArgs&& e){
157 CallEvent<ClickAcross>(widget, e);
158 }, 0xE0),
159 FetchEvent<ClickAcross>(controller).Add([this]{
160 yunseq(orig_loc = Point::Invalid, locked_bounds = Rect(),
161 focused = {BorderArea::Center, BorderArea::Center});
162 }, 0xE0)
163 );
164 }
165
166 } // namespace UI;
167
168 } // namespace YSLib;
169
YSLib::UI::BorderArea::Right
YSLib::UI::InvalidateParent
void InvalidateParent(IWidget &wgt)
Definition: ywidget.cpp:144
YSLib::UI::GetSizeOf
pt pt Y const IWidget &wgt const IWidget &wgt GetSizeOf
无效化：使相对于部件的子部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.h:156
YSLib::UI::BorderResizer::Margin
Drawing::Padding Margin
Definition: Border.h:136
YModules.h
YSLib::UI::FetchGUIState
YF_API GUIState & FetchGUIState()
取默认图形用户界面公共状态。
Definition: ygui.cpp:442
YSLib::Drawing::GetVerticalOf
SDst GetVerticalOf(const Padding &m)
取竖直边距和。
Definition: ygdi.h:116
YSLib::UI::SetBoundsOf
void SetBoundsOf(IWidget &wgt, const Rect &r)
Definition: ywidget.cpp:53
YSLib::UI::BorderArea::Down
YSLib::UI::BorderResizer::orig_loc
Point orig_loc
Definition: Border.h:118
YSLib::Drawing::bounds
bounds
Definition: ydraw.h:188
YSLib::UI::PaintEventArgs
部件绘制参数。
Definition: ywgtevt.h:276
YSLib::UI::BorderStyle::BorderStyle
BorderStyle()
Definition: Border.cpp:42
YSLib::Drawing::Size::Height
SDst Height
宽和高。
Definition: ygdibase.h:258
YSLib::Drawing::GBinaryGroup< SPos >::Invalid
static const GBinaryGroup Invalid
无效（不在屏幕坐标系中）对象。
Definition: ygdibase.h:57
YSLib::UI::Styles::InactiveBorder
不活动边框背景。
Definition: ystyle.h:193
YSLib::UI::BorderStyle::InactiveColor
Color InactiveColor
Definition: Border.h:48
YSLib::UI::BorderResizer::Area
pair< BorderArea, BorderArea > Area
区域类型。
Definition: Border.h:115
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:748
YSLib::UI::IsFocused
YF_API bool IsFocused(const IWidget &)
判断部件是否取得焦点。
Definition: yfocus.cpp:38
YSLib::UI::BorderBrush::Style
BorderStyle Style
边框样式。
Definition: Border.h:66
YSLib::UI::GetBoundsOf
pt pt Y const IWidget &wgt const IWidget &wgt const IWidget &wgt GetBoundsOf
Definition: ywidget.h:163
platform::Descriptions::Notice
Definition: ycommon.h:76
YSLib::Drawing::GBinaryGroup::Y
_type Y
分量。
Definition: ygdibase.h:59
YSLib::UI::BorderArea::Up
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: ygdibase.h:416
YSLib::UI::RoutedEventArgs::Direct
直接事件：仅当遍历至目标控件时触发。
Definition: ywgtevt.h:104
YSLib::Drawing::GBinaryGroup< SPos >
YSLib::UI::SPos
const IWidget &wgt SPos
Definition: ywidget.h:104
YSLib::Drawing::Padding::Top
SPos Top
Definition: ygdi.h:52
YSLib::UI::BorderResizer::HostMode
bool HostMode
宿主模式：指定是否在设置边界后同时调整锁定的边界位置。
Definition: Border.h:134
YSLib::UI::BorderResizer::focused
Area focused
Definition: Border.h:125
YSLib::Drawing::GBinaryGroup::X
_type X
Definition: ygdibase.h:59
YSLib::UI::BorderResizer::MinSize
Size MinSize
指定部件应该保持的最小大小。
Definition: Border.h:141
YSLib::Drawing::Padding::Left
SPos Left
Definition: ygdi.h:52
ystdex::to_string
std::string to_string(unsigned char val)
转换为字符串。
Definition: string.hpp:353
YSLib::UI::BorderArea::Left
YTraceDe
#define YTraceDe(...)
YCLib 默认调试跟踪。
Definition: Debug.h:269
YSLib::UI::BorderArea::Center
YSLib::UI::BorderResizer::locked_bounds
Rect locked_bounds
锁定的部件边界。
Definition: Border.h:124
YSLib::UI::Styles::ActiveBorder
活动边框背景。
Definition: ystyle.h:192
YSLib::UI::BorderStyle::ActiveColor
Color ActiveColor
Definition: Border.h:48
YSLib::UI::BorderArea
BorderArea
边框区域。
Definition: Border.h:93
YSLib::UI::BorderResizer::widget
std::reference_wrapper< IWidget > widget
Definition: Border.h:126
YSLib::SwitchInterval
size_t SwitchInterval(_type v, const _type *a, size_t n) ynothrow
计算满足指定的值 v 在区间 [a[i], a[i + 1]) 内最小的 i 。
Definition: ycutil.h:221
YSLib::UI::CursorEventArgs
指针设备输入事件参数类。
Definition: ywgtevt.h:183
YSLib::Drawing::Size::Width
SDst Width
Definition: ygdibase.h:258
YSLib::Drawing::DrawRect
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
YSLib::UI::BorderResizer::Wrap
void Wrap()
加载事件。
Definition: Border.cpp:79