summaryrefslogtreecommitdiff
path: root/dash
diff options
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2016-07-04 18:35:14 +0200
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2016-07-04 18:35:14 +0200
commit03651257fc7a58bf4ede79d548ccb0fb4743b111 (patch)
tree120fc2d61e544420ccf7459a07d3a55a1da9b1ac /dash
parentaf82d17282d84853c1f01214ed79577978d1c7ef (diff)
PreviewContainer: use nux::Animation for handling resizing animation
(bzr r4132.6.9)
Diffstat (limited to 'dash')
-rw-r--r--dash/previews/PreviewContainer.cpp83
-rw-r--r--dash/previews/PreviewContainer.h13
-rw-r--r--dash/previews/StandaloneApplicationPreview.cpp5
-rw-r--r--dash/previews/StandaloneErrorPreview.cpp5
-rw-r--r--dash/previews/StandaloneMoviePreview.cpp5
-rw-r--r--dash/previews/StandaloneMusicPaymentPreview.cpp5
-rw-r--r--dash/previews/StandaloneSocialPreview.cpp5
7 files changed, 48 insertions, 73 deletions
diff --git a/dash/previews/PreviewContainer.cpp b/dash/previews/PreviewContainer.cpp
index 63f6e55c1..deee716a4 100644
--- a/dash/previews/PreviewContainer.cpp
+++ b/dash/previews/PreviewContainer.cpp
@@ -23,6 +23,7 @@
#include "PreviewContainer.h"
#include <Nux/HLayout.h>
+#include "unity-shared/AnimationUtils.h"
#include "unity-shared/IntrospectableWrappers.h"
#include "unity-shared/TimeUtil.h"
#include "unity-shared/PreviewStyle.h"
@@ -49,7 +50,6 @@ namespace
const int ANIM_DURATION_LONG = 500;
const int PREVIEW_SPINNER_WAIT = 2000;
-const std::string ANIMATION_IDLE = "animation-idle";
const RawPixel CHILDREN_SPACE = 6_em;
}
@@ -113,7 +113,7 @@ public:
StopPreviewWait();
// the parents layout will not change based on the previews.
preview->SetReconfigureParentLayoutOnGeometryChange(false);
-
+
AddChild(preview.GetPointer());
AddView(preview.GetPointer());
preview->SetVisible(false);
@@ -409,23 +409,17 @@ PreviewContainer::PreviewContainer(NUX_FILE_LINE_DECL)
, scale(1.0)
, preview_layout_(nullptr)
, nav_disabled_(Navigation::NONE)
- , navigation_progress_speed_(0.0)
- , navigation_count_(0)
+ , animation_(ANIM_DURATION_LONG)
{
SetAcceptKeyNavFocusOnMouseDown(false);
SetAcceptKeyNavFocusOnMouseEnter(false);
SetupViews();
- last_progress_time_.tv_sec = 0;
- last_progress_time_.tv_nsec = 0;
key_down.connect(sigc::mem_fun(this, &PreviewContainer::OnKeyDown));
mouse_click.connect(sigc::mem_fun(this, &PreviewContainer::OnMouseDown));
scale.changed.connect(sigc::mem_fun(this, &PreviewContainer::UpdateScale));
-}
-
-PreviewContainer::~PreviewContainer()
-{
+ animation_.updated.connect(sigc::mem_fun(this, &PreviewContainer::QueueAnimation));
}
void PreviewContainer::Preview(dash::Preview::Ptr preview_model, Navigation direction)
@@ -503,28 +497,22 @@ void PreviewContainer::SetupViews()
layout->AddSpace(0, 1);
- preview_layout_->start_navigation.connect([this]()
+ preview_layout_->start_navigation.connect([this]
{
- // reset animation clock.
- if (navigation_count_ == 0)
- clock_gettime(CLOCK_MONOTONIC, &last_progress_time_);
-
- float navigation_progress_remaining = CLAMP((1.0 - preview_layout_->GetAnimationProgress()) + navigation_count_, 1.0f, 10.0f);
- navigation_count_++;
+ if (animation_.CurrentState() == na::Animation::State::Running)
+ preview_layout_->UpdateAnimationProgress(1, 1);
- navigation_progress_speed_ = navigation_progress_remaining / ANIM_DURATION_LONG;
- QueueAnimation();
+ animation::Start(animation_, animation::Direction::FORWARD);
});
- preview_layout_->continue_navigation.connect([this]()
+ preview_layout_->continue_navigation.connect([this]
{
- QueueAnimation();
+ QueueAnimation(animation_.GetCurrentValue());
});
- preview_layout_->end_navigation.connect([this]()
+ preview_layout_->end_navigation.connect([this]
{
- navigation_count_ = 0;
- navigation_progress_speed_ = 0;
+ animation_.Stop();
});
navigate_right.connect( [this]() { preview_layout_->StartPreviewWait(); } );
@@ -551,17 +539,6 @@ void PreviewContainer::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_d
gfx_engine.QRP_Color(GetX(), GetY(), GetWidth(), GetHeight(), nux::Color(0.0f, 0.0f, 0.0f, 0.0f));
}
- // rely on the compiz event loop to come back to us in a nice throttling
- if (AnimationInProgress())
- {
- if (!animation_timer_)
- animation_timer_.reset(new glib::Timeout(1000/60, sigc::mem_fun(this, &PreviewContainer::QueueAnimation)));
- }
- else if (preview_layout_ && preview_layout_->IsAnimating())
- {
- preview_layout_->UpdateAnimationProgress(1.0f, 1.0f);
- }
-
// Paint using ProcessDraw2. ProcessDraw is overrided by empty impl so we can control z order.
if (preview_layout_)
{
@@ -573,23 +550,9 @@ void PreviewContainer::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_d
gfx_engine.PopClippingRectangle();
}
-bool PreviewContainer::AnimationInProgress()
+namespace
{
- // short circuit to avoid unneeded calculations
- struct timespec current;
- clock_gettime(CLOCK_MONOTONIC, &current);
-
- if (preview_layout_ == nullptr)
- return false;
-
- // hover in animation
- if (navigation_progress_speed_ > 0)
- return true;
-
- return false;
-}
-
-static float easeInOutQuart(float t)
+double easeInOutQuart(double t)
{
t = CLAMP(t, 0.0, 1.0);
t*=2.0f;
@@ -599,28 +562,20 @@ static float easeInOutQuart(float t)
return -0.5f * (pow(t, 4)- 2);
}
}
+}
-float PreviewContainer::GetSwipeAnimationProgress(struct timespec const& current) const
+double PreviewContainer::GetSwipeAnimationProgress(struct timespec const& current) const
{
- DeltaTime time_delta = TimeUtil::TimeDelta(&current, &last_progress_time_);
- float progress = preview_layout_->GetAnimationProgress() + (navigation_progress_speed_ * time_delta);
-
- return progress;
+ return preview_layout_ ? preview_layout_->GetAnimationProgress() : 0 + animation_.GetCurrentValue();
}
-bool PreviewContainer::QueueAnimation()
+void PreviewContainer::QueueAnimation(double progress)
{
- animation_timer_.reset();
-
- timespec current;
- clock_gettime(CLOCK_MONOTONIC, &current);
- float progress = GetSwipeAnimationProgress(current);
+ g_print("Queue animation %f\n",progress);
if (preview_layout_)
preview_layout_->UpdateAnimationProgress(progress, easeInOutQuart(progress)); // ease in/out.
- last_progress_time_ = current;
QueueDraw();
- return false;
}
bool PreviewContainer::AcceptKeyNavFocus()
diff --git a/dash/previews/PreviewContainer.h b/dash/previews/PreviewContainer.h
index 877322284..519daeba1 100644
--- a/dash/previews/PreviewContainer.h
+++ b/dash/previews/PreviewContainer.h
@@ -26,6 +26,7 @@
#include <Nux/Nux.h>
#include <Nux/View.h>
#include <Nux/VLayout.h>
+#include <NuxCore/Animation.h>
#include <UnityCore/Preview.h>
#include "Preview.h"
#include "unity-shared/Introspectable.h"
@@ -57,7 +58,6 @@ public:
NUX_DECLARE_OBJECT_TYPE(PreviewContainer, nux::View);
PreviewContainer(NUX_FILE_LINE_PROTO);
- virtual ~PreviewContainer();
void Preview(dash::Preview::Ptr preview_model, Navigation direction);
@@ -98,10 +98,8 @@ protected:
private:
void SetupViews();
- bool AnimationInProgress();
- float GetSwipeAnimationProgress(struct timespec const& current) const;
-
- bool QueueAnimation();
+ void QueueAnimation(double progress);
+ double GetSwipeAnimationProgress(struct timespec const& current) const;
private:
void UpdateScale(double scale);
@@ -114,11 +112,8 @@ private:
Navigation nav_disabled_;
// Animation
- struct timespec last_progress_time_;
- float navigation_progress_speed_;
- int navigation_count_;
+ nux::animation::AnimateValue<double> animation_;
- glib::Source::UniquePtr animation_timer_;
friend class PreviewContent;
};
diff --git a/dash/previews/StandaloneApplicationPreview.cpp b/dash/previews/StandaloneApplicationPreview.cpp
index e24f5acaa..7c2120064 100644
--- a/dash/previews/StandaloneApplicationPreview.cpp
+++ b/dash/previews/StandaloneApplicationPreview.cpp
@@ -21,10 +21,12 @@
#include "config.h"
#include "Nux/Nux.h"
+#include "Nux/NuxTimerTickSource.h"
#include "Nux/VLayout.h"
#include "Nux/WindowThread.h"
#include "NuxGraphics/GraphicsEngine.h"
#include <Nux/Layout.h>
+#include <NuxCore/AnimationController.h>
#include <NuxCore/Logger.h>
#include <UnityCore/Variant.h>
#include <UnityCore/ApplicationPreview.h>
@@ -341,6 +343,9 @@ int main(int argc, char **argv)
&TestRunner::InitWindowThread,
test_runner);
+ nux::NuxTimerTickSource tick_source;
+ nux::animation::AnimationController animation_controller(tick_source);
+
wt->Run (NULL);
delete wt;
return 0;
diff --git a/dash/previews/StandaloneErrorPreview.cpp b/dash/previews/StandaloneErrorPreview.cpp
index 9a03221c6..4757c3103 100644
--- a/dash/previews/StandaloneErrorPreview.cpp
+++ b/dash/previews/StandaloneErrorPreview.cpp
@@ -24,6 +24,8 @@
#include "Nux/VLayout.h"
#include "Nux/WindowThread.h"
#include "NuxGraphics/GraphicsEngine.h"
+#include "Nux/NuxTimerTickSource.h"
+#include <NuxCore/AnimationController.h>
#include <Nux/Layout.h>
#include <NuxCore/Logger.h>
#include <UnityCore/Variant.h>
@@ -228,6 +230,9 @@ int main(int argc, char **argv)
&TestRunner::InitWindowThread,
test_runner);
+ nux::NuxTimerTickSource tick_source;
+ nux::animation::AnimationController animation_controller(tick_source);
+
wt->Run (NULL);
delete wt;
return 0;
diff --git a/dash/previews/StandaloneMoviePreview.cpp b/dash/previews/StandaloneMoviePreview.cpp
index 0d0bd7e26..9d183e3c9 100644
--- a/dash/previews/StandaloneMoviePreview.cpp
+++ b/dash/previews/StandaloneMoviePreview.cpp
@@ -20,10 +20,12 @@
#include <gtk/gtk.h>
#include "Nux/Nux.h"
+#include "Nux/NuxTimerTickSource.h"
#include "Nux/VLayout.h"
#include "Nux/WindowThread.h"
#include "NuxGraphics/GraphicsEngine.h"
#include <Nux/Layout.h>
+#include <NuxCore/AnimationController.h>
#include <NuxCore/Logger.h>
#include <UnityCore/Variant.h>
#include <UnityCore/ApplicationPreview.h>
@@ -257,6 +259,9 @@ int main(int argc, char **argv)
&TestRunner::InitWindowThread,
test_runner);
+ nux::NuxTimerTickSource tick_source;
+ nux::animation::AnimationController animation_controller(tick_source);
+
wt->Run (NULL);
delete wt;
return 0;
diff --git a/dash/previews/StandaloneMusicPaymentPreview.cpp b/dash/previews/StandaloneMusicPaymentPreview.cpp
index 4d59587dc..745061b9f 100644
--- a/dash/previews/StandaloneMusicPaymentPreview.cpp
+++ b/dash/previews/StandaloneMusicPaymentPreview.cpp
@@ -21,9 +21,11 @@
#include "Nux/Nux.h"
#include "Nux/VLayout.h"
+#include "Nux/NuxTimerTickSource.h"
#include "Nux/WindowThread.h"
#include "NuxGraphics/GraphicsEngine.h"
#include <Nux/Layout.h>
+#include <NuxCore/AnimationController.h>
#include <NuxCore/Logger.h>
#include <UnityCore/Variant.h>
#include <UnityCore/Preview.h>
@@ -232,6 +234,9 @@ int main(int argc, char **argv)
&TestRunner::InitWindowThread,
test_runner);
+ nux::NuxTimerTickSource tick_source;
+ nux::animation::AnimationController animation_controller(tick_source);
+
wt->Run (NULL);
delete wt;
return 0;
diff --git a/dash/previews/StandaloneSocialPreview.cpp b/dash/previews/StandaloneSocialPreview.cpp
index a73d9ba56..e7ee69331 100644
--- a/dash/previews/StandaloneSocialPreview.cpp
+++ b/dash/previews/StandaloneSocialPreview.cpp
@@ -20,10 +20,12 @@
#include "config.h"
#include "Nux/Nux.h"
+#include "Nux/NuxTimerTickSource.h"
#include "Nux/VLayout.h"
#include "Nux/WindowThread.h"
#include "NuxGraphics/GraphicsEngine.h"
#include <Nux/Layout.h>
+#include <NuxCore/AnimationController.h>
#include <NuxCore/Logger.h>
#include <UnityCore/Variant.h>
#include <UnityCore/SocialPreview.h>
@@ -291,6 +293,9 @@ int main(int argc, char **argv)
&TestRunner::InitWindowThread,
test_runner);
+ nux::NuxTimerTickSource tick_source;
+ nux::animation::AnimationController animation_controller(tick_source);
+
wt->Run (NULL);
delete wt;
return 0;