Actualizada la clase screen con nuevos procedimientos. Incluído el fichero const.h. Cambio de tamaño de ventana y pantalla completa

This commit is contained in:
2022-08-30 17:59:10 +02:00
parent 16b7bcc091
commit a5c983df9d
9 changed files with 162 additions and 54 deletions

View File

@@ -1,18 +1,17 @@
#include "screen.h"
#include "const.h"
#include <string>
#include <stdio.h>
// Constructor
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, int gameInternalResX, int gameInternalResY)
{
// Inicializa variables
this->window = window;
this->renderer = renderer;
this->options = options;
gameCanvasWidth = SCREEN_WIDTH;
gameCanvasHeight = SCREEN_HEIGHT;
gameCanvasWidth = gameInternalResX;
gameCanvasHeight = gameInternalResY;
// Establece el modo de video
setVideoMode(options->fullScreenMode);
@@ -25,6 +24,14 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
if (gameCanvas == NULL)
printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError());
// Calcula los anclajes
anchor.left = 0;
anchor.right = gameCanvasWidth;
anchor.center = gameCanvasWidth / 2;
anchor.top = 0;
anchor.bottom = gameCanvasHeight;
anchor.middle = gameCanvasHeight / 2;
}
// Destructor
@@ -82,7 +89,7 @@ void Screen::setVideoMode(int fullScreenMode)
}
// Si está activo el modo de pantalla completa añade el borde
if (fullScreenMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
else if (fullScreenMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
{
// Obten el alto y el ancho de la ventana
SDL_GetWindowSize(window, &screenWidth, &screenHeight);
@@ -130,4 +137,33 @@ void Screen::setVideoMode(int fullScreenMode)
// Modifica el tamaño del renderizador
SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight);
}
// Actualiza el valor de la variable
options->fullScreenMode = fullScreenMode;
}
// Camibia entre pantalla completa y ventana
void Screen::switchVideoMode()
{
if (options->fullScreenMode == 0)
{
setVideoMode(SDL_WINDOW_FULLSCREEN_DESKTOP);
}
else
{
setVideoMode(0);
}
}
// Cambia el tamaño de la ventana
void Screen::setWindowSize(int size)
{
options->windowSize = size;
setVideoMode(0);
}
// Cambia el color del borde
void Screen::setBorderColor(color_t color)
{
borderColor = color;
}