From b46256575ff3353dcad79276458d2e42d3ade81a Mon Sep 17 00:00:00 2001 From: David Given Date: Thu, 5 Dec 2024 23:41:26 +0100 Subject: [PATCH 1/4] Add a configuration setting to allow the animation speed to be set. --- src/confscreen.cpp | 20 ++++++++++++++++++++ src/solvespace.cpp | 4 ++++ src/solvespace.h | 1 + src/ui.h | 2 ++ 4 files changed, 27 insertions(+) diff --git a/src/confscreen.cpp b/src/confscreen.cpp index b4be1f82a..ada6e1059 100644 --- a/src/confscreen.cpp +++ b/src/confscreen.cpp @@ -207,6 +207,11 @@ void TextWindow::ScreenChangeFindConstraintTimeout(int link, uint32_t v) { SS.TW.edit.meaning = Edit::FIND_CONSTRAINT_TIMEOUT; } +void TextWindow::ScreenChangeAnimationSpeed(int link, uint32_t v) { + SS.TW.ShowEditControl(3, std::to_string(SS.animationSpeed)); + SS.TW.edit.meaning = Edit::ANIMATION_SPEED; +} + void TextWindow::ShowConfiguration() { int i; Printf(true, "%Ft user color (r, g, b)"); @@ -366,6 +371,10 @@ void TextWindow::ShowConfiguration() { Printf(false, "%Ft redundant constraint timeout (in ms)%E"); Printf(false, "%Ba %d %Fl%Ll%f[change]%E", SS.timeoutRedundantConstr, &ScreenChangeFindConstraintTimeout); + Printf(false, ""); + Printf(false, "%Ft animation speed (in ms)%E"); + Printf(false, "%Ba %d %Fl%Ll%f[change]%E", + SS.animationSpeed, &ScreenChangeAnimationSpeed); if(canvas) { const char *gl_vendor, *gl_renderer, *gl_version; @@ -563,6 +572,17 @@ bool TextWindow::EditControlDoneForConfiguration(const std::string &s) { } break; } + case Edit::ANIMATION_SPEED: { + int speed = atoi(s.c_str()); + if(speed) { + if(speed >= 1) { + SS.animationSpeed = speed; + } else { + SS.animationSpeed = 1000; + } + } + break; + } default: return false; } diff --git a/src/solvespace.cpp b/src/solvespace.cpp index aa135eaff..fbbddd4ac 100644 --- a/src/solvespace.cpp +++ b/src/solvespace.cpp @@ -54,6 +54,8 @@ void SolveSpaceUI::Init() { exportMaxSegments = settings->ThawInt("ExportMaxSegments", 64); // Timeout value for finding redundant constrains (ms) timeoutRedundantConstr = settings->ThawInt("TimeoutRedundantConstraints", 1000); + // Animation speed calculation base time (ms) + animationSpeed = settings->ThawInt("AnimationSpeed", 1000); // View units viewUnits = (Unit)settings->ThawInt("ViewUnits", (uint32_t)Unit::MM); // Number of digits after the decimal point @@ -239,6 +241,8 @@ void SolveSpaceUI::Exit() { settings->FreezeInt("ExportMaxSegments", (uint32_t)exportMaxSegments); // Timeout for finding which constraints to fix Jacobian settings->FreezeInt("TimeoutRedundantConstraints", (uint32_t)timeoutRedundantConstr); + // Animation speed + settings->FreezeInt("AnimationSpeed", (uint32_t)animationSpeed); // View units settings->FreezeInt("ViewUnits", (uint32_t)viewUnits); // Number of digits after the decimal point diff --git a/src/solvespace.h b/src/solvespace.h index 6c3daa737..96e66ccf6 100644 --- a/src/solvespace.h +++ b/src/solvespace.h @@ -569,6 +569,7 @@ class SolveSpaceUI { double exportChordTol; int exportMaxSegments; int timeoutRedundantConstr; //milliseconds + int animationSpeed; //milliseconds double cameraTangent; double gridSpacing; double exportScale; diff --git a/src/ui.h b/src/ui.h index 49c1be64f..eef546ece 100644 --- a/src/ui.h +++ b/src/ui.h @@ -323,6 +323,7 @@ class TextWindow { LIGHT_AMBIENT = 118, FIND_CONSTRAINT_TIMEOUT = 119, EXPLODE_DISTANCE = 120, + ANIMATION_SPEED = 121, // For TTF text TTF_TEXT = 300, // For the step dimension screen @@ -505,6 +506,7 @@ class TextWindow { static void ScreenChangeGCodeParameter(int link, uint32_t v); static void ScreenChangeAutosaveInterval(int link, uint32_t v); static void ScreenChangeFindConstraintTimeout(int link, uint32_t v); + static void ScreenChangeAnimationSpeed(int link, uint32_t v); static void ScreenChangeStyleName(int link, uint32_t v); static void ScreenChangeStyleMetric(int link, uint32_t v); static void ScreenChangeStyleTextAngle(int link, uint32_t v); From 381ac476697cfe0bbc7c33821bc1b564e88ea507 Mon Sep 17 00:00:00 2001 From: David Given Date: Thu, 5 Dec 2024 23:59:12 +0100 Subject: [PATCH 2/4] Honour the animation speed setting when doing animations. --- src/graphicswin.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/graphicswin.cpp b/src/graphicswin.cpp index 59da9cb1c..abb80db82 100644 --- a/src/graphicswin.cpp +++ b/src/graphicswin.cpp @@ -503,12 +503,18 @@ void GraphicsWindow::AnimateOnto(Quaternion quatf, Vector offsetf) { // Animate transition, unless it's a tiny move. int64_t t0 = GetMilliseconds(); - int32_t dt = (mp < 0.01 && mo < 10) ? (-20) : - (int32_t)(100 + 600*mp + 0.4*mo); - // Don't ever animate for longer than 800 ms; we can get absurdly + int32_t dt = (mp < 0.01 && mo < 10) ? 0 : + (int32_t)(SS.animationSpeed*0.75*mp + SS.animationSpeed*0.0005*mo); + // Apply a minimum animation time, for small moves. This gets overridden by the maximum setting + // so setting the animation speed to 0 disables animations entirely. + dt = std::max(dt, 100 /* ms */); + // Don't ever animate for longer than animationSpeed ms; we can get absurdly // long translations (as measured in pixels) if the user zooms out, moves, // and then zooms in again. - if(dt > 800) dt = 800; + dt = std::min(dt, SS.animationSpeed); + // If the resulting animation time is very short, disable it completely. + if (dt < 100) dt = -20; + Quaternion dq = quatf.Times(quat0.Inverse()); if(!animateTimer) { From 4ed06e9a5d44ea1d2b448245442fc877154459ba Mon Sep 17 00:00:00 2001 From: David Given Date: Fri, 6 Dec 2024 00:03:29 +0100 Subject: [PATCH 3/4] Change the default animation speed to 800ms to mostly match the original behaviour. --- src/confscreen.cpp | 12 +++++------- src/solvespace.cpp | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/confscreen.cpp b/src/confscreen.cpp index ada6e1059..329465463 100644 --- a/src/confscreen.cpp +++ b/src/confscreen.cpp @@ -372,7 +372,7 @@ void TextWindow::ShowConfiguration() { Printf(false, "%Ba %d %Fl%Ll%f[change]%E", SS.timeoutRedundantConstr, &ScreenChangeFindConstraintTimeout); Printf(false, ""); - Printf(false, "%Ft animation speed (in ms)%E"); + Printf(false, "%Ft animation speed (in ms; 0 to disable)%E"); Printf(false, "%Ba %d %Fl%Ll%f[change]%E", SS.animationSpeed, &ScreenChangeAnimationSpeed); @@ -574,12 +574,10 @@ bool TextWindow::EditControlDoneForConfiguration(const std::string &s) { } case Edit::ANIMATION_SPEED: { int speed = atoi(s.c_str()); - if(speed) { - if(speed >= 1) { - SS.animationSpeed = speed; - } else { - SS.animationSpeed = 1000; - } + if(speed >= 0) { + SS.animationSpeed = speed; + } else { + SS.animationSpeed = 800; } break; } diff --git a/src/solvespace.cpp b/src/solvespace.cpp index fbbddd4ac..34cddf1cf 100644 --- a/src/solvespace.cpp +++ b/src/solvespace.cpp @@ -55,7 +55,7 @@ void SolveSpaceUI::Init() { // Timeout value for finding redundant constrains (ms) timeoutRedundantConstr = settings->ThawInt("TimeoutRedundantConstraints", 1000); // Animation speed calculation base time (ms) - animationSpeed = settings->ThawInt("AnimationSpeed", 1000); + animationSpeed = settings->ThawInt("AnimationSpeed", 800); // View units viewUnits = (Unit)settings->ThawInt("ViewUnits", (uint32_t)Unit::MM); // Number of digits after the decimal point From 34a1b3a289a4fc4d5a95ff19a167a9f582e05b87 Mon Sep 17 00:00:00 2001 From: David Given Date: Fri, 6 Dec 2024 19:55:06 +0100 Subject: [PATCH 4/4] Make the very short animation bound even shorter. --- src/graphicswin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphicswin.cpp b/src/graphicswin.cpp index abb80db82..07d24f675 100644 --- a/src/graphicswin.cpp +++ b/src/graphicswin.cpp @@ -513,7 +513,7 @@ void GraphicsWindow::AnimateOnto(Quaternion quatf, Vector offsetf) { // and then zooms in again. dt = std::min(dt, SS.animationSpeed); // If the resulting animation time is very short, disable it completely. - if (dt < 100) dt = -20; + if (dt < 10) dt = -20; Quaternion dq = quatf.Times(quat0.Inverse());