Actualizando las clases comunes a sus ultimas versiones
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#include "screen.h"
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
// Constructor
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, 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;
|
||||
@@ -12,10 +12,14 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
|
||||
this->asset = asset;
|
||||
|
||||
// Crea los objetos
|
||||
notify = new Notify(renderer, asset->get("smb2.png"), asset->get("smb2.txt"));
|
||||
notify = new Notify(renderer, asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav"), options);
|
||||
|
||||
gameCanvasWidth = gameInternalResX;
|
||||
gameCanvasHeight = gameInternalResY;
|
||||
gameCanvasWidth = options->gameWidth;
|
||||
gameCanvasHeight = options->gameHeight;
|
||||
borderWidth = options->borderWidth * 2;
|
||||
borderHeight = options->borderHeight * 2;
|
||||
notificationLogicalWidth = gameCanvasWidth;
|
||||
notificationLogicalHeight = gameCanvasHeight;
|
||||
|
||||
iniFade();
|
||||
iniSpectrumFade();
|
||||
@@ -27,19 +31,14 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
|
||||
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
|
||||
if (gameCanvas == nullptr)
|
||||
{
|
||||
printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el modo de video
|
||||
setVideoMode(options->fullScreenMode);
|
||||
|
||||
// Calcula los anclajes
|
||||
anchor.left = 0;
|
||||
anchor.right = gameCanvasWidth;
|
||||
anchor.center = gameCanvasWidth / 2;
|
||||
anchor.top = 0;
|
||||
anchor.bottom = gameCanvasHeight;
|
||||
anchor.middle = gameCanvasHeight / 2;
|
||||
setVideoMode(options->videoMode);
|
||||
|
||||
// Inicializa variables
|
||||
notifyActive = false;
|
||||
@@ -85,96 +84,103 @@ void Screen::blit()
|
||||
}
|
||||
|
||||
// Establece el modo de video
|
||||
void Screen::setVideoMode(int fullScreenMode)
|
||||
void Screen::setVideoMode(int videoMode)
|
||||
{
|
||||
// Muestra el puntero
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
|
||||
// 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};
|
||||
windowWidth = gameCanvasWidth + borderWidth;
|
||||
windowHeight = gameCanvasHeight + borderHeight;
|
||||
dest = {0 + (borderWidth / 2), 0 + (borderHeight / 2), gameCanvasWidth, gameCanvasHeight};
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
screenWidth = gameCanvasWidth * options->windowSize;
|
||||
screenHeight = gameCanvasHeight * options->windowSize;
|
||||
windowWidth = gameCanvasWidth;
|
||||
windowHeight = gameCanvasHeight;
|
||||
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);
|
||||
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||
SDL_SetWindowSize(window, windowWidth * options->windowSize, windowHeight * options->windowSize);
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
// Oculta el puntero
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
|
||||
// Obten el alto y el ancho de la ventana
|
||||
SDL_GetWindowSize(window, &screenWidth, &screenHeight);
|
||||
SDL_GetWindowSize(window, &windowWidth, &windowHeight);
|
||||
|
||||
// Aplica el escalado al rectangulo donde se pinta la textura del juego
|
||||
if (options->integerScale)
|
||||
{
|
||||
// Calcula el tamaño de la escala máxima
|
||||
int scale = 0;
|
||||
while (((gameCanvasWidth * (scale + 1)) <= screenWidth) && ((gameCanvasHeight * (scale + 1)) <= screenHeight))
|
||||
while (((gameCanvasWidth * (scale + 1)) <= windowWidth) && ((gameCanvasHeight * (scale + 1)) <= windowHeight))
|
||||
{
|
||||
scale++;
|
||||
}
|
||||
|
||||
dest.w = gameCanvasWidth * scale;
|
||||
dest.h = gameCanvasHeight * scale;
|
||||
dest.x = (screenWidth - dest.w) / 2;
|
||||
dest.y = (screenHeight - dest.h) / 2;
|
||||
dest.x = (windowWidth - dest.w) / 2;
|
||||
dest.y = (windowHeight - dest.h) / 2;
|
||||
}
|
||||
else if (options->keepAspect)
|
||||
{
|
||||
float ratio = (float)gameCanvasWidth / (float)gameCanvasHeight;
|
||||
if ((screenWidth - gameCanvasWidth) >= (screenHeight - gameCanvasHeight))
|
||||
if ((windowWidth - gameCanvasWidth) >= (windowHeight - gameCanvasHeight))
|
||||
{
|
||||
dest.h = screenHeight;
|
||||
dest.w = (int)((screenHeight * ratio) + 0.5f);
|
||||
dest.x = (screenWidth - dest.w) / 2;
|
||||
dest.y = (screenHeight - dest.h) / 2;
|
||||
dest.h = windowHeight;
|
||||
dest.w = (int)((windowHeight * ratio) + 0.5f);
|
||||
dest.x = (windowWidth - dest.w) / 2;
|
||||
dest.y = (windowHeight - dest.h) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
dest.w = screenWidth;
|
||||
dest.h = (int)((screenWidth / ratio) + 0.5f);
|
||||
dest.x = (screenWidth - dest.w) / 2;
|
||||
dest.y = (screenHeight - dest.h) / 2;
|
||||
dest.w = windowWidth;
|
||||
dest.h = (int)((windowWidth / ratio) + 0.5f);
|
||||
dest.x = (windowWidth - dest.w) / 2;
|
||||
dest.y = (windowHeight - dest.h) / 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dest.w = screenWidth;
|
||||
dest.h = screenHeight;
|
||||
dest.w = windowWidth;
|
||||
dest.h = windowHeight;
|
||||
dest.x = dest.y = 0;
|
||||
}
|
||||
|
||||
// Modifica el tamaño del renderizador
|
||||
SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight);
|
||||
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
options->fullScreenMode = fullScreenMode;
|
||||
// Actualiza las opciones
|
||||
options->videoMode = videoMode;
|
||||
options->screen.windowWidth = windowWidth;
|
||||
options->screen.windowHeight = windowHeight;
|
||||
|
||||
// Establece el tamaño de las notificaciones
|
||||
setNotificationSize();
|
||||
}
|
||||
|
||||
// Camibia entre pantalla completa y ventana
|
||||
void Screen::switchVideoMode()
|
||||
{
|
||||
options->fullScreenMode = (options->fullScreenMode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
|
||||
setVideoMode(options->fullScreenMode);
|
||||
options->videoMode = (options->videoMode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
|
||||
setVideoMode(options->videoMode);
|
||||
}
|
||||
|
||||
// Cambia el tamaño de la ventana
|
||||
@@ -197,9 +203,15 @@ void Screen::setBlendMode(SDL_BlendMode blendMode)
|
||||
}
|
||||
|
||||
// Establece el tamaño del borde
|
||||
void Screen::setBorderSize(float s)
|
||||
void Screen::setBorderWidth(int s)
|
||||
{
|
||||
options->borderSize = s;
|
||||
options->borderWidth = s;
|
||||
}
|
||||
|
||||
// Establece el tamaño del borde
|
||||
void Screen::setBorderHeight(int s)
|
||||
{
|
||||
options->borderHeight = s;
|
||||
}
|
||||
|
||||
// Establece si se ha de ver el borde en el modo ventana
|
||||
@@ -301,7 +313,7 @@ void Screen::iniSpectrumFade()
|
||||
const std::vector<std::string> vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"};
|
||||
for (auto v : vColors)
|
||||
{
|
||||
spectrumColor.push_back(stringToColor(p_zxspectrum, v));
|
||||
spectrumColor.push_back(stringToColor(options->palette, v));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,7 +344,7 @@ void Screen::renderSpectrumFade()
|
||||
const float step = (float)spectrumFadeCounter / (float)spectrumFadeLenght;
|
||||
const int max = spectrumColor.size() - 1;
|
||||
const int index = max + (0 - max) * step;
|
||||
const color_t c = spectrumColor.at(index);
|
||||
const color_t c = spectrumColor[index];
|
||||
SDL_SetTextureColorMod(gameCanvas, c.r, c.g, c.b);
|
||||
}
|
||||
|
||||
@@ -358,7 +370,7 @@ void Screen::updateNotifier()
|
||||
}
|
||||
|
||||
// Muestra una notificación de texto por pantalla;
|
||||
void Screen::showText(std::string text)
|
||||
void Screen::showNotification(std::string text)
|
||||
{
|
||||
notify->showText(text);
|
||||
}
|
||||
@@ -371,8 +383,31 @@ void Screen::renderNotifications()
|
||||
return;
|
||||
}
|
||||
|
||||
//SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight);
|
||||
SDL_RenderSetLogicalSize(renderer, gameCanvasWidth*2, gameCanvasHeight*2);
|
||||
//SDL_RenderSetLogicalSize(renderer, notificationLogicalWidth, notificationLogicalHeight);
|
||||
notify->render();
|
||||
SDL_RenderSetLogicalSize(renderer, gameCanvasWidth, gameCanvasHeight);
|
||||
//SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||
}
|
||||
|
||||
// Establece el tamaño de las notificaciones
|
||||
void Screen::setNotificationSize()
|
||||
{
|
||||
if (options->videoMode == 0)
|
||||
{
|
||||
if (options->windowSize == 3)
|
||||
{
|
||||
notificationLogicalWidth = (windowWidth * 3) / 2;
|
||||
notificationLogicalHeight = (windowHeight * 3) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
notificationLogicalWidth = windowWidth * 2;
|
||||
notificationLogicalHeight = windowHeight * 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (options->videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
||||
{
|
||||
notificationLogicalWidth = windowWidth / 3;
|
||||
notificationLogicalHeight = windowHeight / 3;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user