forked from skift-org/skift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommon.cpp
113 lines (95 loc) · 2.64 KB
/
Common.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
#include <libwidget/Theme.h>
#include "terminal/Common.h"
RefPtr<Font> font()
{
static RefPtr<Font> font = nullptr;
if (font == nullptr)
{
font = Font::get("mono").take_value();
}
return font;
}
static ThemeColorRole _color_to_role[terminal::_COLOR_COUNT] = {
[terminal::BLACK] = THEME_ANSI_BLACK,
[terminal::RED] = THEME_ANSI_RED,
[terminal::GREEN] = THEME_ANSI_GREEN,
[terminal::YELLOW] = THEME_ANSI_YELLOW,
[terminal::BLUE] = THEME_ANSI_BLUE,
[terminal::MAGENTA] = THEME_ANSI_MAGENTA,
[terminal::CYAN] = THEME_ANSI_CYAN,
[terminal::GREY] = THEME_ANSI_WHITE,
[terminal::BRIGHT_BLACK] = THEME_ANSI_BRIGHT_BLACK,
[terminal::BRIGHT_RED] = THEME_ANSI_BRIGHT_RED,
[terminal::BRIGHT_GREEN] = THEME_ANSI_BRIGHT_GREEN,
[terminal::BRIGHT_YELLOW] = THEME_ANSI_BRIGHT_YELLOW,
[terminal::BRIGHT_BLUE] = THEME_ANSI_BRIGHT_BLUE,
[terminal::BRIGHT_MAGENTA] = THEME_ANSI_BRIGHT_MAGENTA,
[terminal::BRIGHT_CYAN] = THEME_ANSI_BRIGHT_CYAN,
[terminal::BRIGHT_GREY] = THEME_ANSI_BRIGHT_WHITE,
[terminal::FOREGROUND] = THEME_ANSI_FOREGROUND,
[terminal::BACKGROUND] = THEME_ANSI_BACKGROUND,
};
Color color(terminal::Color terminal_color)
{
return theme_get_color(_color_to_role[terminal_color]);
}
static Vec2i _cell_size = Vec2i(7, 16);
Recti cell_bound(int x, int y)
{
return {
Vec2i(x, y) * _cell_size,
_cell_size,
};
}
Vec2i cell_size()
{
return _cell_size;
}
void render_cell(
Painter &painter,
int x,
int y,
Codepoint codepoint,
terminal::Color foreground,
terminal::Color background,
terminal::Attributes attributes)
{
Recti bound = cell_bound(x, y);
if (attributes.invert)
{
swap(foreground, background);
}
if (background != terminal::BACKGROUND)
{
painter.clear(bound, color(background));
}
if (attributes.underline)
{
painter.draw_line(
bound.position() + Vec2i(0, 14),
bound.position() + Vec2i(bound.width(), 14),
color(foreground));
}
if (codepoint == U' ')
{
return;
}
auto &glyph = font()->glyph(codepoint);
painter.draw_glyph(
*font(),
glyph,
bound.position() + Vec2i(0, 13),
color(foreground));
if (attributes.bold)
{
painter.draw_glyph(
*font(),
glyph,
bound.position() + Vec2i(1, 13),
color(foreground));
}
}
void render_cell(Painter &painter, int x, int y, terminal::Cell cell)
{
render_cell(painter, x, y, cell.codepoint, cell.attributes.foreground, cell.attributes.background, cell.attributes);
}