]> git.localhorst.tv Git - gworm.git/blob - src/graphics/Window.cpp
basic gravity calculations
[gworm.git] / src / graphics / Window.cpp
1 #include "Window.h"
2
3 #include <algorithm>
4 #include <cassert>
5 #include <stdexcept>
6 #include <string>
7
8 using std::runtime_error;
9
10
11 namespace gworm {
12
13 const Vector<int> Window::POS_CENTER(
14         SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
15 const Vector<int> Window::POS_UNDEF(
16         SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED);
17
18
19 Window::Window(
20         const char *title,
21         Vector<int> pos,
22         Vector<int> size,
23         Uint32 flags)
24 : win(SDL_CreateWindow(title, pos.x, pos.y, size.x, size.y, flags)) {
25         if (!win) {
26                 throw runtime_error(std::string("create window ") + title
27                         + ": " + SDL_GetError());
28         }
29 }
30
31 Window::~Window() {
32         if (win) SDL_DestroyWindow(win);
33 }
34
35 Window::Window(Window &&other)
36 : win(other.win) {
37         other.win = nullptr;
38 }
39
40 Window &Window::operator =(Window &&other) {
41         std::swap(win, other.win);
42         return *this;
43 }
44
45
46 Vector<int> Window::Size() const {
47         assert(win);
48         Vector<int> size;
49         SDL_GetWindowSize(win, &size.x, &size.y);
50         return size;
51 }
52
53
54 Canvas Window::CreateCanvas(Uint32 flags) {
55         return Canvas(win, -1, flags);
56 }
57
58 }