coastline 0.0.4
Loading...
Searching...
No Matches
textgrid.h
Go to the documentation of this file.
1#pragma once
2
8
9#include <array>
10#include <cstdint>
11#include <optional>
12#include <string>
13#include <string_view>
14
15namespace coastline {
16
18inline constexpr int GRID_COLUMNS = 80;
19
21inline constexpr int GRID_ROWS = 25;
22
24inline constexpr int CELL_WIDTH = 8;
25
27inline constexpr int CELL_HEIGHT = 16;
28
48
51 {0x00, 0x00, 0x00},
52 {0x00, 0x00, 0xAA},
53 {0x00, 0xAA, 0x00},
54 {0x00, 0xAA, 0xAA},
55 {0xAA, 0x00, 0x00},
56 {0xAA, 0x00, 0xAA},
57 {0xAA, 0x55, 0x00},
58 {0xAA, 0xAA, 0xAA},
59 {0x55, 0x55, 0x55},
60 {0x55, 0x55, 0xFF},
61 {0x55, 0xFF, 0x55},
62 {0x55, 0xFF, 0xFF},
63 {0xFF, 0x55, 0x55},
64 {0xFF, 0x55, 0xFF},
65 {0xFF, 0xFF, 0x55},
66 {0xFF, 0xFF, 0xFF},
67}};
68
70inline constexpr std::uint8_t REPLACEMENT_GLYPH = 0;
71
79
84std::uint8_t Cp437FromCodepoint(char32_t codepoint);
85
91
97
99class TextGrid {
100public:
106 TextCell &At(int column, int row);
107
113 const TextCell &At(int column, int row) const;
114
126 void Fill(int column,
127 int row,
128 int width,
129 int height,
130 std::uint8_t glyph,
131 CgaColor foreground,
132 CgaColor background);
133
144 void Write(int column,
145 int row,
147 CgaColor foreground,
148 CgaColor background,
149 int width = -1);
150
161 void WriteUtf8(int column,
162 int row,
163 std::string_view text,
164 CgaColor foreground,
165 CgaColor background,
166 int width = -1);
167
179 void Box(int column,
180 int row,
181 int width,
182 int height,
183 CgaColor foreground,
184 CgaColor background,
185 bool doubled);
186
196 void Shadow(int column, int row, int width, int height);
197
200
201private:
203 TextCell m_outside{};
204};
205
206} // namespace coastline
The cells of the screen and the place of the text cursor.
Definition textgrid.h:99
void Shadow(int column, int row, int width, int height)
Darken the cells one row below and two columns right of a box, as the shadow of a dialog of the QBASI...
const TextCell & At(int column, int row) const
void Box(int column, int row, int width, int height, CgaColor foreground, CgaColor background, bool doubled)
Draw the frame of a box with the lines of code page 437 and fill its inside.
std::optional< std::array< int, 2 > > cursor
The cell the text cursor blinks in, or none when it does not show.
Definition textgrid.h:199
void Write(int column, int row, std::u32string_view text, CgaColor foreground, CgaColor background, int width=-1)
Write text along a row, a cell for each code point, cut at width cells.
void Fill(int column, int row, int width, int height, std::uint8_t glyph, CgaColor foreground, CgaColor background)
Fill a rectangle of cells with one character in two colours.
TextCell & At(int column, int row)
void WriteUtf8(int column, int row, std::string_view text, CgaColor foreground, CgaColor background, int width=-1)
Write UTF-8 text along a row, as Write() writes code points.
Definition assetimport.h:11
constexpr int CELL_WIDTH
The width of a cell in pixels.
Definition textgrid.h:24
CgaColor
The 16 colours of CGA, by their number.
Definition textgrid.h:30
@ Cyan
Definition textgrid.h:34
@ White
Definition textgrid.h:46
@ LightBlue
Definition textgrid.h:40
@ Yellow
Definition textgrid.h:45
@ LightGreen
Definition textgrid.h:41
@ DarkGray
Definition textgrid.h:39
@ Blue
Definition textgrid.h:32
@ Magenta
Definition textgrid.h:36
@ LightCyan
Definition textgrid.h:42
@ Green
Definition textgrid.h:33
@ Black
Definition textgrid.h:31
@ Brown
Definition textgrid.h:37
@ Red
Definition textgrid.h:35
@ LightMagenta
Definition textgrid.h:44
@ LightRed
Definition textgrid.h:43
@ LightGray
Definition textgrid.h:38
constexpr int CELL_HEIGHT
The height of a cell in pixels.
Definition textgrid.h:27
std::u32string DecodeUtf8(std::string_view text)
constexpr int GRID_ROWS
The rows of the grid.
Definition textgrid.h:21
constexpr std::array< std::array< std::uint8_t, 3 >, 16 > CGA_PALETTE
The red, green, and blue of each colour of CGA, by its number.
Definition textgrid.h:50
constexpr int GRID_COLUMNS
The columns of the grid.
Definition textgrid.h:18
constexpr std::uint8_t REPLACEMENT_GLYPH
The glyph drawn for a character code page 437 does not have.
Definition textgrid.h:70
std::string EncodeUtf8(std::u32string_view text)
std::uint8_t Cp437FromCodepoint(char32_t codepoint)
A cell of the grid.
Definition textgrid.h:73
bool underline
Definition textgrid.h:77
CgaColor foreground
Definition textgrid.h:75
std::uint8_t glyph
Definition textgrid.h:74
CgaColor background
Definition textgrid.h:76