-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.h
More file actions
56 lines (45 loc) · 983 Bytes
/
window.h
File metadata and controls
56 lines (45 loc) · 983 Bytes
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
#pragma once
#include "SDL.h"
#include "cassert"
#include "surface.h"
#include <string>
class Window {
private:
SDL_Window* window = nullptr;
Surface surface;
std::string name {};
int width {};
int height {};
public:
Window()
: name("SDL2 Window")
, width(640)
, height(480) {
assert(SDL_Init(SDL_INIT_VIDEO) >= 0);
window = SDL_CreateWindow(name.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN);
assert(window);
surface = SDL_GetWindowSurface(window);
}
Window(const Window& other) = default;
Window& operator=(const Window& other) = default;
~Window() {
SDL_DestroyWindow(window);
SDL_Quit();
}
void setSurface(Surface& new_surface) {
surface = Surface(new_surface);
SDL_UpdateWindowSurface(window);
}
SDL_Window* getWindow() {
return window;
}
SDL_Surface* getSurface() {
return surface.get();
}
int getWidth() {
return width;
}
int getHeight() {
return height;
}
};