summaryrefslogtreecommitdiff
diff options
-rw-r--r--dash/previews/PreviewContainer.cpp137
-rw-r--r--dash/previews/StandaloneApplicationPreview.cpp65
-rw-r--r--unity-shared/PreviewStyle.cpp90
-rw-r--r--unity-shared/PreviewStyle.h1
4 files changed, 200 insertions, 93 deletions
diff --git a/dash/previews/PreviewContainer.cpp b/dash/previews/PreviewContainer.cpp
index c37b1ee42..6703bfb11 100644
--- a/dash/previews/PreviewContainer.cpp
+++ b/dash/previews/PreviewContainer.cpp
@@ -29,6 +29,7 @@
#include "unity-shared/PreviewStyle.h"
#include "PreviewNavigator.h"
#include <boost/math/constants/constants.hpp>
+#include "config.h"
namespace unity
{
@@ -58,13 +59,22 @@ const std::string ANIMATION_IDLE = "animation-idle";
class PreviewContent : public nux::Layout
{
public:
- PreviewContent(const PreviewContainer*const parent)
- : progress_(0.0)
+ PreviewContent(PreviewContainer*const parent)
+ : parent_(parent)
+ , progress_(0.0)
, animating_(false)
- , parent_(parent) {}
+ , waiting_preview_(false)
+ , rotation_(0.0)
+ {
+ Style& style = previews::Style::Instance();
+
+ spin_= style.GetSearchSpinIcon(256);
+ }
void PushPreview(previews::Preview::Ptr preview, Navigation direction)
{
+ StopPreviewWait();
+
if (preview)
{
AddView(preview.GetPointer());
@@ -172,6 +182,43 @@ public:
}
}
+ void StartPreviewWait()
+ {
+ preview_wait_timer_.reset(new glib::Timeout(300, [&] () {
+
+ if (waiting_preview_)
+ return false;
+
+ waiting_preview_ = true;
+
+ rotate_matrix_.Rotate_z(0.0f);
+ rotation_ = 0.0f;
+ parent_->QueueDraw();
+ return false;
+ }));
+ }
+
+ void StopPreviewWait()
+ {
+ preview_wait_timer_.reset();
+ waiting_preview_ = false;
+ parent_->QueueDraw();
+ }
+
+ bool OnFrameTimeout()
+ {
+ frame_timeout_.reset();
+ rotation_ += 0.1f;
+
+ if (rotation_ >= 360.0f)
+ rotation_ = 0.0f;
+
+ rotate_matrix_.Rotate_z(rotation_);
+ parent_->QueueDraw();
+
+ return false;
+ }
+
// Dont draw in process draw. this is so we can control the z order.
void ProcessDraw(nux::GraphicsEngine& gfx_engine, bool force_draw)
{
@@ -182,6 +229,57 @@ public:
if (swipe_.preview && swipe_.preview->IsVisible()) { swipe_.preview->ProcessDraw(gfx_engine, force_draw); }
if (current_preview_ && current_preview_->IsVisible()) { current_preview_->ProcessDraw(gfx_engine, force_draw); }
+
+ if (waiting_preview_)
+ {
+ nux::Geometry const& base = GetGeometry();
+
+ unsigned int alpha, src, dest = 0;
+ gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
+ gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ nux::TexCoordXForm texxform;
+ texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
+ texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
+ texxform.min_filter = nux::TEXFILTER_LINEAR;
+ texxform.mag_filter = nux::TEXFILTER_LINEAR;
+
+ nux::Geometry spin_geo(base.x + ((base.width - spin_->GetWidth()) / 2),
+ base.y + ((base.height - spin_->GetHeight()) / 2),
+ spin_->GetWidth(),
+ spin_->GetHeight());
+ // Geometry (== Rect) uses integers which were rounded above,
+ // hence an extra 0.5 offset for odd sizes is needed
+ // because pure floating point is not being used.
+ int spin_offset_w = !(base.width % 2) ? 0 : 1;
+ int spin_offset_h = !(base.height % 2) ? 0 : 1;
+
+ gfx_engine.PushModelViewMatrix(nux::Matrix4::TRANSLATE(-spin_geo.x - (spin_geo.width + spin_offset_w) / 2.0f,
+ -spin_geo.y - (spin_geo.height + spin_offset_h) / 2.0f, 0));
+ gfx_engine.PushModelViewMatrix(rotate_matrix_);
+ gfx_engine.PushModelViewMatrix(nux::Matrix4::TRANSLATE(spin_geo.x + (spin_geo.width + spin_offset_w) / 2.0f,
+ spin_geo.y + (spin_geo.height + spin_offset_h) / 2.0f, 0));
+
+ gfx_engine.QRP_1Tex(spin_geo.x,
+ spin_geo.y,
+ spin_geo.width,
+ spin_geo.height,
+ spin_->GetDeviceTexture(),
+ texxform,
+ nux::color::White);
+
+ gfx_engine.PopModelViewMatrix();
+ gfx_engine.PopModelViewMatrix();
+ gfx_engine.PopModelViewMatrix();
+
+ gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
+
+ if (!frame_timeout_)
+ {
+ frame_timeout_.reset(new glib::Timeout(22, sigc::mem_fun(this, &PreviewContent::OnFrameTimeout)));
+ }
+ }
+
_queued_draw = false;
}
@@ -189,8 +287,10 @@ public:
sigc::signal<void> continue_navigation;
sigc::signal<void> end_navigation;
-protected:
private:
+ PreviewContainer*const parent_;
+
+ // Swipe animation
struct PreviewSwipe
{
Navigation direction;
@@ -198,14 +298,22 @@ private:
void reset() { preview.Release(); }
};
- std::queue<PreviewSwipe> push_preview_;
-
previews::Preview::Ptr current_preview_;
+ std::queue<PreviewSwipe> push_preview_;
PreviewSwipe swipe_;
float progress_;
bool animating_;
- const PreviewContainer*const parent_;
+
+ // wait animation
+ glib::Source::UniquePtr preview_wait_timer_;
+ glib::Source::UniquePtr _frame_timeout;
+ bool waiting_preview_;
+ nux::ObjectPtr<nux::BaseTexture> spin_;
+
+ glib::Source::UniquePtr frame_timeout_;
+ nux::Matrix4 rotate_matrix_;
+ float rotation_;
};
NUX_IMPLEMENT_OBJECT_TYPE(PreviewContainer);
@@ -301,6 +409,9 @@ void PreviewContainer::SetupViews()
navigation_count_ = 0;
navigation_progress_speed_ = 0;
});
+
+ navigate_right.connect( [&]() { content_layout_->StartPreviewWait(); } );
+ navigate_left.connect( [&]() { content_layout_->StartPreviewWait(); } );
}
void PreviewContainer::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
@@ -361,18 +472,6 @@ static float easeInOutQuart(float t)
}
}
-// static float easeInOutCubic(float t)
-// {
-// t = CLAMP(t, 0.0, 1.0);
-// t*=2.0f;
-// if(t < 1.0f) {
-// return 0.5f*pow(t, 3);
-// } else {
-// t -= 2.0f;
-// return 0.5f*(pow(t, 3) + 2);
-// }
-// }
-
float PreviewContainer::GetSwipeAnimationProgress(struct timespec const& current) const
{
int time_delta = TimeUtil::TimeDelta(&current, &last_progress_time_);
diff --git a/dash/previews/StandaloneApplicationPreview.cpp b/dash/previews/StandaloneApplicationPreview.cpp
index bae07ecb3..f9873f0fa 100644
--- a/dash/previews/StandaloneApplicationPreview.cpp
+++ b/dash/previews/StandaloneApplicationPreview.cpp
@@ -127,6 +127,7 @@ public:
previews::PreviewContainer::Ptr container_;
nux::Layout *layout_;
int nav_iter;
+ glib::Source::UniquePtr preview_wait_timer_;
};
TestRunner::TestRunner ()
@@ -235,43 +236,49 @@ The service allows users to communicate with peers by voice, video, and instant
void TestRunner::NavLeft()
{
- std::stringstream app_name;
- app_name << "Title " << --nav_iter;
+ preview_wait_timer_.reset(new glib::Timeout(2000, [&] () {
- const char* subtitle = "Version 3.2, Size 32 MB";
- const char* description = "Skype is a proprietary voice-over-Internet Protocol service and software application originally created by Niklas Zennström and Janus Friis in 2003, and owned by Microsoft since 2011. \
-The service allows users to communicate with peers by voice, video, and instant messaging over the Internet. Phone calls may be placed to recipients on the traditional telephone networks. Calls to other users within the Skype service are free of charge, while calls to landline telephones and mobile phones are charged via a debit-based user account system.";
- // creates a generic preview object
- glib::Object<GIcon> iconHint1(g_icon_new_for_string("/usr/share/unity/5/lens-nav-music.svg", NULL));
- glib::Object<GIcon> iconHint2(g_icon_new_for_string("/usr/share/unity/5/lens-nav-home.svg", NULL));
- glib::Object<GIcon> iconHint3(g_icon_new_for_string("/usr/share/unity/5/lens-nav-people.svg", NULL));
+ std::stringstream app_name;
+ app_name << "Title " << --nav_iter;
- glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_application_preview_new()));
+ const char* subtitle = "Version 3.2, Size 32 MB";
+ const char* description = "Skype is a proprietary voice-over-Internet Protocol service and software application originally created by Niklas Zennström and Janus Friis in 2003, and owned by Microsoft since 2011. \
+ The service allows users to communicate with peers by voice, video, and instant messaging over the Internet. Phone calls may be placed to recipients on the traditional telephone networks. Calls to other users within the Skype service are free of charge, while calls to landline telephones and mobile phones are charged via a debit-based user account system.";
+ // creates a generic preview object
+ glib::Object<GIcon> iconHint1(g_icon_new_for_string("/usr/share/unity/5/lens-nav-music.svg", NULL));
+ glib::Object<GIcon> iconHint2(g_icon_new_for_string("/usr/share/unity/5/lens-nav-home.svg", NULL));
+ glib::Object<GIcon> iconHint3(g_icon_new_for_string("/usr/share/unity/5/lens-nav-people.svg", NULL));
- unity_protocol_application_preview_set_app_icon(UNITY_PROTOCOL_APPLICATION_PREVIEW(proto_obj.RawPtr()), g_icon_new_for_string("/home/nick/SkypeIcon.png", NULL));
- unity_protocol_application_preview_set_license(UNITY_PROTOCOL_APPLICATION_PREVIEW(proto_obj.RawPtr()), "Proprietary");
- unity_protocol_application_preview_set_copyright(UNITY_PROTOCOL_APPLICATION_PREVIEW(proto_obj.RawPtr()), "(c) Skype 2012");
- unity_protocol_application_preview_set_last_update(UNITY_PROTOCOL_APPLICATION_PREVIEW(proto_obj.RawPtr()), "11th Apr 2012");
- unity_protocol_application_preview_set_rating(UNITY_PROTOCOL_APPLICATION_PREVIEW(proto_obj.RawPtr()), 0.8);
- unity_protocol_application_preview_set_num_ratings(UNITY_PROTOCOL_APPLICATION_PREVIEW(proto_obj.RawPtr()), 1223);
+ glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_application_preview_new()));
- unity_protocol_preview_set_image_source_uri(proto_obj, "file:///home/nick/Skype.png");
- unity_protocol_preview_set_title(proto_obj, app_name.str().c_str());
- unity_protocol_preview_set_subtitle(proto_obj, subtitle);
- unity_protocol_preview_set_description(proto_obj, description);
- unity_protocol_preview_add_action(proto_obj, "uninstall", "Uninstall", iconHint1, 0);
- unity_protocol_preview_add_action(proto_obj, "launch", "Launch", iconHint2, 0);
- unity_protocol_preview_add_info_hint(proto_obj, "time", "Total time", iconHint1, g_variant_new("s", "16 h 34miin 45sec"));
- unity_protocol_preview_add_info_hint(proto_obj, "energy", "Energy", iconHint2, g_variant_new("s", "58.07 mWh"));
- unity_protocol_preview_add_info_hint(proto_obj, "load", "CPU Load", iconHint3, g_variant_new("i", 22));
- glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())),
- glib::StealRef());
+ unity_protocol_application_preview_set_app_icon(UNITY_PROTOCOL_APPLICATION_PREVIEW(proto_obj.RawPtr()), g_icon_new_for_string("/home/nick/SkypeIcon.png", NULL));
+ unity_protocol_application_preview_set_license(UNITY_PROTOCOL_APPLICATION_PREVIEW(proto_obj.RawPtr()), "Proprietary");
+ unity_protocol_application_preview_set_copyright(UNITY_PROTOCOL_APPLICATION_PREVIEW(proto_obj.RawPtr()), "(c) Skype 2012");
+ unity_protocol_application_preview_set_last_update(UNITY_PROTOCOL_APPLICATION_PREVIEW(proto_obj.RawPtr()), "11th Apr 2012");
+ unity_protocol_application_preview_set_rating(UNITY_PROTOCOL_APPLICATION_PREVIEW(proto_obj.RawPtr()), 0.8);
+ unity_protocol_application_preview_set_num_ratings(UNITY_PROTOCOL_APPLICATION_PREVIEW(proto_obj.RawPtr()), 1223);
- dash::Preview::Ptr preview_model(dash::Preview::PreviewForVariant(v));
- container_->Preview(preview_model, previews::Navigation::LEFT);
+ unity_protocol_preview_set_image_source_uri(proto_obj, "file:///home/nick/Skype.png");
+ unity_protocol_preview_set_title(proto_obj, app_name.str().c_str());
+ unity_protocol_preview_set_subtitle(proto_obj, subtitle);
+ unity_protocol_preview_set_description(proto_obj, description);
+ unity_protocol_preview_add_action(proto_obj, "uninstall", "Uninstall", iconHint1, 0);
+ unity_protocol_preview_add_action(proto_obj, "launch", "Launch", iconHint2, 0);
+ unity_protocol_preview_add_info_hint(proto_obj, "time", "Total time", iconHint1, g_variant_new("s", "16 h 34miin 45sec"));
+ unity_protocol_preview_add_info_hint(proto_obj, "energy", "Energy", iconHint2, g_variant_new("s", "58.07 mWh"));
+ unity_protocol_preview_add_info_hint(proto_obj, "load", "CPU Load", iconHint3, g_variant_new("i", 22));
+
+ glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())),
+ glib::StealRef());
+
+ dash::Preview::Ptr preview_model(dash::Preview::PreviewForVariant(v));
+ container_->Preview(preview_model, previews::Navigation::LEFT);
+
+ return false;
+ }));
}
void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData)
diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp
index 8dd27c8df..41cbbbd10 100644
--- a/unity-shared/PreviewStyle.cpp
+++ b/unity-shared/PreviewStyle.cpp
@@ -41,17 +41,45 @@ nux::logging::Logger logger("unity.dash.previews.style");
typedef nux::ObjectPtr<nux::BaseTexture> BaseTexturePtr;
+template <int default_size = 1>
class LazyLoadTexture
{
public:
- LazyLoadTexture(std::string const& filename, int size = -1);
- nux::BaseTexture* texture();
+ LazyLoadTexture(std::string const& filename)
+ : filename_(filename) {}
+
+ nux::BaseTexture* texture(int size = default_size)
+ {
+ auto tex_iter = textures_.find(size);
+ if (tex_iter != textures_.end())
+ return tex_iter->second.GetPointer();
+
+ return LoadTexture(size).GetPointer();
+ }
+
private:
- void LoadTexture();
+ BaseTexturePtr LoadTexture(int size)
+ {
+ BaseTexturePtr texture;
+ std::string full_path = PKGDATADIR + filename_;
+ glib::Object<GdkPixbuf> pixbuf;
+ glib::Error error;
+
+ pixbuf = ::gdk_pixbuf_new_from_file_at_size(full_path.c_str(), size, size, &error);
+ if (error)
+ {
+ LOG_WARN(logger) << "Unable to texture " << full_path << " at size '" << size << "' : " << error;
+ }
+ else
+ {
+ texture.Adopt(nux::CreateTexture2DFromPixbuf(pixbuf, true));
+ }
+ textures_[size] = texture;
+ return texture;
+ }
private:
std::string filename_;
- int size_;
- BaseTexturePtr texture_;
+ std::map<int, BaseTexturePtr> textures_;
};
} // namespace
@@ -62,20 +90,22 @@ class Style::Impl
public:
Impl(Style* owner)
: owner_(owner)
- , preview_nav_left_texture_("/preview_previous.svg", 32)
- , preview_nav_right_texture_("/preview_next.svg", 32)
- , preview_play_texture_("/preview_play.svg", 32)
- , preview_pause_texture_("/preview_pause.svg", 32)
+ , preview_nav_left_texture_("/preview_previous.svg")
+ , preview_nav_right_texture_("/preview_next.svg")
+ , preview_play_texture_("/preview_play.svg")
+ , preview_pause_texture_("/preview_pause.svg")
+ , preview_spin_texture_("/search_spin.svg")
{
}
~Impl() {}
Style* owner_;
- LazyLoadTexture preview_nav_left_texture_;
- LazyLoadTexture preview_nav_right_texture_;
- LazyLoadTexture preview_play_texture_;
- LazyLoadTexture preview_pause_texture_;
+ LazyLoadTexture<32> preview_nav_left_texture_;
+ LazyLoadTexture<32> preview_nav_right_texture_;
+ LazyLoadTexture<32> preview_play_texture_;
+ LazyLoadTexture<32> preview_pause_texture_;
+ LazyLoadTexture<32> preview_spin_texture_;
};
@@ -320,41 +350,11 @@ nux::BaseTexture* Style::GetPauseIcon()
return pimpl->preview_pause_texture_.texture();
}
-
-
-namespace
-{
-LazyLoadTexture::LazyLoadTexture(std::string const& filename, int size)
- : filename_(filename)
- , size_(size)
+nux::BaseTexture* Style::GetSearchSpinIcon(int size)
{
+ return pimpl->preview_spin_texture_.texture(size);
}
-nux::BaseTexture* LazyLoadTexture::texture()
-{
- if (!texture_)
- LoadTexture();
- return texture_.GetPointer();
-}
-
-void LazyLoadTexture::LoadTexture()
-{
- std::string full_path = PKGDATADIR + filename_;
- glib::Object<GdkPixbuf> pixbuf;
- glib::Error error;
-
- pixbuf = ::gdk_pixbuf_new_from_file_at_size(full_path.c_str(), size_, size_, &error);
- if (error)
- {
- LOG_WARN(logger) << "Unable to texture " << full_path << ": " << error;
- }
- else
- {
- texture_.Adopt(nux::CreateTexture2DFromPixbuf(pixbuf, true));
- }
-}
-
-} // namesspace
} // namespace previews
} // namespace dash
diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h
index a63a5b3de..44c5f1832 100644
--- a/unity-shared/PreviewStyle.h
+++ b/unity-shared/PreviewStyle.h
@@ -124,6 +124,7 @@ public:
nux::BaseTexture* GetNavRightIcon();
nux::BaseTexture* GetPlayIcon();
nux::BaseTexture* GetPauseIcon();
+ nux::BaseTexture* GetSearchSpinIcon(int size = -1);
protected:
class Impl;