blob: d6ae6cbce31d5b3fcb462ca754d283e6be02e65f (
plain)
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
|
#include "video.hpp"
#include "debug.hpp"
#include <exception>
#include <cstdint>
extern "C" {
#include <SDL2/SDL.h>
}
using namespace wrapsdl2;
window::window(const std::string& title, std::size_t width, std::size_t height) {
// create (hidden) window
m_window = SDL_CreateWindow(
title.c_str(),
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
static_cast<int>(width),
static_cast<int>(height),
SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN
);
if (m_window == NULL) {
throw std::runtime_error("failed to create SDL window");
}
// create surface
m_surface = SDL_GetWindowSurface(m_window);
}
window::~window() {
SDL_FreeSurface(m_surface);
SDL_DestroyWindow(m_window);
}
void window::show() { SDL_ShowWindow(m_window); }
void window::hide() { SDL_HideWindow(m_window); }
void window::raise() { SDL_RaiseWindow(m_window); }
bool window::visible() {
std::uint32_t flags = SDL_GetWindowFlags(m_window);
return flags & SDL_WINDOW_SHOWN;
}
void window::update() {
SDL_UpdateWindowSurface(m_window);
}
|