|
|
|
|
@@ -13,7 +13,7 @@
|
|
|
|
|
#include "notifier.h" // Para Notify
|
|
|
|
|
#include "options.h"
|
|
|
|
|
#include "mouse.h"
|
|
|
|
|
//#include "surface.h"
|
|
|
|
|
// #include "surface.h"
|
|
|
|
|
|
|
|
|
|
// [SINGLETON]
|
|
|
|
|
Screen *Screen::screen_ = nullptr;
|
|
|
|
|
@@ -58,13 +58,9 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
|
|
|
|
game_texture_ = createTexture(renderer, options.game.width, options.game.height);
|
|
|
|
|
|
|
|
|
|
// Crea la textura donde se dibuja el borde que rodea el area de juego
|
|
|
|
|
border_texture_ = createTexture(renderer,options.game.width + options.video.border.width * 2, options.game.height + options.video.border.height * 2);
|
|
|
|
|
border_texture_ = createTexture(renderer, options.game.width + options.video.border.width * 2, options.game.height + options.video.border.height * 2);
|
|
|
|
|
setBorderColor(border_color_);
|
|
|
|
|
|
|
|
|
|
// Crea la surface donde se pinta el juego
|
|
|
|
|
//surface_ = std::make_shared<Surface>(nullptr, options.game.width, options.game.height);
|
|
|
|
|
//surface_->loadPalette(Asset::get()->get("test.gif"));
|
|
|
|
|
|
|
|
|
|
// Establece el modo de video
|
|
|
|
|
setVideoMode(options.video.mode);
|
|
|
|
|
|
|
|
|
|
@@ -89,17 +85,10 @@ void Screen::clean(Color color)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Prepara para empezar a dibujar en la textura de juego
|
|
|
|
|
void Screen::start()
|
|
|
|
|
{
|
|
|
|
|
//surface_->clear(surface_->getSurface(), surface_->getTransparentColor());
|
|
|
|
|
SDL_SetRenderTarget(renderer_, game_texture_);
|
|
|
|
|
}
|
|
|
|
|
void Screen::start() { SDL_SetRenderTarget(renderer_, game_texture_); }
|
|
|
|
|
|
|
|
|
|
// Prepara para empezar a dibujar en la textura del borde
|
|
|
|
|
void Screen::startDrawOnBorder()
|
|
|
|
|
{
|
|
|
|
|
SDL_SetRenderTarget(renderer_, border_texture_);
|
|
|
|
|
}
|
|
|
|
|
void Screen::startDrawOnBorder() { SDL_SetRenderTarget(renderer_, border_texture_); }
|
|
|
|
|
|
|
|
|
|
// Vuelca el contenido del renderizador en pantalla
|
|
|
|
|
void Screen::render()
|
|
|
|
|
@@ -107,10 +96,6 @@ void Screen::render()
|
|
|
|
|
// Renderiza sobre gameCanvas los overlays
|
|
|
|
|
renderNotifications();
|
|
|
|
|
|
|
|
|
|
//fillTextureWithColor(renderer_, surface_texture_, 0xFF, 0x00, 0xFF, 0xFF);
|
|
|
|
|
//surface_->copyToTexture(renderer_, surface_texture_);
|
|
|
|
|
//SDL_RenderCopy(renderer_, surface_texture_, nullptr, nullptr);
|
|
|
|
|
|
|
|
|
|
// Si está el borde activo, vuelca gameCanvas sobre borderCanvas
|
|
|
|
|
if (options.video.border.enabled)
|
|
|
|
|
{
|
|
|
|
|
@@ -135,52 +120,22 @@ void Screen::renderWithoutNotifier()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Establece el modo de video
|
|
|
|
|
void Screen::setVideoMode(int videoMode)
|
|
|
|
|
void Screen::setVideoMode(int video_mode)
|
|
|
|
|
{
|
|
|
|
|
// Aplica el modo de video
|
|
|
|
|
// Actualiza las opciones
|
|
|
|
|
options.video.mode = video_mode;
|
|
|
|
|
|
|
|
|
|
// Modo ventana
|
|
|
|
|
if (videoMode == 0)
|
|
|
|
|
{
|
|
|
|
|
// Muestra el puntero
|
|
|
|
|
SDL_ShowCursor(SDL_ENABLE);
|
|
|
|
|
// Mostrar u ocultar el cursor según el modo
|
|
|
|
|
SDL_ShowCursor(options.video.mode == 0 ? SDL_ENABLE : SDL_DISABLE);
|
|
|
|
|
|
|
|
|
|
SDL_SetWindowFullscreen(window_, videoMode);
|
|
|
|
|
// Configura el modo de pantalla y ajusta la ventana
|
|
|
|
|
SDL_SetWindowFullscreen(window_, options.video.mode);
|
|
|
|
|
adjustWindowSize();
|
|
|
|
|
adjustGameCanvasRect();
|
|
|
|
|
adjustRenderLogicalSize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Modo pantalla completa
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Oculta el puntero
|
|
|
|
|
SDL_ShowCursor(SDL_DISABLE);
|
|
|
|
|
adjustWindowSize();
|
|
|
|
|
|
|
|
|
|
adjustGameCanvasRect();
|
|
|
|
|
SDL_SetWindowFullscreen(window_, videoMode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Actualiza las opciones
|
|
|
|
|
options.video.mode = videoMode;
|
|
|
|
|
|
|
|
|
|
// Reinicia los shaders
|
|
|
|
|
if (options.video.shaders)
|
|
|
|
|
{
|
|
|
|
|
const std::string glsl_file = window_height_ == 192 ? "crtpi_192.glsl" : "crtpi_240.glsl";
|
|
|
|
|
std::ifstream f(Asset::get()->get(glsl_file).c_str());
|
|
|
|
|
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
|
|
|
|
|
|
|
|
|
if (options.video.border.enabled)
|
|
|
|
|
{
|
|
|
|
|
shader::init(window_, border_texture_, source.c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
shader::init(window_, game_texture_, source.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
resetShaders();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Camibia entre pantalla completa y ventana
|
|
|
|
|
@@ -195,13 +150,13 @@ bool Screen::decWindowZoom()
|
|
|
|
|
{
|
|
|
|
|
if (options.video.mode == 0)
|
|
|
|
|
{
|
|
|
|
|
int previous_zoom = options.window.zoom;
|
|
|
|
|
const int PREVIOUS_ZOOM = options.window.zoom;
|
|
|
|
|
--options.window.zoom;
|
|
|
|
|
options.window.zoom = std::max(options.window.zoom, 1);
|
|
|
|
|
|
|
|
|
|
if (options.window.zoom != previous_zoom)
|
|
|
|
|
if (options.window.zoom != PREVIOUS_ZOOM)
|
|
|
|
|
{
|
|
|
|
|
adjustWindowSize();
|
|
|
|
|
setVideoMode(options.video.mode);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -214,13 +169,13 @@ bool Screen::incWindowZoom()
|
|
|
|
|
{
|
|
|
|
|
if (options.video.mode == 0)
|
|
|
|
|
{
|
|
|
|
|
int previous_zoom = options.window.zoom;
|
|
|
|
|
const int PREVIOUS_ZOOM = options.window.zoom;
|
|
|
|
|
++options.window.zoom;
|
|
|
|
|
options.window.zoom = std::min(options.window.zoom, options.window.max_zoom);
|
|
|
|
|
|
|
|
|
|
if (options.window.zoom != previous_zoom)
|
|
|
|
|
if (options.window.zoom != PREVIOUS_ZOOM)
|
|
|
|
|
{
|
|
|
|
|
adjustWindowSize();
|
|
|
|
|
setVideoMode(options.video.mode);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -240,22 +195,13 @@ void Screen::setBorderColor(Color color)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cambia el tipo de mezcla
|
|
|
|
|
void Screen::setBlendMode(SDL_BlendMode blendMode)
|
|
|
|
|
{
|
|
|
|
|
SDL_SetRenderDrawBlendMode(renderer_, blendMode);
|
|
|
|
|
}
|
|
|
|
|
void Screen::setBlendMode(SDL_BlendMode blendMode) { SDL_SetRenderDrawBlendMode(renderer_, blendMode); }
|
|
|
|
|
|
|
|
|
|
// Establece el tamaño del borde
|
|
|
|
|
void Screen::setBorderWidth(int s)
|
|
|
|
|
{
|
|
|
|
|
options.video.border.width = s;
|
|
|
|
|
}
|
|
|
|
|
void Screen::setBorderWidth(int s) { options.video.border.width = s; }
|
|
|
|
|
|
|
|
|
|
// Establece el tamaño del borde
|
|
|
|
|
void Screen::setBorderHeight(int s)
|
|
|
|
|
{
|
|
|
|
|
options.video.border.height = s;
|
|
|
|
|
}
|
|
|
|
|
void Screen::setBorderHeight(int s) { options.video.border.height = s; }
|
|
|
|
|
|
|
|
|
|
// Establece si se ha de ver el borde en el modo ventana
|
|
|
|
|
void Screen::setBorderEnabled(bool value) { options.video.border.enabled = value; }
|
|
|
|
|
@@ -264,16 +210,11 @@ void Screen::setBorderEnabled(bool value) { options.video.border.enabled = value
|
|
|
|
|
void Screen::toggleBorder()
|
|
|
|
|
{
|
|
|
|
|
options.video.border.enabled = !options.video.border.enabled;
|
|
|
|
|
adjustWindowSize();
|
|
|
|
|
adjustGameCanvasRect();
|
|
|
|
|
adjustRenderLogicalSize();
|
|
|
|
|
setVideoMode(options.video.mode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Dibuja las notificaciones
|
|
|
|
|
void Screen::renderNotifications()
|
|
|
|
|
{
|
|
|
|
|
Notifier::get()->render();
|
|
|
|
|
}
|
|
|
|
|
void Screen::renderNotifications() { Notifier::get()->render(); }
|
|
|
|
|
|
|
|
|
|
// Copia el gameCanvas en el borderCanvas
|
|
|
|
|
void Screen::gameCanvasToBorderCanvas()
|
|
|
|
|
@@ -325,16 +266,10 @@ void Screen::update()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Muestra la ventana
|
|
|
|
|
void Screen::show()
|
|
|
|
|
{
|
|
|
|
|
SDL_ShowWindow(window_);
|
|
|
|
|
}
|
|
|
|
|
void Screen::show() { SDL_ShowWindow(window_); }
|
|
|
|
|
|
|
|
|
|
// Oculta la ventana
|
|
|
|
|
void Screen::hide()
|
|
|
|
|
{
|
|
|
|
|
SDL_HideWindow(window_);
|
|
|
|
|
}
|
|
|
|
|
void Screen::hide() { SDL_HideWindow(window_); }
|
|
|
|
|
|
|
|
|
|
// Calcula el tamaño de la ventana
|
|
|
|
|
void Screen::adjustWindowSize()
|
|
|
|
|
@@ -353,11 +288,11 @@ void Screen::adjustWindowSize()
|
|
|
|
|
int old_pos_x, old_pos_y;
|
|
|
|
|
SDL_GetWindowPosition(window_, &old_pos_x, &old_pos_y);
|
|
|
|
|
|
|
|
|
|
int new_pos_x = old_pos_x + (old_width - (window_width_ * options.window.zoom)) / 2;
|
|
|
|
|
int new_pos_y = old_pos_y + (old_height - (window_height_ * options.window.zoom)) / 2;
|
|
|
|
|
const int NEW_POS_X = old_pos_x + (old_width - (window_width_ * options.window.zoom)) / 2;
|
|
|
|
|
const int NEW_POS_Y = old_pos_y + (old_height - (window_height_ * options.window.zoom)) / 2;
|
|
|
|
|
|
|
|
|
|
SDL_SetWindowSize(window_, window_width_ * options.window.zoom, window_height_ * options.window.zoom);
|
|
|
|
|
SDL_SetWindowPosition(window_, std::max(new_pos_x, WINDOWS_DECORATIONS_), std::max(new_pos_y, 0));
|
|
|
|
|
SDL_SetWindowPosition(window_, std::max(NEW_POS_X, WINDOWS_DECORATIONS_), std::max(NEW_POS_Y, 0));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -372,12 +307,7 @@ void Screen::adjustGameCanvasRect()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ajusta el tamaño lógico del renderizador
|
|
|
|
|
void Screen::adjustRenderLogicalSize()
|
|
|
|
|
{
|
|
|
|
|
const int extra_width = options.video.border.enabled ? options.video.border.width * 2 : 0;
|
|
|
|
|
const int extra_height = options.video.border.enabled ? options.video.border.height * 2 : 0;
|
|
|
|
|
SDL_RenderSetLogicalSize(renderer_, options.game.width + extra_width, options.game.height + extra_height);
|
|
|
|
|
}
|
|
|
|
|
void Screen::adjustRenderLogicalSize() { SDL_RenderSetLogicalSize(renderer_, window_width_, window_height_); }
|
|
|
|
|
|
|
|
|
|
// Obtiene el tamaño máximo de zoom posible para la ventana
|
|
|
|
|
int Screen::getMaxZoom()
|
|
|
|
|
@@ -387,10 +317,23 @@ int Screen::getMaxZoom()
|
|
|
|
|
SDL_GetCurrentDisplayMode(0, &DM);
|
|
|
|
|
|
|
|
|
|
// Calcula el máximo factor de zoom que se puede aplicar a la pantalla
|
|
|
|
|
const int max_zoom = std::min(DM.w / window_width_, (DM.h - WINDOWS_DECORATIONS_) / window_height_);
|
|
|
|
|
const int MAX_ZOOM = std::min(DM.w / window_width_, (DM.h - WINDOWS_DECORATIONS_) / window_height_);
|
|
|
|
|
|
|
|
|
|
// Normaliza los valores de zoom
|
|
|
|
|
options.window.zoom = std::min(options.window.zoom, max_zoom);
|
|
|
|
|
options.window.zoom = std::min(options.window.zoom, MAX_ZOOM);
|
|
|
|
|
|
|
|
|
|
return max_zoom;
|
|
|
|
|
return MAX_ZOOM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reinicia los shaders
|
|
|
|
|
void Screen::resetShaders()
|
|
|
|
|
{
|
|
|
|
|
if (options.video.shaders)
|
|
|
|
|
{
|
|
|
|
|
const std::string GLSL_FILE = window_height_ == 192 ? "crtpi_192.glsl" : "crtpi_240.glsl";
|
|
|
|
|
std::ifstream f(Asset::get()->get(GLSL_FILE).c_str());
|
|
|
|
|
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
|
|
|
|
|
|
|
|
|
shader::init(window_, options.video.border.enabled ? border_texture_ : game_texture_, source.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|