-
Notifications
You must be signed in to change notification settings - Fork 1
/
ui.hpp
94 lines (67 loc) · 1.92 KB
/
ui.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
#ifndef UI_HPP
#define UI_HPP
#include <memory>
#include <exception>
#include <vector>
#include <thread>
#include <SDL.h>
#include "util.hpp"
void UIInit();
void UIQuit();
class Sprite {
private:
enum {
SOURCE_RGB,
SOURCE_IMAGE
} sourceType;
std::uint8_t red, green, blue;
ImplicitPtr<SDL_Surface> surface;
ImplicitPtr<SDL_Texture> texture;
public:
Sprite(std::uint8_t red, std::uint8_t green, std::uint8_t blue) : sourceType(SOURCE_RGB), red(red), green(green), blue(blue) {};
Sprite(const char *path);
void render(SDL_Renderer *renderer, SDL_Rect *rect);
};
typedef unsigned int SpriteID;
class UIDisplay {
private:
int x, y, width, height;
std::vector<Sprite> sprites;
std::vector<SpriteID> screen;
ImplicitPtr<SDL_Window> window;
ImplicitPtr<SDL_Renderer> renderer;
int spriteWidth, spriteHeight;
int columnNumber, rowNumber;
volatile bool cont;
public:
UIDisplay(
int display = 0,
int x = 0, int y = 0,
int width = -1, int height = -1,
int columnNumber = 20, int rowNumber = 20,
bool fullscreen = false,
const char *title = ""
);
int getX() const noexcept {return x;}
int getY() const noexcept {return y;}
int getWidth() const noexcept {return width;}
int getHeight() const noexcept {return height;}
SpriteID registerSprite(const Sprite &sprite);
void blitSprite(int x, int y, SpriteID id);
void refresh();
void startRefreshing();
void stopRefreshing();
};
class UIDisplayError : public std::exception {
private:
ImplicitPtr<char> reason;
public:
UIDisplayError();
virtual const char *what() const noexcept {return reason;}
};
typedef struct {
SDL_Rect rect;
std::vector<SDL_DisplayMode> modes;
} UIDisplayInfo;
std::vector<UIDisplayInfo> UIGetDisplayInfo();
#endif