-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdraw.cpp
More file actions
103 lines (76 loc) · 1.92 KB
/
draw.cpp
File metadata and controls
103 lines (76 loc) · 1.92 KB
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
#include "draw.h"
extern ISurface* surface;
extern IEngine* engine;
matrix4x4 &draw::w2s = matrix4x4();
void draw::ToScreen(const Vector& world, Vector& scr)
{
float w;
scr.x = w2s[0][0] * world.x + w2s[0][1] * world.y + w2s[0][2] * world.z + w2s[0][3];
scr.y = w2s[1][0] * world.x + w2s[1][1] * world.y + w2s[1][2] * world.z + w2s[1][3];
w = w2s[3][0] * world.x + w2s[3][1] * world.y + w2s[3][2] * world.z + w2s[3][3];
if (w < 0.001f)
{
scr.x *= 100000.f;
scr.y *= 100000.f;
}
else
{
float invw = 1.0f / w;
scr.x *= invw;
scr.y *= invw;
}
int sw, sh;
engine->GetScreenSize(sw, sh);
float x = sw / 2;
float y = sh / 2;
x += 0.5f * scr.x * sw + 0.5f;
y -= 0.5f * scr.y * sh + 0.5f;
scr.x = x;
scr.y = y;
}
void draw::Line(int x0, int y0, int x1, int y1, unsigned color)
{
surface->DrawSetColor(RGBA(color));
surface->DrawLine(x0, y0, x1, y1);
}
void draw::Rect(int x0, int y0, int x1, int y1, unsigned color)
{
surface->DrawSetColor(RGBA(color));
surface->DrawFilledRect(x0, y0, x0 + x1, y0 + y1);
}
void draw::OutlinedRect(int x0, int y0, int x1, int y1, unsigned color)
{
surface->DrawSetColor(RGBA(color));
surface->DrawOutlinedRect(x0, y0, x0 + x1, y0 + y1);
}
void draw::Text(int x, int y, int align, unsigned color, const char* text, ...)
{
wchar_t wstr[128];
char cstr[256];
va_list va_alist;
va_start(va_alist, text);
vsprintf(cstr, text, va_alist);
va_end(va_alist);
MultiByteToWideChar(CP_UTF8, 0, cstr, -1, wstr, 128);
if (align)
{
int w, h;
surface->GetTextSize(GetFont(), wstr, w, h);
if (align == 1 && w > 0)
w /= 2;
x -= w;
}
surface->DrawSetTextColor(RGBA(color));
surface->DrawSetTextPos(x, y);
surface->DrawPrintText(wstr, strlen(cstr));
}
unsigned long draw::GetFont()
{
static unsigned long font = 0;
if (!font)
{
font = surface->CreateFont();
surface->SetFontGlyphSet(font, "sketchflow print normal", 11, 500, 0, 0, 0x200, 0, 0);
}
return font;
}