-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.h
83 lines (61 loc) · 1.98 KB
/
window.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
#ifndef WINDOW_H
#define WINDOW_H
#include <string>
#include <SDL2/SDL.h>
#include "color.h"
#include "emuGL.h"
namespace emuGL
{
class Window
{
friend class Shape;
public:
Window(std::string title, int width, int height, Point position, Color bgColor)
: m_title(title),
m_w(width),
m_h(height),
m_pos(position),
m_bgCol(bgColor)
{ initializeSdlObjects(); }
Window(std::string title, int width, int height, Color bgColor)
: Window{title, width, height, {SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED}, bgColor}
{}
Window(std::string title, int width, int height, Point position)
: Window{title, width, height, position, Colors::white}
{}
Window(std::string title, int width, int height)
: Window{title, width, height, {SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED}, Colors::white}
{}
~Window()
{
SDL_DestroyRenderer(m_renderer);
SDL_DestroyWindow(m_window);
SDL_Quit();
}
Window() = delete;
Window(const Window&) = delete;
Window operator=(const Window&) = delete;
/**
* updates a GUI window.
* does not have a main loop, it should be used inside a main loop.
*/
void update();
void attach(const Shape& shape) { m_shapes.push_back(&shape); }
const Color& bgColor() { return m_bgCol; }
void setBgColor(const Color& color) { m_bgCol = color; }
int height() { return m_h; }
int width() { return m_w; }
private:
std::string m_title;
int m_w;
int m_h;
Point m_pos;
Color m_bgCol;
std::vector<const Shape*> m_shapes;
SDL_Window* m_window {};
SDL_Renderer* m_renderer {};
SDL_Event m_currEvent;
void initializeSdlObjects();
};
}
#endif /* WINDOW_H */