1 #include "ge211_window.h" 2 #include "ge211_error.h" 8 using namespace detail;
10 Window::Window(
const std::string& title, Dimensions dim)
11 : ptr_{SDL_CreateWindow(title.c_str(),
12 SDL_WINDOWPOS_UNDEFINED,
13 SDL_WINDOWPOS_UNDEFINED,
20 throw Host_error{
"Could not create window"};
23 uint32_t Window::get_flags_() const noexcept
25 return SDL_GetWindowFlags(get_raw_());
31 SDL_GetWindowSize(get_raw_(), &result.width, &result.height);
37 SDL_SetWindowSize(get_raw_(), dims.
width, dims.
height);
39 if (get_dimensions() != dims)
43 const char* Window::get_title() const noexcept
45 return SDL_GetWindowTitle(get_raw_());
48 void Window::set_title(
const std::string& title) noexcept
50 SDL_SetWindowTitle(get_raw_(), title.c_str());
53 bool Window::get_resizeable() const noexcept
55 return (get_flags_() & SDL_WINDOW_RESIZABLE) != 0;
58 void Window::set_resizeable(
bool resizable) noexcept
60 SDL_SetWindowResizable(get_raw_(), resizable? SDL_TRUE : SDL_FALSE);
66 SDL_GetWindowPosition(get_raw_(), &result.x, &result.y);
72 SDL_SetWindowPosition(get_raw_(), position.
x, position.
y);
75 const Position Window::centered{SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED};
77 bool Window::get_fullscreen() const noexcept
79 return (get_flags_() & SDL_WINDOW_FULLSCREEN) != 0;
82 void Window::set_fullscreen(
bool fullscreen)
84 uint32_t flags = fullscreen? SDL_WINDOW_FULLSCREEN : 0;
86 if (SDL_SetWindowFullscreen(get_raw_(), flags) < 0)
87 throw Host_error{
"Window::set_fullscreen: failed"};
93 SDL_GetDisplayBounds(0, &rect);
94 return {rect.w, rect.h};
97 Dimensions Window::max_window_dimensions() const noexcept
99 int top, left, bottom, right;
100 SDL_GetWindowBordersSize(get_raw_(), &top, &left, &bottom, &right);
103 SDL_GetDisplayUsableBounds(0, &rect);
105 return {rect.w - left - right, rect.h - top - bottom};
Coordinate width
The width of the object.
Coordinate height
The height of the object.
The game engine namespace.
Coordinate x
The x coordinate.
Coordinate y
The y coordiante.
Indicates an exception from the host environment being passed along by ge211.
Represents the dimensions of an object, or more generally, the displacement between two Basic_positio...
A position in the T-valued Cartesian plane.
Indicates that an error was encountered by the game engine or in the client's environment.