YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
DSReader.h
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2010 - 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 #ifndef INC_YReader_DSReader_h_
29 #define INC_YReader_DSReader_h_ 1
30 
31 #include <YSLib/UI/textarea.h>
32 #include <YSLib/Service/yftext.h>
33 #include <YSLib/Service/textmgr.h>
34 #include <Helper/DSMain.h>
35 
37 
39 
41 
42 using Drawing::Color;
43 using Drawing::PixelType;
44 
45 
52 {
53 public:
58  typedef enum : u16
59  {
60  Null = 0,
61  Scroll = 1,
62  Up = 2,
63  Down = 0,
64  Line = 4,
65  Screen = 0,
66  LineUp = Line | Up,
67  LineDown = Line | Down,
68  ScreenUp = Screen | Up,
69  ScreenDown = Screen | Down,
70  LineUpScroll = LineUp | Scroll,
71  LineDownScroll = LineDown | Scroll,
72  ScreenUpScroll = ScreenUp | Scroll,
73  ScreenDownScroll = ScreenDown | Scroll
74  } Command;
75 
76 private:
81  unique_ptr<Text::TextFileBuffer> p_text;
82  Drawing::FontCache& fc;
83 
91  Text::TextFileBuffer::Iterator i_top;
92  Text::TextFileBuffer::Iterator i_btm;
94 
106 
107 public:
114  Drawing::Padding Margin;
115 
116 private:
125 
126 public:
131  std::function<void()> ViewChanged;
132 
141  DualScreenReader(SDst w = MainScreenWidth,
143  Drawing::FontCache& fc_ = FetchDefaultFontCache());
144 
146  DefPred(const ynothrow, BufferReady, bool(p_text));
147  DefPred(const ynothrow, TextTop, i_top == p_text->GetBegin()) \
149  DefPred(const ynothrow, TextBottom, i_btm == p_text->GetEnd()) \
151 
157  DefGetter(const ynothrow, Color, Color, area_up.Color)
162  DefGetter(const ynothrow, const Drawing::Font&, Font, area_up.Font)
163  DefGetter(const ynothrow, u8, LineGap, area_up.LineGap) \
165  DefGetter(const ynothrow, Text::Encoding, Encoding, p_text
166  ? p_text->GetEncoding() : Text::CharSet::Null)
167 
172  DefGetter(const ynothrow, size_t, TextSize,
173  p_text ? p_text->GetTextSize() : 0)
182  DefGetter(const ynothrow, size_t, TopPosition,
183  p_text ? p_text->GetPosition(i_top) : 0)
184  DefGetter(const ynothrow, size_t, BottomPosition,
185  p_text ? p_text->GetPosition(i_btm) : 0)
187 
193  Text::TextFileBuffer&
194  GetTextBufferRef() ythrow(LoggedEvent)
195  {
196  if(p_text)
197  return *p_text;
198  throw LoggedEvent("Null text buffer pointer found.");
199  }
200 
201  PDefH(void, SetColor, Color c = Drawing::ColorSpace::Black)
202  ImplUnseq(area_up.Color = c, area_dn.Color = c)
203 
208  void
209  SetFont(const Drawing::Font&);
210  void
211  SetFontSize(Drawing::FontSize = Drawing::Font::DefaultSize); \
213  void
214  SetLineGap(u8 = 0);
215 
219  void
220  SetVisible(bool = true);
221 
222 private:
224  void
225  AdjustForFirstNewline();
226 
228  void
229  AdjustForPrevNewline();
230 
231 public:
237  void
238  AdjustMargins();
239 
246  Drawing::FontSize
247  AdjustScrollOffset();
248 
253  void
254  Attach(YSLib::UI::Window&, YSLib::UI::Window&);
255 
260  void
261  Detach();
262 
267  bool
268  Execute(Command);
269 
274  void
275  Invalidate();
276 
285  void
286  Locate(size_t);
287 
289  void
290  LoadText(TextFile&);
291 
292 private:
294  void
295  MoveUpForLastLine(ptrdiff_t, size_t);
296 
298  Text::TextFileBuffer::Iterator
299  PutLastLine();
300 
301 public:
303  void
304  Reset();
305 
315  Drawing::FontSize
316  ScrollByPixel(Drawing::FontSize);
317 
325  void
326  Stretch(SDst);
327 
332  void
333  UnloadText();
334 
341  void
342  UpdateView();
343 };
344 
345 DefBitmaskOperations(DualScreenReader::Command, u16)
346 
348 
350 
351 YSL_END
352 
353 #endif
354