Initial
This commit is contained in:
38
src/window/window.cpp
Normal file
38
src/window/window.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <window/window.hpp>
|
||||
|
||||
namespace Game::Window {
|
||||
Window::Window() : mWindow(nullptr), mRunning(false) {}
|
||||
|
||||
Window::~Window() {
|
||||
if (mWindow) {
|
||||
SDL_DestroyWindow(mWindow);
|
||||
mWindow = nullptr;
|
||||
mRunning = false;
|
||||
SDL_Quit();
|
||||
}
|
||||
}
|
||||
|
||||
bool Window::init(int width, int height, const std::string& title) {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) { return false; }
|
||||
mWindow = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_SHOWN);
|
||||
if (!mWindow) {
|
||||
SDL_Quit();
|
||||
return false;
|
||||
}
|
||||
|
||||
mRunning = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Window::run() {
|
||||
SDL_Event event;
|
||||
while (mRunning) {
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
mRunning = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user