74 lines
2.2 KiB
C++
74 lines
2.2 KiB
C++
// sdl_manager.hpp - Gestor d'inicialització de SDL3
|
|
// © 2025 Port a C++20 amb SDL3
|
|
|
|
#ifndef SDL_MANAGER_HPP
|
|
#define SDL_MANAGER_HPP
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
#include "core/rendering/color_oscillator.hpp"
|
|
|
|
class SDLManager {
|
|
public:
|
|
SDLManager(); // Constructor per defecte (usa Defaults::)
|
|
SDLManager(int width, int height,
|
|
bool fullscreen); // Constructor amb configuració
|
|
~SDLManager();
|
|
|
|
// No permetre còpia ni assignació
|
|
SDLManager(const SDLManager&) = delete;
|
|
SDLManager& operator=(const SDLManager&) = delete;
|
|
|
|
// [NUEVO] Gestió de finestra dinàmica
|
|
void increaseWindowSize(); // F2: +100px
|
|
void decreaseWindowSize(); // F1: -100px
|
|
void toggleFullscreen(); // F3
|
|
bool
|
|
handleWindowEvent(const SDL_Event& event); // Per a SDL_EVENT_WINDOW_RESIZED
|
|
|
|
// Funcions principals (renderitzat)
|
|
void neteja(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0);
|
|
void presenta();
|
|
|
|
// [NUEVO] Actualització de colors (oscil·lació)
|
|
void updateColors(float delta_time);
|
|
|
|
// [NUEVO] Actualitzar comptador de FPS
|
|
void updateFPS(float delta_time);
|
|
|
|
// Getters
|
|
SDL_Renderer* obte_renderer() { return renderer_; }
|
|
|
|
// [NUEVO] Actualitzar títol de la finestra
|
|
void setWindowTitle(const std::string& title);
|
|
|
|
private:
|
|
SDL_Window* finestra_;
|
|
SDL_Renderer* renderer_;
|
|
|
|
// [NUEVO] Variables FPS
|
|
float fps_accumulator_;
|
|
int fps_frame_count_;
|
|
int fps_display_;
|
|
|
|
// [NUEVO] Estat de la finestra
|
|
int current_width_; // Mida física actual
|
|
int current_height_;
|
|
bool is_fullscreen_;
|
|
int max_width_; // Calculat des del display
|
|
int max_height_;
|
|
|
|
// [NUEVO] Funcions internes
|
|
void calculateMaxWindowSize(); // Llegir resolució del display
|
|
void applyWindowSize(int width, int height); // Canviar mida + centrar
|
|
void updateLogicalPresentation(); // Actualitzar viewport
|
|
|
|
// [NUEVO] Oscil·lador de colors
|
|
Rendering::ColorOscillator color_oscillator_;
|
|
};
|
|
|
|
#endif // SDL_MANAGER_HPP
|