canvi de pc (treballant en Screen::applySettings())
This commit is contained in:
@@ -1,25 +1,25 @@
|
||||
#include "screen.h"
|
||||
#include <SDL3/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
||||
#include <SDL3/SDL_error.h> // Para SDL_GetError
|
||||
#include <SDL3/SDL_hints.h> // Para SDL_SetHint, SDL_HINT_RENDER_DRIVER
|
||||
#include <SDL3/SDL_init.h> // Para SDL_Init, SDL_INIT_VIDEO
|
||||
#include <SDL3/SDL_log.h> // Para SDL_LogCategory, SDL_LogError, SDL_L...
|
||||
#include <SDL3/SDL_pixels.h> // Para SDL_PixelFormat
|
||||
#include <SDL3/SDL_surface.h> // Para SDL_ScaleMode
|
||||
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <algorithm> // Para min, max
|
||||
#include <fstream> // Para basic_ifstream, ifstream
|
||||
#include <iterator> // Para istreambuf_iterator, operator==
|
||||
#include <memory> // Para __shared_ptr_access, shared_ptr
|
||||
#include <string> // Para allocator, char_traits, operator+
|
||||
#include "asset.h" // Para Asset
|
||||
#include "external/jail_shader.h" // Para init, render
|
||||
#include "mouse.h" // Para updateCursorVisibility
|
||||
#include "notifier.h" // Para Notifier
|
||||
#include "options.h" // Para Options, options, WindowOptions, Vid...
|
||||
#include "resource.h" // Para Resource
|
||||
#include "ui/service_menu.h" // Para ServiceMenu
|
||||
#include "text.h" // Para Text
|
||||
#include <SDL3/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
||||
#include <SDL3/SDL_error.h> // Para SDL_GetError
|
||||
#include <SDL3/SDL_hints.h> // Para SDL_SetHint, SDL_HINT_RENDER_DRIVER
|
||||
#include <SDL3/SDL_init.h> // Para SDL_Init, SDL_INIT_VIDEO
|
||||
#include <SDL3/SDL_log.h> // Para SDL_LogCategory, SDL_LogError, SDL_L...
|
||||
#include <SDL3/SDL_pixels.h> // Para SDL_PixelFormat
|
||||
#include <SDL3/SDL_surface.h> // Para SDL_ScaleMode
|
||||
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <algorithm> // Para min, max
|
||||
#include <fstream> // Para basic_ifstream, ifstream
|
||||
#include <iterator> // Para istreambuf_iterator, operator==
|
||||
#include <memory> // Para __shared_ptr_access, shared_ptr
|
||||
#include <string> // Para allocator, char_traits, operator+
|
||||
#include "asset.h" // Para Asset
|
||||
#include "external/jail_shader.h" // Para init, render
|
||||
#include "mouse.h" // Para updateCursorVisibility
|
||||
#include "notifier.h" // Para Notifier
|
||||
#include "options.h" // Para Options, options, WindowOptions, Vid...
|
||||
#include "resource.h" // Para Resource
|
||||
#include "ui/service_menu.h" // Para ServiceMenu
|
||||
#include "text.h" // Para Text
|
||||
|
||||
// Singleton
|
||||
Screen *Screen::instance_ = nullptr;
|
||||
@@ -44,7 +44,7 @@ Screen::Screen()
|
||||
dst_rect_(SDL_FRect{0, 0, static_cast<float>(param.game.width), static_cast<float>(param.game.height)})
|
||||
{
|
||||
// Arranca SDL VIDEO, crea la ventana y el renderizador
|
||||
initSDL();
|
||||
initSDLVideo();
|
||||
|
||||
// Crea la textura de destino
|
||||
game_canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
||||
@@ -53,9 +53,6 @@ Screen::Screen()
|
||||
// Inicializa variables
|
||||
adjustRenderLogicalSize();
|
||||
|
||||
// Inicializa los shaders
|
||||
initShaders();
|
||||
|
||||
// Crea el objeto de texto
|
||||
createText();
|
||||
|
||||
@@ -63,6 +60,10 @@ Screen::Screen()
|
||||
debug_info_.text = text_;
|
||||
setDebugInfoEnabled(true);
|
||||
#endif
|
||||
|
||||
// Inicializa los shaders
|
||||
show();
|
||||
initShaders();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -125,12 +126,8 @@ void Screen::renderScreen()
|
||||
// Establece el modo de video
|
||||
void Screen::setFullscreenMode(bool mode)
|
||||
{
|
||||
// Actualiza las opciones
|
||||
Options::video.fullscreen = mode;
|
||||
|
||||
// Configura el modo de pantalla
|
||||
SDL_SetWindowFullscreen(window_, Options::video.fullscreen);
|
||||
|
||||
initShaders();
|
||||
}
|
||||
|
||||
@@ -271,7 +268,6 @@ void Screen::loadShaders()
|
||||
// Inicializa los shaders
|
||||
void Screen::initShaders()
|
||||
{
|
||||
show(); // Se ha de ejecutar con la ventana visible
|
||||
loadShaders();
|
||||
shader::init(window_, game_canvas_, shader_source_);
|
||||
}
|
||||
@@ -280,22 +276,22 @@ void Screen::initShaders()
|
||||
void Screen::adjustWindowSize()
|
||||
{
|
||||
// Establece el nuevo tamaño
|
||||
const int WIDTH = param.game.width * Options::window.size;
|
||||
const int HEIGHT = param.game.height * Options::window.size;
|
||||
const int WIDTH = param.game.width * Options::window.size;
|
||||
const int HEIGHT = param.game.height * Options::window.size;
|
||||
|
||||
int old_width, old_height;
|
||||
SDL_GetWindowSize(window_, &old_width, &old_height);
|
||||
int old_width, old_height;
|
||||
SDL_GetWindowSize(window_, &old_width, &old_height);
|
||||
|
||||
int old_pos_x, old_pos_y;
|
||||
SDL_GetWindowPosition(window_, &old_pos_x, &old_pos_y);
|
||||
int old_pos_x, old_pos_y;
|
||||
SDL_GetWindowPosition(window_, &old_pos_x, &old_pos_y);
|
||||
|
||||
const int NEW_POS_X = old_pos_x + (old_width - WIDTH) / 2;
|
||||
const int NEW_POS_Y = old_pos_y + (old_height - HEIGHT) / 2;
|
||||
const int NEW_POS_X = old_pos_x + (old_width - WIDTH) / 2;
|
||||
const int NEW_POS_Y = old_pos_y + (old_height - HEIGHT) / 2;
|
||||
|
||||
SDL_SetWindowPosition(window_, std::max(NEW_POS_X, WINDOWS_DECORATIONS_), std::max(NEW_POS_Y, 0));
|
||||
SDL_SetWindowSize(window_, WIDTH, HEIGHT);
|
||||
SDL_SetWindowPosition(window_, std::max(NEW_POS_X, WINDOWS_DECORATIONS_), std::max(NEW_POS_Y, 0));
|
||||
SDL_SetWindowSize(window_, WIDTH, HEIGHT);
|
||||
|
||||
initShaders();
|
||||
initShaders();
|
||||
}
|
||||
|
||||
// Renderiza todos los overlays y efectos
|
||||
@@ -323,7 +319,7 @@ void Screen::renderAttenuate()
|
||||
}
|
||||
|
||||
// Arranca SDL VIDEO y crea la ventana
|
||||
bool Screen::initSDL()
|
||||
bool Screen::initSDLVideo()
|
||||
{
|
||||
// Indicador de éxito
|
||||
auto success = true;
|
||||
@@ -405,8 +401,8 @@ void Screen::getDisplayInfo()
|
||||
static_cast<int>(param.game.width), static_cast<int>(param.game.height), Options::window.size);
|
||||
|
||||
Options::video.info = std::to_string(static_cast<int>(DM->w)) + "x" +
|
||||
std::to_string(static_cast<int>(DM->h)) + " @ " +
|
||||
std::to_string(static_cast<int>(DM->refresh_rate)) + " Hz";
|
||||
std::to_string(static_cast<int>(DM->h)) + " @ " +
|
||||
std::to_string(static_cast<int>(DM->refresh_rate)) + " Hz";
|
||||
|
||||
// Calcula el máximo factor de zoom que se puede aplicar a la pantalla
|
||||
const int MAX_ZOOM = std::min(DM->w / param.game.width, (DM->h - WINDOWS_DECORATIONS_) / param.game.height);
|
||||
@@ -451,8 +447,8 @@ void Screen::applySettings()
|
||||
{
|
||||
SDL_SetRenderVSync(renderer_, Options::video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
|
||||
SDL_SetRenderLogicalPresentation(Screen::get()->getRenderer(), param.game.width, param.game.height, Options::video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX);
|
||||
adjustWindowSize();
|
||||
setFullscreenMode();
|
||||
adjustWindowSize();
|
||||
}
|
||||
|
||||
// Crea el objeto de texto
|
||||
|
||||
Reference in New Issue
Block a user