This repository was archived by the owner on Apr 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathborder.cpp
More file actions
140 lines (123 loc) · 3.21 KB
/
border.cpp
File metadata and controls
140 lines (123 loc) · 3.21 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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "stdafx.hpp"
#include "border.hpp"
namespace curses {
namespace detail {
//#elif defined(CURSES_UNIX)
//
//#else
//// VESA EGA, VGA etc
//#endif // UNICODE
struct single_line_corners {
private:
typedef char_t char_t;
single_line_corners() {}
public:
static CURSES_FORCEINLINE char_t top_left() {
static char_t rlt = CRS_SINLE_TOP_LEFT;
return rlt;
}
static CURSES_FORCEINLINE char_t top_right() {
static char_t rlt = CRS_SINLE_TOP_RIGHT;
return rlt;
}
static CURSES_FORCEINLINE char_t bottom_left() {
static char_t rlt = CRS_SINLE_BOTTOM_LEFT;
return rlt;
}
static CURSES_FORCEINLINE char_t bottom_right() {
static char_t rlt = CRS_SINLE_BOTTOM_RIGHT;
return rlt;
}
static CURSES_FORCEINLINE char_t horizontal() {
static char_t rlt = CRS_SINLE_HORIZONTAL;
return rlt;
}
static CURSES_FORCEINLINE char_t vertical() {
static char_t rlt = CRS_SINLE_VERTICAL;
return rlt;
}
};
struct double_line_corners {
private:
double_line_corners() {}
public:
static CURSES_FORCEINLINE char_t top_left() {
static char_t rlt = CRS_DOUBLE_TOP_LEFT;
return rlt;
}
static CURSES_FORCEINLINE char_t top_right() {
static char_t rlt = CRS_DOUBLE_TOP_RIGHT;
return rlt;
}
static CURSES_FORCEINLINE char_t bottom_left() {
static char_t rlt = CRS_DOUBLE_BOTTOM_LEFT;
return rlt;
}
static CURSES_FORCEINLINE char_t bottom_right() {
static char_t rlt = CRS_DOUBLE_BOTTOM_RIGHT;
return rlt;
}
static CURSES_FORCEINLINE char_t horizontal() {
static char_t rlt = CRS_DOUBLE_HORIZONTAL;
return rlt;
}
static CURSES_FORCEINLINE char_t vertical() {
static char_t rlt = CRS_DOUBLE_VERTICAL;
return rlt;
}
};
template<class corners>
class generic_border {
public:
void out(const pen* p,const bounds& bds,const text_color& color) {
p->set_color(color);
// top line
p->outch(0, 0, corners::top_left());
hor_line(p, position(1,0), bds.width-1);
p->outch(bds.width-1, 0, corners::top_right() );
// bottom line
p->outch(0, bds.height-1, corners::bottom_left());
hor_line(p, position(1,bds.height-1), bds.width-1);
p->outch(bds.width-1, bds.height-1, corners::bottom_right());
// left line
vert_line(p, position(0,1), bds.height-1);
// right line
vert_line(p, position(bds.width-1,1), bds.height-1);
}
private:
inline void hor_line(const pen* p, const position& start, uint8_t width)
{
p->out_line(start.x, start.y, width, corners::horizontal() );
}
inline void vert_line(const pen* p, const position& start, uint8_t height) {
for(uint8_t y = start.y; y < height; y++) {
p->outch(start.x, y, corners::vertical() );
}
}
};
} // namesapce detail
//border
border::border(const text_color& color):
color_(color)
{}
border::~border() CURSES_NOEXCEPT
{}
// single_line_border
single_line_border::single_line_border(const text_color& c):
border(c)
{}
void single_line_border::out(const pen* p, const bounds& bds)
{
static detail::generic_border<detail::single_line_corners> impl;
impl.out(p,bds,color());
}
// double_line_border
double_line_border::double_line_border(const text_color& c):
border(c)
{}
void double_line_border::out(const pen* p, const bounds& bds)
{
static detail::generic_border<detail::double_line_corners> impl;
impl.out(p,bds,color());
}
} // namespace curses