Fixed bookmark jump transition bug

This commit is contained in:
Yousef Khadadeh 2026-04-09 10:20:40 +03:00
parent bacca9ff68
commit 4aa810fe43
7 changed files with 21 additions and 9 deletions

View file

@ -3,6 +3,7 @@
#include "Helpers/FixedPoint.hpp"
#include "Helpers/MathExtras.hpp"
#include "MainProgram.hpp"
#include "TimePoint.hpp"
#include "World.hpp"
#include "InputManager.hpp"
#include <Helpers/Logger.hpp>
@ -65,7 +66,7 @@ void DrawCamera::scale_up(World& w, const WorldScalar& scaleUpAmount) {
void DrawCamera::update_main(World& w) {
if(smoothMove.occurring) {
BezierEasing zoomAnim{w.main.conf.jumpTransitionEasing};
float smoothTime = smooth_two_way_time(smoothMove.moveTime, w.main.deltaTime, true, w.main.conf.jumpTransitionTime);
float smoothTime = smooth_two_way_animation_time_get_lerp(smoothMove.moveTime, w.main.deltaTime, true, w.main.conf.jumpTransitionTime);
float lerpTime;
float rotationLerpTime = zoomAnim(smoothTime);
lerpTime = zoomAnim(smoothTime);

View file

@ -21,7 +21,7 @@ void CheckBox::layout(const Clay_ElementId& id, const std::function<bool()>& isT
}
void CheckBox::update() {
if(smooth_two_way_time(hoverAnimation, gui.io.deltaTime, mouseHovering, CHECKBOX_ANIMATION_TIME))
if(smooth_two_way_animation_time_check_for_change(hoverAnimation, gui.io.deltaTime, mouseHovering, CHECKBOX_ANIMATION_TIME))
gui.invalidate_draw_element(this);
if(oldIsTicked != isTicked()) {
gui.invalidate_draw_element(this);

View file

@ -34,8 +34,8 @@ template <typename T> class NumberSlider : public Element {
}
virtual void update() {
smooth_two_way_time(dd.holdAnimation, gui.io.deltaTime, dd.isHeld, HOLD_ANIMATION_TIME);
smooth_two_way_time(dd.hoverAnimation, gui.io.deltaTime, mouseHovering, gui.io.theme->hoverExpandTime);
smooth_two_way_animation_time(dd.holdAnimation, gui.io.deltaTime, dd.isHeld, HOLD_ANIMATION_TIME);
smooth_two_way_animation_time(dd.hoverAnimation, gui.io.deltaTime, mouseHovering, gui.io.theme->hoverExpandTime);
if(oldDD != dd) {
gui.invalidate_draw_element(this, {
.top = 10.0f,

View file

@ -19,7 +19,7 @@ void RadioButton::layout(const Clay_ElementId& id, const std::function<bool()>&
}
void RadioButton::update() {
if(smooth_two_way_time(hoverAnimation, gui.io.deltaTime, mouseHovering, RADIOBUTTON_ANIMATION_TIME))
if(smooth_two_way_animation_time_check_for_change(hoverAnimation, gui.io.deltaTime, mouseHovering, RADIOBUTTON_ANIMATION_TIME))
gui.invalidate_draw_element(this);
if(oldIsTicked != isTicked()) {
gui.invalidate_draw_element(this);

View file

@ -71,11 +71,11 @@ void MainProgram::update() {
while(std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - lastFrameTime).count() < 1.0 / conf.fpsLimit);
lastFrameTime = std::chrono::steady_clock::now();
input.update();
deltaTime.update_time_since();
deltaTime.update_time_point();
input.update();
g.update();
toolbar.update();

View file

@ -21,7 +21,7 @@ TimePoint::operator float() const {
return get_time_since();
}
bool smooth_two_way_time(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration) {
bool smooth_two_way_animation_time_check_for_change(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration) {
float newTimeToUpdate = std::clamp(isWay1 ? (timeToUpdate + deltaTime) : (timeToUpdate - deltaTime), 0.0f, animDuration);
if(newTimeToUpdate != timeToUpdate) {
timeToUpdate = newTimeToUpdate;
@ -30,6 +30,15 @@ bool smooth_two_way_time(float& timeToUpdate, float deltaTime, bool isWay1, floa
return false;
}
float smooth_two_way_animation_time_get_lerp(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration) {
timeToUpdate = std::clamp(isWay1 ? (timeToUpdate + deltaTime) : (timeToUpdate - deltaTime), 0.0f, animDuration);
return timeToUpdate / animDuration;
}
void smooth_two_way_animation_time(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration) {
timeToUpdate = std::clamp(isWay1 ? (timeToUpdate + deltaTime) : (timeToUpdate - deltaTime), 0.0f, animDuration);
}
WorldVec lerp_world_vec_double(const WorldVec& v1, const WorldVec& v2, double t) {
return {FixedPoint::lerp_double(v1.x(), v2.x(), t), FixedPoint::lerp_double(v1.y(), v2.y(), t)};
}

View file

@ -30,7 +30,9 @@ template<typename TimeType> SkColor4f lerp_vec(const SkColor4f& t1, const SkColo
std::lerp(t1[3], t2[3], t)};
}
bool smooth_two_way_time(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration);
bool smooth_two_way_animation_time_check_for_change(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration);
float smooth_two_way_animation_time_get_lerp(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration);
void smooth_two_way_animation_time(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration);
class TimePoint {
public: