feat(notifier): entrada/eixida per temps amb easing, configurable a ui.yaml
This commit is contained in:
1 parent
f816e75cc0
commit
970fe2b4db
6 files changed
+68
-27
No files matched your search
@@ -69,26 +69,38 @@ void Notifier::init(std::shared_ptr<Text> text, const Palette& ui_palette) {
|
||||
|
||||
void Notifier::update(int delta_ms) {
|
||||
const auto& geo = UiConfig::get().notifier();
|
||||
const float DT = static_cast<float>(delta_ms) / 1000.0F;
|
||||
switch (status_) {
|
||||
case Status::RISING:
|
||||
y_ += geo.slide_speed * DT;
|
||||
if (y_ >= static_cast<float>(geo.margin_top + geo.border_px)) {
|
||||
y_ = static_cast<float>(geo.margin_top + geo.border_px);
|
||||
case Status::RISING: {
|
||||
slide_elapsed_ms_ += delta_ms;
|
||||
if (slide_elapsed_ms_ >= geo.slide_ms) {
|
||||
y_ = slide_y_on_;
|
||||
status_ = Status::ACTIVE;
|
||||
} else {
|
||||
const float T = static_cast<float>(slide_elapsed_ms_) / static_cast<float>(geo.slide_ms);
|
||||
const float K = geo.slide_in_curve(T);
|
||||
y_ = slide_y_off_ + ((slide_y_on_ - slide_y_off_) * K);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Status::ACTIVE:
|
||||
remaining_ms_ -= delta_ms;
|
||||
if (remaining_ms_ <= 0) { status_ = Status::VANISHING; }
|
||||
break;
|
||||
case Status::VANISHING:
|
||||
y_ -= geo.slide_speed * DT;
|
||||
if (y_ <= static_cast<float>(-current_box_h_ - geo.border_px)) {
|
||||
y_ = static_cast<float>(-current_box_h_ - geo.border_px - geo.margin_top);
|
||||
status_ = Status::HIDDEN;
|
||||
if (remaining_ms_ <= 0) {
|
||||
slide_elapsed_ms_ = 0;
|
||||
status_ = Status::VANISHING;
|
||||
}
|
||||
break;
|
||||
case Status::VANISHING: {
|
||||
slide_elapsed_ms_ += delta_ms;
|
||||
if (slide_elapsed_ms_ >= geo.slide_ms) {
|
||||
y_ = slide_y_off_;
|
||||
status_ = Status::HIDDEN;
|
||||
} else {
|
||||
const float T = static_cast<float>(slide_elapsed_ms_) / static_cast<float>(geo.slide_ms);
|
||||
const float K = geo.slide_out_curve(T);
|
||||
y_ = slide_y_on_ + ((slide_y_off_ - slide_y_on_) * K);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -146,6 +158,12 @@ void Notifier::notify(const std::string& text, Uint8 text_color, Uint8 bg_color,
|
||||
current_text_color_ = text_color;
|
||||
current_bg_color_ = bg_color;
|
||||
remaining_ms_ = time_ms;
|
||||
y_ = static_cast<float>(-current_box_h_ - geo.border_px - geo.margin_top);
|
||||
|
||||
// Posicions extremes en y (top-left de la caixa). Off = totalment fora
|
||||
// del canvas per dalt; On = posició final amb la vora respectada.
|
||||
slide_y_off_ = static_cast<float>(-current_box_h_ - geo.border_px - geo.margin_top);
|
||||
slide_y_on_ = static_cast<float>(geo.margin_top + geo.border_px);
|
||||
slide_elapsed_ms_ = 0;
|
||||
y_ = slide_y_off_;
|
||||
status_ = Status::RISING;
|
||||
}
|
||||
Reference in new issue
Block a user