-
Notifications
You must be signed in to change notification settings - Fork 0
/
SDLGUI.h
78 lines (49 loc) · 1.68 KB
/
SDLGUI.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
#ifndef __SDLGUI_h
#define __SDLGUI_h
#include <thread>
#include <mutex>
#include <string>
#include <dinrhiw/dinrhiw.h>
#include <SDL.h>
bool equal(volatile unsigned char* volatile x, volatile unsigned char* volatile y);
class SDLGUI : public whiteice::VisualizationInterface
{
public:
SDLGUI(const std::string windowtitle);
~SDLGUI();
bool initialize();
// shows/opens graphics window
virtual bool show();
// hides/closes graphics window
virtual bool hide();
// gets maximum X+1 coordinate
virtual unsigned int getScreenX();
// gets maximum Y+1 coordinate
virtual unsigned int getScreenY();
// plots pixel to screen (white as the default)
virtual bool plot(unsigned int x, unsigned int y,
unsigned int r = 255, unsigned int g = 255, unsigned int b = 255);
// clears screen to wanted color (black as the default)
virtual bool clear(unsigned int r = 0, unsigned int g = 0, unsigned int b = 0);
// updates plotted pixels to screen
virtual bool updateScreen();
// blocks until key have been pressed
virtual bool waitKeypress();
// returns true if there have been keypress since the last call
virtual bool keypress();
private:
std::string title;
bool initialized = false;
// keeps updating screen every one second so GUI is responsive
void loop();
bool running = false;
std::mutex thread_mutex;
std::thread* gui_thread = nullptr;
// SDL variables
SDL_Window* window = NULL;
SDL_Renderer* renderer = NULL;
std::mutex sdl_mutex;
volatile unsigned int sdl_keypresses = 0;
volatile bool keypress_happened = false;
};
#endif