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;
|
||||
|
||||
Reference in New Issue
Block a user