Fix: Ajustar dimensionamiento de HelpOverlay para resoluciones bajas
Problemas resueltos: - En 640x360, el overlay generaba textura enorme con letras grandes - El cálculo de font size usaba dimensiones físicas (con zoom aplicado) en lugar de dimensiones lógicas (resolución interna) - No había límite máximo de ancho para el overlay - Padding fijo de 25px era excesivo en pantallas pequeñas Cambios realizados: 1. UIManager: Usar dimensiones lógicas para calcular font size - Nuevo parámetro logical_width/logical_height en initialize() - calculateFontSize() ahora usa altura lógica sin zoom - Escalado híbrido: proporcional en extremos, escalonado en rango medio - Para 640x360: 10px (antes 18px con zoom 2x) - Para 640x480: 12px (antes 24px con zoom 2x) 2. HelpOverlay: Agregar límites máximos de dimensiones - Box width limitado al 95% del ancho físico - Box height limitado al 90% de la altura física - Padding dinámico: 25px para >=600px, escalado para menores - Para 360px altura: padding de 15px (antes 25px fijo) 3. Engine: Pasar dimensiones lógicas a UIManager - initialize() ahora recibe current_screen_width/height Resultado: - 640x360: Overlay compacto con fuente 10px que cabe en pantalla - 640x480: Overlay con fuente 12px (tamaño apropiado) - Tamaño de fuente consistente independiente del zoom de ventana 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -151,7 +151,8 @@ void HelpOverlay::calculateTextDimensions(int& max_width, int& total_height) {
|
||||
}
|
||||
|
||||
int line_height = text_renderer_->getTextHeight();
|
||||
int padding = 25;
|
||||
// Padding dinámico basado en altura física: 25px para >= 600px, escalado proporcionalmente para menores
|
||||
int padding = (physical_height_ >= 600) ? 25 : std::max(10, physical_height_ / 24);
|
||||
|
||||
// Calcular ancho máximo por columna
|
||||
int max_col1_width = 0;
|
||||
@@ -234,11 +235,11 @@ void HelpOverlay::calculateBoxDimensions() {
|
||||
int text_width, text_height;
|
||||
calculateTextDimensions(text_width, text_height);
|
||||
|
||||
// Usar directamente el ancho y altura calculados según el contenido
|
||||
box_width_ = text_width;
|
||||
// Aplicar límites máximos: 95% ancho, 90% altura
|
||||
int max_width = static_cast<int>(physical_width_ * 0.95f);
|
||||
int max_height = static_cast<int>(physical_height_ * 0.90f);
|
||||
|
||||
// Altura: 90% de altura física o altura calculada, el que sea menor
|
||||
int max_height = static_cast<int>(physical_height_ * 0.9f);
|
||||
box_width_ = std::min(text_width, max_width);
|
||||
box_height_ = std::min(text_height, max_height);
|
||||
|
||||
// Centrar en pantalla
|
||||
@@ -333,7 +334,8 @@ void HelpOverlay::rebuildCachedTexture() {
|
||||
|
||||
// Configuración de espaciado
|
||||
int line_height = text_renderer_->getTextHeight();
|
||||
int padding = 25;
|
||||
// Padding dinámico basado en altura física: 25px para >= 600px, escalado proporcionalmente para menores
|
||||
int padding = (physical_height_ >= 600) ? 25 : std::max(10, physical_height_ / 24);
|
||||
|
||||
int current_x = padding; // Coordenadas relativas a la textura (0,0)
|
||||
int current_y = padding;
|
||||
|
||||
@@ -53,6 +53,8 @@ UIManager::UIManager()
|
||||
, theme_manager_(nullptr)
|
||||
, physical_window_width_(0)
|
||||
, physical_window_height_(0)
|
||||
, logical_window_width_(0)
|
||||
, logical_window_height_(0)
|
||||
, current_font_size_(18) { // Tamaño por defecto (medium)
|
||||
}
|
||||
|
||||
@@ -65,14 +67,17 @@ UIManager::~UIManager() {
|
||||
}
|
||||
|
||||
void UIManager::initialize(SDL_Renderer* renderer, ThemeManager* theme_manager,
|
||||
int physical_width, int physical_height) {
|
||||
int physical_width, int physical_height,
|
||||
int logical_width, int logical_height) {
|
||||
renderer_ = renderer;
|
||||
theme_manager_ = theme_manager;
|
||||
physical_window_width_ = physical_width;
|
||||
physical_window_height_ = physical_height;
|
||||
logical_window_width_ = logical_width;
|
||||
logical_window_height_ = logical_height;
|
||||
|
||||
// Calcular tamaño de fuente apropiado según dimensiones físicas
|
||||
current_font_size_ = calculateFontSize(physical_width, physical_height);
|
||||
// Calcular tamaño de fuente apropiado según dimensiones LÓGICAS (sin zoom)
|
||||
current_font_size_ = calculateFontSize(logical_height);
|
||||
|
||||
// Crear renderers de texto
|
||||
text_renderer_debug_ = new TextRenderer();
|
||||
@@ -165,8 +170,9 @@ void UIManager::updatePhysicalWindowSize(int width, int height) {
|
||||
physical_window_width_ = width;
|
||||
physical_window_height_ = height;
|
||||
|
||||
// Calcular nuevo tamaño de fuente apropiado
|
||||
int new_font_size = calculateFontSize(width, height);
|
||||
// Calcular nuevo tamaño de fuente apropiado basado en altura LÓGICA
|
||||
// (las dimensiones lógicas no cambian con zoom, solo con cambios explícitos de resolución)
|
||||
int new_font_size = calculateFontSize(logical_window_height_);
|
||||
|
||||
// Si el tamaño cambió, reinicializar todos los text renderers
|
||||
if (new_font_size != current_font_size_) {
|
||||
@@ -406,20 +412,37 @@ std::string UIManager::gravityDirectionToString(int direction) const {
|
||||
}
|
||||
}
|
||||
|
||||
int UIManager::calculateFontSize(int physical_width, int physical_height) const {
|
||||
// Calcular área física de la ventana
|
||||
int area = physical_width * physical_height;
|
||||
int UIManager::calculateFontSize(int logical_height) const {
|
||||
// Escalado híbrido basado en ALTURA LÓGICA (resolución interna, sin zoom)
|
||||
// Esto asegura que el tamaño de fuente sea consistente independientemente del zoom de ventana
|
||||
// - Proporcional en extremos (muy bajo/alto)
|
||||
// - Escalonado en rango medio (estabilidad)
|
||||
|
||||
// Stepped scaling con 3 tamaños:
|
||||
// - SMALL: < 800x600 (480,000 pixels) → 14px
|
||||
// - MEDIUM: 800x600 a 1920x1080 (2,073,600 pixels) → 18px
|
||||
// - LARGE: > 1920x1080 → 24px
|
||||
int font_size = 14; // Default fallback
|
||||
|
||||
if (area < 480000) {
|
||||
return 14; // Ventanas pequeñas
|
||||
} else if (area < 2073600) {
|
||||
return 18; // Ventanas medianas (default)
|
||||
if (logical_height < 300) {
|
||||
// Rango bajo: proporcional (240px→9.6, 280px→11.2)
|
||||
font_size = logical_height / 25;
|
||||
} else if (logical_height < 380) {
|
||||
// Rango muy bajo (300-379px) → 10px (crítico para 640x360)
|
||||
font_size = 10;
|
||||
} else if (logical_height < 500) {
|
||||
// Rango medio-bajo (380-499px) → 12px
|
||||
font_size = 12;
|
||||
} else if (logical_height < 700) {
|
||||
// Rango medio (500-699px) → 14px
|
||||
font_size = 14;
|
||||
} else if (logical_height < 900) {
|
||||
// Rango medio-alto (700-899px) → 18px
|
||||
font_size = 18;
|
||||
} else {
|
||||
return 24; // Ventanas grandes
|
||||
// Rango alto: proporcional (1080px→27, 1440px→36)
|
||||
font_size = logical_height / 40;
|
||||
}
|
||||
|
||||
// Aplicar límites: mínimo 9px, máximo 36px
|
||||
if (font_size < 9) font_size = 9;
|
||||
if (font_size > 36) font_size = 36;
|
||||
|
||||
return font_size;
|
||||
}
|
||||
|
||||
@@ -46,9 +46,12 @@ class UIManager {
|
||||
* @param theme_manager Gestor de temas (para colores)
|
||||
* @param physical_width Ancho físico de ventana (píxeles reales)
|
||||
* @param physical_height Alto físico de ventana (píxeles reales)
|
||||
* @param logical_width Ancho lógico (resolución interna)
|
||||
* @param logical_height Alto lógico (resolución interna)
|
||||
*/
|
||||
void initialize(SDL_Renderer* renderer, ThemeManager* theme_manager,
|
||||
int physical_width, int physical_height);
|
||||
int physical_width, int physical_height,
|
||||
int logical_width, int logical_height);
|
||||
|
||||
/**
|
||||
* @brief Actualiza UI (FPS counter, notificaciones, texto obsoleto)
|
||||
@@ -148,12 +151,11 @@ class UIManager {
|
||||
std::string gravityDirectionToString(int direction) const;
|
||||
|
||||
/**
|
||||
* @brief Calcula tamaño de fuente apropiado según dimensiones físicas
|
||||
* @param physical_width Ancho físico de ventana
|
||||
* @param physical_height Alto físico de ventana
|
||||
* @return Tamaño de fuente (14px/18px/24px)
|
||||
* @brief Calcula tamaño de fuente apropiado según dimensiones lógicas
|
||||
* @param logical_height Alto lógico (resolución interna, sin zoom)
|
||||
* @return Tamaño de fuente (9-36px)
|
||||
*/
|
||||
int calculateFontSize(int physical_width, int physical_height) const;
|
||||
int calculateFontSize(int logical_height) const;
|
||||
|
||||
// === Recursos de renderizado ===
|
||||
TextRenderer* text_renderer_debug_; // HUD de debug
|
||||
@@ -176,7 +178,9 @@ class UIManager {
|
||||
ThemeManager* theme_manager_; // Gestor de temas (para colores)
|
||||
int physical_window_width_; // Ancho físico de ventana (píxeles reales)
|
||||
int physical_window_height_; // Alto físico de ventana (píxeles reales)
|
||||
int logical_window_width_; // Ancho lógico (resolución interna)
|
||||
int logical_window_height_; // Alto lógico (resolución interna)
|
||||
|
||||
// === Sistema de escalado dinámico de texto ===
|
||||
int current_font_size_; // Tamaño de fuente actual (14/18/24)
|
||||
int current_font_size_; // Tamaño de fuente actual (9-36px)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user