-
Notifications
You must be signed in to change notification settings - Fork 2
/
PlatCurses.h
168 lines (142 loc) · 6.64 KB
/
PlatCurses.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
// Copyright 2012-2024 Mitchell. See LICENSE.
// Scintilla platform for a curses (terminal) environment.
#ifndef PLAT_CURSES_H
#define PLAT_CURSES_H
namespace Scintilla::Internal {
class FontImpl : public Font {
public:
/**
* Sets terminal character attributes for a particular font.
* These attributes are a union of curses attributes and stored in the font's `attrs` member.
*/
FontImpl(const FontParameters &fp);
virtual ~FontImpl() noexcept override = default;
attr_t attrs = 0;
};
class SurfaceImpl : public Surface {
WINDOW *win = nullptr; // curses window to draw on
PRectangle clip;
ColourRGBA pixmapColor;
public:
SurfaceImpl() = default;
~SurfaceImpl() noexcept override;
void Init(WindowID wid) override;
void Init(SurfaceID sid, WindowID wid) override;
std::unique_ptr<Surface> AllocatePixMap(int width, int height) override;
void SetMode(SurfaceMode mode) override;
void Release() noexcept override;
int SupportsFeature(Supports feature) noexcept override;
bool Initialised() override;
int LogPixelsY() override;
int PixelDivisions() override;
int DeviceHeightFont(int points) override;
void LineDraw(Point start, Point end, Stroke stroke) override;
void PolyLine(const Point *pts, size_t npts, Stroke stroke) override;
void Polygon(const Point *pts, size_t npts, FillStroke fillStroke) override;
void RectangleDraw(PRectangle rc, FillStroke fillStroke) override;
void RectangleFrame(PRectangle rc, Stroke stroke) override;
void FillRectangle(PRectangle rc, Fill fill) override;
void FillRectangleAligned(PRectangle rc, Fill fill) override;
void FillRectangle(PRectangle rc, Surface &surfacePattern) override;
void RoundedRectangle(PRectangle rc, FillStroke fillStroke) override;
void AlphaRectangle(PRectangle rc, XYPOSITION cornerSize, FillStroke fillStroke) override;
void GradientRectangle(
PRectangle rc, const std::vector<ColourStop> &stops, GradientOptions options) override;
void DrawRGBAImage(
PRectangle rc, int width, int height, const unsigned char *pixelsImage) override;
void Ellipse(PRectangle rc, FillStroke fillStroke) override;
void Stadium(PRectangle rc, FillStroke fillStroke, Ends ends) override;
void Copy(PRectangle rc, Point from, Surface &surfaceSource) override;
std::unique_ptr<IScreenLineLayout> Layout(const IScreenLine *screenLine) override;
void DrawTextNoClip(PRectangle rc, const Font *font_, XYPOSITION ybase, std::string_view text,
ColourRGBA fore, ColourRGBA back) override;
void DrawTextClipped(PRectangle rc, const Font *font_, XYPOSITION ybase, std::string_view text,
ColourRGBA fore, ColourRGBA back) override;
void DrawTextTransparent(PRectangle rc, const Font *font_, XYPOSITION ybase,
std::string_view text, ColourRGBA fore) override;
void MeasureWidths(const Font *font_, std::string_view text, XYPOSITION *positions) override;
XYPOSITION WidthText(const Font *font_, std::string_view text) override;
void DrawTextNoClipUTF8(PRectangle rc, const Font *font_, XYPOSITION ybase, std::string_view text,
ColourRGBA fore, ColourRGBA back) override;
void DrawTextClippedUTF8(PRectangle rc, const Font *font_, XYPOSITION ybase,
std::string_view text, ColourRGBA fore, ColourRGBA back) override;
void DrawTextTransparentUTF8(PRectangle rc, const Font *font_, XYPOSITION ybase,
std::string_view text, ColourRGBA fore) override;
void MeasureWidthsUTF8(const Font *font_, std::string_view text, XYPOSITION *positions) override;
XYPOSITION WidthTextUTF8(const Font *font_, std::string_view text) override;
XYPOSITION Ascent(const Font *font_) override;
XYPOSITION Descent(const Font *font_) override;
XYPOSITION InternalLeading(const Font *font_) override;
XYPOSITION Height(const Font *font_) override;
XYPOSITION AverageCharWidth(const Font *font_) override;
void SetClip(PRectangle rc) override;
void PopClip() override;
void FlushCachedState() override;
void FlushDrawing() override;
// Custom drawing functions for Curses.
void DrawLineMarker(
const PRectangle &rcWhole, const Font *fontForCharacter, int tFold, const void *data);
void DrawWrapMarker(PRectangle rcPlace, bool isEndMarker, ColourRGBA wrapColour);
void DrawTabArrow(PRectangle rcTab, const ViewStyle &vsDraw);
bool isCallTip = false;
};
class ListBoxImpl : public ListBox {
int height = 5, width = 10;
std::vector<std::string> list;
char types[IMAGE_MAX + 1][5]; // UTF-8 character plus terminating '\0' instead of an image
int selection = 0;
public:
IListBoxDelegate *delegate = nullptr;
ListBoxImpl();
~ListBoxImpl() override = default;
void SetFont(const Font *font) override;
void Create(Window &parent, int ctrlID, Point location_, int lineHeight_, bool unicodeMode_,
Technology technology_) override;
void SetAverageCharWidth(int width) override;
void SetVisibleRows(int rows) override;
int GetVisibleRows() const override;
PRectangle GetDesiredRect() override;
int CaretFromEdge() override;
void Clear() noexcept override;
void Append(char *s, int type) override;
int Length() override;
void Select(int n) override;
int GetSelection() override;
int Find(const char *prefix) override;
std::string GetValue(int n) override;
void RegisterImage(int type, const char *xpm_data) override;
void RegisterRGBAImage(
int type, int width, int height, const unsigned char *pixelsImage) override;
void ClearRegisteredImages() override;
void SetDelegate(IListBoxDelegate *lbDelegate) override;
void SetList(const char *listText, char separator, char typesep) override;
void SetOptions(ListOptions options_) override;
};
void init_colors();
short term_color(ColourRGBA color);
short term_color(short color);
} // namespace Scintilla::Internal
/**
* Returns the given Scintilla `WindowID` as a curses `WINDOW`.
* @param w A Scintilla `WindowID`.
* @return curses `WINDOW`.
*/
#define _WINDOW(w) reinterpret_cast<WINDOW *>(w)
/**
* Returns the curses `COLOR_PAIR` for the given curses foreground and background `COLOR`s.
* This is used simply to enumerate every possible color combination.
* Note: only 256 combinations are possible due to curses portability.
* Note: This references the global curses variable `COLORS` and is not a constant expression.
* @param f The curses foreground `COLOR`.
* @param b The curses background `COLOR`.
* @return int number for defining a curses `COLOR_PAIR`.
*/
#define SCI_COLOR_PAIR(f, b) ((b) * ((COLORS < 16) ? 8 : 16) + (f) + 1)
/**
* Returns a curses color pair from the given fore and back colors.
* @param f Foreground color, either a Scintilla color or curses color.
* @param b Background color, either a Scintilla color or curses color.
* @return curses color pair suitable for calling `COLOR_PAIR()` with.
*/
#define term_color_pair(f, b) SCI_COLOR_PAIR(term_color(f), term_color(b))
#endif