Organize stuffs

This commit is contained in:
Sebastian Cabrera 2025-08-09 21:22:44 -04:00
parent a9240cac6e
commit c120871293
Signed by: okseby
GPG key ID: 2DDBFDEE356CF3DE
13 changed files with 625 additions and 56 deletions

70
src/window/Window.cpp Normal file
View file

@ -0,0 +1,70 @@
#include "Window.h"
#include <iostream>
Window::Window(const std::string& title, int width, int height)
: window_(nullptr), width_(width), height_(height), title_(title) {
window_ = SDL_CreateWindow(
title.c_str(),
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
width,
height,
SDL_WINDOW_SHOWN
);
if (!window_) {
std::cerr << "Window creation failed: " << SDL_GetError() << std::endl;
}
}
Window::~Window() {
if (window_) {
SDL_DestroyWindow(window_);
window_ = nullptr;
}
}
Window::Window(Window&& other) noexcept
: window_(other.window_), width_(other.width_), height_(other.height_), title_(std::move(other.title_)) {
other.window_ = nullptr;
other.width_ = 0;
other.height_ = 0;
}
Window& Window::operator=(Window&& other) noexcept {
if (this != &other) {
if (window_) {
SDL_DestroyWindow(window_);
}
window_ = other.window_;
width_ = other.width_;
height_ = other.height_;
title_ = std::move(other.title_);
other.window_ = nullptr;
other.width_ = 0;
other.height_ = 0;
}
return *this;
}
void Window::show() {
if (window_) {
SDL_ShowWindow(window_);
}
}
void Window::hide() {
if (window_) {
SDL_HideWindow(window_);
}
}
void Window::setTitle(const std::string& title) {
title_ = title;
if (window_) {
SDL_SetWindowTitle(window_, title.c_str());
}
}