Demo: implementado el cambio de tamaño de la ventana

This commit is contained in:
2023-05-07 14:22:14 +02:00
parent 9b9fd15f4e
commit 90ebea4807
5 changed files with 82 additions and 66 deletions

View File

@@ -142,11 +142,11 @@ void Notify::showText(string text1, string text2, int icon)
}
else if (options->notifications.posH == pos_middle)
{
despH = ((options->screen.windowWidth * options->windowSize) / 2 - (width / 2));
despH = ((options->screen.nativeWidth * options->screen.windowZoom) / 2 - (width / 2));
}
else
{
despH = (options->screen.windowWidth * options->windowSize) - width - padding;
despH = (options->screen.nativeWidth * options->screen.windowZoom) - width - padding;
}
// Posición vertical
@@ -157,7 +157,7 @@ void Notify::showText(string text1, string text2, int icon)
}
else
{
despV = (options->screen.windowHeight * options->windowSize) - height - padding;
despV = (options->screen.nativeHeight * options->screen.windowZoom) - height - padding;
}
const int travelDist = height + padding;

View File

@@ -10,10 +10,10 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
this->renderer = renderer;
this->options = options;
gameCanvasWidth = options->gameWidth;
gameCanvasHeight = options->gameHeight;
borderWidth = options->borderWidth * 2;
borderHeight = options->borderHeight * 2;
gameCanvasWidth = options->screen.nativeWidth;
gameCanvasHeight = options->screen.nativeHeight;
borderWidth = options->screen.borderWidth * 2;
borderHeight = options->screen.borderHeight * 2;
iniFade();
iniSpectrumFade();
@@ -32,7 +32,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
}
// Establece el modo de video
setVideoMode(options->videoMode);
setVideoMode(options->screen.mode);
}
// Destructor
@@ -90,7 +90,7 @@ void Screen::setVideoMode(int videoMode)
// Muestra el puntero
SDL_ShowCursor(SDL_ENABLE);
if (options->borderEnabled)
if (options->screen.borderEnabled)
{
windowWidth = gameCanvasWidth + borderWidth;
windowHeight = gameCanvasHeight + borderHeight;
@@ -99,13 +99,17 @@ void Screen::setVideoMode(int videoMode)
else
{
windowWidth = gameCanvasWidth;
windowHeight = gameCanvasHeight;
dest = {0, 0, gameCanvasWidth, gameCanvasHeight};
//windowWidth = gameCanvasWidth;
windowWidth = gameCanvasWidth * options->screen.nativeZoom * options->screen.windowZoom;
//windowHeight = gameCanvasHeight;
windowHeight = gameCanvasHeight * options->screen.nativeZoom * options->screen.windowZoom;
//dest = {0, 0, gameCanvasWidth, gameCanvasHeight};
dest = {0, 0, windowWidth, windowHeight};
}
// Modifica el tamaño de la ventana
SDL_SetWindowSize(window, windowWidth * options->windowSize, windowHeight * options->windowSize);
//SDL_SetWindowSize(window, windowWidth * options->screen.windowZoom, windowHeight * options->screen.windowZoom);
SDL_SetWindowSize(window, windowWidth, windowHeight);
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
}
@@ -119,7 +123,7 @@ void Screen::setVideoMode(int videoMode)
SDL_GetWindowSize(window, &windowWidth, &windowHeight);
// Aplica el escalado al rectangulo donde se pinta la textura del juego
if (options->integerScale)
if (options->screen.integerScale)
{
// Calcula el tamaño de la escala máxima
int scale = 0;
@@ -133,7 +137,7 @@ void Screen::setVideoMode(int videoMode)
dest.x = (windowWidth - dest.w) / 2;
dest.y = (windowHeight - dest.h) / 2;
}
else if (options->keepAspect)
else if (options->screen.keepAspect)
{
float ratio = (float)gameCanvasWidth / (float)gameCanvasHeight;
if ((windowWidth - gameCanvasWidth) >= (windowHeight - gameCanvasHeight))
@@ -163,38 +167,36 @@ void Screen::setVideoMode(int videoMode)
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
// Actualiza las opciones
options->videoMode = videoMode;
options->screen.windowWidth = windowWidth;
options->screen.windowHeight = windowHeight;
options->screen.mode = videoMode;
}
// Camibia entre pantalla completa y ventana
void Screen::switchVideoMode()
{
options->videoMode = (options->videoMode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
setVideoMode(options->videoMode);
options->screen.mode = (options->screen.mode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
setVideoMode(options->screen.mode);
}
// Cambia el tamaño de la ventana
void Screen::setWindowSize(int size)
{
options->windowSize = size;
options->screen.windowZoom = size;
setVideoMode(0);
}
// Reduce el tamaño de la ventana
void Screen::decWindowSize()
{
--options->windowSize;
options->windowSize = std::max(options->windowSize, 1);
--options->screen.windowZoom;
options->screen.windowZoom = std::max(options->screen.windowZoom, 1);
setVideoMode(0);
}
// Aumenta el tamaño de la ventana
void Screen::incWindowSize()
{
++options->windowSize;
options->windowSize = std::min(options->windowSize, 4);
++options->screen.windowZoom;
options->screen.windowZoom = std::min(options->screen.windowZoom, 4);
setVideoMode(0);
}
@@ -213,25 +215,25 @@ void Screen::setBlendMode(SDL_BlendMode blendMode)
// Establece el tamaño del borde
void Screen::setBorderWidth(int s)
{
options->borderWidth = s;
options->screen.borderWidth = s;
}
// Establece el tamaño del borde
void Screen::setBorderHeight(int s)
{
options->borderHeight = s;
options->screen.borderHeight = s;
}
// Establece si se ha de ver el borde en el modo ventana
void Screen::setBorderEnabled(bool value)
{
options->borderEnabled = value;
options->screen.borderEnabled = value;
}
// Cambia entre borde visible y no visible
void Screen::switchBorder()
{
options->borderEnabled = !options->borderEnabled;
options->screen.borderEnabled = !options->screen.borderEnabled;
setVideoMode(0);
}

View File

@@ -559,25 +559,24 @@ bool colorAreEqual(color_t color1, color_t color2)
void initOptions(options_t *options)
{
options->configVersion = "";
options->videoMode = 0;
options->windowSize = 1;
options->filter = 0;
options->vSync = true;
options->gameWidth = 320;
options->gameHeight = 240;
options->integerScale = true;
options->keepAspect = true;
options->borderEnabled = false;
options->borderWidth = 0;
options->borderHeight = 0;
options->palette = p_zxspectrum;
options->console = false;
options->screen.mode = 0;
options->screen.windowZoom = 1;
options->screen.filter = 0;
options->screen.vsync = true;
options->screen.nativeWidth = 320;
options->screen.nativeHeight = 240;
options->screen.nativeZoom = 1;
options->screen.integerScale = true;
options->screen.keepAspect = true;
options->screen.borderEnabled = false;
options->screen.borderWidth = 0;
options->screen.borderHeight = 0;
options->notifications.posV = pos_top;
options->notifications.posH = pos_left;
options->notifications.sound = true;
options->notifications.color = {48, 48, 48};
options->screen.windowWidth = options->gameWidth * options->windowSize;
options->screen.windowHeight = options->gameHeight * options->windowSize;
}

View File

@@ -122,25 +122,24 @@ struct op_stats_t
// Estructura con opciones de la pantalla
struct op_screen_t
{
int windowWidth; // Ancho de la ventana
int windowHeight; // Alto de la ventana
Uint32 mode; // Contiene el valor del modo de pantalla completa
Uint32 filter; // Filtro usado para el escalado de la imagen
bool vsync; // Indica si se quiere usar vsync o no
bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana
int borderWidth; // Cantidad de pixels que se añade en el borde de la ventana
int borderHeight; // Cantidad de pixels que se añade en el borde de la ventana
int nativeWidth; // Ancho de la textura original de renderizado del juego
int nativeHeight; // Alto de la textura original de renderizado del juego
int nativeZoom; // Zoom que se aplica a la textura original de renderizado del juego
int windowZoom; // Zoom que se aplica a la ventana de juegoF
};
// Estructura con todas las opciones de configuración del programa
struct options_t
{
string configVersion; // Versión del programa. Sirve para saber si las opciones son compatibles
Uint32 videoMode; // Contiene el valor del modo de pantalla completa
int windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana
Uint32 filter; // Filtro usado para el escalado de la imagen
bool vSync; // Indica si se quiere usar vsync o no
int gameWidth; // Ancho de la resolucion nativa del juego
int gameHeight; // Alto de la resolucion nativa del juego
bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana
int borderWidth; // Cantidad de pixels que se añade en el borde de la ventana
int borderHeight; // Cantidad de pixels que se añade en el borde de la ventana
palette_e palette; // Paleta de colores a usar en el juego
bool console; // Indica si ha de mostrar información por la consola de texto
cheat_t cheat; // Contiene trucos y ventajas para el juego