summaryrefslogtreecommitdiff
diff options
authorGord Allott <gord.allott@canonical.com>2012-08-10 16:13:35 +0100
committerGord Allott <gord.allott@canonical.com>2012-08-10 16:13:35 +0100
commit19a9ad3b86b55fbe09dd8003a21ee61c260c5c20 (patch)
treee73bebe4dba1cbae73eddc9a153040365e296678
parentc3f1515c91ccbd3b1d6e6ea8cc9f695e8320beac (diff)
parent4af96d27e4489a8c61dbf26db116cca66b3a8f0d (diff)
latest preview ui code
(bzr r2419.6.21)
-rw-r--r--dash/previews/ActionButton.cpp5
-rw-r--r--dash/previews/ActionButton.h2
-rw-r--r--dash/previews/MoviePreview.cpp2
-rw-r--r--dash/previews/PreviewContainer.cpp171
-rw-r--r--dash/previews/PreviewContainer.h2
-rw-r--r--dash/previews/PreviewInfoHintWidget.cpp79
-rw-r--r--dash/previews/PreviewInfoHintWidget.h7
-rw-r--r--dash/previews/StandaloneApplicationPreview.cpp65
-rw-r--r--unity-shared/CoverArt.cpp86
-rw-r--r--unity-shared/CoverArt.h1
-rw-r--r--unity-shared/IconLoader.cpp21
-rw-r--r--unity-shared/PreviewStyle.cpp106
-rw-r--r--unity-shared/PreviewStyle.h7
-rw-r--r--unity-shared/ThumbnailGenerator.cpp21
14 files changed, 345 insertions, 230 deletions
diff --git a/dash/previews/ActionButton.cpp b/dash/previews/ActionButton.cpp
index b65e4f438..9f49b3a6c 100644
--- a/dash/previews/ActionButton.cpp
+++ b/dash/previews/ActionButton.cpp
@@ -94,14 +94,13 @@ void ActionButton::BuildLayout(std::string const& label, std::string const& icon
icon_hint_ = icon_hint;
if (image_)
{
- image_->UnReference();
+ image_.Release();
image_ = NULL;
}
if (!icon_hint_.empty())
{
image_ = new IconTexture(icon_hint, icon_size);
- image_->Reference();
image_->texture_updated.connect([&](nux::BaseTexture*)
{
BuildLayout(label_, icon_hint_);
@@ -137,7 +136,7 @@ void ActionButton::BuildLayout(std::string const& label, std::string const& icon
layout->SetPadding(2, 11, 2, 11);
layout->AddSpace(0,1);
if (image_)
- layout->AddView(image_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
+ layout->AddView(image_.GetPointer(), 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
if (static_text_)
layout->AddView(static_text_.GetPointer(), 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
layout->AddSpace(0,1);
diff --git a/dash/previews/ActionButton.h b/dash/previews/ActionButton.h
index 7c3e3cb32..d2bb11ef5 100644
--- a/dash/previews/ActionButton.h
+++ b/dash/previews/ActionButton.h
@@ -79,7 +79,7 @@ private:
std::string icon_hint_;
std::string font_hint_;
- IconTexture* image_;
+ nux::ObjectPtr<IconTexture> image_;
nux::ObjectPtr<nux::StaticCairoText> static_text_;
};
diff --git a/dash/previews/MoviePreview.cpp b/dash/previews/MoviePreview.cpp
index 7154284d0..290d90d88 100644
--- a/dash/previews/MoviePreview.cpp
+++ b/dash/previews/MoviePreview.cpp
@@ -218,7 +218,7 @@ void MoviePreview::SetupView()
if (!preview_model_->GetInfoHints().empty())
{
- PreviewInfoHintWidget* preview_info_hints = new PreviewInfoHintWidget(preview_model_, style.GetInfoHintIconSizeWidth(), false, true);
+ PreviewInfoHintWidget* preview_info_hints = new PreviewInfoHintWidget(preview_model_, style.GetInfoHintIconSizeWidth());
preview_info_layout->AddView(preview_info_hints, 0);
}
diff --git a/dash/previews/PreviewContainer.cpp b/dash/previews/PreviewContainer.cpp
index c37b1ee42..a2bcdd29d 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);
@@ -214,6 +322,7 @@ PreviewContainer::PreviewContainer(NUX_FILE_LINE_DECL)
: View(NUX_FILE_LINE_PARAM)
, content_layout_(nullptr)
, nav_disabled_(Navigation::NONE)
+ , last_calc_height_(0)
, navigation_progress_speed_(0.0)
, navigation_count_(0)
{
@@ -262,12 +371,13 @@ void PreviewContainer::SetupViews()
layout_ = new nux::HLayout();
SetLayout(layout_);
+ layout_->AddSpace(0, 0);
nav_left_ = new PreviewNavigator(Orientation::LEFT, NUX_TRACKER_LOCATION);
nav_left_->SetMinimumWidth(style.GetNavigatorWidth());
nav_left_->SetMaximumWidth(style.GetNavigatorWidth());
nav_left_->activated.connect([&]() { navigate_left.emit(); });
- layout_->AddView(nav_left_, 0);
+ layout_->AddView(nav_left_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
content_layout_ = new PreviewContent(this);
layout_->AddLayout(content_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
@@ -276,7 +386,9 @@ void PreviewContainer::SetupViews()
nav_right_->SetMinimumWidth(style.GetNavigatorWidth());
nav_right_->SetMaximumWidth(style.GetNavigatorWidth());
nav_right_->activated.connect([&]() { navigate_right.emit(); });
- layout_->AddView(nav_right_, 0);
+ layout_->AddView(nav_right_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
+
+ layout_->AddSpace(0, 0);
content_layout_->start_navigation.connect([&]()
{
@@ -301,6 +413,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)
@@ -334,6 +449,32 @@ void PreviewContainer::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_d
gfx_engine.PopClippingRectangle();
}
+void PreviewContainer::PreLayoutManagement()
+{
+ previews::Style& style = previews::Style::Instance();
+ nux::Geometry const& geo = GetGeometry();
+
+ int available_preview_width = MAX(1, geo.width - nav_left_->GetGeometry().width - nav_right_->GetGeometry().width);
+ int aspect_altered_height = available_preview_width / style.GetPreviewAspectRatio();
+
+ aspect_altered_height = CLAMP(aspect_altered_height, 1, geo.height);
+ if (last_calc_height_ != aspect_altered_height)
+ {
+ last_calc_height_ = aspect_altered_height;
+
+ content_layout_->SetMinimumHeight(aspect_altered_height);
+ content_layout_->SetMaximumHeight(aspect_altered_height);
+
+ nav_left_->SetMinimumHeight(aspect_altered_height);
+ nav_left_->SetMaximumHeight(aspect_altered_height);
+
+ nav_right_->SetMinimumHeight(aspect_altered_height);
+ nav_right_->SetMaximumHeight(aspect_altered_height);
+ }
+
+ View::PreLayoutManagement();
+}
+
bool PreviewContainer::AnimationInProgress()
{
// short circuit to avoid unneeded calculations
@@ -361,18 +502,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/PreviewContainer.h b/dash/previews/PreviewContainer.h
index 13a93b4d0..4a975d158 100644
--- a/dash/previews/PreviewContainer.h
+++ b/dash/previews/PreviewContainer.h
@@ -79,6 +79,7 @@ public:
protected:
void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw);
void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw);
+ void PreLayoutManagement();
nux::Area* KeyNavIteration(nux::KeyNavDirection direction);
@@ -100,6 +101,7 @@ private:
PreviewNavigator* nav_right_;
PreviewContent* content_layout_;
Navigation nav_disabled_;
+ int last_calc_height_;
// Animation
struct timespec last_progress_time_;
diff --git a/dash/previews/PreviewInfoHintWidget.cpp b/dash/previews/PreviewInfoHintWidget.cpp
index 447bc3f55..9e0e4336d 100644
--- a/dash/previews/PreviewInfoHintWidget.cpp
+++ b/dash/previews/PreviewInfoHintWidget.cpp
@@ -44,11 +44,9 @@ const int layout_spacing = 12;
NUX_IMPLEMENT_OBJECT_TYPE(PreviewInfoHintWidget);
-PreviewInfoHintWidget::PreviewInfoHintWidget(dash::Preview::Ptr preview_model, int icon_size, bool visible_icons, bool condensed_format)
+PreviewInfoHintWidget::PreviewInfoHintWidget(dash::Preview::Ptr preview_model, int icon_size)
: View(NUX_TRACKER_LOCATION)
, icon_size_(icon_size)
-, condensed_format_(condensed_format)
-, visible_icons_(visible_icons)
, preview_model_(preview_model)
{
SetupViews();
@@ -58,20 +56,6 @@ PreviewInfoHintWidget::~PreviewInfoHintWidget()
{
}
-void PreviewInfoHintWidget::SetVisibleIcons(bool visible)
-{
- visible_icons_ = visible;
- SetupViews();
- QueueDraw();
-}
-
-void PreviewInfoHintWidget::SetCondensedFormat(bool condensed)
-{
- condensed_format_ = condensed;
- SetupViews();
- QueueDraw();
-}
-
void PreviewInfoHintWidget::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
{
}
@@ -168,28 +152,16 @@ void PreviewInfoHintWidget::SetupViews()
nux::HLayout* hint_layout = new nux::HLayout();
hint_layout->SetSpaceBetweenChildren(layout_spacing);
- if (visible_icons_)
- {
- IconTexture* info_icon = new IconTexture(info_hint->icon_hint, icon_size_);
- info_icon->SetMinimumSize(icon_size_, icon_size_);
- info_icon->SetVisible(true);
- hint_layout->AddView(info_icon, 0);
- }
-
StaticCairoTextPtr info_name;
if (!info_hint->display_name.empty())
{
std::string tmp_display_name = info_hint->display_name;
- if (condensed_format_) { tmp_display_name += ":"; }
+ tmp_display_name += ":";
info_name = new nux::StaticCairoText(tmp_display_name, NUX_TRACKER_LOCATION);
- info_name->SetFont(condensed_format_ ? style.info_hint_bold_font() : style.info_hint_font());
+ info_name->SetFont(style.info_hint_bold_font());
info_name->SetLines(-1);
- if (!condensed_format_)
- {
- info_name->SetMinimumWidth(style.GetInfoHintNameWidth());
- info_name->SetMaximumWidth(style.GetInfoHintNameWidth());
- }
+ info_name->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_RIGHT);
hint_layout->AddView(info_name.GetPointer(), 0, nux::MINOR_POSITION_CENTER);
}
@@ -213,29 +185,42 @@ void PreviewInfoHintWidget::PreLayoutManagement()
previews::Style& style = previews::Style::Instance();
nux::Geometry const& geo = GetGeometry();
+ int info_hint_width = 0;
for (InfoHint const& info_hint : info_hints_)
{
- int max_info_value_width = geo.width;
- if (visible_icons_)
+ int width = style.GetInfoHintNameMinimumWidth();
+ if (info_hint.first)
{
- max_info_value_width -= icon_size_;
- max_info_value_width -= layout_spacing;
+ width = info_hint.first->GetTextExtents().width;
+
+ if (width < style.GetInfoHintNameMinimumWidth())
+ width = style.GetInfoHintNameMinimumWidth();
+ else if (width > style.GetInfoHintNameMaximumWidth())
+ width = style.GetInfoHintNameMaximumWidth();
}
- if (info_hint.first)
+
+ if (info_hint_width < width)
{
- if (condensed_format_)
- {
- max_info_value_width -= info_hint.first->GetTextExtents().width;
- }
- else
- {
- max_info_value_width -= style.GetInfoHintNameWidth();
- }
- max_info_value_width -= layout_spacing;
+ info_hint_width = width;
}
+ }
+
+ int info_value_width = geo.width;
+ info_value_width -= layout_spacing;
+ info_value_width -= info_hint_width;
+ for (InfoHint const& info_hint : info_hints_)
+ {
+ if (info_hint.first)
+ {
+ info_hint.first->SetMinimumWidth(info_hint_width);
+ info_hint.first->SetMaximumWidth(info_hint_width);
+ }
if (info_hint.second)
- info_hint.second->SetMaximumWidth(max_info_value_width);
+ {
+ info_hint.second->SetMinimumWidth(info_value_width);
+ info_hint.second->SetMaximumWidth(info_value_width);
+ }
}
View::PreLayoutManagement();
diff --git a/dash/previews/PreviewInfoHintWidget.h b/dash/previews/PreviewInfoHintWidget.h
index ad7b3eadf..72591c22f 100644
--- a/dash/previews/PreviewInfoHintWidget.h
+++ b/dash/previews/PreviewInfoHintWidget.h
@@ -46,12 +46,9 @@ public:
typedef nux::ObjectPtr<PreviewInfoHintWidget> Ptr;
NUX_DECLARE_OBJECT_TYPE(PreviewInfoHintWidget, nux::View);
- PreviewInfoHintWidget(dash::Preview::Ptr preview_model, int icon_size, bool visible_icons = true, bool condensed_format = false);
+ PreviewInfoHintWidget(dash::Preview::Ptr preview_model, int icon_size);
virtual ~PreviewInfoHintWidget();
- void SetVisibleIcons(bool visible);
- void SetCondensedFormat(bool condensed);
-
// From debug::Introspectable
std::string GetName() const;
void AddProperties(GVariantBuilder* builder);
@@ -72,8 +69,6 @@ protected:
protected:
int icon_size_;
- bool condensed_format_;
- bool visible_icons_;
typedef nux::ObjectPtr<nux::StaticCairoText> StaticCairoTextPtr;
typedef std::pair<StaticCairoTextPtr, StaticCairoTextPtr> InfoHint;
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/CoverArt.cpp b/unity-shared/CoverArt.cpp
index 5854fdbfe..c6949d499 100644
--- a/unity-shared/CoverArt.cpp
+++ b/unity-shared/CoverArt.cpp
@@ -86,49 +86,20 @@ void CoverArt::SetImage(std::string const& image_hint)
GIcon* icon = g_icon_new_for_string(image_hint.c_str(), NULL);
- glib::Object<GFile> image_file;
- if (g_strrstr(image_hint.c_str(), "://"))
+ bool bLoadTexture = false;
+ bLoadTexture |= g_strrstr(image_hint.c_str(), "://") != NULL;
+ if (!bLoadTexture && !image_hint.empty())
{
- /* try to open the source file for reading */
- image_file = g_file_new_for_uri (image_hint.c_str());
+ bLoadTexture |= image_hint[0] == '/' && image_hint.size() > 1;
}
- else
- {
- image_file = g_file_new_for_path (image_hint.c_str());
- }
-
- if (g_file_query_exists(image_file, NULL))
- {
- // for files on disk, we stretch to maximum aspect ratio.
- stretch_image_ = true;
- GFileInputStream *stream;
- GError *error = NULL;
-
- stream = g_file_read (image_file, NULL, &error);
-
- if (error != NULL)
- {
- g_error_free (error);
-
- if (icon != NULL)
- g_object_unref(icon);
- return;
- }
-
- /* stream image into pixel-buffer. */
- glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_stream (G_INPUT_STREAM (stream), NULL, &error));
- g_object_unref (stream);
-
- texture_screenshot_.Adopt(nux::CreateTexture2DFromPixbuf(pixbuf, true));
-
- if (!texture_screenshot_)
- {
- SetNoImageAvailable();
- }
- QueueDraw();
+ // texture from file.
+ if (bLoadTexture)
+ {
+ StartWaiting();
+ slot_handle_ = IconLoader::GetDefault().LoadFromGIconString(image_hint, ~0, sigc::mem_fun(this, &CoverArt::TextureLoaded));
}
- else
+ else if (!image_hint.empty())
{
if (GetLayout())
GetLayout()->RemoveChildObject(overlay_text_);
@@ -144,6 +115,10 @@ void CoverArt::SetImage(std::string const& image_hint)
slot_handle_ = IconLoader::GetDefault().LoadFromIconName(image_hint, icon_width, sigc::mem_fun(this, &CoverArt::IconLoaded));
}
}
+ else
+ {
+ SetNoImageAvailable();
+ }
if (icon != NULL)
g_object_unref(icon);
@@ -262,11 +237,6 @@ void CoverArt::IconLoaded(std::string const& texid, unsigned size, glib::Object<
cairo_paint(cr);
float scale = float(pixbuf_height) / gdk_pixbuf_get_height(pixbuf);
-
- //cairo_translate(cr,
- // static_cast<int>((width - (pixbuf_width * scale)) * 0.5),
- // static_cast<int>((height - (pixbuf_height * scale)) * 0.5));
-
cairo_scale(cr, scale, scale);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
@@ -278,6 +248,22 @@ void CoverArt::IconLoaded(std::string const& texid, unsigned size, glib::Object<
}
}
+void CoverArt::TextureLoaded(std::string const& texid, unsigned size, glib::Object<GdkPixbuf> const& pixbuf)
+{
+ // Finished waiting
+ spinner_timeout_.reset();
+ frame_timeout_.reset();
+ waiting_ = false;
+ stretch_image_ = true;
+
+ if (!pixbuf)
+ {
+ SetNoImageAvailable();
+ return;
+ }
+ texture_screenshot_.Adopt(nux::CreateTexture2DFromPixbuf(pixbuf, true));
+}
+
void CoverArt::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
{
nux::Geometry const& base = GetGeometry();
@@ -287,13 +273,13 @@ void CoverArt::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
unsigned int alpha, src, dest = 0;
gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
- gfx_engine.GetRenderStates().SetBlend(true);
+ gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- gfx_engine.QRP_Color(base.x,
- base.y,
- base.GetWidth(),
- base.GetHeight(),
- nux::Color(0.03f, 0.03f, 0.03f, 0.0f));
+ gfx_engine.QRP_Color(base.x,
+ base.y,
+ base.GetWidth(),
+ base.GetHeight(),
+ nux::Color(0.03f, 0.03f, 0.03f, 0.0f));
if (texture_screenshot_)
{
diff --git a/unity-shared/CoverArt.h b/unity-shared/CoverArt.h
index 13b33cb25..dd5a666fe 100644
--- a/unity-shared/CoverArt.h
+++ b/unity-shared/CoverArt.h
@@ -69,6 +69,7 @@ protected:
bool OnFrameTimeout();
void IconLoaded(std::string const& texid, unsigned size, glib::Object<GdkPixbuf> const& pixbuf);
+ void TextureLoaded(std::string const& texid, unsigned size, glib::Object<GdkPixbuf> const& pixbuf);
void StartWaiting();
void SetNoImageAvailable();
diff --git a/unity-shared/IconLoader.cpp b/unity-shared/IconLoader.cpp
index 2627d914c..78c9e9ea9 100644
--- a/unity-shared/IconLoader.cpp
+++ b/unity-shared/IconLoader.cpp
@@ -268,12 +268,21 @@ private:
glib::Object<GInputStream> stream(
::g_memory_input_stream_new_from_data(contents.Value(), length, nullptr));
- task->result = ::gdk_pixbuf_new_from_stream_at_scale(stream,
- -1,
- task->size,
- TRUE,
- canc,
- &task->error);
+ if (task->size != static_cast<unsigned int>(~0))
+ {
+ task->result = ::gdk_pixbuf_new_from_stream_at_scale(stream,
+ -1,
+ task->size,
+ TRUE,
+ canc,
+ &task->error);
+ }
+ else
+ {
+ task->result = ::gdk_pixbuf_new_from_stream(stream,
+ canc,
+ &task->error);
+ }
::g_input_stream_close(stream, canc, nullptr);
}
}
diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp
index 8dd27c8df..56e55bb4a 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_;
};
@@ -118,14 +148,9 @@ int Style::GetNavigatorIconSize() const
return 24;
}
-int Style::GetPreviewPreferredHeight() const
+float Style::GetPreviewAspectRatio() const
{
- return 390;
-}
-
-int Style::GetPreviewPreferredWidth() const
-{
- return 796;
+ return static_cast<float>(796)/390;
}
int Style::GetDetailsTopMargin() const
@@ -213,11 +238,16 @@ int Style::GetInfoHintIconSizeWidth() const
return 24;
}
-int Style::GetInfoHintNameWidth() const
+int Style::GetInfoHintNameMinimumWidth() const
{
return 100;
}
+int Style::GetInfoHintNameMaximumWidth() const
+{
+ return 160;
+}
+
float Style::GetDescriptionLineSpacing() const
{
return 2.0;
@@ -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* LazyLoadTexture::texture()
-{
- if (!texture_)
- LoadTexture();
- return texture_.GetPointer();
-}
-
-void LazyLoadTexture::LoadTexture()
+nux::BaseTexture* Style::GetSearchSpinIcon(int size)
{
- 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));
- }
+ return pimpl->preview_spin_texture_.texture(size);
}
-} // namesspace
} // namespace previews
} // namespace dash
diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h
index a63a5b3de..23c9ba2f8 100644
--- a/unity-shared/PreviewStyle.h
+++ b/unity-shared/PreviewStyle.h
@@ -59,8 +59,7 @@ public:
int GetNavigatorWidth() const;
int GetNavigatorIconSize() const;
- int GetPreviewPreferredHeight() const;
- int GetPreviewPreferredWidth() const;
+ float GetPreviewAspectRatio() const;
int GetDetailsTopMargin() const;
int GetDetailsBottomMargin() const;
@@ -77,7 +76,8 @@ public:
int GetDetailsPanelMinimumWidth() const;
int GetInfoHintIconSizeWidth() const;
- int GetInfoHintNameWidth() const;
+ int GetInfoHintNameMinimumWidth() const;
+ int GetInfoHintNameMaximumWidth() const;
float GetDescriptionLineSpacing() const;
int GetDescriptionLineCount() const;
@@ -124,6 +124,7 @@ public:
nux::BaseTexture* GetNavRightIcon();
nux::BaseTexture* GetPlayIcon();
nux::BaseTexture* GetPauseIcon();
+ nux::BaseTexture* GetSearchSpinIcon(int size = -1);
protected:
class Impl;
diff --git a/unity-shared/ThumbnailGenerator.cpp b/unity-shared/ThumbnailGenerator.cpp
index e94d0d5af..0245f5f03 100644
--- a/unity-shared/ThumbnailGenerator.cpp
+++ b/unity-shared/ThumbnailGenerator.cpp
@@ -119,8 +119,8 @@ private:
private:
ThumbnailGenerator* parent_;
- glib::Source::UniquePtr idle_;
- glib::Source::UniquePtr idle_return_;
+ glib::Source::UniquePtr thread_create_timer_;
+ glib::Source::UniquePtr thread_return_timer_;
/* Our mutex used when accessing data shared between the main thread and the
thumbnail thread, i.e. the thumbnail_thread_is_running flag and the
@@ -179,9 +179,9 @@ ThumbnailNotifier::Ptr ThumbnailGeneratorImpl::GetThumbnail(std::string const& u
complete_thumbnails_.push_back(complete_thumb);
// Delay the thumbnail update until after this method has returned with the notifier
- if (!idle_return_)
+ if (!thread_return_timer_)
{
- idle_return_.reset(new glib::Idle(sigc::mem_fun(this, &ThumbnailGeneratorImpl::OnThumbnailComplete), glib::Source::Priority::LOW));
+ thread_return_timer_.reset(new glib::Timeout(0, sigc::mem_fun(this, &ThumbnailGeneratorImpl::OnThumbnailComplete), glib::Source::Priority::LOW));
}
pthread_mutex_unlock (&thumbnails_mutex_);
@@ -196,13 +196,14 @@ ThumbnailNotifier::Ptr ThumbnailGeneratorImpl::GetThumbnail(std::string const& u
* MUTEX LOCKED
*********************************/
- if (!idle_ && thumbnail_thread_is_running_ == false)
+ if (!thread_create_timer_ && thumbnail_thread_is_running_ == false)
{
- idle_.reset(new glib::Idle([&]()
+
+ thread_create_timer_.reset(new glib::Timeout(0, [&]()
{
thumbnail_thread_is_running_ = true;
pthread_create (&thumbnail_thread_, NULL, thumbnail_thread_start, this);
- idle_.reset();
+ thread_create_timer_.reset();
return false;
}, glib::Source::Priority::LOW));
}
@@ -271,9 +272,9 @@ void ThumbnailGeneratorImpl::RunGenerate()
complete_thumbnails_.push_back(complete_thumb);
- if (!idle_return_)
+ if (!thread_return_timer_)
{
- idle_return_.reset(new glib::Idle(sigc::mem_fun(this, &ThumbnailGeneratorImpl::OnThumbnailComplete), glib::Source::Priority::LOW));
+ thread_return_timer_.reset(new glib::Timeout(0, sigc::mem_fun(this, &ThumbnailGeneratorImpl::OnThumbnailComplete), glib::Source::Priority::LOW));
}
pthread_mutex_unlock (&thumbnails_mutex_);
@@ -291,7 +292,7 @@ bool ThumbnailGeneratorImpl::OnThumbnailComplete()
if (complete_thumbnails_.size() == 0)
{
- idle_return_.reset();
+ thread_return_timer_.reset();
pthread_mutex_unlock (&thumbnails_mutex_);
return false;
}