-
Notifications
You must be signed in to change notification settings - Fork 1
/
glyph.cpp
138 lines (127 loc) · 2.58 KB
/
glyph.cpp
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
#include "glyph.h"
#include "options.h"
#include "window.h"
#include <sstream>
std::string glyph::save_data()
{
std::stringstream ret;
ret << symbol << " " << int(fg) << " " << int(bg);
return ret.str();
};
void glyph::load_data(std::istream &datastream)
{
int fgtmp, bgtmp;
datastream >> symbol >> fgtmp >> bgtmp;
fg = nc_color(fgtmp);
bg = nc_color(bgtmp);
}
void glyph::load_data_text(std::istream &datastream, std::string owner_name)
{
std::string fgtmp, bgtmp;
char tmpch;
datastream >> tmpch >> fgtmp >> bgtmp;
symbol = tmpch;
fg = color_string(fgtmp);
if (fg == c_null) {
debugmsg("Loaded bad color '%s' (%s)", fgtmp.c_str(), owner_name.c_str());
}
bg = color_string(bgtmp);
if (bg == c_null) {
debugmsg("Loaded bad color '%s' (%s)", fgtmp.c_str(), owner_name.c_str());
}
}
glyph glyph::invert()
{
glyph ret = (*this);
nc_color tmp = ret.fg;
ret.fg = ret.bg;
ret.bg = tmp;
if (NO_BRIGHT_BG) {
ret.bg = non_bright(ret.bg);
}
return ret;
}
glyph glyph::hilite(nc_color back)
{
if (fg == back) {
return invert();
}
glyph ret = (*this);
ret.bg = back;
return ret;
}
std::string glyph::text_formatted()
{
std::stringstream ret;
ret << "<c=" << color_tag(fg) << "," << color_tag(bg) << ">" <<
char(symbol) << "<c=/>";
return ret.str();
}
bool glyph::operator==(const glyph &rhs)
{
return (rhs.fg == fg && rhs.bg == bg && rhs.symbol == symbol);
}
void glyph::make_line_drawing(bool north, bool east, bool south, bool west)
{
if (north) {
if (east) {
if (south) {
if (west) {
symbol = LINE_XXXX;
} else {
symbol = LINE_XXXO;
}
} else {
if (west) {
symbol = LINE_XXOX;
} else {
symbol = LINE_XXOO;
}
}
} else {
if (south) {
if (west) {
symbol = LINE_XOXX;
} else {
symbol = LINE_XOXO;
}
} else {
if (west) {
symbol = LINE_XOOX;
} else {
symbol = LINE_XOXO;
}
}
}
} else {
if (east) {
if (south) {
if (west) {
symbol = LINE_OXXX;
} else {
symbol = LINE_OXXO;
}
} else {
if (west) {
symbol = LINE_OXOX;
} else {
symbol = LINE_OXOX;
}
}
} else {
if (south) {
if (west) {
symbol = LINE_OOXX;
} else {
symbol = LINE_XOXO;
}
} else {
if (west) {
symbol = LINE_OXOX;
} else {
symbol = LINE_XXXX;
}
}
}
}
}