Trabajando en la clase Screen

This commit is contained in:
2022-11-19 07:37:03 +01:00
parent 2216c9632e
commit 8d381010c8
2 changed files with 33 additions and 35 deletions

View File

@@ -16,6 +16,8 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
gameCanvasWidth = options->gameWidth; gameCanvasWidth = options->gameWidth;
gameCanvasHeight = options->gameHeight; gameCanvasHeight = options->gameHeight;
borderWidth = options->gameWidth * options->borderSize;
borderHeight = options->gameHeight * options->borderSize;
iniFade(); iniFade();
iniSpectrumFade(); iniSpectrumFade();
@@ -87,77 +89,71 @@ void Screen::setVideoMode(int videoMode)
{ {
if (options->borderEnabled) if (options->borderEnabled)
{ {
const int incWidth = options->gameWidth * options->borderSize; windowWidth = (gameCanvasWidth + borderWidth) * options->windowSize;
const int incHeight = options->gameHeight * options->borderSize; windowHeight = (gameCanvasHeight + borderHeight) * options->windowSize;
gameCanvasWidth = options->gameWidth + incWidth; dest = {0 + (borderWidth / 2), 0 + (borderHeight / 2), gameCanvasWidth, gameCanvasHeight};
gameCanvasHeight = options->gameHeight + incHeight;
screenWidth = gameCanvasWidth * options->windowSize;
screenHeight = gameCanvasHeight * options->windowSize;
dest = {0 + (incWidth / 2), 0 + (incHeight / 2), options->gameWidth, options->gameHeight};
} }
else else
{ {
gameCanvasWidth = options->gameWidth; windowWidth = gameCanvasWidth * options->windowSize;
gameCanvasHeight = options->gameHeight; windowHeight = gameCanvasHeight * options->windowSize;
screenWidth = gameCanvasWidth * options->windowSize;
screenHeight = gameCanvasHeight * options->windowSize;
dest = {0, 0, gameCanvasWidth, gameCanvasHeight}; dest = {0, 0, gameCanvasWidth, gameCanvasHeight};
} }
// Modifica el tamaño del renderizador y de la ventana // Modifica el tamaño del renderizador y de la ventana
SDL_RenderSetLogicalSize(renderer, gameCanvasWidth, gameCanvasHeight); SDL_RenderSetLogicalSize(renderer, gameCanvasWidth, gameCanvasHeight);
SDL_SetWindowSize(window, screenWidth, screenHeight); SDL_SetWindowSize(window, windowWidth, windowHeight);
} }
// Si está activo el modo de pantalla completa añade el borde // Si está activo el modo de pantalla completa añade el borde
else if (videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP) else if (videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
{ {
// Obten el alto y el ancho de la ventana // Obten el alto y el ancho de la ventana
SDL_GetWindowSize(window, &screenWidth, &screenHeight); SDL_GetWindowSize(window, &windowWidth, &windowHeight);
// Aplica el escalado al rectangulo donde se pinta la textura del juego // Aplica el escalado al rectangulo donde se pinta la textura del juego
if (options->integerScale) if (options->integerScale)
{ {
// Calcula el tamaño de la escala máxima // Calcula el tamaño de la escala máxima
int scale = 0; int scale = 0;
while (((gameCanvasWidth * (scale + 1)) <= screenWidth) && ((gameCanvasHeight * (scale + 1)) <= screenHeight)) while (((gameCanvasWidth * (scale + 1)) <= windowWidth) && ((gameCanvasHeight * (scale + 1)) <= windowHeight))
{ {
scale++; scale++;
} }
dest.w = gameCanvasWidth * scale; dest.w = gameCanvasWidth * scale;
dest.h = gameCanvasHeight * scale; dest.h = gameCanvasHeight * scale;
dest.x = (screenWidth - dest.w) / 2; dest.x = (windowWidth - dest.w) / 2;
dest.y = (screenHeight - dest.h) / 2; dest.y = (windowHeight - dest.h) / 2;
} }
else if (options->keepAspect) else if (options->keepAspect)
{ {
float ratio = (float)gameCanvasWidth / (float)gameCanvasHeight; float ratio = (float)gameCanvasWidth / (float)gameCanvasHeight;
if ((screenWidth - gameCanvasWidth) >= (screenHeight - gameCanvasHeight)) if ((windowWidth - gameCanvasWidth) >= (windowHeight - gameCanvasHeight))
{ {
dest.h = screenHeight; dest.h = windowHeight;
dest.w = (int)((screenHeight * ratio) + 0.5f); dest.w = (int)((windowHeight * ratio) + 0.5f);
dest.x = (screenWidth - dest.w) / 2; dest.x = (windowWidth - dest.w) / 2;
dest.y = (screenHeight - dest.h) / 2; dest.y = (windowHeight - dest.h) / 2;
} }
else else
{ {
dest.w = screenWidth; dest.w = windowWidth;
dest.h = (int)((screenWidth / ratio) + 0.5f); dest.h = (int)((windowWidth / ratio) + 0.5f);
dest.x = (screenWidth - dest.w) / 2; dest.x = (windowWidth - dest.w) / 2;
dest.y = (screenHeight - dest.h) / 2; dest.y = (windowHeight - dest.h) / 2;
} }
} }
else else
{ {
dest.w = screenWidth; dest.w = windowWidth;
dest.h = screenHeight; dest.h = windowHeight;
dest.x = dest.y = 0; dest.x = dest.y = 0;
} }
// Modifica el tamaño del renderizador // Modifica el tamaño del renderizador
SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight); SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
} }
// Actualiza el valor de la variable // Actualiza el valor de la variable
@@ -365,7 +361,7 @@ void Screen::renderNotifications()
// return; // return;
// } // }
SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight); SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
notify->render(); notify->render();
SDL_RenderSetLogicalSize(renderer, gameCanvasWidth, gameCanvasHeight); SDL_RenderSetLogicalSize(renderer, gameCanvasWidth, gameCanvasHeight);
} }

View File

@@ -24,10 +24,12 @@ private:
Notify *notify; // Dibuja notificaciones por pantalla Notify *notify; // Dibuja notificaciones por pantalla
// Variables // Variables
int screenWidth; // Ancho de la pantalla o ventana int windowWidth; // Ancho de la pantalla o ventana
int screenHeight; // Alto de la pantalla o ventana int windowHeight; // Alto de la pantalla o ventana
int gameCanvasWidth; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego int gameCanvasWidth; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego
int gameCanvasHeight; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego int gameCanvasHeight; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego
int borderWidth; // Anchura del borde
int borderHeight; // Anltura del borde
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
bool notifyActive; // Indica si hay notificaciones activas bool notifyActive; // Indica si hay notificaciones activas