clang-format
This commit is contained in:
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user