-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathPage840_Screen.cpp
More file actions
53 lines (53 loc) · 1.42 KB
/
Page840_Screen.cpp
File metadata and controls
53 lines (53 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "Page840_Screen.h"
// initialize static member
Screen::Action Screen::Menu[] = { &Screen::home,
&Screen::forward,
&Screen::back,
&Screen::up,
&Screen::down
};
Screen& Screen::move(Directions cm)
{
// run the element indexed by cm on this object
return (this->*Menu[cm])(); // Menu[cm] points to a member function
}
inline Screen& Screen::home()
{
cursor = 0;
return *this;
}
inline Screen& Screen::forward()
{
if(cursor < height * width - 1)
++cursor;
return *this;
}
inline Screen& Screen::back()
{
if(cursor > 0)
--cursor;
else
cursor = 0;
return *this;
}
inline Screen& Screen::up()
{
if(cursor - width > 0)
cursor -= width;
else
cursor = 0;
return *this;
}
inline Screen& Screen::down()
{
if(cursor + width < height * width)
cursor += width;
else
cursor = height * width - 1;
return *this;
}
// Note: in this file, only home, forward, back, up and down are inline. We can't
// declare a function as inline if it's in a source file and it will be called
// by functions in other source files. Or the compiler would complain that it
// cannot find the definition of the function. See this link:
// https://stackoverflow.com/questions/7883022/inline-in-source-file