afegides les normes de les guidelines jailerianes
This commit is contained in:
+31
-18
@@ -37,23 +37,22 @@ Screen::Screen()
|
||||
// Arranca SDL VIDEO, crea la ventana y el renderizador
|
||||
initSDL();
|
||||
|
||||
// Obtiene información sobre la pantalla
|
||||
getDisplayInfo();
|
||||
|
||||
// Ajusta los tamaños
|
||||
adjustWindowSize();
|
||||
|
||||
// Crea la textura donde se dibujan los graficos del juego
|
||||
game_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, options.game.width, options.game.height);
|
||||
game_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, options.logo.width, options.logo.height);
|
||||
if (!game_texture_)
|
||||
{
|
||||
// Registrar el error si está habilitado
|
||||
if (options.console)
|
||||
{
|
||||
std::cerr << "Error: game_texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: game_texture_ could not be created! SDL Error: %s", SDL_GetError());
|
||||
}
|
||||
SDL_SetTextureScaleMode(game_texture_, options.video.scale_mode);
|
||||
|
||||
// Crea la surface donde se dibujan los graficos del juego
|
||||
game_surface_ = std::make_shared<Surface>(options.game.width, options.game.height);
|
||||
game_surface_ = std::make_shared<Surface>(options.logo.width, options.logo.height);
|
||||
game_surface_->setPalette(readPalFile("jailgames.pal"));
|
||||
game_surface_->clear(0);
|
||||
|
||||
@@ -115,7 +114,7 @@ void Screen::toggleFullscreen()
|
||||
// Reduce el tamaño de la ventana
|
||||
bool Screen::decWindowZoom()
|
||||
{
|
||||
if (options.video.fullscreen == 0)
|
||||
if (!options.video.fullscreen)
|
||||
{
|
||||
const int PREVIOUS_ZOOM = options.window.zoom;
|
||||
--options.window.zoom;
|
||||
@@ -123,7 +122,7 @@ bool Screen::decWindowZoom()
|
||||
|
||||
if (options.window.zoom != PREVIOUS_ZOOM)
|
||||
{
|
||||
setFullscreenMode(options.video.fullscreen);
|
||||
adjustWindowSize();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -134,7 +133,7 @@ bool Screen::decWindowZoom()
|
||||
// Aumenta el tamaño de la ventana
|
||||
bool Screen::incWindowZoom()
|
||||
{
|
||||
if (options.video.fullscreen == 0)
|
||||
if (!options.video.fullscreen)
|
||||
{
|
||||
const int PREVIOUS_ZOOM = options.window.zoom;
|
||||
++options.window.zoom;
|
||||
@@ -142,7 +141,7 @@ bool Screen::incWindowZoom()
|
||||
|
||||
if (options.window.zoom != PREVIOUS_ZOOM)
|
||||
{
|
||||
setFullscreenMode(options.video.fullscreen);
|
||||
adjustWindowSize();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -159,8 +158,8 @@ void Screen::update()
|
||||
// Calcula el tamaño de la ventana
|
||||
void Screen::adjustWindowSize()
|
||||
{
|
||||
window_width_ = options.game.width;
|
||||
window_height_ = options.game.height;
|
||||
window_width_ = options.logo.width;
|
||||
window_height_ = options.logo.height;
|
||||
|
||||
// Establece el nuevo tamaño
|
||||
if (!options.video.fullscreen)
|
||||
@@ -237,7 +236,7 @@ bool Screen::initSDL()
|
||||
}
|
||||
|
||||
// Crea la ventana
|
||||
window_ = SDL_CreateWindow(options.window.caption.c_str(), options.game.width * options.window.zoom, options.game.height * options.window.zoom, SDL_WINDOW_OPENGL);
|
||||
window_ = SDL_CreateWindow(options.window.caption.c_str(), options.logo.width * options.window.zoom, options.logo.height * options.window.zoom, SDL_WINDOW_OPENGL);
|
||||
if (!window_)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window could not be created! SDL Error: %s", SDL_GetError());
|
||||
@@ -255,7 +254,7 @@ bool Screen::initSDL()
|
||||
else
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
|
||||
SDL_SetRenderLogicalPresentation(renderer_, options.game.width, options.game.height, SDL_LOGICAL_PRESENTATION_INTEGER_SCALE);
|
||||
SDL_SetRenderLogicalPresentation(renderer_, options.logo.width, options.logo.height, SDL_LOGICAL_PRESENTATION_INTEGER_SCALE);
|
||||
SDL_SetWindowFullscreen(window_, options.video.fullscreen);
|
||||
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetRenderVSync(renderer_, options.video.vertical_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
|
||||
@@ -285,7 +284,7 @@ void Screen::getDisplayInfo()
|
||||
auto DM = SDL_GetCurrentDisplayMode(displays[0]);
|
||||
|
||||
// Calcula el máximo factor de zoom que se puede aplicar a la pantalla
|
||||
options.window.max_zoom = std::min(DM->w / options.game.width, DM->h / options.game.height);
|
||||
options.window.max_zoom = std::min(DM->w / options.logo.width, DM->h / options.logo.height);
|
||||
options.window.zoom = std::min(options.window.zoom, options.window.max_zoom);
|
||||
|
||||
// Muestra información sobre el tamaño de la pantalla y de la ventana de juego
|
||||
@@ -293,18 +292,32 @@ void Screen::getDisplayInfo()
|
||||
static_cast<int>(DM->w), static_cast<int>(DM->h), static_cast<int>(DM->refresh_rate));
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Window resolution: %dx%d x%d",
|
||||
static_cast<int>(options.game.width), static_cast<int>(options.game.height), options.window.zoom);
|
||||
static_cast<int>(options.logo.width), static_cast<int>(options.logo.height), options.window.zoom);
|
||||
|
||||
options.video.info = std::to_string(static_cast<int>(DM->w)) + " X " +
|
||||
std::to_string(static_cast<int>(DM->h)) + " AT " +
|
||||
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 / options.game.width, (DM->h - WINDOWS_DECORATIONS_) / options.game.height);
|
||||
const int MAX_ZOOM = std::min(DM->w / options.logo.width, (DM->h - WINDOWS_DECORATIONS_) / options.logo.height);
|
||||
|
||||
// Normaliza los valores de zoom
|
||||
options.window.zoom = std::min(options.window.zoom, MAX_ZOOM);
|
||||
|
||||
SDL_free(displays);
|
||||
}
|
||||
}
|
||||
|
||||
// Activa / desactiva el escalado entero
|
||||
void Screen::toggleIntegerScale()
|
||||
{
|
||||
options.video.integer_scale = !options.video.integer_scale;
|
||||
SDL_SetRenderLogicalPresentation(Screen::get()->getRenderer(), options.logo.width, options.logo.height, options.video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX);
|
||||
}
|
||||
|
||||
// Activa / desactiva el vsync
|
||||
void Screen::toggleVSync()
|
||||
{
|
||||
options.video.vertical_sync = !options.video.vertical_sync;
|
||||
SDL_SetRenderVSync(renderer_, options.video.vertical_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
|
||||
}
|
||||
Reference in New Issue
Block a user