-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graphics.h
154 lines (139 loc) · 4.02 KB
/
Graphics.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
/*
* PlayLib - V1.5
*
* Description: Biblioteca grafica 2D.
*
* Author: Augusto Baffa (VisionLab - PUC-Rio)
* Web: http://www.inf.puc-rio.br/~abaffa/
* Email: elima@inf.puc-rio.br
*
*
*/
#ifndef _GRAPHICS_H_
#define _GRAPHICS_H_
#include "freeglut.h"
#include <math.h>
//Teclas Especiais
#define KEY_F1 128
#define KEY_F2 129
#define KEY_F3 130
#define KEY_F4 131
#define KEY_F5 132
#define KEY_F6 133
#define KEY_F7 134
#define KEY_F8 135
#define KEY_F9 136
#define KEY_F10 137
#define KEY_F11 138
#define KEY_F12 139
#define KEY_LEFT 227
#define KEY_UP 228
#define KEY_RIGHT 229
#define KEY_DOWN 230
#define KEY_PAGE_UP 231
#define KEY_PAGE_DOWN 232
#define KEY_HOME 233
#define KEY_END 234
#define KEY_INSERT 235
#define KEY_ESC 27
#define KEY_ENTER 13
#define KEY_BACKSPACE 8
#define KEY_LEFTCTRL 241
#define KEY_RIGHTCTRL 242
#define KEY_LEFTSHIFT 239
#define KEY_RIGHTSHIFT 240
#define KEY_LEFTALT 243
#define KEY_RIGHTALT 244
#define KEY_TAB 9
//Botoes do Mouse
#define MOUSE_LEFT_BUTTON 0x0000
#define MOUSE_MIDDLE_BUTTON 0x0001
#define MOUSE_RIGHT_BUTTON 0x0002
//Estados dos botões do mouse
#define MOUSE_STATE_DOWN 0x0000
#define MOUSE_STATE_UP 0x0001
//Estados das teclas
#define KEY_STATE_DOWN 0x0000
#define KEY_STATE_UP 0x0001
//Font Weights
#define FONT_WEIGHT_NONE 0
#define FONT_WEIGHT_THIN 100
#define FONT_WEIGHT_EXTRALIGHT 200
#define FONT_WEIGHT_LIGHT 300
#define FONT_WEIGHT_NORMAL 400
#define FONT_WEIGHT_MEDIUM 500
#define FONT_WEIGHT_SEMIBOLD 600
#define FONT_WEIGHT_BOLD 700
#define FONT_WEIGHT_EXTRABOLD 800
#define FONT_WEIGHT_HEAVY 900
typedef void (*MainLoolCallback)();
typedef void (*MouseMotionCallback)(int x, int y);
typedef void (*MouseClickCallback)(int button, int state, int x, int y);
typedef void (*KeyboardInputCallback)(int key, int state, int x, int y);
namespace PlayLib
{
typedef struct{
int r;
int g;
int b;
} Color;
class Image
{
public:
Image();
unsigned int image;
int x;
int y;
int width;
int height;
bool active;
typedef void (*OnClickCallback)(int button, int state, int xx, int yy);
OnClickCallback onclickcallback;
void LoadPNGImage(char *filename);
void SetOnClick(void (*callback)(int button, int state, int xx, int yy));
void SetPosition(int px, int py, int pwidth, int pheight);
private:
void OnClick(int button, int state, int xx, int yy);
};
class Graphics
{
public:
Graphics();
void CreateMainWindow(int sizeX, int sizeY, char title[]);
void SetMainLoop(void (*callback)());
void SetKeyboardInput(void (*callback)(int key, int state, int x, int y));
void SetMouseClickInput(void (*callback)(int button, int state, int x, int y));
void SetMouseMotionInput(void (*callback)(int x, int y));
void StartMainLoop(void);
void DrawText2D(int x, int y, const char *text, ...);
void SetTextFont(const char *font_name, int size, int weight, bool italic, bool underline);
void DrawImage2D(Image image);
void DrawImage2D(int x, int y, int width, int height, Image image);
void DrawImage2D(int x, int y, int width, int height, int crop_x, int crop_y, int crop_width, int crop_height, Image image);
void DrawLine2D(int x1, int y1, int x2, int y2);
void DrawPoint2D(int x, int y);
void RotateBegin(float angle);
void RotateEnd();
void DrawCircle2D(int x, int y, int radius);
void FillCircle2D(int x, int y, int radius, int segments);
void DrawTriangle2D(int x1, int y1, int x2, int y2, int x3, int y3);
void FillTriangle2D(int x1, int y1, int x2, int y2, int x3, int y3);
void FillRectangle2D(int x1, int y1, int x2, int y2);
void DrawRectangle2D(int x1, int y1, int x2, int y2);
void SetBackgroundColor(float r, float g, float b);
void SetColor(float r, float g, float b);
void SetLineWidth(float width);
void SetFullscreen(bool enable);
float GetFPS();
float GetElapsedTime();
int GetScreenWidth();
int GetScreenHeight();
Color GetColor(int x, int y);
Color GetColor(int x, int y, Image image);
private:
bool is_rotating;
float rotation_angle;
};
}
using namespace PlayLib;
#endif