YSTest: ReaderSettingUI.cpp 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

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

- 文件列表
- 文件成员

ReaderSettingUI.cpp
浏览该文件的文档.
1 /*
2 © 2012-2016 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 < size(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({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 make_shared<TextList::ListType>(Encodings | ystdex::get_value,
130 ystdex::cend(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 const auto fetch_scroll_durations([](bool is_smooth){
189 const auto postfix(is_smooth ? u"毫秒/像素行" : u"毫秒/文本行");
190 auto& lst(*new TextList::ListType(20U));
191 const std::uint16_t delta(is_smooth ? 10 : 100);
192 std::uint16_t t(0);
193
194 std::generate(lst.begin(), lst.end(), [&, is_smooth, delta]{
195 return String(to_string(t += delta)) + postfix;
196 });
197 return share_raw(&lst);
198 });
199
200 ddlScrollTiming.SetList(e.Value ? get_init<true>(fetch_scroll_durations,
201 true) : get_init<false>(fetch_scroll_durations, false));
202 ddlScrollTiming.Text = ddlScrollTiming.GetList()[size_t(e.Value
203 ? smooth_scroll_duration.count() / 10U : scroll_duration.count()
204 / 100U) - 1U],
205 Invalidate(ddlScrollTiming);
206 },
207 ddlScrollTiming.GetConfirmed() += [&, this](IndexEventArgs&& e) ynothrow{
208 if(cbSmoothScroll.IsTicked())
209 smooth_scroll_duration = milliseconds((e.Value + 1U) * 10);
210 else
211 scroll_duration = milliseconds((e.Value + 1U) * 100);
212 },
213 FetchEvent<TouchHeld>(boxColor) += OnTouchHeld_Dragging,
214 FetchEvent<Click>(boxColor.btnOK) += [this]{
215 if(pColor)
216 {
217 // TODO: Determine less area to be invalidated.
218 *pColor = boxColor.GetColor();
219 lblAreaDown.ForeColor = lblAreaUp.ForeColor;
220 Invalidate(lblAreaUp), Invalidate(lblAreaDown);
221 pColor = {};
222 }
223 }
224 );
225 }
226 ImplDeDtor(SettingPanel)
227
228 SettingPanel&
229 SettingPanel::operator<<(const ReaderSetting& s)
230 {
231 auto& node(dynWgts.WidgetNode);
232 DeclDynWidgetN(DropDownList, ddlFont, node, "pnlPage1")
233 DeclDynWidgetN(CheckButton, cbSmoothScroll, node, "pnlPage3")
234
235 yunseq(
236 lblAreaUp.ForeColor = s.FontColor,
237 lblAreaUp.Background = SolidBrush(s.UpColor),
238 lblAreaUp.Font = s.Font,
239 lblAreaDown.ForeColor = s.FontColor,
240 lblAreaDown.Background = SolidBrush(s.DownColor),
241 lblAreaDown.Font = s.Font,
242 ddlFont.Text = s.Font.GetFamilyName(),
243 scroll_duration = s.ScrollDuration,
244 smooth_scroll_duration = s.SmoothScrollDuration
245 ),
246 cbSmoothScroll.Tick(s.SmoothScroll ? CheckBox::Checked
247 : CheckBox::Unchecked);
248 UpdateInfo();
249 return *this;
250 }
251
252 SettingPanel&
253 SettingPanel::operator>>(ReaderSetting& s)
254 {
255 auto& node(dynWgts.WidgetNode);
256 DeclDynWidgetN(CheckButton, cbSmoothScroll, node, "pnlPage3")
257
258 yunseq(
259 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 );
267 return *this;
268 }
269
270 void
271 SettingPanel::UpdateInfo()
272 {
273 lblAreaUp.Text = u"上屏文字大小: "
274 + String(to_string(lblAreaUp.Font.GetSize()) + " 。");
275 }
276
277 } // namespace YReader;
278
YReader::SettingPanel::operator>>
SettingPanel & operator>>(ReaderSetting &)
保存设置。
Definition: ReaderSettingUI.cpp:253
YReader::SettingPanel::lblAreaDown
Label lblAreaDown
Definition: ReaderSettingUI.h:65
platform::p
while p p
Definition: YCLib/FileSystem.h:225
ystdex::to_string
std::string to_string(const std::thread::id &)
转换 thread::id 为字符串表示。
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:740
YSLib::Drawing::SolidBrush::Color
Drawing::Color Color
Definition: YBrush.h:61
ystdex::get_init
auto get_init(_fInit &&f, _tParams &&...args) -> decltype(f(std::forward< decltype(args)>(args)...))&
取类型标识和初始化调用指定的对象。
Definition: utility.hpp:243
YSLib::Drawing::FontSize
std::uint8_t FontSize
字体大小。
Definition: Font.h:73
ystdex::cpp2014::cend
auto cend(const _tRange &c) -> decltype(std::end(c))
Definition: range.hpp:87
ystdex::get_value
const second_tag get_value
Definition: iterator.hpp:589
YSLib::UI::MCheckBox::TickedArgs
MSelector::SelectedArgs TickedArgs
选择框选中状态参数类型。
Definition: Selector.h:105
YSLib::FetchDefaultFontCache
YF_API Drawing::FontCache & FetchDefaultFontCache()
取默认字体缓存。 字体缓存初始化失败。
Definition: Initialization.cpp:493
YSLib::UI::MTextList::ListType
vector< ItemType > ListType
列表类型。
Definition: ListControl.h:142
CHRLib::e
const char const char * e
Definition: CharacterProcessing.h:109
YSLib::UI::DialogPanel
对话面板。
Definition: UIContainerEx.h:78
YSLib::UI::MLabel::ForeColor
Color ForeColor
默认前景色。
Definition: Label.h:77
YReader
Definition: About.h:33
YSLib::UI::OnTouchHeld_Dragging
YF_API void OnTouchHeld_Dragging(CursorEventArgs &&)
处理屏幕接触移动事件：拖放按下部件。
Definition: YControl.cpp:145
NPL::SXML::ParseOption::String
platform::size_t
YF_API size_t
Definition: FileIO.h:1262
YReader::AddButtonToTabBar
void AddButtonToTabBar(TabControl &, ValueNode &, const string &, const String &, SDst=64)
向标签栏和节点添加按钮。
Definition: Shells.cpp:156
YReader::ReaderSetting::Font
Drawing::Font Font
Definition: ReaderSetting.h:45
DeclDynWidgetN
#define DeclDynWidgetN(_t, _n,...)
声明指定节点下的按相同名称访问的动态部件。
Definition: Loader.h:307
YReader::ReaderSetting
阅读器设置。
Definition: ReaderSetting.h:41
YSLib::UI::AddWidgets
void AddWidgets(_tCon &con, _tWidgets &...wgts)
向部件容器添加子部件。
Definition: YUIContainer.h:443
YSLib::Text::String
YSLib 标准字符串（使用 UCS-2 作为内部编码）。
Definition: YString.h:46
YReader::ReaderSetting::UpColor
Color UpColor
Definition: ReaderSetting.h:44
YReader::SettingPanel::SettingPanel
SettingPanel()
Definition: ReaderSettingUI.cpp:87
YReader::FetchEncodingString
String FetchEncodingString(MTextList::IndexType)
取编码字符串。
Definition: ReaderSettingUI.cpp:75
YSLib::UI::Invalidate
YF_API void Invalidate(IWidget &, const Rect &)
无效化：使相对部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: YWidget.cpp:108
YReader::ImplDeDtor
ImplDeDtor(AboutPanel) SystemInformationPanel
Definition: About.cpp:103
YReader::ReaderSetting::FontColor
Color FontColor
Definition: ReaderSetting.h:44
ystdex::share_raw
std::shared_ptr< _type > share_raw(_type *p, _tParams &&...args)
Definition: memory.hpp:664
YReader::ReaderSetting::DownColor
Color DownColor
Definition: ReaderSetting.h:44
ystdex::path_category::node
ystdex::size
auto size(const _tRange &c) -> decltype(c.size())
类容器访问。
Definition: range.hpp:233
DeclDynWidget
#define DeclDynWidget(_t, _n,...)
声明动态部件。
Definition: Loader.h:300
YSLib::UI::Widget::Background
HBrush Background
背景。
Definition: YWidget.h:391
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:996
YSLib::Drawing::SolidBrush
单色画刷。
Definition: YBrush.h:58
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:293
YSLib::UI::MTextList::IndexType
typename ListType::size_type IndexType
索引类型。
Definition: ListControl.h:143
YSLib::UI::DynamicWidget::WidgetNode
ValueNode WidgetNode
Definition: Loader.h:284
YReader::SettingPanel::lblAreaUp
Label lblAreaUp
标签：文本区域示例。
Definition: ReaderSettingUI.h:65
YReader::ReaderSetting::SmoothScroll
bool SmoothScroll
平滑滚屏。
Definition: ReaderSetting.h:50
YReader::FetchWidgetLoader
WidgetLoader & FetchWidgetLoader()
Definition: Shells.cpp:127
YSLib::FetchFontFamilyNames
YF_API shared_ptr< UI::TextList::ListType > FetchFontFamilyNames()
取字型家族名称。
Definition: ShellHelper.cpp:106
YSLib::i
return i
Definition: YCoreUtilities.h:176
YSLib::Text::Encodings
yconstexpr const EncodingInfoItem Encodings[]
编码信息。
Definition: ShellHelper.h:110
YReader::SettingPanel::dynWgts
DynamicWidget dynWgts
Definition: ReaderSettingUI.h:59
YSLib::UI::BoundaryPriority
yconstexpr const EventPriority BoundaryPriority(0x60)
YB_LIKELY
#define YB_LIKELY(_expr)
Definition: ydef.h:437
Text
YSLib::UI::MLabel::Text
String Text
标签文本。
Definition: Label.h:94
YReader::SettingPanel::smooth_scroll_duration
std::chrono::milliseconds smooth_scroll_duration
平滑滚屏间隔。
Definition: ReaderSettingUI.h:89
YReader::ReaderSetting::ScrollDuration
std::chrono::milliseconds ScrollDuration
滚屏间隔。
Definition: ReaderSetting.h:55
ReaderSettingUI.h
阅读器设置界面。
YReader::SettingPanel
设置面板。
Definition: ReaderSettingUI.h:49
YReader::SettingPanel::UpdateInfo
void UpdateInfo()
更新示例文本。
Definition: ReaderSettingUI.cpp:271
YReader::SettingPanel::scroll_duration
std::chrono::milliseconds scroll_duration
滚屏间隔。
Definition: ReaderSettingUI.h:84
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:140
YSLib::UI::MLabel::Font
Drawing::Font Font
字体。
Definition: Label.h:78
YSLib::UI::IndexEventArgs
GValueEventArgs< size_t > IndexEventArgs
索引事件。
Definition: ListControl.h:47
YReader::ReaderSetting::SmoothScrollDuration
std::chrono::milliseconds SmoothScrollDuration
平滑滚屏间隔。
Definition: ReaderSetting.h:60