feat: Dynamic text scaling based on physical window size
Sistema de escalado dinámico de texto con 3 tamaños según área de ventana:
1. TextRenderer improvements:
- Añadido reinitialize(int new_font_size) para cambiar tamaño en runtime
- Almacena font_path_ para permitir recarga de fuente
- Cierra fuente anterior y abre nueva con diferente tamaño
- Verifica si tamaño es igual antes de reinicializar (optimización)
2. UIManager - Font size calculation:
- Añadido calculateFontSize() con stepped scaling por área:
* SMALL (< 800x600): 14px
* MEDIUM (800x600 a 1920x1080): 18px
* LARGE (> 1920x1080): 24px
- Tracking de current_font_size_ para detectar cambios
- Inicialización con tamaño dinámico en initialize()
- Reinitialización automática en updatePhysicalWindowSize()
3. UIManager - Propagation:
- Reinitializa 3 TextRenderer instances cuando cambia tamaño
- Propaga nuevo tamaño a HelpOverlay
- Detecta cambios solo cuando área cruza umbrales (eficiencia)
4. HelpOverlay integration:
- Acepta font_size como parámetro en initialize()
- Añadido reinitializeFontSize() para cambios dinámicos
- Recalcula dimensiones del box cuando cambia fuente
- Marca textura para rebuild completo tras cambio
Resultado:
- Ventanas pequeñas: texto 14px (más espacio para contenido)
- Ventanas medianas: texto 18px (tamaño original, óptimo)
- Ventanas grandes: texto 24px (mejor legibilidad)
- Cambios automáticos al redimensionar ventana (F1/F2/F3/F4)
- Sin impacto en performance (solo recalcula al cruzar umbrales)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -84,15 +84,15 @@ HelpOverlay::~HelpOverlay() {
|
||||
delete text_renderer_;
|
||||
}
|
||||
|
||||
void HelpOverlay::initialize(SDL_Renderer* renderer, ThemeManager* theme_mgr, int physical_width, int physical_height) {
|
||||
void HelpOverlay::initialize(SDL_Renderer* renderer, ThemeManager* theme_mgr, int physical_width, int physical_height, int font_size) {
|
||||
renderer_ = renderer;
|
||||
theme_mgr_ = theme_mgr;
|
||||
physical_width_ = physical_width;
|
||||
physical_height_ = physical_height;
|
||||
|
||||
// Crear renderer de texto con tamaño reducido (18px en lugar de 24px)
|
||||
// Crear renderer de texto con tamaño dinámico
|
||||
text_renderer_ = new TextRenderer();
|
||||
text_renderer_->init(renderer, "data/fonts/FunnelSans-Regular.ttf", 18, true);
|
||||
text_renderer_->init(renderer, "data/fonts/FunnelSans-Regular.ttf", font_size, true);
|
||||
|
||||
calculateBoxDimensions();
|
||||
}
|
||||
@@ -106,6 +106,19 @@ void HelpOverlay::updatePhysicalWindowSize(int physical_width, int physical_heig
|
||||
texture_needs_rebuild_ = true;
|
||||
}
|
||||
|
||||
void HelpOverlay::reinitializeFontSize(int new_font_size) {
|
||||
if (!text_renderer_) return;
|
||||
|
||||
// Reinicializar text renderer con nuevo tamaño
|
||||
text_renderer_->reinitialize(new_font_size);
|
||||
|
||||
// Recalcular dimensiones del box (el texto ahora tiene distinto tamaño)
|
||||
calculateBoxDimensions();
|
||||
|
||||
// Marcar textura para regeneración completa
|
||||
texture_needs_rebuild_ = true;
|
||||
}
|
||||
|
||||
void HelpOverlay::calculateTextDimensions(int& max_width, int& total_height) {
|
||||
if (!text_renderer_) {
|
||||
max_width = 0;
|
||||
|
||||
@@ -24,7 +24,7 @@ class HelpOverlay {
|
||||
/**
|
||||
* @brief Inicializa el overlay con renderer y theme manager
|
||||
*/
|
||||
void initialize(SDL_Renderer* renderer, ThemeManager* theme_mgr, int physical_width, int physical_height);
|
||||
void initialize(SDL_Renderer* renderer, ThemeManager* theme_mgr, int physical_width, int physical_height, int font_size);
|
||||
|
||||
/**
|
||||
* @brief Renderiza el overlay si está visible
|
||||
@@ -36,6 +36,11 @@ class HelpOverlay {
|
||||
*/
|
||||
void updatePhysicalWindowSize(int physical_width, int physical_height);
|
||||
|
||||
/**
|
||||
* @brief Reinitializa el tamaño de fuente (cuando cambia el tamaño de ventana)
|
||||
*/
|
||||
void reinitializeFontSize(int new_font_size);
|
||||
|
||||
/**
|
||||
* @brief Toggle visibilidad del overlay
|
||||
*/
|
||||
|
||||
@@ -32,7 +32,8 @@ UIManager::UIManager()
|
||||
, renderer_(nullptr)
|
||||
, theme_manager_(nullptr)
|
||||
, physical_window_width_(0)
|
||||
, physical_window_height_(0) {
|
||||
, physical_window_height_(0)
|
||||
, current_font_size_(18) { // Tamaño por defecto (medium)
|
||||
}
|
||||
|
||||
UIManager::~UIManager() {
|
||||
@@ -51,16 +52,18 @@ void UIManager::initialize(SDL_Renderer* renderer, ThemeManager* theme_manager,
|
||||
physical_window_width_ = physical_width;
|
||||
physical_window_height_ = physical_height;
|
||||
|
||||
// Calcular tamaño de fuente apropiado según dimensiones físicas
|
||||
current_font_size_ = calculateFontSize(physical_width, physical_height);
|
||||
|
||||
// Crear renderers de texto
|
||||
text_renderer_ = new TextRenderer();
|
||||
text_renderer_debug_ = new TextRenderer();
|
||||
text_renderer_notifier_ = new TextRenderer();
|
||||
|
||||
// Inicializar renderers
|
||||
// (el tamaño se configura dinámicamente en Engine según resolución)
|
||||
text_renderer_->init(renderer, "data/fonts/FunnelSans-Regular.ttf", 18, true);
|
||||
text_renderer_debug_->init(renderer, "data/fonts/FunnelSans-Regular.ttf", 18, true);
|
||||
text_renderer_notifier_->init(renderer, "data/fonts/FunnelSans-Regular.ttf", 18, true);
|
||||
// Inicializar renderers con tamaño dinámico
|
||||
text_renderer_->init(renderer, "data/fonts/FunnelSans-Regular.ttf", current_font_size_, true);
|
||||
text_renderer_debug_->init(renderer, "data/fonts/FunnelSans-Regular.ttf", current_font_size_, true);
|
||||
text_renderer_notifier_->init(renderer, "data/fonts/FunnelSans-Regular.ttf", current_font_size_, true);
|
||||
|
||||
// Crear y configurar sistema de notificaciones
|
||||
notifier_ = new Notifier();
|
||||
@@ -69,7 +72,7 @@ void UIManager::initialize(SDL_Renderer* renderer, ThemeManager* theme_manager,
|
||||
|
||||
// Crear y configurar sistema de ayuda (overlay)
|
||||
help_overlay_ = new HelpOverlay();
|
||||
help_overlay_->initialize(renderer, theme_manager_, physical_width, physical_height);
|
||||
help_overlay_->initialize(renderer, theme_manager_, physical_width, physical_height, current_font_size_);
|
||||
|
||||
// Inicializar FPS counter
|
||||
fps_last_time_ = SDL_GetTicks();
|
||||
@@ -154,6 +157,32 @@ void UIManager::updateVSyncText(bool enabled) {
|
||||
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);
|
||||
|
||||
// Si el tamaño cambió, reinicializar todos los text renderers
|
||||
if (new_font_size != current_font_size_) {
|
||||
current_font_size_ = new_font_size;
|
||||
|
||||
// Reinicializar text renderers con nuevo tamaño
|
||||
if (text_renderer_) {
|
||||
text_renderer_->reinitialize(current_font_size_);
|
||||
}
|
||||
if (text_renderer_debug_) {
|
||||
text_renderer_debug_->reinitialize(current_font_size_);
|
||||
}
|
||||
if (text_renderer_notifier_) {
|
||||
text_renderer_notifier_->reinitialize(current_font_size_);
|
||||
}
|
||||
|
||||
// Reinicializar help overlay con nuevo tamaño de fuente
|
||||
if (help_overlay_) {
|
||||
help_overlay_->reinitializeFontSize(current_font_size_);
|
||||
}
|
||||
}
|
||||
|
||||
// Actualizar componentes de UI con nuevas dimensiones
|
||||
notifier_->updateWindowSize(width, height);
|
||||
if (help_overlay_) {
|
||||
help_overlay_->updatePhysicalWindowSize(width, height);
|
||||
@@ -376,3 +405,21 @@ std::string UIManager::gravityDirectionToString(int direction) const {
|
||||
default: return "Desconocida";
|
||||
}
|
||||
}
|
||||
|
||||
int UIManager::calculateFontSize(int physical_width, int physical_height) const {
|
||||
// Calcular área física de la ventana
|
||||
int area = physical_width * physical_height;
|
||||
|
||||
// Stepped scaling con 3 tamaños:
|
||||
// - SMALL: < 800x600 (480,000 pixels) → 14px
|
||||
// - MEDIUM: 800x600 a 1920x1080 (2,073,600 pixels) → 18px
|
||||
// - LARGE: > 1920x1080 → 24px
|
||||
|
||||
if (area < 480000) {
|
||||
return 14; // Ventanas pequeñas
|
||||
} else if (area < 2073600) {
|
||||
return 18; // Ventanas medianas (default)
|
||||
} else {
|
||||
return 24; // Ventanas grandes
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,6 +166,14 @@ 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)
|
||||
*/
|
||||
int calculateFontSize(int physical_width, int physical_height) const;
|
||||
|
||||
// === Recursos de renderizado ===
|
||||
TextRenderer* text_renderer_; // Texto obsoleto (DEPRECATED)
|
||||
TextRenderer* text_renderer_debug_; // HUD de debug
|
||||
@@ -194,4 +202,7 @@ 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)
|
||||
|
||||
// === Sistema de escalado dinámico de texto ===
|
||||
int current_font_size_; // Tamaño de fuente actual (14/18/24)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user