-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.hh
54 lines (44 loc) · 1.29 KB
/
window.hh
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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright (c) 2017 Chris Gregory [email protected]
*/
#ifndef HEADER_GUARD_WINDOW_H
#define HEADER_GUARD_WINDOW_H
#include <SDL2/SDL.h>
#include <utility>
#include "error.hh"
namespace sdl {
class renderer;
class window {
SDL_Window* _window;
public:
window(const char* title, int x, int y, int w, int h,
Uint32 flags)
: window(SDL_CreateWindow(title, x, y, w, h, flags)) {}
explicit window(SDL_Window* window)
: _window(window) {
throw_if(!window);
}
~window() noexcept { SDL_DestroyWindow(_window); }
window(window&& other) noexcept : _window(0) { swap(other); }
window& operator=(window&& other) noexcept {
swap(other);
return *this;
}
SDL_Window* get() noexcept { return _window; }
void swap(window& other) { std::swap(_window, other._window); }
int width() const noexcept {
int w;
SDL_GetWindowSize(_window, &w, nullptr);
return w;
}
int height() const noexcept {
int h;
SDL_GetWindowSize(_window, nullptr, &h);
return h;
}
};
}
#endif