diff --git a/source/screen.cpp b/source/screen.cpp index 70e37786..f15ba770 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -40,13 +40,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer) : window_(window), renderer_(renderer) { - // Obtiene información sobre la pantalla - SDL_DisplayMode DM; - SDL_GetCurrentDisplayMode(0, &DM); - - // Calcula el máximo factor de zoom que se puede aplicar a la pantalla - options.window.max_zoom = std::min(DM.w / options.game.width, DM.h / options.game.height); - adjustGameCanvasRect(); adjustWindowSize(); @@ -81,6 +74,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer) setVideoMode(options.video.mode); // Muestra la ventana + SDL_SetWindowPosition(window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); show(); } @@ -191,7 +185,7 @@ void Screen::setVideoMode(int videoMode) // Camibia entre pantalla completa y ventana void Screen::toggleVideoMode() { - options.video.mode = (options.video.mode == 0) ? SDL_WINDOW_FULLSCREEN : 0; + options.video.mode = (options.video.mode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0; setVideoMode(options.video.mode); } @@ -201,7 +195,8 @@ bool Screen::decWindowZoom() if (options.video.mode == 0) { int previous_zoom = options.window.zoom; - options.window.zoom = std::max(--options.window.zoom, 1); + --options.window.zoom; + options.window.zoom = std::max(options.window.zoom, 1); if (options.window.zoom != previous_zoom) { @@ -213,14 +208,14 @@ bool Screen::decWindowZoom() return false; } - // Aumenta el tamaño de la ventana bool Screen::incWindowZoom() { if (options.video.mode == 0) { int previous_zoom = options.window.zoom; - options.window.zoom = std::min(++options.window.zoom, options.window.max_zoom); + ++options.window.zoom; + options.window.zoom = std::min(options.window.zoom, options.window.max_zoom); if (options.window.zoom != previous_zoom) { @@ -348,11 +343,24 @@ void Screen::adjustWindowSize() window_width_ = options.game.width + (options.video.border.enabled ? options.video.border.width * 2 : 0); window_height_ = options.game.height + (options.video.border.enabled ? options.video.border.height * 2 : 0); + // Establece el nuevo tamaño if (options.video.mode == 0) { + int old_width, old_height; + SDL_GetWindowSize(window_, &old_width, &old_height); + + int old_pos_x, old_pos_y; + SDL_GetWindowPosition(window_, &old_pos_x, &old_pos_y); + + int new_pos_x = old_pos_x + (old_width - (window_width_ * options.window.zoom)) / 2; + int new_pos_y = old_pos_y + (old_height - (window_height_ * options.window.zoom)) / 2; + SDL_SetWindowSize(window_, window_width_ * options.window.zoom, window_height_ * options.window.zoom); - SDL_SetWindowPosition(window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); + SDL_SetWindowPosition(window_, std::max(new_pos_x, 30), std::max(new_pos_y, 10)); } + + options.window.max_zoom = getMaxZoom(); + renderBlackFrame(); } // Ajusta game_canvas_rect_ @@ -371,4 +379,24 @@ void Screen::adjustRenderLogicalSize() const int extra_width = options.video.border.enabled ? options.video.border.width * 2 : 0; const int extra_height = options.video.border.enabled ? options.video.border.height * 2 : 0; SDL_RenderSetLogicalSize(renderer_, options.game.width + extra_width, options.game.height + extra_height); +} + +// Obtiene el tamaño máximo de zoom posible para la ventana +int Screen::getMaxZoom() +{ + // Obtiene información sobre la pantalla + SDL_DisplayMode DM; + SDL_GetCurrentDisplayMode(0, &DM); + + // Calcula el máximo factor de zoom que se puede aplicar a la pantalla + return std::min(DM.w / window_width_, DM.h / window_height_); +} + +// Renderiza un frame negro +void Screen::renderBlackFrame() +{ + SDL_SetRenderTarget(renderer_, nullptr); + SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF); + SDL_RenderClear(renderer_); + SDL_RenderPresent(renderer_); } \ No newline at end of file diff --git a/source/screen.h b/source/screen.h index ec6c55ed..d34278c5 100644 --- a/source/screen.h +++ b/source/screen.h @@ -51,6 +51,12 @@ private: // Ajusta el tamaño lógico del renderizador void adjustRenderLogicalSize(); + // Obtiene el tamaño máximo de zoom posible para la ventana + int getMaxZoom(); + + // Renderiza un frame negro + void renderBlackFrame(); + // Constructor Screen(SDL_Window *window, SDL_Renderer *renderer); diff --git a/source/utils.h b/source/utils.h index 647ae993..5fca2e73 100644 --- a/source/utils.h +++ b/source/utils.h @@ -3,6 +3,7 @@ #include // for SDL_Rect, SDL_Point #include // for Uint8 #include // for string +#include // Tipos de paleta enum class Palette : int