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 
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),
55 }
56 
57 
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
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
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 
132 
133  if(HostMode)
134  {
135  const auto&
136  off(bounds.GetPoint() - locked_bounds.GetPoint());
137 
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;
147  locked_bounds.GetPointRef() -= off;
148  }
149  else
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]{
162  }, 0xE0)
163  );
164 }
165 
166 } // namespace UI;
167 
168 } // namespace YSLib;
169 
void InvalidateParent(IWidget &wgt)
Definition: ywidget.cpp:144
pt pt Y const IWidget &wgt const IWidget &wgt GetSizeOf
无效化:使相对于部件的子部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.h:156
Drawing::Padding Margin
Definition: Border.h:136
YF_API GUIState & FetchGUIState()
取默认图形用户界面公共状态。
Definition: ygui.cpp:442
SDst GetVerticalOf(const Padding &m)
取竖直边距和。
Definition: ygdi.h:116
void SetBoundsOf(IWidget &wgt, const Rect &r)
Definition: ywidget.cpp:53
部件绘制参数。
Definition: ywgtevt.h:276
SDst Height
宽和高。
Definition: ygdibase.h:258
static const GBinaryGroup Invalid
无效(不在屏幕坐标系中)对象。
Definition: ygdibase.h:57
不活动边框背景。
Definition: ystyle.h:193
pair< BorderArea, BorderArea > Area
区域类型。
Definition: Border.h:115
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:748
YF_API bool IsFocused(const IWidget &)
判断部件是否取得焦点。
Definition: yfocus.cpp:38
BorderStyle Style
边框样式。
Definition: Border.h:66
pt pt Y const IWidget &wgt const IWidget &wgt const IWidget &wgt GetBoundsOf
Definition: ywidget.h:163
屏幕标准矩形:表示屏幕矩形区域。
Definition: ygdibase.h:416
直接事件:仅当遍历至目标控件时触发。
Definition: ywgtevt.h:104
const IWidget &wgt SPos
Definition: ywidget.h:104
bool HostMode
宿主模式:指定是否在设置边界后同时调整锁定的边界位置。
Definition: Border.h:134
Size MinSize
指定部件应该保持的最小大小。
Definition: Border.h:141
std::string to_string(unsigned char val)
转换为字符串。
Definition: string.hpp:353
#define YTraceDe(...)
YCLib 默认调试跟踪。
Definition: Debug.h:269
Rect locked_bounds
锁定的部件边界。
Definition: Border.h:124
活动边框背景。
Definition: ystyle.h:192
BorderArea
边框区域。
Definition: Border.h:93
std::reference_wrapper< IWidget > widget
Definition: Border.h:126
size_t SwitchInterval(_type v, const _type *a, size_t n) ynothrow
计算满足指定的值 v 在区间 [a[i], a[i + 1]) 内最小的 i 。
Definition: ycutil.h:221
指针设备输入事件参数类。
Definition: ywgtevt.h:183
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
void Wrap()
加载事件。
Definition: Border.cpp:79