Wizard Engine
2D cross-platform game engine built around SDL2
 
Loading...
Searching...
No Matches
window.cpp
1/*
2 Wizard Engine
3 Copyright (C) 2023-2024 Zana Domán
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
23#define __WIZARD_ENGINE_INTERNAL__
24
27
28SDL_Window* wze::window::_base = {};
29uint16_t wze::window::_width = {};
30uint16_t wze::window::_height = {};
31
32SDL_Window* wze::window::base() {
33 return _base;
34}
35
36uint16_t wze::window::width() {
37 return _width;
38}
39
40uint16_t wze::window::height() {
41 return _height;
42}
43
44std::string wze::window::title() {
45 return SDL_GetWindowTitle(base());
46}
47
48void wze::window::set_title(std::string const& title) {
49 SDL_SetWindowTitle(base(), title.c_str());
50}
51
52void wze::window::set_icon(std::shared_ptr<image> const& icon) {
53 SDL_SetWindowIcon(base(), icon.get());
54}
55
56bool wze::window::visible() {
57 return (bool)(SDL_GetWindowFlags(base()) & SDL_WINDOW_SHOWN);
58}
59
60bool wze::window::focused() {
61 return (bool)(SDL_GetWindowFlags(base()) & SDL_WINDOW_INPUT_FOCUS);
62}
63
64void wze::window::initialize(std::string const& title, uint16_t width,
65 uint16_t height) {
66 _base = SDL_CreateWindow(title.empty() ? "Wizard Engine" : title.c_str(),
67 SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
68 width, height,
69 SDL_WINDOW_RESIZABLE
70#ifndef __EMSCRIPTEN__
71 | SDL_WINDOW_FULLSCREEN_DESKTOP
72#endif /* __EMSCRIPTEN__ */
73 );
74 if (!(bool)base()) {
75 throw exception(SDL_GetError());
76 }
77 _width = width;
78 _height = height;
79 set_icon(assets::load_image("./wizard_engine/icon.png"));
80}
Generic exception.
Subsystem to handle game window.