diff --git a/source/common/screen.cpp b/source/common/screen.cpp index 47815da..bcca940 100644 --- a/source/common/screen.cpp +++ b/source/common/screen.cpp @@ -16,6 +16,8 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options gameCanvasWidth = options->gameWidth; gameCanvasHeight = options->gameHeight; + borderWidth = options->gameWidth * options->borderSize; + borderHeight = options->gameHeight * options->borderSize; iniFade(); iniSpectrumFade(); @@ -87,77 +89,71 @@ void Screen::setVideoMode(int videoMode) { if (options->borderEnabled) { - const int incWidth = options->gameWidth * options->borderSize; - const int incHeight = options->gameHeight * options->borderSize; - gameCanvasWidth = options->gameWidth + incWidth; - gameCanvasHeight = options->gameHeight + incHeight; - screenWidth = gameCanvasWidth * options->windowSize; - screenHeight = gameCanvasHeight * options->windowSize; - dest = {0 + (incWidth / 2), 0 + (incHeight / 2), options->gameWidth, options->gameHeight}; + windowWidth = (gameCanvasWidth + borderWidth) * options->windowSize; + windowHeight = (gameCanvasHeight + borderHeight) * options->windowSize; + dest = {0 + (borderWidth / 2), 0 + (borderHeight / 2), gameCanvasWidth, gameCanvasHeight}; } else { - gameCanvasWidth = options->gameWidth; - gameCanvasHeight = options->gameHeight; - screenWidth = gameCanvasWidth * options->windowSize; - screenHeight = gameCanvasHeight * options->windowSize; + windowWidth = gameCanvasWidth * options->windowSize; + windowHeight = gameCanvasHeight * options->windowSize; dest = {0, 0, gameCanvasWidth, gameCanvasHeight}; } // Modifica el tamaño del renderizador y de la ventana 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 else if (videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP) { // 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 if (options->integerScale) { // Calcula el tamaño de la escala máxima int scale = 0; - while (((gameCanvasWidth * (scale + 1)) <= screenWidth) && ((gameCanvasHeight * (scale + 1)) <= screenHeight)) + while (((gameCanvasWidth * (scale + 1)) <= windowWidth) && ((gameCanvasHeight * (scale + 1)) <= windowHeight)) { scale++; } dest.w = gameCanvasWidth * scale; dest.h = gameCanvasHeight * scale; - dest.x = (screenWidth - dest.w) / 2; - dest.y = (screenHeight - dest.h) / 2; + dest.x = (windowWidth - dest.w) / 2; + dest.y = (windowHeight - dest.h) / 2; } else if (options->keepAspect) { float ratio = (float)gameCanvasWidth / (float)gameCanvasHeight; - if ((screenWidth - gameCanvasWidth) >= (screenHeight - gameCanvasHeight)) + if ((windowWidth - gameCanvasWidth) >= (windowHeight - gameCanvasHeight)) { - dest.h = screenHeight; - dest.w = (int)((screenHeight * ratio) + 0.5f); - dest.x = (screenWidth - dest.w) / 2; - dest.y = (screenHeight - dest.h) / 2; + dest.h = windowHeight; + dest.w = (int)((windowHeight * ratio) + 0.5f); + dest.x = (windowWidth - dest.w) / 2; + dest.y = (windowHeight - dest.h) / 2; } else { - dest.w = screenWidth; - dest.h = (int)((screenWidth / ratio) + 0.5f); - dest.x = (screenWidth - dest.w) / 2; - dest.y = (screenHeight - dest.h) / 2; + dest.w = windowWidth; + dest.h = (int)((windowWidth / ratio) + 0.5f); + dest.x = (windowWidth - dest.w) / 2; + dest.y = (windowHeight - dest.h) / 2; } } else { - dest.w = screenWidth; - dest.h = screenHeight; + dest.w = windowWidth; + dest.h = windowHeight; dest.x = dest.y = 0; } // Modifica el tamaño del renderizador - SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight); + SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight); } // Actualiza el valor de la variable @@ -360,12 +356,12 @@ void Screen::showText(std::string text) // Dibuja las notificaciones void Screen::renderNotifications() { - // if (!notifyActive) - // { - // return; - // } + // if (!notifyActive) + // { + // return; + // } - SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight); + SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight); notify->render(); SDL_RenderSetLogicalSize(renderer, gameCanvasWidth, gameCanvasHeight); } \ No newline at end of file diff --git a/source/common/screen.h b/source/common/screen.h index b3282a4..041ab83 100644 --- a/source/common/screen.h +++ b/source/common/screen.h @@ -24,10 +24,12 @@ private: Notify *notify; // Dibuja notificaciones por pantalla // Variables - int screenWidth; // Ancho de la pantalla o ventana - int screenHeight; // Alto de la pantalla o ventana + int windowWidth; // Ancho 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 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 color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla bool notifyActive; // Indica si hay notificaciones activas