-
Notifications
You must be signed in to change notification settings - Fork 4
/
Canvas.h
119 lines (102 loc) · 3.05 KB
/
Canvas.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
#pragma once
#include <bakkesmod\wrappers\canvaswrapper.h>
// Macro from wingdi.h
#undef GetCharWidth
namespace Canvas {
struct Color {
unsigned char r = 0;
unsigned char g = 255;
unsigned char b = 0;
unsigned char a = 255;
const static Color WHITE;
const static Color BLACK;
const static Color RED;
const static Color GREEN;
const static Color BLUE;
operator LinearColor()
{
return LinearColor{ (float)this->r, (float)this->g, (float)this->b, (float)this->a };
}
};
inline Color to_color(LinearColor lColor)
{
return Color{ (unsigned char)lColor.R, (unsigned char)lColor.G, (unsigned char)lColor.B, (unsigned char)lColor.A };
}
enum class Alignment {
LEFT = -1,
CENTER = 0,
RIGHT = 1,
};
struct CanvasColumnOptions {
Alignment alignment = Alignment::LEFT;
float width = 0; // 0 for auto
std::optional<float> maxWidth;
};
struct CanvasTableOptions {
Color textColor = Color::WHITE;
bool background = true;
Color backgroundColor = Color::BLACK;
bool borders = false;
Color borderColor = Color::WHITE;
float width = 0; // 0 for auto
float padding = 5;
};
struct CanvasTableContext {
int totalCols = 0;
CanvasTableOptions tableOptions;
std::vector<CanvasColumnOptions> columnOptions;
std::vector<std::vector<std::string>> rows;
float verticalPadding = 3;
};
struct CanvasContext {
CanvasWrapper canvas;
bool ctxSet;
float scale = 1.0f;
char alpha = (char)255;
CanvasTableContext tableContext;
CanvasContext() : canvas(NULL) {
ctxSet = false;
}
};
void SetContext(CanvasWrapper canvas);
bool IsContextSet();
float GetCharHeight();
float GetStringWidth(std::string str);
// Forward methods
void SetColor(char red, char green, char blue, char alpha);
void SetPosition(Vector2 pos);
Vector2 GetPosition();
void DrawBox(Vector2 size);
void FillBox(Vector2 size);
void FillTriangle(Vector2 p1, Vector2 p2, Vector2 p3, LinearColor color);
void DrawLine(Vector2 start, Vector2 end);
void DrawLine(Vector2 start, Vector2 end, float width);
void DrawRect(Vector2 start, Vector2 end);
Vector2 Project(Vector location);
Vector2 GetSize();
void SetPosition(Vector2F pos);
Vector2F GetPositionFloat();
void DrawBox(Vector2F size);
void FillBox(Vector2F size);
void FillTriangle(Vector2F p1, Vector2F p2, Vector2F p3, LinearColor color);
void DrawString(std::string text);
void DrawString(std::string text, float xScale, float yScale);
void DrawLine(Vector2F start, Vector2F end);
void DrawLine(Vector2F start, Vector2F end, float width);
void DrawRect(Vector2F start, Vector2F end);
Vector2F ProjectF(Vector location);
// Helpers
char GetGlobalAlpha();
void SetGlobalAlpha(char alpha);
void SetColor(Color color);
void SetColor(Color color, char alpha);
void SetScale(float scale);
void SetPosition(int x, int y);
void SetPosition(float x, float y);
void DrawRect(Vector2 size);
void BeginTable(CanvasTableOptions tableOptions = {});
void Columns(std::vector<CanvasColumnOptions> columns);
void Row(const std::vector<std::string>& rowData);
void EndTable();
float GetTableRowHeight();
}