Fix: Notificaciones con colores dinámicos y transiciones LERP

Problema resuelto:
1. Color del tema saliente: Notificaciones mostraban color del tema ANTIGUO
2. Sin transiciones LERP: Notificaciones no participaban en transiciones suaves

Cambios implementados:
- Arquitectura cambiada de estática a dinámica
- Notifier ahora consulta ThemeManager cada frame en render()
- Eliminados colores estáticos de struct Notification
- Notifier::init() recibe puntero a ThemeManager
- Notifier::show() ya no recibe parámetros de color
- Simplificado showNotificationForAction() (-23 líneas)

Fix crítico de inicialización:
- ThemeManager ahora se inicializa ANTES de updatePhysicalWindowSize()
- Previene nullptr en notifier_.init() que causaba que no se mostraran

Resultado:
-  Notificaciones usan color del tema DESTINO (no origen)
-  Transiciones LERP suaves automáticas durante cambios de tema
-  Código más limpio y centralizado en ThemeManager
-  -50 líneas de código duplicado eliminadas

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-10 07:55:55 +02:00
parent 10a4234d49
commit d93ac04ee3
3 changed files with 51 additions and 69 deletions

View File

@@ -1,5 +1,6 @@
#include "notifier.h"
#include "../text/textrenderer.h"
#include "../theme_manager.h"
#include "../defines.h"
#include "../utils/easing_functions.h"
#include <SDL3/SDL.h>
@@ -7,6 +8,7 @@
Notifier::Notifier()
: renderer_(nullptr)
, text_renderer_(nullptr)
, theme_manager_(nullptr)
, window_width_(0)
, window_height_(0)
, current_notification_(nullptr) {
@@ -16,12 +18,13 @@ Notifier::~Notifier() {
clear();
}
bool Notifier::init(SDL_Renderer* renderer, TextRenderer* text_renderer, int window_width, int window_height) {
bool Notifier::init(SDL_Renderer* renderer, TextRenderer* text_renderer, ThemeManager* theme_manager, int window_width, int window_height) {
renderer_ = renderer;
text_renderer_ = text_renderer;
theme_manager_ = theme_manager;
window_width_ = window_width;
window_height_ = window_height;
return (renderer_ != nullptr && text_renderer_ != nullptr);
return (renderer_ != nullptr && text_renderer_ != nullptr && theme_manager_ != nullptr);
}
void Notifier::updateWindowSize(int window_width, int window_height) {
@@ -29,7 +32,7 @@ void Notifier::updateWindowSize(int window_width, int window_height) {
window_height_ = window_height;
}
void Notifier::show(const std::string& text, Uint64 duration, SDL_Color color, SDL_Color bg_color) {
void Notifier::show(const std::string& text, Uint64 duration) {
if (text.empty()) {
return;
}
@@ -47,8 +50,7 @@ void Notifier::show(const std::string& text, Uint64 duration, SDL_Color color, S
notif.state = NotificationState::SLIDING_IN;
notif.alpha = 1.0f;
notif.y_offset = -50.0f; // Comienza 50px arriba (fuera de pantalla)
notif.color = color;
notif.bg_color = bg_color;
// NOTA: Los colores se obtienen dinámicamente desde ThemeManager en render()
// Añadir a cola
notification_queue_.push(notif);
@@ -115,10 +117,29 @@ void Notifier::update(Uint64 current_time) {
}
void Notifier::render() {
if (!current_notification_ || !text_renderer_ || !renderer_) {
if (!current_notification_ || !text_renderer_ || !renderer_ || !theme_manager_) {
return;
}
// Obtener colores DINÁMICOS desde ThemeManager (incluye LERP automático)
int text_r, text_g, text_b;
theme_manager_->getCurrentThemeTextColor(text_r, text_g, text_b);
SDL_Color text_color = {
static_cast<Uint8>(text_r),
static_cast<Uint8>(text_g),
static_cast<Uint8>(text_b),
static_cast<Uint8>(current_notification_->alpha * 255.0f)
};
int bg_r, bg_g, bg_b;
theme_manager_->getCurrentNotificationBackgroundColor(bg_r, bg_g, bg_b);
SDL_Color bg_color = {
static_cast<Uint8>(bg_r),
static_cast<Uint8>(bg_g),
static_cast<Uint8>(bg_b),
255
};
// Calcular dimensiones del texto en píxeles FÍSICOS
// IMPORTANTE: Usar getTextWidthPhysical() en lugar de getTextWidth()
// para obtener el ancho REAL de la fuente (sin escalado lógico)
@@ -137,13 +158,9 @@ void Notifier::render() {
// Renderizar fondo semitransparente (con bypass de presentación lógica)
float bg_alpha = current_notification_->alpha * NOTIFICATION_BG_ALPHA;
renderBackground(x, y, bg_width, bg_height, bg_alpha, current_notification_->bg_color);
renderBackground(x, y, bg_width, bg_height, bg_alpha, bg_color);
// Renderizar texto con alpha usando printAbsolute (tamaño físico fijo)
Uint8 text_alpha = static_cast<Uint8>(current_notification_->alpha * 255.0f);
SDL_Color text_color = current_notification_->color;
text_color.a = text_alpha;
int text_x = x + NOTIFICATION_PADDING;
int text_y = y + NOTIFICATION_PADDING;