YSTest: ReaderSettingUI.cpp 源文件

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
75 FetchEncodingString(MTextList::IndexType i)
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
87 SettingPanel::SettingPanel()
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,
130 (Encodings + arrlen(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&
230 SettingPanel::operator<<(const ReaderSetting& s)
231 {
232 auto& node(dynWgts.WidgetNode);
233 DeclDynWidgetN(DropDownList, ddlFont, node, "pnlPage1")
234 DeclDynWidgetN(CheckButton, cbSmoothScroll, node, "pnlPage3")
235
236 yunseq(
237 lblAreaUp.ForeColor = s.FontColor,
238 lblAreaUp.Background = SolidBrush(s.UpColor),
239 lblAreaUp.Font = s.Font,
240 lblAreaDown.ForeColor = s.FontColor,
241 lblAreaDown.Background = SolidBrush(s.DownColor),
242 lblAreaDown.Font = s.Font,
243 ddlFont.Text = s.Font.GetFamilyName(),
244 scroll_duration = s.ScrollDuration,
245 smooth_scroll_duration = s.SmoothScrollDuration
246 ),
247 cbSmoothScroll.Tick(s.SmoothScroll ? CheckBox::Checked
248 : CheckBox::Unchecked);
249 UpdateInfo();
250 return *this;
251 }
252
253 SettingPanel&
254 SettingPanel::operator>>(ReaderSetting& s)
255 {
256 auto& node(dynWgts.WidgetNode);
257 DeclDynWidgetNode(CheckButton, cbSmoothScroll)
258
259 yunseq(s.UpColor = lblAreaUp.Background.target<SolidBrush>()->Color,
260 s.DownColor = lblAreaDown.Background.target<SolidBrush>()->Color,
261 s.FontColor = lblAreaUp.ForeColor,
262 s.Font = lblAreaUp.Font,
263 s.SmoothScroll = cbSmoothScroll.IsTicked(),
264 s.ScrollDuration = scroll_duration,
265 s.SmoothScrollDuration = smooth_scroll_duration);
266 return *this;
267 }
268
269 void
270 SettingPanel::UpdateInfo()
271 {
272 lblAreaUp.Text = u"上屏文字大小: "
273 + String(to_string(lblAreaUp.Font.GetSize()) + " 。");
274 }
275
276 } // namespace YReader;
277
YReader::ReaderSetting::ScrollDuration
std::chrono::milliseconds ScrollDuration
滚屏间隔。
Definition: ReaderSetting.h:55
YSLib::UI::MTextList::IndexType
typename ListType::size_type IndexType
索引类型。
Definition: label.h:149
YSLib::UI::SolidBrush::Color
Drawing::Color Color
Definition: YBrush.h:49
YSLib::UI::IndexEventArgs
GValueEventArgs< MTextList::IndexType > IndexEventArgs
索引事件。
Definition: textlist.h:47
YSLib::Text::Encodings
yconstexpr EncodingInfoItem Encodings[]
编码信息。
Definition: ShellHelper.h:101
YSLib::UI::MLabel::Font
Drawing::Font Font
字体。
Definition: label.h:61
YReader::ReaderSetting::Font
Drawing::Font Font
Definition: ReaderSetting.h:45
ystdex::arrlen
size_t arrlen(_type(&)[_vN])
计算指定数组类型对象的长度。
Definition: utility.hpp:196
YSLib::UI::Invalidate
YF_API void Invalidate(IWidget &, const Rect &)
无效化：使相对于部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.cpp:111
YReader::SettingPanel::lblAreaUp
Label lblAreaUp
标签：文本区域示例。
Definition: ReaderSettingUI.h:65
YSLib::UI::DynamicWidget::WidgetNode
ValueNode WidgetNode
Definition: Loader.h:251
YSLib::UI::MCheckBox::TickedArgs
MSelector::SelectedArgs TickedArgs
选择框选中状态参数类型。
Definition: Selector.h:107
ystdex::share_raw
std::shared_ptr< _type > share_raw(const _pSrc &p)
Definition: memory.hpp:165
YSLib::UI::OnTouchHeld_Dragging
YF_API void OnTouchHeld_Dragging(CursorEventArgs &&)
处理屏幕接触移动事件：拖放按下部件。
Definition: ycontrol.cpp:144
YReader::ReaderSetting
阅读器设置。
Definition: ReaderSetting.h:41
YSLib::UI::BoundaryPriority
yconstexpr EventPriority BoundaryPriority(0x60)
YSLib::FetchFontFamilyNames
YF_API shared_ptr< UI::TextList::ListType > FetchFontFamilyNames()
取字型家族名称。
Definition: ShellHelper.cpp:106
ReaderSettingUI.h
阅读器设置界面。
YReader::SettingPanel::operator<<
SettingPanel & operator<<(const ReaderSetting &)
读取设置。
Definition: ReaderSettingUI.cpp:230
YSLib::UI::AddWidgets
void AddWidgets(_tCon &con, _tWidgets &...wgts)
向部件容器添加子部件。
Definition: yuicont.h:400
YReader::SettingPanel::smooth_scroll_duration
std::chrono::milliseconds smooth_scroll_duration
平滑滚屏间隔。
Definition: ReaderSettingUI.h:94
YSLib::UI::MLabel::Text
String Text
标签文本。
Definition: label.h:76
DeclDynWidgetN
#define DeclDynWidgetN(_t, _n,...)
声明指定节点下的按相同名称访问的动态部件。
Definition: Loader.h:270
YReader::SettingPanel::SettingPanel
SettingPanel()
Definition: ReaderSettingUI.cpp:87
ystdex::get_value
const second_tag get_value
Definition: iterator.hpp:785
YSLib::Text::String
YSLib 标准字符串（使用 UCS-2 作为内部编码）。
Definition: ystring.h:47
YSLib::UI::Widget::Background
HBrush Background
背景。
Definition: ywidget.h:374
YSLib::Drawing::Point
GBinaryGroup< SPos > Point
屏幕二维点（直角坐标表示）。
Definition: ygdibase.h:235
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:748
YReader::ReaderSetting::UpColor
Color UpColor
Definition: ReaderSetting.h:44
YReader::ReaderSetting::SmoothScroll
bool SmoothScroll
平滑滚屏。
Definition: ReaderSetting.h:50
YReader::SettingPanel::dynWgts
DynamicWidget dynWgts
Definition: ReaderSettingUI.h:59
YReader::FetchWidgetLoader
WidgetLoader & FetchWidgetLoader()
Definition: Shells.cpp:130
YSLib::FetchDefaultFontCache
YF_API Drawing::FontCache & FetchDefaultFontCache()
取默认字体缓存。
Definition: Initialization.cpp:394
YReader::SettingPanel::UpdateInfo
void UpdateInfo()
更新示例文本。
Definition: ReaderSettingUI.cpp:270
YReader::SettingPanel
设置面板。
Definition: ReaderSettingUI.h:49
DeclDynWidget
#define DeclDynWidget(_t, _n,...)
声明动态部件。
Definition: Loader.h:263
ystdex::get_init
auto get_init(_fInit &&f, _tParams &&...args) -> decltype(f(std::forward< decltype(args)>(args)...))&
取类型标识和初始化调用指定的对象。
Definition: utility.hpp:310
YReader::ReaderSetting::DownColor
Color DownColor
Definition: ReaderSetting.h:44
ystdex::to_string
std::string to_string(unsigned char val)
转换为字符串。
Definition: string.hpp:353
YReader::FetchEncodingString
String FetchEncodingString(MTextList::IndexType)
取编码字符串。
Definition: ReaderSettingUI.cpp:75
platform_ex::Windows::s
return s
Definition: MinGW32.cpp:49
YReader::ReaderSetting::SmoothScrollDuration
std::chrono::milliseconds SmoothScrollDuration
平滑滚屏间隔。
Definition: ReaderSetting.h:60
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
YSLib::UI::SolidBrush
单色画刷。
Definition: YBrush.h:46
YB_LIKELY
#define YB_LIKELY(expr)
Definition: ydef.h:297
YSLib::UI::Widget::ForeColor
Color ForeColor
默认前景色。
Definition: ywidget.h:375
YReader::AddButtonToTabBar
void AddButtonToTabBar(TabControl &, const ValueNode &, const string &, const String &, SDst=64)
向标签栏和节点添加按钮。
Definition: Shells.cpp:158
YSLib::u16
std::uint16_t u16
Definition: yadaptor.h:68
YSLib::Drawing::Size
屏幕区域大小。
Definition: ygdibase.h:249
YReader::SettingPanel::scroll_duration
std::chrono::milliseconds scroll_duration
滚屏间隔。
Definition: ReaderSettingUI.h:89
YSLib::UI::DialogPanel
对话面板。
Definition: uicontx.h:73
DeclDynWidgetNode
#define DeclDynWidgetNode(_t, _n)
声明名称为 node 的节点下的按相同名称访问的动态部件。
Definition: Loader.h:276
YSLib::Drawing::FontSize
u8 FontSize
字体大小。
Definition: Font.h:63
YReader::SettingPanel::operator>>
SettingPanel & operator>>(ReaderSetting &)
保存设置。
Definition: ReaderSettingUI.cpp:254
YReader::ReaderSetting::FontColor
Color FontColor
Definition: ReaderSetting.h:44
YReader::SettingPanel::lblAreaDown
Label lblAreaDown
Definition: ReaderSettingUI.h:65