-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSGL.h
117 lines (93 loc) · 2.95 KB
/
SGL.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
/*********************************************************
COPYRIGHT NOTICE (C) 2014 Erik Örjehag SGL
You may:
* Make profit using this library.
* Distribute this library.
* Alter the source code.
You may not:
* Leave out proper creadit. If this library
(or a altered version) is used for non
personal use a link to the official website
or the GitHub repository is appropritate.
**********************************************************/
#pragma once;
#include <windows.h>
#include <gdiplus.h>
#pragma comment (lib,"Gdiplus.lib")
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, int nCmdShow);
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
DWORD WINAPI UserThread(LPVOID lpParameter);
class SGL
{
public:
static const Gdiplus::DashStyle SOLID = Gdiplus::DashStyleSolid;
static const Gdiplus::DashStyle DASHED = Gdiplus::DashStyleDash;
static const Gdiplus::DashStyle DOTTED = Gdiplus::DashStyleDot;
private:
int width, height;
HDC screenDC;
HDC bufferDC;
PAINTSTRUCT ps;
HANDLE mxUseGraphics;
Gdiplus::Graphics *graphics;
Gdiplus::GraphicsState gs[100];
unsigned gslen;
int fontSize;
float strokeWidth;
Gdiplus::DashStyle strokeStyle;
byte alpha, red, green, blue;
Gdiplus::Pen *pen;
Gdiplus::SolidBrush *brush;
float xPenPos;
float yPenPos;
void updateTools();
public:
// These should ideally be hidden from the user.
SGL();
HANDLE hUserThread;
HANDLE evCanDraw;
HWND window;
void resize();
void cleanUp();
// ------------------------------------
// API
void waitTillCanUseGraphics();
void stopUsingGraphics();
void render();
void setStrokeWidth(float w);
void setStrokeStyle(int s);
void setColor(byte r, byte g, byte b);
void setAlpha(float a);
void setFontSize(int s);
void setWindowSize(int w, int h);
void setWindowTitle(const WCHAR str[]);
int getWidth();
int getHeight();
void save();
void restore();
void translate(float x, float y);
void rotate(float angle);
void scale(float x, float y);
void clear(byte r, byte g, byte b);
void fillRect(float x, float y, float w, float h);
void fillTriangle(float x, float y, float w, float h);
void fillCircle(float x, float y, float r);
void fillEllipse(float x, float y, float w, float h);
void fillPolygon(Gdiplus::Point &points, int count);
void strokeRect(float x, float y, float w, float h);
void strokeTriangle(float x, float y, float w, float h);
void strokeCircle(float x, float y, float r);
void strokeEllipse(float x, float y, float w, float h);
void strokePolygon(Gdiplus::Point &points, int count);
void drawLine(float startx, float starty, float endx, float endy);
void moveTo(float x, float y);
void lineTo(float x, float y);
void drawString(const WCHAR str[], float x, float y);
void drawImage(Gdiplus::Image *img, float x, float y);
void drawPixel(float x, float y);
Gdiplus::Graphics *useGDI();
Gdiplus::Pen *copyPen();
Gdiplus::SolidBrush *copyBrush();
};
extern SGL *sgl;
void main();