forked from jaildesigner-jailgames/jaildoctors_dilemma
Arreglada la clase Screen. Había un lio de conceptos con varias variables
This commit is contained in:
@@ -3,15 +3,19 @@
|
||||
#include <iostream>
|
||||
|
||||
// Constructor
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, int gameInternalResX, int gameInternalResY)
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options)
|
||||
{
|
||||
// Inicializa variables
|
||||
this->window = window;
|
||||
this->renderer = renderer;
|
||||
this->options = options;
|
||||
this->asset = asset;
|
||||
|
||||
gameCanvasWidth = gameInternalResX;
|
||||
gameCanvasHeight = gameInternalResY;
|
||||
// Crea los objetos
|
||||
notify = new Notify(renderer, asset->get("smb2.png"), asset->get("smb2.txt"));
|
||||
|
||||
gameCanvasWidth = options->gameWidth;
|
||||
gameCanvasHeight = options->gameHeight;
|
||||
|
||||
iniFade();
|
||||
iniSpectrumFade();
|
||||
@@ -27,15 +31,16 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, i
|
||||
}
|
||||
|
||||
// Establece el modo de video
|
||||
setVideoMode(options->fullScreenMode);
|
||||
setVideoMode(options->videoMode);
|
||||
|
||||
// Calcula los anclajes
|
||||
anchor.left = 0;
|
||||
anchor.right = gameCanvasWidth;
|
||||
anchor.center = gameCanvasWidth / 2;
|
||||
anchor.top = 0;
|
||||
anchor.bottom = gameCanvasHeight;
|
||||
anchor.middle = gameCanvasHeight / 2;
|
||||
// Inicializa variables
|
||||
notifyActive = false;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Screen::~Screen()
|
||||
{
|
||||
delete notify;
|
||||
}
|
||||
|
||||
// Limpia la pantalla
|
||||
@@ -64,42 +69,49 @@ void Screen::blit()
|
||||
// Copia la textura de juego en el renderizador en la posición adecuada
|
||||
SDL_RenderCopy(renderer, gameCanvas, nullptr, &dest);
|
||||
|
||||
// Dibuja las notificaciones
|
||||
// renderNotifications();
|
||||
|
||||
// Muestra por pantalla el renderizador
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
// Establece el modo de video
|
||||
void Screen::setVideoMode(int fullScreenMode)
|
||||
void Screen::setVideoMode(int videoMode)
|
||||
{
|
||||
// Aplica el modo de video
|
||||
SDL_SetWindowFullscreen(window, fullScreenMode);
|
||||
SDL_SetWindowFullscreen(window, videoMode);
|
||||
|
||||
// Si está activo el modo ventana quita el borde
|
||||
if (fullScreenMode == 0)
|
||||
if (videoMode == 0)
|
||||
{
|
||||
if (options->borderEnabled)
|
||||
{
|
||||
const int incWidth = gameCanvasWidth * options->borderSize;
|
||||
const int incHeight = gameCanvasHeight * options->borderSize;
|
||||
screenWidth = gameCanvasWidth + incWidth;
|
||||
screenHeight = gameCanvasHeight + incHeight;
|
||||
dest = {0 + (incWidth / 2), 0 + (incHeight / 2), gameCanvasWidth, gameCanvasHeight};
|
||||
const int incWidth = options->gameWidth * options->borderSize;
|
||||
const int incHeight = options->gameHeight * options->borderSize;
|
||||
gameCanvasWidth = options->gameWidth + incWidth;
|
||||
gameCanvasHeight = options->gameHeight + incHeight;
|
||||
screenWidth = gameCanvasWidth * options->windowSize;
|
||||
screenHeight = gameCanvasHeight * options->windowSize;
|
||||
dest = {0 + (incWidth / 2), 0 + (incHeight / 2), options->gameWidth, options->gameHeight};
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
screenWidth = gameCanvasWidth;
|
||||
screenHeight = gameCanvasHeight;
|
||||
gameCanvasWidth = options->gameWidth;
|
||||
gameCanvasHeight = options->gameHeight;
|
||||
screenWidth = gameCanvasWidth * options->windowSize;
|
||||
screenHeight = gameCanvasHeight * options->windowSize;
|
||||
dest = {0, 0, gameCanvasWidth, gameCanvasHeight};
|
||||
}
|
||||
|
||||
// Modifica el tamaño del renderizador y de la ventana
|
||||
SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight);
|
||||
SDL_SetWindowSize(window, screenWidth * options->windowSize, screenHeight * options->windowSize);
|
||||
SDL_RenderSetLogicalSize(renderer, gameCanvasWidth, gameCanvasHeight);
|
||||
SDL_SetWindowSize(window, screenWidth, screenHeight);
|
||||
}
|
||||
|
||||
// Si está activo el modo de pantalla completa añade el borde
|
||||
else if (fullScreenMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
||||
else if (videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
||||
{
|
||||
// Obten el alto y el ancho de la ventana
|
||||
SDL_GetWindowSize(window, &screenWidth, &screenHeight);
|
||||
@@ -149,22 +161,14 @@ void Screen::setVideoMode(int fullScreenMode)
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
options->fullScreenMode = fullScreenMode;
|
||||
options->videoMode = videoMode;
|
||||
}
|
||||
|
||||
// Camibia entre pantalla completa y ventana
|
||||
void Screen::switchVideoMode()
|
||||
{
|
||||
if (options->fullScreenMode == 0)
|
||||
{
|
||||
options->fullScreenMode = SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
}
|
||||
else
|
||||
{
|
||||
options->fullScreenMode = 0;
|
||||
}
|
||||
|
||||
setVideoMode(options->fullScreenMode);
|
||||
options->videoMode = (options->videoMode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
|
||||
setVideoMode(options->videoMode);
|
||||
}
|
||||
|
||||
// Cambia el tamaño de la ventana
|
||||
@@ -338,4 +342,30 @@ void Screen::renderFX()
|
||||
{
|
||||
renderFade();
|
||||
renderSpectrumFade();
|
||||
}
|
||||
|
||||
// Actualiza el notificador
|
||||
void Screen::updateNotifier()
|
||||
{
|
||||
notify->update();
|
||||
notifyActive = notify->active();
|
||||
}
|
||||
|
||||
// Muestra una notificación de texto por pantalla;
|
||||
void Screen::showText(std::string text)
|
||||
{
|
||||
notify->showText(text);
|
||||
}
|
||||
|
||||
// Dibuja las notificaciones
|
||||
void Screen::renderNotifications()
|
||||
{
|
||||
if (!notifyActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight);
|
||||
notify->render();
|
||||
SDL_RenderSetLogicalSize(renderer, gameCanvasWidth, gameCanvasHeight);
|
||||
}
|
||||
Reference in New Issue
Block a user