X-Git-Url: http://git.localhorst.tv/?p=space.git;a=blobdiff_plain;f=src%2Fgraphics%2FWindow.cpp;fp=src%2Fgraphics%2FWindow.cpp;h=7cf1b3a9dd1da54eb64afbd41a8607b2b32a9e99;hp=0000000000000000000000000000000000000000;hb=61c2d30a60d586cbe63885885c6a373c7713af1e;hpb=08d0e47634e1632c96ebe3308535a86f5e625b40 diff --git a/src/graphics/Window.cpp b/src/graphics/Window.cpp new file mode 100644 index 0000000..7cf1b3a --- /dev/null +++ b/src/graphics/Window.cpp @@ -0,0 +1,58 @@ +#include "Window.h" + +#include +#include +#include +#include + +using std::runtime_error; + + +namespace space { + +const Vector Window::POS_CENTER( + SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); +const Vector Window::POS_UNDEF( + SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED); + + +Window::Window( + const char *title, + Vector pos, + Vector size, + Uint32 flags) +: win(SDL_CreateWindow(title, pos.x, pos.y, size.x, size.y, flags)) { + if (!win) { + throw runtime_error(std::string("create window ") + title + + ": " + SDL_GetError()); + } +} + +Window::~Window() { + if (win) SDL_DestroyWindow(win); +} + +Window::Window(Window &&other) +: win(other.win) { + other.win = nullptr; +} + +Window &Window::operator =(Window &&other) { + std::swap(win, other.win); + return *this; +} + + +Vector Window::Size() const { + assert(win); + Vector size; + SDL_GetWindowSize(win, &size.x, &size.y); + return size; +} + + +Canvas Window::CreateCanvas(Uint32 flags) { + return Canvas(win, -1, flags); +} + +}