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:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user