Repository navigation
Expand file tree
/
Copy pathrsdl.hpp
More file actions
103 lines (92 loc) · 2.47 KB
/
Copy pathrsdl.hpp
File metadata and controls
103 lines (92 loc) · 2.47 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
#ifndef __RSDL_H__
#define __RSDL_H__
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
struct Point {
Point(int x, int y);
int x;
int y;
Point operator+(const Point) const;
Point operator-(const Point) const;
Point operator*(const int)const;
Point operator/(const int) const;
Point &operator+=(const Point);
Point &operator-=(const Point);
Point &operator*=(const int);
Point &operator/=(const int);
operator SDL_Point();
};
Point operator*(const int, const Point);
std::ostream &operator<<(std::ostream &stream, const Point);
struct RGB {
RGB(int r, int g, int b);
Uint8 red;
Uint8 green;
Uint8 blue;
};
const RGB WHITE(255, 255, 255);
const RGB YELLOW(255, 255, 0);
const RGB MAGENTA(255, 0, 255);
const RGB RED(255, 0, 0);
const RGB CYAN(0, 255, 255);
const RGB GREEN(0, 255, 0);
const RGB BLUE(0, 0, 255);
const RGB BLACK(0, 0, 0);
class Event {
public:
Event();
Event(SDL_Event _sdlEvent);
enum EventType {
NA,
LCLICK,
RCLICK,
LRELEASE,
RRELEASE,
MMOTION,
KEY_PRESS,
QUIT
};
EventType get_type() const;
Point get_mouse_position() const;
Point get_relative_mouse_position() const;
char get_pressed_key() const;
protected:
SDL_Event sdlEvent;
};
class Window {
public:
Window(Point size = Point(640, 480), std::string title = "RSDL");
~Window();
Window &operator=(const Window &);
void draw_img(std::string filename, Point src = Point(0, 0),
Point size = Point(0, 0), double angle = 0,
bool flip_horizontal = false, bool flip_vertical = false);
void show_text(std::string input, Point src, RGB color = WHITE,
std::string font_addr = "FreeSans.ttf", int size = 24);
void draw_point(Point, RGB color = WHITE);
void draw_line(Point src, Point dst, RGB color = WHITE);
void draw_rect(Point src, Point size, RGB color = WHITE,
unsigned int line_width = 4);
void fill_rect(Point src, Point size, RGB color = WHITE);
void fill_circle(Point center, int radius, RGB color = WHITE);
void update_screen();
void clear();
Event poll_for_event();
void dump_err();
protected:
Point size;
SDL_Window *win;
SDL_Renderer *renderer;
std::map<std::string, SDL_Texture *> texture_cache;
std::map<std::string, TTF_Font *> fonts_cache;
void set_color(RGB color);
void init();
};
void delay(int millisecond);
Point get_current_mouse_position();
#endif