-
Notifications
You must be signed in to change notification settings - Fork 0
/
SDL_Screen.hpp
182 lines (138 loc) · 7.54 KB
/
SDL_Screen.hpp
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#ifndef SDL_SCREEN_HPP
#define SDL_SCREEN_HPP
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <cmath>
#include <vector>
#include <sstream>
class SDL_Screen{
protected:
int _width;
int _height;
long _ms;
SDL_Window *w;
SDL_Renderer *r;
SDL_Event e;
const char * title;
double _fps;
double fps_max = 180;
static bool instanceExist;
bool program_running;
unsigned char _red;
unsigned char _green;
unsigned char _blue;
unsigned char _alpha;
void SDL_ExitWithError(const char *string);
double distance(double x1, double y1, double x2, double y2);
public:
/// @brief creates a screen of 600*480 entitled "SDL_Screen" with 30 fps and Open SDL (initialisation)
SDL_Screen();
/// @brief creates a screen entitled "SDL_Screen" with 30 fps
/// @param window_width width of the screen
/// @param window_height height of the screen
SDL_Screen(double window_width, double window_height);
/// @brief creates a screen entitled "SDL_Screen" and Open SDL (initialisation)
/// @param window_width width of the screen
/// @param window_height height of the screen
/// @param fps frames per second
SDL_Screen(double window_width, double window_height, double fps);
/// @brief creates a screen of 600*480 with 30 fps and Open SDL (initialisation)
/// @param window_title title of the new screen
SDL_Screen(const char* window_title);
/// @brief creates a screen with 30 fps
/// @param window_width width of the screen
/// @param window_height height of the screen
/// @param window_title title of the screen
SDL_Screen(double window_width, double window_height, const char* window_title);
/// @brief creates a screen and Open SDL (initialisation)
/// @param window_width width of the screen
/// @param window_height height of the screen
/// @param window_title title of the screen
/// @param fps frames per second
SDL_Screen(double window_width, double window_height, const char* window_title, double fps);
/// @brief Quit SDL, prints if it's a success or not in the cout
~SDL_Screen();
bool OpenSDL();
int W();
int H();
double getFPS();
/// @brief refresh the screen with the new shapes
/// @return true if successful
bool refresh();
/// @brief refresh the screen with the new shapes and adds to the cout calculations ticks, freezed ticks and total ticks
/// @return true if successful
bool refreshAndDetails();
/// @brief refresh the screen with the new shapes and asks for events
/// @return true if successful
bool refreshAndEvents();
/// @brief refresh the screen with the new shapes, asks for events and adds to the cout calculations ticks, freezed ticks and total ticks
/// @return true if successful
bool refreshAndDetailsAndEvents();
bool freeze(unsigned int ms);
bool CloseSDL();
void point(double x, double y);
void point(double x, double y, double thickness);
void setColor(int red, int green, int blue, int alpha);
void setColor(int red, int green, int blue);
void setColor(int grey);
void bg();
void bg(int grey);
void bg(int red, int green, int blue);
void updateSize();
void line(int x1, int y1, int x2, int y2);
/// @brief creates an empty square
/// @param x the upper left x-coordinate
/// @param y the upper left y-coordinate
/// @param size the widht and height of the square
void emptyRect(int x, int y, int size);//optimized
/// @brief creates an empty rectangle
/// @param x the upper left x-coordinate
/// @param y the upper left y-coordinate
/// @param width the width of the rectangle
/// @param height the height of the rectangle
void emptyRect(int x, int y, int width, int height);//optimized
void emptyRect(int x, int y, int width, int height, int rounding);
void emptyRect(int x, int y, int width, int height, int rounding, unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255);
//void emptyRect(int x, int y, int width, int height, int rounding_top_left, int rounding_top_right, int rounding_bottom_right, int rounding_bottom_left);//todo
/// @brief creates a filled square
/// @param x the upper left x-coordinate
/// @param y the upper left y-coordinate
/// @param size the witdh and height of the square
void filledRect(int x, int y, int size);//optimized
/// @brief creates a filled rectangle
/// @param x the upper left x-coordinate
/// @param y the upper left y-coordinate
/// @param width the width of the rectangle
/// @param height the height of the rectangle
void filledRect(int x, int y, int width, int height);//optimized
void filledRect(int x, int y, int width, int height, int rounding);//optimized
void filledRect(int x, int y, int width, int height, int rounding, unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255);//optimized
//void filledRect(int x, int y, int width, int height, int rounding_top_left, int rounding_top_right, int rounding_bottom_right, int rounding_bottom_left);//todo
void filledCircle(int x, int y, int radius);//optimized
void filledCircle(int x, int y, int radius, unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255);//optimized
void filledCircle(int x, int y, int width, int height);//optimized
void emptyCircle(int x, int y, int radius);//optimized
void emptyCircle(int x, int y, int width, int height);//optimized
//void emptyCircle(int x, int y, int width, int height, double thickness);
void filledTriangleP(int x1, int y1, int x2, int y2, int x3, int y3);//more precise version
void filledTriangle(int x1, int y1, int x2, int y2, int x3, int y3);
void emptyTriangle(int x1, int y1, int x2, int y2, int x3, int y3);
void filledPolygon(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
void emptyPolygon(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
bool setFPS(double fps);
bool isRunning();
void stopRunning();
virtual void events();
static bool rollover(int mx, int my, int x, int y, int w, int h);
bool setFont(TTF_Font **font, const char * font_file, int size);
bool text(int x, int y, const char * text, TTF_Font *font);
bool text(int x, int y, const char * text, TTF_Font *font, unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255);
//bool text(int x, int y, std::string text, TTF_Font *font, unsigned char red=255, unsigned char green=255, unsigned char blue=255, unsigned char alpha=255){
void paragraph(int x, int y, const char* text, TTF_Font* font,
unsigned char red, unsigned char green=255, unsigned char blue=255, unsigned char alpha=255);
void paragraph(int x, int y, const char* text, TTF_Font* font);
void displayPortions(int cut_x, int cut_y, unsigned char red=255, unsigned char green=0, unsigned char blue=0);
std::string add_ENTER_every(int n, std::string str);
};
#endif