Trabajando en el escalado entero y el tamaño personalizable de la ventana de renderizado a traves de las opciones
This commit is contained in:
@@ -37,6 +37,9 @@ Director::Director(std::string path)
|
|||||||
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
||||||
mOptions->filter = FILTER_NEAREST;
|
mOptions->filter = FILTER_NEAREST;
|
||||||
mOptions->vSync = true;
|
mOptions->vSync = true;
|
||||||
|
mOptions->screenHeight = SCREEN_HEIGHT;
|
||||||
|
mOptions->screenWidth = SCREEN_WIDTH;
|
||||||
|
mOptions->integerScale = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
@@ -46,7 +49,7 @@ Director::Director(std::string path)
|
|||||||
initSDL();
|
initSDL();
|
||||||
|
|
||||||
// Crea el objeto para dibujar en pantalla (Requiere initSDL)
|
// Crea el objeto para dibujar en pantalla (Requiere initSDL)
|
||||||
mScreen = new Screen(mWindow, mRenderer);
|
mScreen = new Screen(mWindow, mRenderer, mOptions->screenWidth, mOptions->screenHeight, mOptions->integerScale);
|
||||||
|
|
||||||
// Inicializa JailAudio
|
// Inicializa JailAudio
|
||||||
initJailAudio();
|
initJailAudio();
|
||||||
@@ -193,7 +196,7 @@ bool Director::initSDL()
|
|||||||
SDL_SetRenderDrawColor(mRenderer, 0x00, 0x00, 0x00, 0xFF);
|
SDL_SetRenderDrawColor(mRenderer, 0x00, 0x00, 0x00, 0xFF);
|
||||||
|
|
||||||
// Establece el tamaño del buffer de renderizado
|
// Establece el tamaño del buffer de renderizado
|
||||||
SDL_RenderSetLogicalSize(mRenderer, REAL_SCREEN_WIDTH, REAL_SCREEN_HEIGHT);
|
SDL_RenderSetLogicalSize(mRenderer, mOptions->screenWidth, mOptions->screenHeight);
|
||||||
|
|
||||||
// Establece el modo de mezcla
|
// Establece el modo de mezcla
|
||||||
SDL_SetRenderDrawBlendMode(mRenderer, SDL_BLENDMODE_BLEND);
|
SDL_SetRenderDrawBlendMode(mRenderer, SDL_BLENDMODE_BLEND);
|
||||||
@@ -357,13 +360,16 @@ bool Director::loadConfigFile()
|
|||||||
{
|
{
|
||||||
// Pone unos valores por defecto
|
// Pone unos valores por defecto
|
||||||
mOptions->fullScreenMode = 0;
|
mOptions->fullScreenMode = 0;
|
||||||
mOptions->windowSize = 3;
|
mOptions->windowSize = 1;
|
||||||
mOptions->language = en_UK;
|
mOptions->language = en_UK;
|
||||||
mOptions->difficulty = DIFFICULTY_NORMAL;
|
mOptions->difficulty = DIFFICULTY_NORMAL;
|
||||||
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
|
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
|
||||||
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
||||||
mOptions->filter = FILTER_NEAREST;
|
mOptions->filter = FILTER_NEAREST;
|
||||||
mOptions->vSync = true;
|
mOptions->vSync = true;
|
||||||
|
mOptions->screenHeight = 480;
|
||||||
|
mOptions->screenWidth = 640;
|
||||||
|
mOptions->integerScale = true;
|
||||||
|
|
||||||
// Indicador de éxito en la carga
|
// Indicador de éxito en la carga
|
||||||
bool success = true;
|
bool success = true;
|
||||||
@@ -392,6 +398,9 @@ bool Director::loadConfigFile()
|
|||||||
SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
||||||
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
||||||
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
|
||||||
|
|
||||||
// Cierra el fichero
|
// Cierra el fichero
|
||||||
SDL_RWclose(file);
|
SDL_RWclose(file);
|
||||||
@@ -415,6 +424,9 @@ bool Director::loadConfigFile()
|
|||||||
SDL_RWread(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
SDL_RWread(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
||||||
SDL_RWread(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
SDL_RWread(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
||||||
SDL_RWread(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
SDL_RWread(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
||||||
|
SDL_RWread(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
|
||||||
|
SDL_RWread(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
|
||||||
|
SDL_RWread(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
|
||||||
|
|
||||||
// Normaliza los valores
|
// Normaliza los valores
|
||||||
if (!((mOptions->fullScreenMode == 0) ||
|
if (!((mOptions->fullScreenMode == 0) ||
|
||||||
@@ -451,6 +463,9 @@ bool Director::saveConfigFile()
|
|||||||
SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
||||||
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
||||||
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
|
||||||
|
|
||||||
printf("Writing file %s\n", filename.c_str());
|
printf("Writing file %s\n", filename.c_str());
|
||||||
|
|
||||||
|
|||||||
@@ -2,18 +2,33 @@
|
|||||||
#include "const.h"
|
#include "const.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, int screenWidth, int screenHeight, bool integerScale)
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
mWindow = window;
|
mWindow = window;
|
||||||
mRenderer = renderer;
|
mRenderer = renderer;
|
||||||
|
|
||||||
mScreenWidth = REAL_SCREEN_WIDTH;
|
mScreenWidth = screenWidth;
|
||||||
mScreenHeight = REAL_SCREEN_HEIGHT;
|
mScreenHeight = screenHeight;
|
||||||
mGameCanvasWidth = SCREEN_WIDTH;
|
mGameCanvasWidth = SCREEN_WIDTH;
|
||||||
mGameCanvasHeight = SCREEN_HEIGHT;
|
mGameCanvasHeight = SCREEN_HEIGHT;
|
||||||
mGameCanvasPosX = (mScreenWidth - mGameCanvasWidth) / 2;
|
mGameCanvasPosX = (mScreenWidth - mGameCanvasWidth) / 2;
|
||||||
mGameCanvasPosY = (mScreenHeight - mGameCanvasHeight) / 2;
|
mGameCanvasPosY = (mScreenHeight - mGameCanvasHeight) / 2;
|
||||||
|
mIntegerScale = integerScale;
|
||||||
|
|
||||||
|
// Calcula el tamaño de la escala máxima
|
||||||
|
mScale = 0;
|
||||||
|
int width = mGameCanvasWidth;
|
||||||
|
int height = mGameCanvasHeight;
|
||||||
|
while (((width * (mScale + 1)) < mScreenWidth) && ((height * (mScale + 1)) < mScreenHeight))
|
||||||
|
{
|
||||||
|
mScale++;
|
||||||
|
}
|
||||||
|
|
||||||
|
width = width * mScale;
|
||||||
|
height = height * mScale;
|
||||||
|
mGameCanvasPosX = (mScreenWidth - width) / 2;
|
||||||
|
mGameCanvasPosY = (mScreenHeight - height) / 2;
|
||||||
|
|
||||||
mBorderColor = {0x27, 0x27, 0x36};
|
mBorderColor = {0x27, 0x27, 0x36};
|
||||||
mBorderColor = {0x00, 0x00, 0x00};
|
mBorderColor = {0x00, 0x00, 0x00};
|
||||||
@@ -54,7 +69,7 @@ void Screen::blit()
|
|||||||
SDL_RenderClear(mRenderer);
|
SDL_RenderClear(mRenderer);
|
||||||
|
|
||||||
// Rectangulo de destino donde se dibujarà la textura con el juego
|
// Rectangulo de destino donde se dibujarà la textura con el juego
|
||||||
SDL_Rect dest = {mGameCanvasPosX, mGameCanvasPosY, mGameCanvasWidth, mGameCanvasHeight};
|
SDL_Rect dest = {mGameCanvasPosX, mGameCanvasPosY, mGameCanvasWidth*mScale, mGameCanvasHeight*mScale};
|
||||||
|
|
||||||
// Copia la textura de juego en el renderizador en la posición adecuada
|
// Copia la textura de juego en el renderizador en la posición adecuada
|
||||||
SDL_RenderCopy(mRenderer, mGameCanvas, NULL, &dest);
|
SDL_RenderCopy(mRenderer, mGameCanvas, NULL, &dest);
|
||||||
|
|||||||
@@ -19,12 +19,14 @@ private:
|
|||||||
int mGameCanvasHeight; // Alto de la textura donde se dibuja el juego
|
int mGameCanvasHeight; // Alto de la textura donde se dibuja el juego
|
||||||
int mGameCanvasPosX; // Posicion en el eje X donde se dibujará la textura del juego dentro de la pantalla
|
int mGameCanvasPosX; // Posicion en el eje X donde se dibujará la textura del juego dentro de la pantalla
|
||||||
int mGameCanvasPosY; // Posicion en el eje Y donde se dibujará la textura del juego dentro de la pantalla
|
int mGameCanvasPosY; // Posicion en el eje Y donde se dibujará la textura del juego dentro de la pantalla
|
||||||
|
bool mIntegerScale; // Indica si la textura se escala en multiplos enteros
|
||||||
|
Uint8 mScale; // Contiene el valor por el cual se multiplica el GameCanvas para aprovechar el maximo de pantalla
|
||||||
|
|
||||||
color_t mBorderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
color_t mBorderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen(SDL_Window *windows, SDL_Renderer *renderer);
|
Screen(SDL_Window *windows, SDL_Renderer *renderer, int screenWidth, int screenHeight, bool integerScale = false);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Screen();
|
~Screen();
|
||||||
|
|||||||
@@ -517,7 +517,7 @@ void Title::updateMenuLabels()
|
|||||||
void Title::applyOptions()
|
void Title::applyOptions()
|
||||||
{
|
{
|
||||||
SDL_SetWindowFullscreen(mWindow, mOptions->fullScreenMode);
|
SDL_SetWindowFullscreen(mWindow, mOptions->fullScreenMode);
|
||||||
SDL_SetWindowSize(mWindow, SCREEN_WIDTH * mOptions->windowSize, SCREEN_HEIGHT * mOptions->windowSize);
|
SDL_SetWindowSize(mWindow, mOptions->screenWidth * mOptions->windowSize, mOptions->screenHeight * mOptions->windowSize);
|
||||||
mLang->setLang(mOptions->language);
|
mLang->setLang(mOptions->language);
|
||||||
|
|
||||||
updateMenuLabels();
|
updateMenuLabels();
|
||||||
|
|||||||
@@ -64,9 +64,12 @@ struct options_t
|
|||||||
input_t input[2]; // Modo de control (teclado o mando)
|
input_t input[2]; // Modo de control (teclado o mando)
|
||||||
Uint8 language; // Idioma usado en el juego
|
Uint8 language; // Idioma usado en el juego
|
||||||
Uint32 fullScreenMode; // Contiene el valor del modo de pantalla completa
|
Uint32 fullScreenMode; // Contiene el valor del modo de pantalla completa
|
||||||
Uint8 windowSize; // Contiene el valor del tamaño de la ventana
|
Uint8 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
|
Uint32 filter; // Filtro usado para el escalado de la imagen
|
||||||
bool vSync; // Indica si se quiere usar vsync o no
|
bool vSync; // Indica si se quiere usar vsync o no
|
||||||
|
int screenWidth; // Ancho de la pantalla/ventana
|
||||||
|
int screenHeight; // Alto de la pantalla/ventana
|
||||||
|
bool integerScale; // Indica si el escalado de la imagen ha de ser entero
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calcula el cuadrado de la distancia entre dos puntos
|
// Calcula el cuadrado de la distancia entre dos puntos
|
||||||
|
|||||||
Reference in New Issue
Block a user