-
Notifications
You must be signed in to change notification settings - Fork 8
/
Area.h
259 lines (225 loc) · 5.34 KB
/
Area.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
* Portions Copyright (c) 1999 GMRS Software GmbH
* Carl-von-Linde-Str. 38, D-85716 Unterschleissheim, http://www.gmrs.de
* All rights reserved.
*
* Author: Arno Unkrig <arno@unkrig.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License in the file COPYING for more details.
*/
#ifndef __Area_h_INCLUDED__ /* { */
#define __Area_h_INCLUDED__
#include <sys/types.h>
#include <string>
#include "iconvstream.h"
#include "istr.h"
using std::string;
struct Cell {
int character;
char attribute;
/* these are the decoration properties */
enum {
NONE = 0<<0,
UNDERLINE = 1<<0,
BOLD = 1<<1,
STRIKETHROUGH = 1<<2,
FGCOLOUR = 1<<3,
BGCOLOUR = 1<<4,
COLOUR = FGCOLOUR | BGCOLOUR
};
/* 8-bit colours */
unsigned char fgcolour;
unsigned char bgcolour;
enum {
/* standard */
BLACK = 0,
RED = 1,
GREEN = 2,
YELLOW = 3,
BLUE = 4,
MAGENTA = 5,
CYAN = 6,
WHITE = 7,
/* intense (bright) */
BRBLACK = 8,
BRRED = 9,
BRGREEN = 10,
BRYELLOW = 11,
BRBLUE = 12,
BRMAGENTA = 13,
BRCYAN = 14,
BRWHITE = 15,
/* 216 colours: 16 + 36 * r + 6 * g + b */
/* shades of grey: 233-255 */
DKGREY = 238,
GREY = 244,
BRGREY = 250
};
void clear()
{
character = ' ';
attribute = NONE;
}
};
class Line {
public:
typedef size_t size_type;
Line(size_type l = 0);
Line(const char *);
Line(const string &);
Line(const istr &);
~Line();
size_type length() const
{
return length_;
}
bool empty() const
{
return length_ == 0;
}
const Cell &operator[](size_type x) const
{
return cells_[x];
}
Cell &operator[](size_type x)
{
return cells_[x];
}
const Cell *cells() const
{
return cells_;
}
void resize(size_type l);
void enlarge(size_type l)
{
if (l > length_)
resize(l);
}
void insert(const Line &, size_type x);
void insert(const char *, size_type x);
void insert(const string &, size_type x);
void append(char c);
void append(const Line &l);
void append(const char *p);
const Line &operator+=(char c)
{
append(c);
return *this;
}
const Line &operator+=(const Line &l)
{
append(l);
return *this;
}
const Line &operator+=(const char *p)
{
append(p);
return *this;
}
void set_bgcolour(unsigned char clr);
void set_fgcolour(unsigned char clr);
void add_attribute(char addition);
private:
Line(const Line &);
const Line &operator=(const Line &);
size_type length_;
Cell *cells_;
friend class Area;
};
class Area {
public:
typedef size_t size_type;
enum {
LEFT, CENTER, RIGHT,
TOP, MIDDLE, BOTTOM
};
Area();
Area(size_type w, size_type h = 0, char = ' ', char = Cell::NONE);
Area(const char *);
Area(const string &);
Area(const Line &);
Area(const istr &);
~Area();
size_type width() const
{
return width_;
}
size_type height() const
{
return height_;
}
const Cell *operator[](size_type y) const
{
return cells_[y];
}
Cell *operator[](size_type y)
{
return cells_[y];
}
const Area &operator>>=(size_type rs);
const Area &operator>>=(const char *prefix);
void resize(size_type w, size_type h);
void enlarge(size_type w, size_type h);
void insert(const Line &l, size_type x, size_type y)
{
insert(l.cells_, l.length_, x, y);
}
void insert(const Area &, size_type x, size_type y);
void insert(
const Area &,
size_type x,
size_type y,
size_type w,
size_type h,
int halign,
int valign
);
void insert(const Cell &, size_type x, size_type y);
void insert(const Cell *, size_type count, size_type x, size_type y);
void insert(char, size_type x, size_type y);
void insert(const string &, size_type x, size_type y);
void prepend(int n); // Prepend blank lines at top
void append(int n) // Append blank lines at bottom
{
enlarge(width(), height() + n);
}
const Area &operator+=(const Area &); // Append at bottom!
const Area &operator+=(int n)
{
append(n);
return *this;
}
void fill(const Cell &, size_type x, size_type y, size_type w, size_type h);
void fill(char, size_type x, size_type y, size_type w, size_type h);
void set_bgcolour(unsigned char clr);
void set_fgcolour(unsigned char clr);
void add_attribute(char addition); // ...but not to left and right free areas
void add_attribute(
char addition,
size_type x,
size_type y,
size_type w,
size_type h
);
/* see Area.cpp for the defaults for the below variables */
static bool use_backspaces;
static bool use_ansi;
static Area::size_type widthsize;
static Area::size_type heightsize;
private:
Area(const Area &);
const Area &operator=(const Area &);
size_type width_;
size_type height_;
Cell **cells_;
friend iconvstream &operator<<(iconvstream&, const Area &);
};
#endif /* } */