YSTest: Border.cpp 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

Border.cpp
浏览该文件的文档.
1 /*
2 © 2013-2015, 2018-2020 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 // for ystdex::max;
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(FetchGUIConfiguration().Colors[Styles::ActiveBorder]),
44 InactiveColor(FetchGUIConfiguration().Colors[Styles::InactiveBorder])
45 {}
46
47
48 void
49 BorderBrush::operator()(PaintEventArgs&& e) const
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) const
60 {
61 const auto comp([](SPos q, SPos left, SDst left2) ynothrow{
62 if(q >= 0)
63 {
64 // XXX: Conversion to 'SPos' might be implementation-defined.
65 const SPos a[]{SPos(), left, SPos(left2)};
66 const auto n(SwitchInterval(q, a, 3));
67
68 if(n < 3)
69 return BorderArea(n);
70 }
71 return BorderArea::Center;
72 });
73 const Size& size(GetSizeOf(widget));
74
75 return {comp(pt.X, Margin.Left, size.Width - GetHorizontalOf(Margin)),
76 comp(pt.Y, Margin.Top, size.Height - GetVerticalOf(Margin))};
77 }
78
79 void
80 BorderResizer::Wrap()
81 {
82 auto& controller(widget.get().GetController());
83
84 yunseq(
85 FetchEvent<TouchDown>(controller).Add([this](CursorEventArgs&& e){
86 yunseq(orig_loc = FetchGUIState().CursorLocation,
87 locked_bounds = GetBoundsOf(widget), focused = CheckArea(e));
88 }, 0xE0),
89 FetchEvent<TouchHeld>(controller).Add([this](CursorEventArgs&& e){
90 if(e.Strategy == RoutedEventArgs::Direct
91 && focused != Area(BorderArea::Center, BorderArea::Center))
92 {
93 auto& st(FetchGUIState());
94
95 if(st.CheckDraggingOffset())
96 {
97 const auto offset(st.CursorLocation - orig_loc);
98 auto bounds(locked_bounds);
99
100 // XXX: Conversion to 'SPos' might be implementation-defined.
101 switch(focused.first)
102 {
103 case BorderArea::Left:
104 bounds.Width = SDst(ystdex::max<SPos>(SPos(MinSize.Width),
105 SPos(locked_bounds.Width) - offset.X));
106 bounds.X += SPos(locked_bounds.Width) - SPos(bounds.Width);
107 break;
108 case BorderArea::Right:
109 bounds.Width = SDst(ystdex::max<SPos>(SPos(MinSize.Width),
110 SPos(locked_bounds.Width) + offset.X));
111 break;
112 default:
113 ;
114 }
115 switch(focused.second)
116 {
117 case BorderArea::Up:
118 bounds.Height = SDst(ystdex::max<SPos>(SPos(MinSize.Height),
119 SPos(locked_bounds.Height) - offset.Y));
120 bounds.Y += SPos(locked_bounds.Height)
121 - SPos(bounds.Height);
122 break;
123 case BorderArea::Down:
124 bounds.Height = SDst(ystdex::max<SPos>(SPos(MinSize.Height),
125 SPos(locked_bounds.Height) + offset.Y));
126 break;
127 default:
128 ;
129 }
130 YTraceDe(Notice, "BorderResizer: new bounds = %s.",
131 to_string(bounds).c_str());
132 InvalidateParent(widget);
133 if(RootMode)
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::Styles::ActiveBorder
@ ActiveBorder
活动边框背景。
Definition: YStyle.h:321
YSLib::Drawing::Size::Width
SDst Width
宽和高。
Definition: YGDIBase.h:545
YSLib::UI::BorderStyle::InactiveColor
Color InactiveColor
Definition: Border.h:49
size
size_t size
Definition: memory_resource.cpp:295
YSLib::Drawing::Rect::Width
SDst Width
长。
Definition: YGDIBase.h:545
YSLib::UI::BorderResizer::widget
lref< IWidget > widget
Definition: Border.h:137
YSLib::UI::IsFocused
YF_API bool IsFocused(const IWidget &)
判断部件是否取得焦点。
Definition: YFocus.cpp:38
YSLib::UI::SPos
const IWidget &wgt SPos
Definition: YWidget.h:109
YSLib::UI::BorderArea::Left
@ Left
YSLib::UI::ynothrow
AView &y ynothrow
Definition: YWidgetView.cpp:47
YSLib::UI::BorderResizer::RootMode
bool RootMode
根模式：指定部件为通过外部接口和宿主交互的顶层部件。
Definition: Border.h:147
YSLib::Drawing::Size::Height
SDst Height
Definition: YGDIBase.h:545
YSLib::UI::BorderBrush::Style
BorderStyle Style
边框样式。
Definition: Border.h:75
YSLib::UI::BorderArea::Up
@ Up
YSLib::UI::BorderArea::Center
@ Center
YSLib::UI::CursorEventArgs
指针设备输入事件参数类。
Definition: YWidgetEvent.h:216
YSLib::UI::SetBoundsOf
void SetBoundsOf(IWidget &wgt, const Rect &r)
Definition: YWidget.cpp:56
YSLib::UI::BorderStyle::BorderStyle
BorderStyle()
Definition: Border.cpp:42
YSLib::UI::GetSizeOf
YB_ATTR_nodiscard YB_PURE pt pt Y YB_ATTR_nodiscard YB_PURE const IWidget &wgt const IWidget &wgt GetSizeOf
无效化：使相对部件的子部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: YWidget.h:165
YSLib::Drawing::GBinaryGroup< SPos >::Invalid
static const GBinaryGroup Invalid
无效（不在屏幕坐标系中）对象。
Definition: YGDIBase.h:298
YSLib::UI::BorderArea::Down
@ Down
YSLib::Drawing::Padding::Left
SPos Left
空白距离：左、右、上、下。
Definition: YGDI.h:52
YSLib::UI::BorderArea
BorderArea
边框区域。
Definition: Border.h:104
YSLib::UI::BorderResizer::orig_loc
Point orig_loc
Definition: Border.h:128
YSLib::UI::BorderResizer::locked_bounds
Rect locked_bounds
锁定的部件边界。
Definition: Border.h:134
YSLib::Drawing::Padding::Top
SPos Top
Definition: YGDI.h:52
YSLib::UI::GetBoundsOf
YB_ATTR_nodiscard YB_PURE pt pt Y YB_ATTR_nodiscard YB_PURE const IWidget &wgt const IWidget &wgt const IWidget &wgt GetBoundsOf
Definition: YWidget.h:172
YSLib::UI::RoutedEventArgs::Direct
@ Direct
直接事件：仅当遍历至目标控件时触发。
Definition: YWidgetEvent.h:113
YSLib::UI::BorderArea::Right
@ Right
platform::Descriptions::Notice
@ Notice
Definition: YCommon.h:184
YSLib::UI::InvalidateParent
void InvalidateParent(IWidget &wgt)
Definition: YWidget.cpp:141
YSLib::UI::FetchGUIConfiguration
GUIConfiguration & FetchGUIConfiguration()
Definition: YGUI.cpp:517
YSLib::Drawing::GBinaryGroup< SPos >
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:1535
YTraceDe
#define YTraceDe(...)
YCLib 默认调试跟踪。
Definition: Debug.h:407
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
YSLib::Drawing::GBinaryGroup::X
_type X
分量。
Definition: YGDIBase.h:305
ystdex::to_string
std::string to_string(const std::thread::id &)
转换 thread::id 为字符串表示。
YSLib::UI::e
void e
Definition: YWidget.h:356
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:788
YSLib::UI::BorderResizer::MinSize
Size MinSize
指定部件应该保持的最小大小。
Definition: Border.h:154
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
YModules.h
YSLib 用户界面模块配置文件。
YSLib::Drawing::Rect::Height
SDst Height
宽。
Definition: YGDIBase.h:545
ystdex::lref::get
_type & get() const
Definition: ref.hpp:96
YSLib::Drawing::bounds
The boundary is out of the const Rect & bounds
Definition: YDraw.h:127
YSLib::UI::PaintEventArgs
部件绘制参数。
Definition: YWidgetEvent.h:330
NPL::c_str
YF_API const char src c_str())) YF_API void InstallDirectory(const string &
安装目录：复制目录树。
Definition: Dependency.h:140
YSLib::Drawing::GetVerticalOf
YB_ATTR_nodiscard YB_PURE const Padding &m ynothrowv GetVerticalOf
Definition: YGDI.h:151
YSLib::UI::BorderResizer::Wrap
void Wrap()
加载事件。
Definition: Border.cpp:80
YSLib::UI::Styles::InactiveBorder
@ InactiveBorder
不活动边框背景。
Definition: YStyle.h:322
YSLib::UI::BorderStyle::ActiveColor
Color ActiveColor
Definition: Border.h:49
YSLib::Drawing::GBinaryGroup::Y
_type Y
Definition: YGDIBase.h:305
YSLib::Drawing::GetHorizontalOf
YB_ATTR_nodiscard YB_PURE GetHorizontalOf
Definition: YGDI.h:146
YSLib::UI::BorderResizer::Margin
Drawing::Padding Margin
指定边框相对部件边界以内的范围的边距。
Definition: Border.h:149
platform::SPos
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:43
YSLib::UI::BorderResizer::Area
pair< BorderArea, BorderArea > Area
区域类型。
Definition: Border.h:125
YSLib::UI::FetchGUIState
GUIState & FetchGUIState() ynothrow
Definition: YGUI.cpp:506
ystdex::details::off
size_t off
Definition: operators.hpp:198
YSLib::Drawing::DrawRect
void DrawRect(const Graphics &g, const Rect &bounds, const Rect &r, Color c)
Definition: YDraw.cpp:136
YSLib::UI::BorderResizer::focused
Area focused
Definition: Border.h:135
YSLib::a
YB_PURE const _type * a
Definition: YCoreUtilities.h:168