YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ReaderSettingUI.cpp
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2013.
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 YSL_BEGIN_NAMESPACE(YReader)
31 
32 using namespace Text;
33 using std::chrono::milliseconds;
34 
35 String
36 FetchEncodingString(MTextList::IndexType i)
37 {
38  if(YB_LIKELY(i < arrlen(Encodings)))
39  {
40  const auto& pr(Encodings[i]);
41 
42  return String(to_string(pr.first) + ": ") + pr.second;
43  }
44  return u"---";
45 }
46 
47 
49  : DialogPanel(Size(MainScreenWidth, MainScreenHeight)),
50  lblAreaUp({20, 12, 216, 72}), lblAreaDown({20, 108, 216, 72}),
51  btnFontSizeDecrease({20, 32, 80, 22}),
52  btnFontSizeIncrease({148, 32, 80, 22}),
53  btnSetUpBack({20, 64, 80, 22}), btnSetDownBack({148, 64, 80, 22}),
54  btnTextColor({20, 96, 80, 22}),
55  ddlFont({148, 96, 80, 22}, FetchFontFamilyNames()),
56  ddlEncoding({20, 128, 192, 22}, share_raw(new
57  TextList::ListType(Encodings | ystdex::get_value, (Encodings
59  cbSmoothScroll({20, 160, 72, 18}),
60  ddlScrollTiming({96, 160, 128, 22}),
61  boxColor(Point(4, 80)), pColor(), current_encoding(),
63 {
64  const auto set_font_size([this](FontSize size){
65  lblAreaUp.Font.SetSize(size),
66  lblAreaDown.Font.SetSize(size);
67  UpdateInfo();
68  Invalidate(lblAreaUp),
70  });
71 
75  Add(boxColor, 112U),
76  SetVisibleOf(boxColor, false);
77  yunseq(
78  btnFontSizeDecrease.Text = u"减小字体",
79  btnFontSizeIncrease.Text = u"增大字体",
80  btnSetUpBack.Text = u"上屏颜色...",
81  btnSetDownBack.Text = u"下屏颜色...",
82  btnTextColor.Text = u"文字颜色...",
83  cbSmoothScroll.Text = u"平滑滚屏",
84  // FetchEvent<Paint>(lblColorAreaUp).Add(BorderBrush(BorderStyle),
85  // BoundaryPriority),
86  // FetchEvent<Paint>(lblColorAreaDown).Add(BorderBrush(BorderStyle),
87  // BoundaryPriority),
88  FetchEvent<KeyDown>(*this) += OnEvent_StopRouting<KeyEventArgs>,
89  FetchEvent<KeyHeld>(*this) += OnEvent_StopRouting<KeyEventArgs>,
90  FetchEvent<Click>(btnFontSizeDecrease)
91  += [this, set_font_size](TouchEventArgs&&){
92  auto size(lblAreaUp.Font.GetSize());
93 
94  if(YB_LIKELY(size > Font::MinimalSize))
95  set_font_size(--size);
96  },
97  FetchEvent<Click>(btnFontSizeIncrease)
98  += [this, set_font_size](TouchEventArgs&&){
99  auto size(lblAreaUp.Font.GetSize());
100 
101  if(YB_LIKELY(size < Font::MaximalSize))
102  set_font_size(++size);
103  },
104  FetchEvent<Click>(btnTextColor) += [this](TouchEventArgs&&){
105  boxColor.SetColor(*(pColor = &lblAreaUp.ForeColor));
106  Show(boxColor);
107  },
108  FetchEvent<Click>(btnSetUpBack) += [this](TouchEventArgs&&){
109  boxColor.SetColor(*(pColor
110  = &lblAreaUp.Background.target<SolidBrush>()->Color));
111  Show(boxColor);
112  },
113  FetchEvent<Click>(btnSetDownBack) += [this](TouchEventArgs&&){
114  boxColor.SetColor(*(pColor
115  = &lblAreaDown.Background.target<SolidBrush>()->Color));
116  Show(boxColor);
117  },
118  ddlFont.GetConfirmed() += [this](IndexEventArgs&&){
119  if(const auto p = FetchDefaultFontCache()
120  .GetFontFamilyPtr(ddlFont.Text.GetMBCS().c_str()))
121  {
122  lblAreaUp.Font = Font(*p, lblAreaUp.Font.GetSize());
123  lblAreaDown.Font = lblAreaUp.Font;
124  Invalidate(lblAreaUp),
126  }
127  },
128  ddlEncoding.GetConfirmed() += [this](IndexEventArgs&& e){
129  yunseq(current_encoding = Encodings[e.Value].first,
130  lblAreaDown.Text = FetchEncodingString(e.Value)),
132  },
133  cbSmoothScroll.GetTicked() += [this](CheckBox::TickedArgs&& e){
134  using ystdex::get_init;
135 
136  static yconstexpr auto fetch_scroll_durations([](bool is_smooth)
137  {
138  const auto postfix(is_smooth ? u"毫秒/像素行" : u"毫秒/文本行");
139  auto& lst(*new TextList::ListType(20U));
140  const u16 delta(is_smooth ? 10 : 100);
141  u16 t(0);
142 
143  std::generate(lst.begin(), lst.end(), [&, is_smooth, delta]{
144  return String(to_string(t += delta)) + postfix;
145  });
146  return share_raw(&lst);
147  });
148 
149  ddlScrollTiming.SetList(e.Value ? get_init<true>(
150  fetch_scroll_durations, true) : get_init<false>(
151  fetch_scroll_durations, false));
152  ddlScrollTiming.Text = ddlScrollTiming.GetList()[(e.Value
153  ? smooth_scroll_duration.count() / 10U : scroll_duration.count()
154  / 100U) - 1U],
156  },
157  ddlScrollTiming.GetConfirmed() += [this](IndexEventArgs&& e){
158  if(cbSmoothScroll.IsTicked())
159  smooth_scroll_duration = milliseconds((e.Value + 1U) * 10);
160  else
161  scroll_duration = milliseconds((e.Value + 1U) * 100);
162  },
163  FetchEvent<TouchMove>(boxColor) += OnTouchMove_Dragging,
164  FetchEvent<Click>(boxColor.btnOK) += [this](TouchEventArgs&&){
165  if(pColor)
166  {
167  // TODO: Determine less area to be invalidated.
168  *pColor = boxColor.GetColor();
169  lblAreaDown.ForeColor = lblAreaUp.ForeColor;
170  Invalidate(lblAreaUp),
172  pColor = nullptr;
173  }
174  }
175  );
176 }
177 
180 {
181  yunseq(lblAreaUp.ForeColor = s.FontColor,
182  lblAreaUp.Background = SolidBrush(s.UpColor),
183  lblAreaUp.Font = s.Font,
184  lblAreaDown.ForeColor = s.FontColor,
185  lblAreaDown.Background = SolidBrush(s.DownColor),
186  lblAreaDown.Font = s.Font,
187  ddlFont.Text = s.Font.GetFamilyName(),
191  UpdateInfo();
192  return *this;
193 }
194 
197 {
198  yunseq(s.UpColor = lblAreaUp.Background.target<SolidBrush>()->Color,
199  s.DownColor = lblAreaDown.Background.target<SolidBrush>()->Color,
200  s.FontColor = lblAreaUp.ForeColor,
201  s.Font = lblAreaUp.Font,
202  s.SmoothScroll = cbSmoothScroll.IsTicked(),
205  return *this;
206 }
207 
208 void
210 {
211  lblAreaUp.Text = u"上屏文字大小: "
212  + String(to_string(lblAreaUp.Font.GetSize()) + " 。");
213 }
214 
215 YSL_END_NAMESPACE(YReader)
216