Un altre punteret a pendre per cul: options
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "screen.h"
|
||||
#include "options.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
@@ -9,19 +10,18 @@
|
||||
#include "dbgtxt.h"
|
||||
|
||||
// Constructor
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input *input, options_t *options)
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input *input)
|
||||
{
|
||||
// Copia punteros
|
||||
this->window = window;
|
||||
this->renderer = renderer;
|
||||
this->asset = asset;
|
||||
this->input = input;
|
||||
this->options = options;
|
||||
|
||||
// Inicializa variables
|
||||
SDL_GetRendererOutputSize(renderer, &windowWidth, &windowHeight);
|
||||
gameCanvasWidth = options->video.gameWidth;
|
||||
gameCanvasHeight = options->video.gameHeight;
|
||||
gameCanvasWidth = options.video.gameWidth;
|
||||
gameCanvasHeight = options.video.gameHeight;
|
||||
dest = {0, 0, 0, 0};
|
||||
borderColor = {0, 0, 0};
|
||||
flashEffect.enabled = false;
|
||||
@@ -48,7 +48,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input *
|
||||
infoResolution = std::to_string(DM.w) + " X " + std::to_string(DM.h) + " AT " + std::to_string(DM.refresh_rate) + " HZ";
|
||||
|
||||
// Crea los objetos
|
||||
notify = new Notify(renderer, asset->get("notify.png"), asset->get("8bithud.png"), asset->get("8bithud.txt"), asset->get("notify.wav"), options);
|
||||
notify = new Notify(renderer, asset->get("notify.png"), asset->get("8bithud.png"), asset->get("8bithud.txt"), asset->get("notify.wav"));
|
||||
|
||||
// Define el color del borde para el modo de pantalla completa
|
||||
borderColor = {0x00, 0x00, 0x00};
|
||||
@@ -57,7 +57,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input *
|
||||
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
|
||||
|
||||
// Establece el modo de video
|
||||
setVideoMode(options->video.mode);
|
||||
setVideoMode(options.video.mode);
|
||||
|
||||
// Muestra la ventana
|
||||
SDL_ShowWindow(window);
|
||||
@@ -115,7 +115,7 @@ void Screen::blit()
|
||||
// Muestra por pantalla el renderizador
|
||||
SDL_RenderPresent(renderer);
|
||||
#else
|
||||
if (options->video.shaders)
|
||||
if (options.video.shaders)
|
||||
{
|
||||
shader::render();
|
||||
}
|
||||
@@ -164,7 +164,7 @@ void Screen::setVideoMode(int videoMode)
|
||||
dest = {0, 0, windowWidth, windowHeight};
|
||||
|
||||
// Modifica el tamaño de la ventana
|
||||
SDL_SetWindowSize(window, windowWidth * options->video.window.size, windowHeight * options->video.window.size);
|
||||
SDL_SetWindowSize(window, windowWidth * options.video.window.size, windowHeight * options.video.window.size);
|
||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
}
|
||||
|
||||
@@ -195,7 +195,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->video.integerScale)
|
||||
if (options.video.integerScale)
|
||||
{
|
||||
// Calcula el tamaño de la escala máxima
|
||||
int scale = 0;
|
||||
@@ -209,7 +209,7 @@ void Screen::setVideoMode(int videoMode)
|
||||
dest.x = (windowWidth - dest.w) / 2;
|
||||
dest.y = (windowHeight - dest.h) / 2;
|
||||
}
|
||||
else if (options->video.keepAspect)
|
||||
else if (options.video.keepAspect)
|
||||
{
|
||||
float ratio = (float)gameCanvasWidth / (float)gameCanvasHeight;
|
||||
if ((windowWidth - gameCanvasWidth) >= (windowHeight - gameCanvasHeight))
|
||||
@@ -239,7 +239,7 @@ void Screen::setVideoMode(int videoMode)
|
||||
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||
#else
|
||||
// Reinicia los shaders
|
||||
if (options->video.shaders)
|
||||
if (options.video.shaders)
|
||||
{
|
||||
std::ifstream f(asset->get("crtpi.glsl").c_str());
|
||||
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
||||
@@ -257,9 +257,9 @@ void Screen::setVideoMode(int videoMode)
|
||||
#endif
|
||||
|
||||
// Actualiza las opciones
|
||||
options->video.mode = videoMode;
|
||||
options->video.window.width = windowWidth;
|
||||
options->video.window.height = windowHeight;
|
||||
options.video.mode = videoMode;
|
||||
options.video.window.width = windowWidth;
|
||||
options.video.window.height = windowHeight;
|
||||
|
||||
// Actualiza variables
|
||||
shakeEffect.origin = dest.x;
|
||||
@@ -268,30 +268,30 @@ void Screen::setVideoMode(int videoMode)
|
||||
// Camibia entre pantalla completa y ventana
|
||||
void Screen::switchVideoMode()
|
||||
{
|
||||
options->video.mode = options->video.mode == SCREEN_VIDEO_MODE_WINDOW ? SCREEN_VIDEO_MODE_FULLSCREEN : SCREEN_VIDEO_MODE_WINDOW;
|
||||
setVideoMode(options->video.mode);
|
||||
options.video.mode = options.video.mode == SCREEN_VIDEO_MODE_WINDOW ? SCREEN_VIDEO_MODE_FULLSCREEN : SCREEN_VIDEO_MODE_WINDOW;
|
||||
setVideoMode(options.video.mode);
|
||||
}
|
||||
|
||||
// Cambia el tamaño de la ventana
|
||||
void Screen::setWindowSize(int size)
|
||||
{
|
||||
options->video.window.size = size;
|
||||
options.video.window.size = size;
|
||||
setVideoMode(SCREEN_VIDEO_MODE_WINDOW);
|
||||
}
|
||||
|
||||
// Reduce el tamaño de la ventana
|
||||
void Screen::decWindowSize()
|
||||
{
|
||||
--options->video.window.size;
|
||||
options->video.window.size = std::max(options->video.window.size, 1);
|
||||
--options.video.window.size;
|
||||
options.video.window.size = std::max(options.video.window.size, 1);
|
||||
setVideoMode(SCREEN_VIDEO_MODE_WINDOW);
|
||||
}
|
||||
|
||||
// Aumenta el tamaño de la ventana
|
||||
void Screen::incWindowSize()
|
||||
{
|
||||
++options->video.window.size;
|
||||
options->video.window.size = std::min(options->video.window.size, 4);
|
||||
++options.video.window.size;
|
||||
options.video.window.size = std::min(options.video.window.size, 4);
|
||||
setVideoMode(SCREEN_VIDEO_MODE_WINDOW);
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ void Screen::checkInput()
|
||||
if (input->checkInput(input_window_fullscreen, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
switchVideoMode();
|
||||
const std::string mode = options->video.mode == SCREEN_VIDEO_MODE_WINDOW ? "Window" : "Fullscreen";
|
||||
const std::string mode = options.video.mode == SCREEN_VIDEO_MODE_WINDOW ? "Window" : "Fullscreen";
|
||||
showNotification(mode + " mode");
|
||||
return;
|
||||
}
|
||||
@@ -332,7 +332,7 @@ void Screen::checkInput()
|
||||
if (input->checkInput(input_window_dec_size, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
decWindowSize();
|
||||
const std::string size = std::to_string(options->video.window.size);
|
||||
const std::string size = std::to_string(options.video.window.size);
|
||||
showNotification("Window size x" + size);
|
||||
return;
|
||||
}
|
||||
@@ -341,7 +341,7 @@ void Screen::checkInput()
|
||||
if (input->checkInput(input_window_inc_size, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
incWindowSize();
|
||||
const std::string size = std::to_string(options->video.window.size);
|
||||
const std::string size = std::to_string(options.video.window.size);
|
||||
showNotification("Window size x" + size);
|
||||
return;
|
||||
}
|
||||
@@ -459,9 +459,9 @@ void Screen::doAttenuate()
|
||||
// Activa/desactiva los shaders
|
||||
void Screen::switchShaders()
|
||||
{
|
||||
options->video.shaders = !options->video.shaders;
|
||||
setVideoMode(options->video.mode);
|
||||
const std::string value = options->video.shaders ? "on" : "off";
|
||||
options.video.shaders = !options.video.shaders;
|
||||
setVideoMode(options.video.mode);
|
||||
const std::string value = options.video.shaders ? "on" : "off";
|
||||
showNotification("Shaders " + value);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user