YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ReaderSettingUI.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 "ReaderSettingUI.h"
29 
30 namespace YReader
31 {
32 
34 namespace
35 {
36 
37 const char TU_ReaderSettingUI[]{u8R"NPL(root
38 ($type "TabControl")($bounds "8 24 240 160")
39 (pnlPage1
40  ($type "Panel")
41  (btnFontSizeDecrease
42  ($type "Button")($bounds "12 12 80 22"))
43  (btnFontSizeIncrease
44  ($type "Button")($bounds "148 12 80 22"))
45  (btnSetUpBack
46  ($type "Button")($bounds "12 44 80 22"))
47  (btnSetDownBack
48  ($type "Button")($bounds "148 44 80 22"))
49  (btnTextColor
50  ($type "Button")($bounds "12 76 80 22"))
51  (ddlFont
52  ($type "DropDownList")($bounds "148 76 80 22"))
53 )
54 (pnlPage2
55  ($type "Panel")
56  (ddlEncoding
57  ($type "DropDownList")($bounds "12 12 192 22"))
58 )
59 (pnlPage3
60  ($type "Panel")
61  (cbSmoothScroll
62  ($type "CheckButton")($bounds "12 12 72 18"))
63  (ddlScrollTiming
64  ($type "DropDownList")($bounds "84 12 128 22"))
65 )
66 
67 )NPL"};
68 
69 } // unnamed namespace;
70 
71 using namespace Text;
72 using std::chrono::milliseconds;
73 
74 String
76 {
77  if(YB_LIKELY(i < arrlen(Encodings)))
78  {
79  const auto& pr(Encodings[i]);
80 
81  return String(to_string(pr.first) + ": ") + pr.second;
82  }
83  return u"---";
84 }
85 
86 
88  : DialogPanel(Size(MainScreenWidth, MainScreenHeight)),
89  dynWgts(FetchWidgetLoader(), TU_ReaderSettingUI),
90  lblAreaUp({20, 12, 216, 72}), lblAreaDown({20, 108, 216, 72}),
91  boxColor(Point(4, 80)), pColor(), current_encoding(),
92  scroll_duration(), smooth_scroll_duration()
93 {
94  // NOTE: Values of durations keep uninitialized. Use carefully.
95  auto& node(dynWgts.WidgetNode);
96  DeclDynWidget(TabControl, root, node)
97  auto& node_pnlPage1(AccessWidgetNode(node, "pnlPage1"));
98  auto& node_pnlPage2(AccessWidgetNode(node, "pnlPage2"));
99  auto& node_pnlPage3(AccessWidgetNode(node, "pnlPage3"));
100  DeclDynWidgetN(Button, btnFontSizeDecrease, node_pnlPage1)
101  DeclDynWidgetN(Button, btnFontSizeIncrease, node_pnlPage1)
102  DeclDynWidgetN(Button, btnSetUpBack, node_pnlPage1)
103  DeclDynWidgetN(Button, btnSetDownBack, node_pnlPage1)
104  DeclDynWidgetN(Button, btnTextColor, node_pnlPage1)
105  DeclDynWidgetN(DropDownList, ddlFont, node_pnlPage1)
106  DeclDynWidgetN(DropDownList, ddlEncoding, node_pnlPage2)
107  DeclDynWidgetN(CheckButton, cbSmoothScroll, node_pnlPage3)
108  DeclDynWidgetN(DropDownList, ddlScrollTiming, node_pnlPage3)
109  const auto set_font_size([this](FontSize size){
110  lblAreaUp.Font.SetSize(size),
111  lblAreaDown.Font.SetSize(size);
112  UpdateInfo();
113  Invalidate(lblAreaUp),
114  Invalidate(lblAreaDown);
115  });
116 
117  AddButtonToTabBar(root, node_pnlPage1, "btnTabDisplay", u"显示设置");
118  AddButtonToTabBar(root, node_pnlPage2, "btnTabText", u"文本设置");
119  AddButtonToTabBar(root, node_pnlPage3, "btnTabOperation", u"操作设置");
120  root.UpdateTabPages();
121  for(const auto& p_pnl : root.GetPages())
122  if(p_pnl)
123  FetchEvent<Paint>(*p_pnl).Add(BorderBrush(), BoundaryPriority);
124  AddWidgets(*this, root),
125  Add(boxColor, 112U),
126  SetVisibleOf(boxColor, false),
127  ddlFont.SetList(FetchFontFamilyNames()),
128  ddlEncoding.SetList(
129  share_raw(new TextList::ListType(Encodings | ystdex::get_value,
131  yunseq(
132  root.Background = nullptr,
133  btnFontSizeDecrease.Text = u"减小字体",
134  btnFontSizeIncrease.Text = u"增大字体",
135  btnSetUpBack.Text = u"上屏颜色...",
136  btnSetDownBack.Text = u"下屏颜色...",
137  btnTextColor.Text = u"文字颜色...",
138  cbSmoothScroll.Text = u"平滑滚屏",
139 // FetchEvent<Paint>(lblColorAreaUp).Add(BorderBrush(BorderStyle),
140 // BoundaryPriority),
141 // FetchEvent<Paint>(lblColorAreaDown).Add(BorderBrush(BorderStyle),
142 // BoundaryPriority),
143  FetchEvent<KeyDown>(*this) += OnEvent_StopRouting<KeyEventArgs>,
144  FetchEvent<KeyHeld>(*this) += OnEvent_StopRouting<KeyEventArgs>,
145  FetchEvent<Click>(btnFontSizeDecrease) += [this, set_font_size]{
146  auto size(lblAreaUp.Font.GetSize());
147 
148  if(YB_LIKELY(size > Font::MinimalSize))
149  set_font_size(--size);
150  },
151  FetchEvent<Click>(btnFontSizeIncrease) += [this, set_font_size]{
152  auto size(lblAreaUp.Font.GetSize());
153 
154  if(YB_LIKELY(size < Font::MaximalSize))
155  set_font_size(++size);
156  },
157  FetchEvent<Click>(btnTextColor) += [this]{
158  boxColor.SetColor(*(pColor = &lblAreaUp.ForeColor));
159  Show(boxColor);
160  },
161  FetchEvent<Click>(btnSetUpBack) += [this]{
162  boxColor.SetColor(
163  *(pColor = &lblAreaUp.Background.target<SolidBrush>()->Color));
164  Show(boxColor);
165  },
166  FetchEvent<Click>(btnSetDownBack) += [this]{
167  boxColor.SetColor(
168  *(pColor = &lblAreaDown.Background.target<SolidBrush>()->Color));
169  Show(boxColor);
170  },
171  ddlFont.GetConfirmed() += [&, this]{
172  if(const auto p = FetchDefaultFontCache()
173  .GetFontFamilyPtr(ddlFont.Text.GetMBCS().c_str()))
174  {
175  lblAreaUp.Font = Font(*p, lblAreaUp.Font.GetSize());
176  lblAreaDown.Font = lblAreaUp.Font;
177  Invalidate(lblAreaUp),
178  Invalidate(lblAreaDown);
179  }
180  },
181  ddlEncoding.GetConfirmed() += [this](IndexEventArgs&& e){
182  yunseq(current_encoding = Encodings[e.Value].first,
183  lblAreaDown.Text = FetchEncodingString(e.Value)),
184  Invalidate(lblAreaDown);
185  },
186  cbSmoothScroll.Ticked += [&, this](CheckBox::TickedArgs&& e){
187  using ystdex::get_init;
188 
189  static yconstexpr auto fetch_scroll_durations([](bool is_smooth)
190  {
191  const auto postfix(is_smooth ? u"毫秒/像素行" : u"毫秒/文本行");
192  auto& lst(*new TextList::ListType(20U));
193  const u16 delta(is_smooth ? 10 : 100);
194  u16 t(0);
195 
196  std::generate(lst.begin(), lst.end(), [&, is_smooth, delta]{
197  return String(to_string(t += delta)) + postfix;
198  });
199  return share_raw(&lst);
200  });
201 
202  ddlScrollTiming.SetList(e.Value ? get_init<true>(fetch_scroll_durations,
203  true) : get_init<false>(fetch_scroll_durations, false));
204  ddlScrollTiming.Text = ddlScrollTiming.GetList()[(e.Value
205  ? smooth_scroll_duration.count() / 10U : scroll_duration.count()
206  / 100U) - 1U],
207  Invalidate(ddlScrollTiming);
208  },
209  ddlScrollTiming.GetConfirmed() += [&, this](IndexEventArgs&& e){
210  if(cbSmoothScroll.IsTicked())
211  smooth_scroll_duration = milliseconds((e.Value + 1U) * 10);
212  else
213  scroll_duration = milliseconds((e.Value + 1U) * 100);
214  },
215  FetchEvent<TouchHeld>(boxColor) += OnTouchHeld_Dragging,
216  FetchEvent<Click>(boxColor.btnOK) += [this]{
217  if(pColor)
218  {
219  // TODO: Determine less area to be invalidated.
220  *pColor = boxColor.GetColor();
221  lblAreaDown.ForeColor = lblAreaUp.ForeColor;
222  Invalidate(lblAreaUp), Invalidate(lblAreaDown);
223  pColor = {};
224  }
225  }
226  );
227 }
228 
229 SettingPanel&
231 {
232  auto& node(dynWgts.WidgetNode);
233  DeclDynWidgetN(DropDownList, ddlFont, node, "pnlPage1")
234  DeclDynWidgetN(CheckButton, cbSmoothScroll, node, "pnlPage3")
235 
236  yunseq(
239  lblAreaUp.Font = s.Font,
242  lblAreaDown.Font = s.Font,
243  ddlFont.Text = s.Font.GetFamilyName(),
246  ),
247  cbSmoothScroll.Tick(s.SmoothScroll ? CheckBox::Checked
248  : CheckBox::Unchecked);
249  UpdateInfo();
250  return *this;
251 }
252 
255 {
256  auto& node(dynWgts.WidgetNode);
257  DeclDynWidgetNode(CheckButton, cbSmoothScroll)
258 
262  s.Font = lblAreaUp.Font,
263  s.SmoothScroll = cbSmoothScroll.IsTicked(),
266  return *this;
267 }
268 
269 void
271 {
272  lblAreaUp.Text = u"上屏文字大小: "
273  + String(to_string(lblAreaUp.Font.GetSize()) + " 。");
274 }
275 
276 } // namespace YReader;
277 
std::chrono::milliseconds ScrollDuration
滚屏间隔。
Definition: ReaderSetting.h:55
typename ListType::size_type IndexType
索引类型。
Definition: label.h:149
Drawing::Color Color
Definition: YBrush.h:49
GValueEventArgs< MTextList::IndexType > IndexEventArgs
索引事件。
Definition: textlist.h:47
yconstexpr EncodingInfoItem Encodings[]
编码信息。
Definition: ShellHelper.h:101
Drawing::Font Font
字体。
Definition: label.h:61
size_t arrlen(_type(&)[_vN])
计算指定数组类型对象的长度。
Definition: utility.hpp:196
YF_API void Invalidate(IWidget &, const Rect &)
无效化:使相对于部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.cpp:111
Label lblAreaUp
标签:文本区域示例。
ValueNode WidgetNode
Definition: Loader.h:251
MSelector::SelectedArgs TickedArgs
选择框选中状态参数类型。
Definition: Selector.h:107
std::shared_ptr< _type > share_raw(const _pSrc &p)
Definition: memory.hpp:165
YF_API void OnTouchHeld_Dragging(CursorEventArgs &&)
处理屏幕接触移动事件:拖放按下部件。
Definition: ycontrol.cpp:144
阅读器设置。
Definition: ReaderSetting.h:41
yconstexpr EventPriority BoundaryPriority(0x60)
YF_API shared_ptr< UI::TextList::ListType > FetchFontFamilyNames()
取字型家族名称。
阅读器设置界面。
SettingPanel & operator<<(const ReaderSetting &)
读取设置。
void AddWidgets(_tCon &con, _tWidgets &...wgts)
向部件容器添加子部件。
Definition: yuicont.h:400
std::chrono::milliseconds smooth_scroll_duration
平滑滚屏间隔。
String Text
标签文本。
Definition: label.h:76
#define DeclDynWidgetN(_t, _n,...)
声明指定节点下的按相同名称访问的动态部件。
Definition: Loader.h:270
const second_tag get_value
Definition: iterator.hpp:785
YSLib 标准字符串(使用 UCS-2 作为内部编码)。
Definition: ystring.h:47
HBrush Background
背景。
Definition: ywidget.h:374
GBinaryGroup< SPos > Point
屏幕二维点(直角坐标表示)。
Definition: ygdibase.h:235
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:748
bool SmoothScroll
平滑滚屏。
Definition: ReaderSetting.h:50
WidgetLoader & FetchWidgetLoader()
Definition: Shells.cpp:130
YF_API Drawing::FontCache & FetchDefaultFontCache()
取默认字体缓存。
void UpdateInfo()
更新示例文本。
设置面板。
#define DeclDynWidget(_t, _n,...)
声明动态部件。
Definition: Loader.h:263
auto get_init(_fInit &&f, _tParams &&...args) -> decltype(f(std::forward< decltype(args)>(args)...))&
取类型标识和初始化调用指定的对象。
Definition: utility.hpp:310
std::string to_string(unsigned char val)
转换为字符串。
Definition: string.hpp:353
String FetchEncodingString(MTextList::IndexType)
取编码字符串。
std::chrono::milliseconds SmoothScrollDuration
平滑滚屏间隔。
Definition: ReaderSetting.h:60
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
单色画刷。
Definition: YBrush.h:46
#define YB_LIKELY(expr)
Definition: ydef.h:297
Color ForeColor
默认前景色。
Definition: ywidget.h:375
void AddButtonToTabBar(TabControl &, const ValueNode &, const string &, const String &, SDst=64)
向标签栏和节点添加按钮。
Definition: Shells.cpp:158
std::uint16_t u16
Definition: yadaptor.h:68
屏幕区域大小。
Definition: ygdibase.h:249
std::chrono::milliseconds scroll_duration
滚屏间隔。
对话面板。
Definition: uicontx.h:73
#define DeclDynWidgetNode(_t, _n)
声明名称为 node 的节点下的按相同名称访问的动态部件。
Definition: Loader.h:276
u8 FontSize
字体大小。
Definition: Font.h:63
SettingPanel & operator>>(ReaderSetting &)
保存设置。