YSTest: DSReader.h 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

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

- 文件列表
- 文件成员

DSReader.h
浏览该文件的文档.
1 /*
2 © 2010-2015 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 #ifndef INC_YReader_DSReader_h_
29 #define INC_YReader_DSReader_h_ 1
30
31 #include <Helper/YModules.h>
32 #include YFM_YSLib_UI_TextArea
33 #include YFM_YSLib_UI_YWindow
34 #include YFM_YSLib_Service_TextFile
35 #include YFM_YSLib_Service_TextManager
36 #include YFM_DS_Helper_DSMain
37 #include YFM_Helper_Initialization
38
39 namespace YSLib
40 {
41
42 namespace DS
43 {
44
45 namespace UI
46 {
47
48 using Drawing::Color;
49
50
56 class DualScreenReader
57 {
58 public:
63 enum Command : std::uint16_t
64 {
65 Null = 0,
66 Scroll = 1,
67 Up = 2,
68 Down = 0,
69 Line = 4,
70 Screen = 0,
71 LineUp = Line | Up,
72 LineDown = Line | Down,
73 ScreenUp = Screen | Up,
74 ScreenDown = Screen | Down,
75 LineUpScroll = LineUp | Scroll,
76 LineDownScroll = LineDown | Scroll,
77 ScreenUpScroll = ScreenUp | Scroll,
78 ScreenDownScroll = ScreenDown | Scroll
79 };
80
81 private:
86 unique_ptr<Text::TextFileBuffer> p_text;
87 Drawing::FontCache& fc;
88
96 Text::TextFileBuffer::iterator i_top;
97 Text::TextFileBuffer::iterator i_btm;
99
105 std::uint16_t overread_line_n;
110 Drawing::FontSize scroll_offset;
111
112 public:
119 Drawing::Padding Margin;
120
121 private:
127 YSLib::UI::BufferedTextArea area_up;
128 YSLib::UI::BufferedTextArea area_dn;
130
131 public:
136 std::function<void()> ViewChanged;
137
146 DualScreenReader(SDst w = MainScreenWidth,
147 SDst h_up = MainScreenHeight, SDst h_down = MainScreenHeight,
148 Drawing::FontCache& fc_ = FetchDefaultFontCache());
149
151 DefPred(const ynothrow, BufferReady, bool(p_text))
153 DefPred(const ynothrow, TextTop, i_top == p_text->begin())
155 DefPred(const ynothrow, TextBottom, i_btm == p_text->end())
156
158 DefGetter(const ynothrow, Text::TextFileBuffer&, BufferRef, Deref(p_text))
164 DefGetter(const ynothrow, Color, Color, area_up.Color)
169 DefGetter(const ynothrow, const Drawing::Font&, Font, area_up.Font)
170 DefGetter(const ynothrow, std::uint8_t, LineGap, area_up.LineGap) \
172 DefGetter(const ynothrow, Text::Encoding, Encoding, p_text
173 ? p_text->GetEncoding() : Text::CharSet::Null)
174
179 DefGetter(const ynothrow, size_t, TextSize,
180 p_text ? p_text->GetTextSize() : 0)
189 DefGetter(const ynothrow, size_t, TopPosition,
190 p_text ? p_text->GetPosition(i_top) : 0)
191 DefGetter(const ynothrow, size_t, BottomPosition,
192 p_text ? p_text->GetPosition(i_btm) : 0)
194
200 Text::TextFileBuffer&
201 GetTextBufferRef() ythrow(LoggedEvent)
202 {
203 if(p_text)
204 return *p_text;
205 throw LoggedEvent("Null text buffer pointer found.");
206 }
207
208 PDefH(void, SetColor, Color c = Drawing::ColorSpace::Black)
209 ImplUnseq(area_up.Color = c, area_dn.Color = c)
210
215 void
216 SetFont(const Drawing::Font&);
217 void
218 SetFontSize(Drawing::FontSize = Drawing::Font::DefaultSize); \
220 void
221 SetLineGap(std::uint8_t = 0);
222
226 void
227 SetVisible(bool = true);
228
229 private:
231 void
232 AdjustForFirstNewline();
233
235 void
236 AdjustForPrevNewline();
237
238 public:
244 void
245 AdjustMargins();
246
253 Drawing::FontSize
254 AdjustScrollOffset();
255
260 void
261 Attach(YSLib::UI::Window&, YSLib::UI::Window&);
262
267 void
268 Detach();
269
274 bool
275 Execute(Command);
276
281 void
282 Invalidate();
283
292 void
293 Locate(size_t);
294
301 void
302 LoadText(ifstream&, Text::Encoding);
303
304 private:
306 void
307 MoveUpForLastLine(ptrdiff_t, size_t);
308
310 Text::TextFileBuffer::iterator
311 PutLastLine();
312
313 public:
315 void
316 Reset();
317
327 Drawing::FontSize
328 ScrollByPixel(Drawing::FontSize);
329
337 void
338 Stretch(SDst);
339
344 void
345 UnloadText();
346
353 void
354 UpdateView();
355 };
356
361 DefBitmaskEnum(DualScreenReader::Command)
362
363 } // namespace UI;
364
365 } // namespace DS;
366
367 } // namespace YSLib;
368
369 #endif
370
YSLib::DS::UI::DualScreenReader::AdjustForPrevNewline
void AdjustForPrevNewline()
Definition: DSReader.cpp:269
YSLib::DS::UI::DualScreenReader::Reset
void Reset()
复位输出显示状态。
Definition: DSReader.cpp:455
YSLib::Drawing::w
The boundary is out of the const Rect SDst w
Definition: YDraw.h:127
YSLib::DS::UI::DualScreenReader::LineUp
Definition: DSReader.h:71
YSLib::Drawing::Font
字体：字模，包含字型、样式和大小。
Definition: Font.h:583
YSLib::DS::UI::DualScreenReader::fc
Drawing::FontCache & fc
字体缓存。
Definition: DSReader.h:87
YSLib::DS::UI::DualScreenReader::Stretch
void Stretch(SDst)
伸缩：从最大值起向上调整（减少）下文字区域的高后更新视图。
Definition: DSReader.cpp:495
YSLib::DS::UI::DualScreenReader::LineUpScroll
Definition: DSReader.h:75
YSLib::UI::BufferedTextArea
缓冲文本区域。
Definition: TextArea.h:79
YSLib::Drawing::FontSize
std::uint8_t FontSize
字体大小。
Definition: Font.h:73
YSLib::DS::UI::DualScreenReader::Null
Definition: DSReader.h:65
YSLib::DS::UI::DualScreenReader::area_up
YSLib::UI::BufferedTextArea area_up
上下屏幕对应文本区域。
Definition: DSReader.h:127
YSLib::DS::UI::DualScreenReader::TextTop
TextTop
Definition: DSReader.h:153
YSLib::FetchDefaultFontCache
YF_API Drawing::FontCache & FetchDefaultFontCache()
取默认字体缓存。 字体缓存初始化失败。
Definition: Initialization.cpp:493
YSLib::Consoles::Black
Definition: YConsole.h:53
DefBitmaskEnum
#define DefBitmaskEnum(_tEnum)
Definition: YBaseMacro.h:475
YSLib::Drawing::FontCache
字体缓存。
Definition: Font.h:460
YSLib::DS::UI::DualScreenReader::Line
Definition: DSReader.h:69
YSLib::DS::UI::DualScreenReader::LoadText
void LoadText(ifstream &, Text::Encoding)
载入指定编码的文本。
Definition: DSReader.cpp:419
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::DS::UI::DualScreenReader::Execute
bool Execute(Command)
执行阅读器命令。
Definition: DSReader.cpp:320
YSLib::DS::UI::DualScreenReader::Up
Definition: DSReader.h:67
YSLib::Drawing::Padding
空白样式。
Definition: YGDI.h:46
YSLib::DS::UI::DualScreenReader::i_btm
Text::TextFileBuffer::iterator i_btm
Definition: DSReader.h:97
YSLib::PDefH
PDefH(Environment &, FetchEnvironment,) ImplRet(FetchGlobalInstance().GetEnvironmentRef()) inline PDefH(GUIHost &
取单一环境对象引用。
YSLib::DS::UI::DualScreenReader::ScrollByPixel
Drawing::FontSize ScrollByPixel(Drawing::FontSize)
向下滚屏指定像素行。
Definition: DSReader.cpp:468
YSLib::DS::UI::DualScreenReader::AdjustScrollOffset
Drawing::FontSize AdjustScrollOffset()
调整滚屏像素偏移量：立即继续滚动至下一整文本行。
Definition: DSReader.cpp:292
YSLib::DS::UI::DualScreenReader::SetVisible
void SetVisible(bool=true)
设置文本区域可见性。
Definition: DSReader.cpp:238
YSLib::Text::TextFileBuffer::iterator
目标编码迭代器类型。
Definition: TextManager.h:68
YSLib::DS::UI::DualScreenReader
双屏阅读器。
Definition: DSReader.h:56
YSLib::DS::UI::DualScreenReader::overread_line_n
std::uint16_t overread_line_n
读入文件结束后的空行数。
Definition: DSReader.h:105
YSLib::DS::UI::DualScreenReader::Detach
void Detach()
从窗口分离。
Definition: DSReader.cpp:307
YSLib::DS::UI::DualScreenReader::ScreenDownScroll
Definition: DSReader.h:78
YSLib::DS::UI::DualScreenReader::UnloadText
void UnloadText()
卸载文本。
Definition: DSReader.cpp:508
YSLib::LoggedEvent
记录日志的异常事件类。
Definition: YException.h:49
Color
Pixel Color
Definition: CharRenderer.cpp:58
YSLib::DS::UI::DualScreenReader::DualScreenReader
DualScreenReader(SDst w=MainScreenWidth, SDst h_up=MainScreenHeight, SDst h_down=MainScreenHeight, Drawing::FontCache &fc_=FetchDefaultFontCache())
构造。
Definition: DSReader.cpp:214
YSLib::DS::UI::DualScreenReader::MoveUpForLastLine
void MoveUpForLastLine(ptrdiff_t, size_t)
Definition: DSReader.cpp:438
YSLib::DS::UI::DualScreenReader::LineDownScroll
Definition: DSReader.h:76
CHRLib::c
c
Definition: CharacterProcessing.h:81
CHRLib::CharSet::Encoding
Encoding
字符流编码标识。
Definition: Encoding.h:58
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:240
ImplUnseq
#define ImplUnseq(...)
Definition: YBaseMacro.h:110
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
YSLib::DS::UI::DualScreenReader::SetFontSize
void SetFontSize(Drawing::FontSize=Drawing::Font::DefaultSize)
设置文本区域的字体大小。
Definition: DSReader.cpp:255
YSLib::DS::UI::DualScreenReader::i_top
Text::TextFileBuffer::iterator i_top
文本区域输入迭代器。
Definition: DSReader.h:96
std
Definition: memory.hpp:1100
platform::Deref
yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:440
YSLib::DS::UI::DualScreenReader::ViewChanged
std::function< void()> ViewChanged
视图变更回调函数。
Definition: DSReader.h:136
YSLib::DS::UI::DualScreenReader::scroll_offset
Drawing::FontSize scroll_offset
滚屏像素偏移量。
Definition: DSReader.h:110
DS
YSLib::DS::UI::DualScreenReader::LineDown
Definition: DSReader.h:72
YSLib::DS::UI::DualScreenReader::AdjustForFirstNewline
void AdjustForFirstNewline()
Definition: DSReader.cpp:263
YSLib::DS::UI::DualScreenReader::ScreenDown
Definition: DSReader.h:74
YSLib::DS::UI::DualScreenReader::Attach
void Attach(YSLib::UI::Window &, YSLib::UI::Window &)
附加到窗口。
Definition: DSReader.cpp:299
YSLib::DS::UI::DualScreenReader::ScreenUpScroll
Definition: DSReader.h:77
Drawing
YSLib::DS::UI::DualScreenReader::Scroll
Definition: DSReader.h:66
YSLib::DS::UI::DualScreenReader::UpdateView
void UpdateView()
更新视图。
Definition: DSReader.cpp:516
UI
YSLib::DS::UI::DualScreenReader::Margin
Drawing::Padding Margin
公用边距。
Definition: DSReader.h:119
YSLib::DS::UI::DualScreenReader::PutLastLine
Text::TextFileBuffer::iterator PutLastLine()
Definition: DSReader.cpp:449
YSLib::DS::UI::DualScreenReader::p_text
unique_ptr< Text::TextFileBuffer > p_text
文本资源。
Definition: DSReader.h:86
YSLib::DS::UI::DualScreenReader::SetLineGap
void SetLineGap(std::uint8_t=0)
设置行距。
Definition: DSReader.cpp:228
YSLib::DS::UI::DualScreenReader::Command
Command
命令类型。
Definition: DSReader.h:63
YSLib::DS::UI::DualScreenReader::Locate
void Locate(size_t)
文本定位。
Definition: DSReader.cpp:395
YSLib::DS::UI::DualScreenReader::area_dn
YSLib::UI::BufferedTextArea area_dn
Definition: DSReader.h:128
YSLib::Drawing::Color
The boundary is out of the const Rect SDst SPos SPos SPos Color
Definition: YDraw.h:127
YSLib::DS::UI::DualScreenReader::Invalidate
void Invalidate()
无效化文本区域，并调用 ViewChanged （仅当非空）。
Definition: DSReader.cpp:383
Text
YModules.h
YSLib::Text::TextFileBuffer
文本文件块缓冲区。
Definition: TextManager.h:46
YSLib::DS::UI::DualScreenReader::DefPred
DefPred(const ynothrow, BufferReady, bool(p_text)) DefPred(const ynothrow
判断输出位置是否到文本顶端。
YSLib::DS::UI::DualScreenReader::AdjustMargins
void AdjustMargins()
调整边距：使用公用边距更新各文本显示区域的边距。
Definition: DSReader.cpp:275
YSLib::UI::Window
窗口。
Definition: YWindow.h:44
ythrow
#define ythrow(...)
YSLib 动态异常规范：根据是否使用异常规范宏指定或忽略动态异常规范。
Definition: ydef.h:791
ystdex::cpp2011::begin
_type * begin(_type(&&array)[_vN])
Definition: range.hpp:46
YSLib::DS::UI::DualScreenReader::Screen
Definition: DSReader.h:70
YSLib::DS::UI::DualScreenReader::ScreenUp
Definition: DSReader.h:73
YSLib::DS::UI::DualScreenReader::Down
Definition: DSReader.h:68
ystdex::cpp2011::end
_type * end(_type(&&array)[_vN])
Definition: range.hpp:54
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:43