diff --git a/source/engine.cpp b/source/engine.cpp index f8d7ba7..c9c71c7 100644 --- a/source/engine.cpp +++ b/source/engine.cpp @@ -237,7 +237,9 @@ bool Engine::initialize(int width, int height, int zoom, bool fullscreen, AppMod // Inicializar UIManager (HUD, FPS, notificaciones) // NOTA: Debe llamarse DESPUÉS de calcular physical_window_* y ThemeManager ui_manager_ = std::make_unique(); - ui_manager_->initialize(renderer_, theme_manager_.get(), physical_window_width_, physical_window_height_); + ui_manager_->initialize(renderer_, theme_manager_.get(), + physical_window_width_, physical_window_height_, + current_screen_width_, current_screen_height_); // Inicializar ShapeManager (gestión de figuras 3D) shape_manager_ = std::make_unique(); diff --git a/source/ui/help_overlay.cpp b/source/ui/help_overlay.cpp index abba3e1..01c866b 100644 --- a/source/ui/help_overlay.cpp +++ b/source/ui/help_overlay.cpp @@ -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(physical_width_ * 0.95f); + int max_height = static_cast(physical_height_ * 0.90f); - // Altura: 90% de altura física o altura calculada, el que sea menor - int max_height = static_cast(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; diff --git a/source/ui/ui_manager.cpp b/source/ui/ui_manager.cpp index 9027bb0..3480eb8 100644 --- a/source/ui/ui_manager.cpp +++ b/source/ui/ui_manager.cpp @@ -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; } diff --git a/source/ui/ui_manager.hpp b/source/ui/ui_manager.hpp index fb76ffd..15640d7 100644 --- a/source/ui/ui_manager.hpp +++ b/source/ui/ui_manager.hpp @@ -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) };