Skip to content

Commit

Permalink
Gui: Add easing to navigation animations
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexbas committed Jan 30, 2024
1 parent 6c7f672 commit e272b8a
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/Gui/NavigationAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void NavigationAnimation::onStop([[maybe_unused]] bool finished)

FixedTimeAnimation::FixedTimeAnimation(NavigationStyle* navigation, const SbRotation& orientation,
const SbVec3f& rotationCenter, const SbVec3f& translation,
int duration)
int duration, bool useEasing)
: NavigationAnimation(navigation)
, targetOrientation(orientation)
, targetTranslation(translation)
Expand All @@ -53,6 +53,10 @@ FixedTimeAnimation::FixedTimeAnimation(NavigationStyle* navigation, const SbRota
setDuration(duration);
setStartValue(0.0);
setEndValue(duration * 1.0);

if (useEasing) {
setEasingCurve(QEasingCurve::InOutCubic);
}
}

void FixedTimeAnimation::initialize()
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/NavigationAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class GuiExport FixedTimeAnimation : public NavigationAnimation
public:
explicit FixedTimeAnimation(NavigationStyle* navigation, const SbRotation& orientation,
const SbVec3f& rotationCenter, const SbVec3f& translation,
int duration);
int duration, bool useEasing);

private:
float angularVelocity; // [rad/ms]
Expand Down
1 change: 1 addition & 0 deletions src/Gui/PreferencePackTemplates/View.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<FCBool Name="ShowNaviCube" Value="1"/>
<FCBool Name="ShowSelectionBoundingBox" Value="0"/>
<FCBool Name="UseNavigationAnimations" Value="1"/>
<FCBool Name="UseEasingAnimations" Value="1"/>
<FCBool Name="UseSpinningAnimations" Value="0"/>
<FCFloat Name="AnimationDuration" Value="500"/>
<FCBool Name="UseVBO" Value="0"/>
Expand Down
2 changes: 2 additions & 0 deletions src/Gui/PreferencePages/DlgSettingsNavigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ void DlgSettingsNavigation::saveSettings()
ui->rotationCenterColor->onSave();
ui->spinBoxZoomStep->onSave();
ui->spinBoxAnimationDuration->onSave();
ui->checkBoxEasingAnimations->onSave();
ui->checkBoxSpinningAnimations->onSave();
ui->qspinNewDocScale->onSave();
ui->prefStepByTurn->onSave();
Expand Down Expand Up @@ -134,6 +135,7 @@ void DlgSettingsNavigation::loadSettings()
ui->rotationCenterColor->onRestore();
ui->spinBoxZoomStep->onRestore();
ui->spinBoxAnimationDuration->onRestore();
ui->checkBoxEasingAnimations->onRestore();
ui->checkBoxSpinningAnimations->onRestore();
ui->qspinNewDocScale->onRestore();
ui->prefStepByTurn->onRestore();
Expand Down
29 changes: 24 additions & 5 deletions src/Gui/PreferencePages/DlgSettingsNavigation.ui
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
<property name="toolTip">
<string>Base color for all elements</string>
</property>
<property name="color">
<property name="color" stdset="0">
<color alpha="128">
<red>226</red>
<green>232</green>
Expand Down Expand Up @@ -267,16 +267,16 @@
<number>1</number>
</property>
<property name="minimum">
<double>1.0</double>
<double>1.000000000000000</double>
</property>
<property name="maximum">
<double>100.0</double>
<double>100.000000000000000</double>
</property>
<property name="singleStep">
<double>0.5</double>
<double>0.500000000000000</double>
</property>
<property name="value">
<double>5.0</double>
<double>5.000000000000000</double>
</property>
<property name="prefEntry" stdset="0">
<cstring>RotationCenterSize</cstring>
Expand Down Expand Up @@ -756,6 +756,25 @@ Mouse tilting is not disabled by this setting.</string>
</spacer>
</item>
<item row="2" column="0">
<widget class="Gui::PrefCheckBox" name="checkBoxEasingAnimations">
<property name="toolTip">
<string>Enable an easing function to accelerate and decelerate the animation at the start and end</string>
</property>
<property name="text">
<string>Enable easing</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>UseEasingAnimations</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>View</cstring>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="Gui::PrefCheckBox" name="checkBoxSpinningAnimations">
<property name="toolTip">
<string>Enable spinning animations that are used in some navigation styles after dragging</string>
Expand Down
6 changes: 5 additions & 1 deletion src/Gui/View3DInventorViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3310,8 +3310,12 @@ void View3DInventorViewer::startAnimation(const SbRotation& orientation,
->GetInt("AnimationDuration", 500);
}

bool useEasing = App::GetApplication()
.GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")
->GetBool("UseEasingAnimations", true);

auto animation = std::make_shared<FixedTimeAnimation>(
navigation, orientation, rotationCenter, translation, duration);
navigation, orientation, rotationCenter, translation, duration, useEasing);

navigation->startAnimating(animation, wait);
}
Expand Down
1 change: 1 addition & 0 deletions src/Gui/View3DSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ void View3DSettings::applySettings()
OnChange(*hGrp,"CornerCoordSystemSize");
OnChange(*hGrp,"ShowAxisCross");
OnChange(*hGrp,"UseNavigationAnimations");
OnChange(*hGrp,"UseEasingAnimations");
OnChange(*hGrp,"UseSpinningAnimations");
OnChange(*hGrp,"Gradient");
OnChange(*hGrp,"RadialGradient");
Expand Down

0 comments on commit e272b8a

Please sign in to comment.