clang-format
This commit is contained in:
@@ -13,25 +13,33 @@
|
||||
// --- Implementación de las estructuras de animación ---
|
||||
|
||||
void MenuRenderer::ResizeAnimation::start(float from_w, float from_h, float to_w, float to_h) {
|
||||
start_width = from_w; start_height = from_h;
|
||||
target_width = to_w; target_height = to_h;
|
||||
start_width = from_w;
|
||||
start_height = from_h;
|
||||
target_width = to_w;
|
||||
target_height = to_h;
|
||||
elapsed = 0.0F;
|
||||
active = true;
|
||||
}
|
||||
void MenuRenderer::ResizeAnimation::stop() { active = false;
|
||||
void MenuRenderer::ResizeAnimation::stop() {
|
||||
active = false;
|
||||
elapsed = 0.0F;
|
||||
}
|
||||
|
||||
void MenuRenderer::ShowHideAnimation::startShow(float to_w, float to_h) {
|
||||
type = Type::SHOWING; target_width = to_w; target_height = to_h;
|
||||
type = Type::SHOWING;
|
||||
target_width = to_w;
|
||||
target_height = to_h;
|
||||
elapsed = 0.0F;
|
||||
active = true;
|
||||
}
|
||||
void MenuRenderer::ShowHideAnimation::startHide() { type = Type::HIDING;
|
||||
void MenuRenderer::ShowHideAnimation::startHide() {
|
||||
type = Type::HIDING;
|
||||
elapsed = 0.0F;
|
||||
active = true;
|
||||
}
|
||||
void MenuRenderer::ShowHideAnimation::stop() { type = Type::NONE; active = false;
|
||||
void MenuRenderer::ShowHideAnimation::stop() {
|
||||
type = Type::NONE;
|
||||
active = false;
|
||||
elapsed = 0.0F;
|
||||
}
|
||||
|
||||
@@ -62,7 +70,7 @@ void MenuRenderer::render(const ServiceMenu *menu_state) {
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), BORDER_COLOR.r, BORDER_COLOR.g, BORDER_COLOR.b, 255);
|
||||
SDL_RenderRect(Screen::get()->getRenderer(), &rect_);
|
||||
SDL_RenderRect(Screen::get()->getRenderer(), &border_rect_);
|
||||
|
||||
|
||||
// Solo renderizar contenido si la animación lo permite
|
||||
if (shouldShowContent()) {
|
||||
// Dibuja el título
|
||||
@@ -101,7 +109,7 @@ void MenuRenderer::render(const ServiceMenu *menu_state) {
|
||||
void MenuRenderer::update(const ServiceMenu *menu_state) {
|
||||
float delta_time = 1.0F / 60.0F; // Asumiendo 60 FPS
|
||||
updateAnimations(delta_time);
|
||||
|
||||
|
||||
if (visible_) {
|
||||
updateColorCounter();
|
||||
param.service_menu.selected_color = getAnimatedSelectedColor();
|
||||
@@ -110,7 +118,7 @@ void MenuRenderer::update(const ServiceMenu *menu_state) {
|
||||
|
||||
// --- Nuevos métodos de control ---
|
||||
|
||||
void MenuRenderer::show(const ServiceMenu* menu_state) {
|
||||
void MenuRenderer::show(const ServiceMenu *menu_state) {
|
||||
if (visible_) {
|
||||
return;
|
||||
}
|
||||
@@ -118,13 +126,13 @@ void MenuRenderer::show(const ServiceMenu* menu_state) {
|
||||
|
||||
// Calcula el tamaño final y lo usa para la animación
|
||||
SDL_FRect target_rect = calculateNewRect(menu_state);
|
||||
|
||||
|
||||
// Detener cualquier animación anterior
|
||||
resize_animation_.stop();
|
||||
|
||||
|
||||
// Iniciar animación de mostrar
|
||||
show_hide_animation_.startShow(target_rect.w, target_rect.h);
|
||||
|
||||
|
||||
// El tamaño inicial es cero para la animación
|
||||
rect_.w = 0.0F;
|
||||
rect_.h = 0.0F;
|
||||
@@ -194,14 +202,13 @@ auto MenuRenderer::calculateNewRect(const ServiceMenu *menu_state) -> SDL_FRect
|
||||
const auto &display_options = menu_state->getDisplayOptions();
|
||||
lower_height_ = ((!display_options.empty() ? display_options.size() - 1 : 0) * (options_height_ + options_padding_)) + options_height_ + (lower_padding_ * 2);
|
||||
height_ = std::min(upper_height_ + lower_height_, max_menu_height_);
|
||||
|
||||
|
||||
SDL_FRect new_rect = {0, 0, (float)width_, (float)height_};
|
||||
|
||||
|
||||
// La posición x, y se establecerá en `updatePosition`
|
||||
return new_rect;
|
||||
}
|
||||
|
||||
|
||||
void MenuRenderer::resize(const ServiceMenu *menu_state) {
|
||||
SDL_FRect new_rect = calculateNewRect(menu_state);
|
||||
|
||||
@@ -219,7 +226,7 @@ void MenuRenderer::setSize(const ServiceMenu *menu_state) {
|
||||
SDL_FRect new_rect = calculateNewRect(menu_state);
|
||||
rect_.w = new_rect.w;
|
||||
rect_.h = new_rect.h;
|
||||
|
||||
|
||||
show_hide_animation_.stop();
|
||||
resize_animation_.stop();
|
||||
|
||||
@@ -242,7 +249,7 @@ void MenuRenderer::updateAnimations(float delta_time) {
|
||||
void MenuRenderer::updateShowHideAnimation(float delta_time) {
|
||||
show_hide_animation_.elapsed += delta_time;
|
||||
float duration = show_hide_animation_.duration;
|
||||
|
||||
|
||||
if (show_hide_animation_.elapsed >= duration) {
|
||||
if (show_hide_animation_.type == ShowHideAnimation::Type::SHOWING) {
|
||||
rect_.w = show_hide_animation_.target_width;
|
||||
@@ -286,7 +293,6 @@ void MenuRenderer::updateResizeAnimation(float delta_time) {
|
||||
options_y_ = rect_.y + upper_height_ + lower_padding_;
|
||||
}
|
||||
|
||||
|
||||
void MenuRenderer::updatePosition() {
|
||||
switch (position_mode_) {
|
||||
case PositionMode::CENTERED:
|
||||
|
||||
@@ -37,7 +37,7 @@ class MenuRenderer {
|
||||
|
||||
// --- Nuevos: Métodos de configuración de posición ---
|
||||
void setPosition(float x, float y, PositionMode mode);
|
||||
|
||||
|
||||
// Método para notificar al renderer que el layout puede haber cambiado
|
||||
void onLayoutChanged(const ServiceMenu *menu_state);
|
||||
void setLayout(const ServiceMenu *menu_state);
|
||||
@@ -77,27 +77,29 @@ class MenuRenderer {
|
||||
|
||||
// --- Estructuras de Animación (inspirado en WindowMessage) ---
|
||||
struct ResizeAnimation {
|
||||
bool active = false;
|
||||
float start_width, start_height;
|
||||
float target_width, target_height;
|
||||
float elapsed = 0.0F;
|
||||
float duration = 0.2F;
|
||||
bool active = false;
|
||||
float start_width, start_height;
|
||||
float target_width, target_height;
|
||||
float elapsed = 0.0F;
|
||||
float duration = 0.2F;
|
||||
|
||||
void start(float from_w, float from_h, float to_w, float to_h);
|
||||
void stop();
|
||||
void start(float from_w, float from_h, float to_w, float to_h);
|
||||
void stop();
|
||||
} resize_animation_;
|
||||
|
||||
struct ShowHideAnimation {
|
||||
enum class Type { NONE, SHOWING, HIDING };
|
||||
Type type = Type::NONE;
|
||||
bool active = false;
|
||||
float target_width, target_height;
|
||||
float elapsed = 0.0F;
|
||||
float duration = 0.25F;
|
||||
enum class Type { NONE,
|
||||
SHOWING,
|
||||
HIDING };
|
||||
Type type = Type::NONE;
|
||||
bool active = false;
|
||||
float target_width, target_height;
|
||||
float elapsed = 0.0F;
|
||||
float duration = 0.25F;
|
||||
|
||||
void startShow(float to_w, float to_h);
|
||||
void startHide();
|
||||
void stop();
|
||||
void startShow(float to_w, float to_h);
|
||||
void startHide();
|
||||
void stop();
|
||||
} show_hide_animation_;
|
||||
|
||||
// --- Anchos precalculados ---
|
||||
@@ -109,7 +111,7 @@ class MenuRenderer {
|
||||
auto calculateNewRect(const ServiceMenu *menu_state) -> SDL_FRect;
|
||||
void resize(const ServiceMenu *menu_state);
|
||||
void setSize(const ServiceMenu *menu_state);
|
||||
|
||||
|
||||
void updateAnimations(float delta_time);
|
||||
void updateResizeAnimation(float delta_time);
|
||||
void updateShowHideAnimation(float delta_time);
|
||||
|
||||
@@ -49,7 +49,7 @@ void ServiceMenu::toggle() {
|
||||
}
|
||||
|
||||
playBackSound();
|
||||
|
||||
|
||||
if (!enabled_) { // Si está cerrado, abrir
|
||||
reset();
|
||||
Options::gamepad_manager.assignAndLinkGamepads();
|
||||
|
||||
@@ -26,13 +26,11 @@ void WindowMessage::render() {
|
||||
SDL_Renderer* renderer = Screen::get()->getRenderer();
|
||||
|
||||
// Dibujar fondo con transparencia
|
||||
SDL_SetRenderDrawColor(renderer, config_.bg_color.r, config_.bg_color.g,
|
||||
config_.bg_color.b, config_.bg_color.a);
|
||||
SDL_SetRenderDrawColor(renderer, config_.bg_color.r, config_.bg_color.g, config_.bg_color.b, config_.bg_color.a);
|
||||
SDL_RenderFillRect(renderer, &rect_);
|
||||
|
||||
// Dibujar borde
|
||||
SDL_SetRenderDrawColor(renderer, config_.border_color.r, config_.border_color.g,
|
||||
config_.border_color.b, config_.border_color.a);
|
||||
SDL_SetRenderDrawColor(renderer, config_.border_color.r, config_.border_color.g, config_.border_color.b, config_.border_color.a);
|
||||
SDL_RenderRect(renderer, &rect_);
|
||||
|
||||
// Solo mostrar contenido si no estamos en animación de show/hide
|
||||
@@ -54,8 +52,7 @@ void WindowMessage::render() {
|
||||
|
||||
// Línea separadora debajo del título (solo si hay título visible)
|
||||
if (!visible_title.empty()) {
|
||||
SDL_SetRenderDrawColor(renderer, config_.border_color.r, config_.border_color.g,
|
||||
config_.border_color.b, config_.border_color.a);
|
||||
SDL_SetRenderDrawColor(renderer, config_.border_color.r, config_.border_color.g, config_.border_color.b, config_.border_color.a);
|
||||
SDL_RenderLine(renderer,
|
||||
rect_.x + config_.padding,
|
||||
current_y - config_.title_separator_spacing / 2.0F,
|
||||
@@ -91,34 +88,34 @@ void WindowMessage::update() {
|
||||
|
||||
void WindowMessage::show() {
|
||||
if (visible_) {
|
||||
return; // Ya visible
|
||||
return; // Ya visible
|
||||
}
|
||||
|
||||
|
||||
visible_ = true;
|
||||
ensureTextFits();
|
||||
|
||||
|
||||
// Detener cualquier animación anterior
|
||||
resize_animation_.stop();
|
||||
|
||||
|
||||
// Iniciar animación de mostrar desde tamaño 0
|
||||
show_hide_animation_.startShow(rect_.w, rect_.h);
|
||||
rect_.w = 0.0F;
|
||||
rect_.h = 0.0F;
|
||||
updatePosition(); // Reposicionar con tamaño 0
|
||||
updatePosition(); // Reposicionar con tamaño 0
|
||||
}
|
||||
|
||||
void WindowMessage::hide() {
|
||||
if (!visible_) {
|
||||
return; // Ya oculto
|
||||
return; // Ya oculto
|
||||
}
|
||||
|
||||
|
||||
// Detener cualquier animación anterior
|
||||
resize_animation_.stop();
|
||||
|
||||
|
||||
// Guardar el tamaño actual para la animación
|
||||
show_hide_animation_.target_width = rect_.w;
|
||||
show_hide_animation_.target_height = rect_.h;
|
||||
|
||||
|
||||
// Iniciar animación de ocultar hacia tamaño 0
|
||||
show_hide_animation_.startHide();
|
||||
}
|
||||
@@ -158,7 +155,7 @@ void WindowMessage::setPosition(float x, float y, PositionMode mode) {
|
||||
void WindowMessage::setSize(float width, float height) {
|
||||
rect_.w = width;
|
||||
rect_.h = height;
|
||||
updatePosition(); // Reposicionar después de cambiar el tamaño
|
||||
updatePosition(); // Reposicionar después de cambiar el tamaño
|
||||
}
|
||||
|
||||
void WindowMessage::centerOnScreen() {
|
||||
@@ -167,18 +164,18 @@ void WindowMessage::centerOnScreen() {
|
||||
|
||||
void WindowMessage::autoSize() {
|
||||
if (show_hide_animation_.active) {
|
||||
return; // No redimensionar durante show/hide
|
||||
return; // No redimensionar durante show/hide
|
||||
}
|
||||
|
||||
|
||||
if (resize_animation_.active) {
|
||||
resize_animation_.stop(); // Detener animación anterior
|
||||
resize_animation_.stop(); // Detener animación anterior
|
||||
}
|
||||
|
||||
|
||||
float old_width = rect_.w;
|
||||
float old_height = rect_.h;
|
||||
|
||||
|
||||
calculateAutoSize();
|
||||
|
||||
|
||||
// Solo animar si hay cambio en el tamaño y la ventana está visible
|
||||
if (visible_ && (old_width != rect_.w || old_height != rect_.h)) {
|
||||
resize_animation_.start(old_width, old_height, rect_.w, rect_.h);
|
||||
@@ -186,21 +183,19 @@ void WindowMessage::autoSize() {
|
||||
rect_.w = old_width;
|
||||
rect_.h = old_height;
|
||||
} else {
|
||||
updatePosition(); // Reposicionar después de ajustar el tamaño
|
||||
updatePosition(); // Reposicionar después de ajustar el tamaño
|
||||
}
|
||||
}
|
||||
|
||||
void WindowMessage::updateStyles() {
|
||||
title_style_ = Text::Style(Text::CENTER | Text::COLOR, config_.title_color,
|
||||
config_.title_color, 0, -2);
|
||||
text_style_ = Text::Style(Text::CENTER | Text::COLOR, config_.text_color,
|
||||
config_.text_color, 0, -2);
|
||||
title_style_ = Text::Style(Text::CENTER | Text::COLOR, config_.title_color, config_.title_color, 0, -2);
|
||||
text_style_ = Text::Style(Text::CENTER | Text::COLOR, config_.text_color, config_.text_color, 0, -2);
|
||||
}
|
||||
|
||||
void WindowMessage::updatePosition() {
|
||||
switch (position_mode_) {
|
||||
case PositionMode::CENTERED:
|
||||
rect_.x = anchor_.x- rect_.w / 2.0F;
|
||||
rect_.x = anchor_.x - rect_.w / 2.0F;
|
||||
rect_.y = anchor_.y - rect_.h / 2.0F;
|
||||
break;
|
||||
case PositionMode::FIXED:
|
||||
@@ -217,10 +212,10 @@ void WindowMessage::updatePosition() {
|
||||
void WindowMessage::ensureTextFits() {
|
||||
float required_width = calculateContentWidth() + (config_.padding * 2) + config_.text_safety_margin;
|
||||
float required_height = calculateContentHeight() + (config_.padding * 2) + config_.text_safety_margin;
|
||||
|
||||
|
||||
// Verificar si el tamaño actual es suficiente
|
||||
if (rect_.w < required_width || rect_.h < required_height) {
|
||||
autoSize(); // Recalcular tamaño automáticamente
|
||||
autoSize(); // Recalcular tamaño automáticamente
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +234,7 @@ void WindowMessage::calculateAutoSize() {
|
||||
// Aplicar límites máximos basados en el tamaño de pantalla
|
||||
float max_width = getScreenWidth() * config_.max_width_ratio;
|
||||
float max_height = getScreenHeight() * config_.max_height_ratio;
|
||||
|
||||
|
||||
rect_.w = std::min(rect_.w, max_width);
|
||||
rect_.h = std::min(rect_.h, max_height);
|
||||
}
|
||||
@@ -264,7 +259,7 @@ auto WindowMessage::calculateContentHeight() const -> float {
|
||||
}
|
||||
|
||||
auto WindowMessage::calculateContentWidth() const -> float {
|
||||
float max_width = config_.min_width - (config_.padding * 2); // Ancho mínimo sin padding
|
||||
float max_width = config_.min_width - (config_.padding * 2); // Ancho mínimo sin padding
|
||||
|
||||
// Ancho del título
|
||||
if (!title_.empty()) {
|
||||
@@ -299,7 +294,7 @@ void WindowMessage::updateAnimation(float delta_time) {
|
||||
if (show_hide_animation_.active) {
|
||||
updateShowHideAnimation(delta_time);
|
||||
}
|
||||
|
||||
|
||||
if (resize_animation_.active) {
|
||||
updateResizeAnimation(delta_time);
|
||||
}
|
||||
@@ -309,9 +304,9 @@ void WindowMessage::updateShowHideAnimation(float delta_time) {
|
||||
if (!show_hide_animation_.active) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
show_hide_animation_.elapsed += delta_time;
|
||||
|
||||
|
||||
if (show_hide_animation_.isFinished(config_.animation_duration)) {
|
||||
// Animación terminada
|
||||
if (show_hide_animation_.type == ShowHideAnimation::Type::SHOWING) {
|
||||
@@ -324,13 +319,13 @@ void WindowMessage::updateShowHideAnimation(float delta_time) {
|
||||
rect_.h = 0.0F;
|
||||
visible_ = false;
|
||||
}
|
||||
|
||||
|
||||
show_hide_animation_.stop();
|
||||
updatePosition();
|
||||
} else {
|
||||
// Interpolar el tamaño
|
||||
float progress = easeOut(show_hide_animation_.getProgress(config_.animation_duration));
|
||||
|
||||
|
||||
if (show_hide_animation_.type == ShowHideAnimation::Type::SHOWING) {
|
||||
// Crecer desde 0 hasta el tamaño objetivo
|
||||
rect_.w = show_hide_animation_.target_width * progress;
|
||||
@@ -340,8 +335,8 @@ void WindowMessage::updateShowHideAnimation(float delta_time) {
|
||||
rect_.w = show_hide_animation_.target_width * (1.0F - progress);
|
||||
rect_.h = show_hide_animation_.target_height * (1.0F - progress);
|
||||
}
|
||||
|
||||
updatePosition(); // Mantener la posición centrada durante la animación
|
||||
|
||||
updatePosition(); // Mantener la posición centrada durante la animación
|
||||
}
|
||||
}
|
||||
|
||||
@@ -349,9 +344,9 @@ void WindowMessage::updateResizeAnimation(float delta_time) {
|
||||
if (!resize_animation_.active) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
resize_animation_.elapsed += delta_time;
|
||||
|
||||
|
||||
if (resize_animation_.isFinished(config_.animation_duration)) {
|
||||
// Animación terminada
|
||||
rect_.w = resize_animation_.target_width;
|
||||
@@ -361,13 +356,13 @@ void WindowMessage::updateResizeAnimation(float delta_time) {
|
||||
} else {
|
||||
// Interpolar el tamaño
|
||||
float progress = easeOut(resize_animation_.getProgress(config_.animation_duration));
|
||||
|
||||
rect_.w = resize_animation_.start_width +
|
||||
(resize_animation_.target_width - resize_animation_.start_width) * progress;
|
||||
rect_.h = resize_animation_.start_height +
|
||||
(resize_animation_.target_height - resize_animation_.start_height) * progress;
|
||||
|
||||
updatePosition(); // Mantener la posición centrada durante la animación
|
||||
|
||||
rect_.w = resize_animation_.start_width +
|
||||
(resize_animation_.target_width - resize_animation_.start_width) * progress;
|
||||
rect_.h = resize_animation_.start_height +
|
||||
(resize_animation_.target_height - resize_animation_.start_height) * progress;
|
||||
|
||||
updatePosition(); // Mantener la posición centrada durante la animación
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,13 +385,13 @@ auto WindowMessage::getTruncatedText(const std::string& text, float available_wi
|
||||
if (text.empty()) {
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
// Si el texto completo cabe, devolverlo tal como está
|
||||
int text_width = text_renderer_->length(text, -2);
|
||||
if (text_width <= available_width) {
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
// Si no hay espacio suficiente, devolver string vacío
|
||||
if (available_width < 10.0F) { // Mínimo espacio para al menos un carácter
|
||||
return "";
|
||||
@@ -406,12 +401,12 @@ auto WindowMessage::getTruncatedText(const std::string& text, float available_wi
|
||||
int left = 0;
|
||||
int right = text.length();
|
||||
int best_length = 0;
|
||||
|
||||
|
||||
while (left <= right) {
|
||||
int mid = (left + right) / 2;
|
||||
std::string partial = text.substr(0, mid);
|
||||
int partial_width = text_renderer_->length(partial, -2);
|
||||
|
||||
|
||||
if (partial_width <= available_width) {
|
||||
best_length = mid;
|
||||
left = mid + 1;
|
||||
@@ -419,6 +414,6 @@ auto WindowMessage::getTruncatedText(const std::string& text, float available_wi
|
||||
right = mid - 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return text.substr(0, best_length);
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "color.h"
|
||||
#include "text.h"
|
||||
#include "text.h"
|
||||
|
||||
class WindowMessage {
|
||||
public:
|
||||
@@ -17,34 +17,34 @@ class WindowMessage {
|
||||
};
|
||||
|
||||
struct Config {
|
||||
// Colores
|
||||
Color bg_color;
|
||||
Color border_color;
|
||||
Color title_color;
|
||||
Color text_color;
|
||||
|
||||
// Espaciado y dimensiones
|
||||
float padding{15.0f};
|
||||
float line_spacing{5.0f};
|
||||
float title_separator_spacing{10.0f}; // Espacio extra para separador del título
|
||||
// Colores
|
||||
Color bg_color;
|
||||
Color border_color;
|
||||
Color title_color;
|
||||
Color text_color;
|
||||
|
||||
// Límites de tamaño
|
||||
float min_width{200.0f};
|
||||
float min_height{100.0f};
|
||||
float max_width_ratio{0.8f}; // % máximo de ancho de pantalla
|
||||
float max_height_ratio{0.8f}; // % máximo de alto de pantalla
|
||||
// Espaciado y dimensiones
|
||||
float padding{15.0f};
|
||||
float line_spacing{5.0f};
|
||||
float title_separator_spacing{10.0f}; // Espacio extra para separador del título
|
||||
|
||||
// Margen de seguridad para texto
|
||||
float text_safety_margin{20.0f}; // Margen extra para evitar texto cortado
|
||||
// Límites de tamaño
|
||||
float min_width{200.0f};
|
||||
float min_height{100.0f};
|
||||
float max_width_ratio{0.8f}; // % máximo de ancho de pantalla
|
||||
float max_height_ratio{0.8f}; // % máximo de alto de pantalla
|
||||
|
||||
// Animaciones
|
||||
float animation_duration{0.3f}; // Duración en segundos para todas las animaciones
|
||||
// Margen de seguridad para texto
|
||||
float text_safety_margin{20.0f}; // Margen extra para evitar texto cortado
|
||||
|
||||
// Constructor con valores por defecto
|
||||
Config()
|
||||
: bg_color{40, 40, 60, 220}, border_color{100, 100, 120, 255}, title_color{255, 255, 255, 255}, text_color{200, 200, 200, 255}
|
||||
// Animaciones
|
||||
float animation_duration{0.3f}; // Duración en segundos para todas las animaciones
|
||||
|
||||
{}
|
||||
// Constructor con valores por defecto
|
||||
Config()
|
||||
: bg_color{40, 40, 60, 220}, border_color{100, 100, 120, 255}, title_color{255, 255, 255, 255}, text_color{200, 200, 200, 255}
|
||||
|
||||
{}
|
||||
};
|
||||
|
||||
WindowMessage(
|
||||
@@ -69,7 +69,7 @@ class WindowMessage {
|
||||
void setTexts(const std::vector<std::string>& texts);
|
||||
void addText(const std::string& text);
|
||||
void clearTexts();
|
||||
|
||||
|
||||
// Control de redimensionado automático
|
||||
void enableAutoResize(bool enabled) { auto_resize_enabled_ = enabled; }
|
||||
[[nodiscard]] auto isAutoResizeEnabled() const -> bool { return auto_resize_enabled_; }
|
||||
@@ -78,20 +78,29 @@ class WindowMessage {
|
||||
void setPosition(float x, float y, PositionMode mode = PositionMode::CENTERED);
|
||||
void setSize(float width, float height);
|
||||
void centerOnScreen();
|
||||
void autoSize(); // Ajusta automáticamente al contenido y reposiciona si es necesario
|
||||
void autoSize(); // Ajusta automáticamente al contenido y reposiciona si es necesario
|
||||
|
||||
// Configuración de colores
|
||||
void setBackgroundColor(const Color& color) { config_.bg_color = color; }
|
||||
void setBorderColor(const Color& color) { config_.border_color = color; }
|
||||
void setTitleColor(const Color& color) { config_.title_color = color; updateStyles(); }
|
||||
void setTextColor(const Color& color) { config_.text_color = color; updateStyles(); }
|
||||
void setTitleColor(const Color& color) {
|
||||
config_.title_color = color;
|
||||
updateStyles();
|
||||
}
|
||||
void setTextColor(const Color& color) {
|
||||
config_.text_color = color;
|
||||
updateStyles();
|
||||
}
|
||||
|
||||
// Configuración de espaciado
|
||||
void setPadding(float padding) { config_.padding = padding; }
|
||||
void setLineSpacing(float spacing) { config_.line_spacing = spacing; }
|
||||
|
||||
|
||||
// Configuración avanzada
|
||||
void setConfig(const Config& config) { config_ = config; updateStyles(); }
|
||||
void setConfig(const Config& config) {
|
||||
config_ = config;
|
||||
updateStyles();
|
||||
}
|
||||
[[nodiscard]] auto getConfig() const -> const Config& { return config_; }
|
||||
|
||||
// Getters
|
||||
@@ -102,15 +111,15 @@ class WindowMessage {
|
||||
private:
|
||||
std::shared_ptr<Text> text_renderer_;
|
||||
Config config_;
|
||||
|
||||
|
||||
// Estado de visibilidad y redimensionado
|
||||
bool visible_ = false;
|
||||
bool auto_resize_enabled_ = true; // Por defecto habilitado
|
||||
|
||||
bool auto_resize_enabled_ = true; // Por defecto habilitado
|
||||
|
||||
// Contenido
|
||||
std::string title_;
|
||||
std::vector<std::string> texts_;
|
||||
|
||||
|
||||
// Posición y tamaño
|
||||
SDL_FRect rect_{0, 0, 300, 200};
|
||||
PositionMode position_mode_ = PositionMode::CENTERED;
|
||||
@@ -118,94 +127,96 @@ class WindowMessage {
|
||||
|
||||
// Animación de redimensionado
|
||||
struct ResizeAnimation {
|
||||
bool active = false;
|
||||
float start_width, start_height;
|
||||
float target_width, target_height;
|
||||
float elapsed = 0.0F;
|
||||
bool active = false;
|
||||
float start_width, start_height;
|
||||
float target_width, target_height;
|
||||
float elapsed = 0.0F;
|
||||
|
||||
void start(float from_w, float from_h, float to_w, float to_h) {
|
||||
start_width = from_w;
|
||||
start_height = from_h;
|
||||
target_width = to_w;
|
||||
target_height = to_h;
|
||||
elapsed = 0.0F;
|
||||
active = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
active = false;
|
||||
elapsed = 0.0F;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto isFinished(float duration) const -> bool {
|
||||
return elapsed >= duration;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto getProgress(float duration) const -> float {
|
||||
return std::min(elapsed / duration, 1.0F);
|
||||
}
|
||||
void start(float from_w, float from_h, float to_w, float to_h) {
|
||||
start_width = from_w;
|
||||
start_height = from_h;
|
||||
target_width = to_w;
|
||||
target_height = to_h;
|
||||
elapsed = 0.0F;
|
||||
active = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
active = false;
|
||||
elapsed = 0.0F;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto isFinished(float duration) const -> bool {
|
||||
return elapsed >= duration;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto getProgress(float duration) const -> float {
|
||||
return std::min(elapsed / duration, 1.0F);
|
||||
}
|
||||
} resize_animation_;
|
||||
|
||||
// Animación de mostrar/ocultar
|
||||
struct ShowHideAnimation {
|
||||
enum class Type { NONE, SHOWING, HIDING };
|
||||
|
||||
Type type = Type::NONE;
|
||||
bool active = false;
|
||||
float target_width, target_height; // Tamaño final al mostrar
|
||||
float elapsed = 0.0F;
|
||||
enum class Type { NONE,
|
||||
SHOWING,
|
||||
HIDING };
|
||||
|
||||
void startShow(float to_w, float to_h) {
|
||||
type = Type::SHOWING;
|
||||
target_width = to_w;
|
||||
target_height = to_h;
|
||||
elapsed = 0.0F;
|
||||
active = true;
|
||||
}
|
||||
|
||||
void startHide() {
|
||||
type = Type::HIDING;
|
||||
elapsed = 0.0F;
|
||||
active = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
type = Type::NONE;
|
||||
active = false;
|
||||
elapsed = 0.0F;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto isFinished(float duration) const -> bool {
|
||||
return elapsed >= duration;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto getProgress(float duration) const -> float {
|
||||
return std::min(elapsed / duration, 1.0F);
|
||||
}
|
||||
Type type = Type::NONE;
|
||||
bool active = false;
|
||||
float target_width, target_height; // Tamaño final al mostrar
|
||||
float elapsed = 0.0F;
|
||||
|
||||
void startShow(float to_w, float to_h) {
|
||||
type = Type::SHOWING;
|
||||
target_width = to_w;
|
||||
target_height = to_h;
|
||||
elapsed = 0.0F;
|
||||
active = true;
|
||||
}
|
||||
|
||||
void startHide() {
|
||||
type = Type::HIDING;
|
||||
elapsed = 0.0F;
|
||||
active = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
type = Type::NONE;
|
||||
active = false;
|
||||
elapsed = 0.0F;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto isFinished(float duration) const -> bool {
|
||||
return elapsed >= duration;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto getProgress(float duration) const -> float {
|
||||
return std::min(elapsed / duration, 1.0F);
|
||||
}
|
||||
} show_hide_animation_;
|
||||
|
||||
// Estilos
|
||||
Text::Style title_style_;
|
||||
Text::Style text_style_;
|
||||
|
||||
|
||||
// Métodos privados
|
||||
void calculateAutoSize();
|
||||
void updatePosition(); // Actualiza la posición según el modo y punto de anclaje
|
||||
void updateStyles(); // Actualiza los estilos de texto cuando cambian los colores
|
||||
void ensureTextFits(); // Verifica y ajusta para que todo el texto sea visible
|
||||
void triggerAutoResize(); // Inicia redimensionado automático si está habilitado
|
||||
void updateAnimation(float delta_time); // Actualiza la animación de redimensionado
|
||||
void updateShowHideAnimation(float delta_time); // Actualiza la animación de mostrar/ocultar
|
||||
void updateResizeAnimation(float delta_time); // Actualiza la animación de redimensionado
|
||||
|
||||
void updatePosition(); // Actualiza la posición según el modo y punto de anclaje
|
||||
void updateStyles(); // Actualiza los estilos de texto cuando cambian los colores
|
||||
void ensureTextFits(); // Verifica y ajusta para que todo el texto sea visible
|
||||
void triggerAutoResize(); // Inicia redimensionado automático si está habilitado
|
||||
void updateAnimation(float delta_time); // Actualiza la animación de redimensionado
|
||||
void updateShowHideAnimation(float delta_time); // Actualiza la animación de mostrar/ocultar
|
||||
void updateResizeAnimation(float delta_time); // Actualiza la animación de redimensionado
|
||||
|
||||
// Función de suavizado (ease-out)
|
||||
[[nodiscard]] static auto easeOut(float t) -> float;
|
||||
|
||||
// Métodos para manejo de texto durante animación
|
||||
[[nodiscard]] auto getTruncatedText(const std::string& text, float available_width) const -> std::string;
|
||||
[[nodiscard]] auto getAvailableTextWidth() const -> float;
|
||||
[[nodiscard]] auto shouldShowContent() const -> bool; // Si mostrar el contenido (texto, líneas, etc.)
|
||||
|
||||
[[nodiscard]] auto shouldShowContent() const -> bool; // Si mostrar el contenido (texto, líneas, etc.)
|
||||
|
||||
[[nodiscard]] auto calculateContentHeight() const -> float;
|
||||
[[nodiscard]] auto calculateContentWidth() const -> float;
|
||||
[[nodiscard]] static auto getScreenWidth() -> float;
|
||||
|
||||
Reference in New Issue
Block a user