|
|
|
|
@@ -15,6 +15,15 @@ namespace draw
|
|
|
|
|
SDL_Texture *sdl_texture {nullptr}; // La textura de SDL a la que pintarem la nostra superficie "screen" i que despres volcarem a pantalla
|
|
|
|
|
|
|
|
|
|
static int screen_zoom = 1;
|
|
|
|
|
static bool screen_fullscreen = false;
|
|
|
|
|
static float window_ratio = 1;
|
|
|
|
|
static int canvas_width;
|
|
|
|
|
static int canvas_height;
|
|
|
|
|
static int desktop_width;
|
|
|
|
|
static int desktop_height;
|
|
|
|
|
static int window_width;
|
|
|
|
|
static int window_height;
|
|
|
|
|
char window_title[256];
|
|
|
|
|
|
|
|
|
|
surface *screen {nullptr}; // La superficie screen, que representa la pantalla. Se crea i destrueix internament
|
|
|
|
|
surface *destination {nullptr}; // Punter a la actual superficie de destí
|
|
|
|
|
@@ -34,26 +43,72 @@ namespace draw
|
|
|
|
|
bool fading_out = false;
|
|
|
|
|
bool fading_in = false;
|
|
|
|
|
|
|
|
|
|
void createDisplay()
|
|
|
|
|
{
|
|
|
|
|
// Ajustem el zoom i el ratio, per si tenen valors locs
|
|
|
|
|
if (screen_zoom <= 0) screen_zoom = 1;
|
|
|
|
|
if (window_ratio <= 0) window_ratio = 1;
|
|
|
|
|
|
|
|
|
|
// Ajustem el tamany de la finestra, segons el zoom i el ratio
|
|
|
|
|
window_width = canvas_width*screen_zoom;
|
|
|
|
|
window_height = window_ratio != 1 ? canvas_width*window_ratio*screen_zoom : canvas_height*screen_zoom;
|
|
|
|
|
|
|
|
|
|
// Mentres no càpiga en la pantalla, reduïm el zoom
|
|
|
|
|
while (window_width > desktop_width || window_height > desktop_height) {
|
|
|
|
|
screen_zoom--;
|
|
|
|
|
window_width = canvas_width*screen_zoom;
|
|
|
|
|
window_height = window_ratio != 1 ? canvas_width*window_ratio*screen_zoom : canvas_height*screen_zoom;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sdl_window = SDL_CreateWindow(window_title, window_width, window_height, SDL_WINDOW_OPENGL|(screen_fullscreen?SDL_WINDOW_FULLSCREEN:0));
|
|
|
|
|
if (!sdl_window) {
|
|
|
|
|
SDL_LogCritical(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize window!\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void destroyDisplay()
|
|
|
|
|
{
|
|
|
|
|
SDL_DestroyTexture(sdl_texture);
|
|
|
|
|
SDL_DestroyRenderer(sdl_renderer);
|
|
|
|
|
SDL_DestroyWindow(sdl_window);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Inicialització de tot el que fa falta per a carregar gràfics i pintar en pantalla
|
|
|
|
|
void init(const char *titol, const uint16_t width, const uint16_t height, const int zoom)
|
|
|
|
|
void init(const char *titol, const uint16_t width, const uint16_t height, const int zoom, const bool fullscreen, const float ratio)
|
|
|
|
|
{
|
|
|
|
|
screen_zoom = zoom;
|
|
|
|
|
window_ratio = ratio;
|
|
|
|
|
canvas_width = width;
|
|
|
|
|
canvas_height = height;
|
|
|
|
|
strcpy(window_title, titol);
|
|
|
|
|
|
|
|
|
|
// [TODO] Incloure gestió de pantalla completa
|
|
|
|
|
const SDL_DisplayMode *dm = SDL_GetDesktopDisplayMode(SDL_GetPrimaryDisplay());
|
|
|
|
|
if (!dm)
|
|
|
|
|
{
|
|
|
|
|
SDL_Log("SDL_GetDesktopDisplayMode failed: %s", SDL_GetError());
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
desktop_width = dm->w;
|
|
|
|
|
desktop_height = dm->h;
|
|
|
|
|
|
|
|
|
|
// Inicialització de les estructures de SDL
|
|
|
|
|
sdl_window = SDL_CreateWindow(titol, width * zoom, height * zoom, 0);
|
|
|
|
|
if (!sdl_window) {
|
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize window!\n"); exit(1);
|
|
|
|
|
SDL_LogCritical(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize window!\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
sdl_renderer = SDL_CreateRenderer(sdl_window, NULL);
|
|
|
|
|
if (!sdl_renderer) {
|
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize renderer!\n"); exit(1);
|
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize renderer!\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height);
|
|
|
|
|
SDL_SetTextureScaleMode(sdl_texture, SDL_SCALEMODE_NEAREST);
|
|
|
|
|
if (!sdl_texture) {
|
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize texture!\n"); exit(1);
|
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize texture!\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Creem la superficie "screen" i la establim com a superficie destinació
|
|
|
|
|
|