-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathE32.h
79 lines (66 loc) · 1.62 KB
/
E32.h
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef E32_H
#define E32_H
#include <string.h>
#include <vector>
#include <iostream>
using namespace std;
class Screen;
class Window_mgr {
public:
using ScreenIndex = vector<Screen>::size_type;
void clear(ScreenIndex);
private:
std::vector<Screen> screens;
};
class Screen {
friend void Window_mgr::clear(ScreenIndex);
public:
typedef string::size_type pos;
Screen() = default;
Screen(pos ht, pos wd, char c) : height(ht), width(wd), contents(ht * wd, c) {}
char get() const { return contents[cursor]; }
inline char get(pos ht, pos wd) const;
inline Screen &set(char c);
inline Screen &set(pos, pos, char);
Screen &move(pos r, pos c);
Screen &display(ostream &os)
{ do_display(os); return *this; }
const Screen &display(ostream &os) const
{ do_display(os); return *this; }
private:
pos cursor = 0;
pos height = 0, width = 0;
string contents;
void do_display(ostream &os) const { os << contents;}
};
inline
Screen &Screen::move(pos r, pos c) {
pos row = r * width;
cursor = row + c;
return *this;
}
inline Screen &Screen::set(char c) {
contents[cursor] = c;
return *this;
}
inline Screen &Screen::set(pos r, pos col, char c){
contents[r*width + col] = c;
return *this;
}
char Screen::get(pos r, pos c) const {
pos row = r*width;
return contents[row + c];
}
// class Window_mgr{
// public:
// using ScreenIndex = vector<Screen>::size_type;
// void clear(ScreenIndex);
// private:
// vector<Screen> screens{ Screen(24, 80, ' ')};
// };
void Window_mgr::clear(ScreenIndex i) {
// vector<Screen> screens{ Screen(24, 80, ' ')};
Screen &s = screens[i];
s.contents = string(s.height * s.width, ' ');
}
#endif