forked from jaildesigner-jailgames/jaildoctors_dilemma
Modes de video aclarits (sembla)
La finestra manté la posició al canviar de tamany o activar el borde La finestra ja pot creixer mentres donde de si el escriptori
This commit is contained in:
@@ -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_
|
||||
@@ -372,3 +380,23 @@ void Screen::adjustRenderLogicalSize()
|
||||
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_);
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||
#include <string> // for string
|
||||
#include <vector>
|
||||
|
||||
// Tipos de paleta
|
||||
enum class Palette : int
|
||||
|
||||
Reference in New Issue
Block a user