diff options
| author | Nick Dedekind <nicholas.dedekind@gmail.com> | 2012-08-08 10:38:10 +0100 |
|---|---|---|
| committer | Nick Dedekind <nicholas.dedekind@gmail.com> | 2012-08-08 10:38:10 +0100 |
| commit | e5ced20c8b6674892502b8be9f8454ae02e9daed (patch) | |
| tree | 1d997d34ab3b00e6f4858179e03c7410843a5b6b /dash/previews | |
| parent | 8e00d4dc94d87a1b3351e7ef5f62c56c46ac46a6 (diff) | |
Improved movie previews.
(bzr r2419.4.47)
Diffstat (limited to 'dash/previews')
| -rw-r--r-- | dash/previews/CMakeLists.txt | 7 | ||||
| -rw-r--r-- | dash/previews/MoviePreview.cpp | 23 | ||||
| -rw-r--r-- | dash/previews/MoviePreview.h | 2 | ||||
| -rw-r--r-- | dash/previews/PreviewInfoHintWidget.cpp | 106 | ||||
| -rw-r--r-- | dash/previews/PreviewInfoHintWidget.h | 17 | ||||
| -rw-r--r-- | dash/previews/StandaloneMoviePreview.cpp | 250 |
6 files changed, 378 insertions, 27 deletions
diff --git a/dash/previews/CMakeLists.txt b/dash/previews/CMakeLists.txt index 87fbd8c22..c01f6abc9 100644 --- a/dash/previews/CMakeLists.txt +++ b/dash/previews/CMakeLists.txt @@ -61,6 +61,13 @@ add_dependencies (music_previews previews-lib) target_link_libraries (music_previews previews-lib unity-shared) # +# Music Standalone variant +# +add_executable (movie_previews StandaloneMoviePreview.cpp) +add_dependencies (movie_previews previews-lib) +target_link_libraries (movie_previews previews-lib unity-shared) + +# # Thumbnail Standalone # add_executable (thumbnailer StandaloneThumbnailer.cpp) diff --git a/dash/previews/MoviePreview.cpp b/dash/previews/MoviePreview.cpp index 3cc04c541..7eafd2e29 100644 --- a/dash/previews/MoviePreview.cpp +++ b/dash/previews/MoviePreview.cpp @@ -34,6 +34,7 @@ #include "MoviePreview.h" #include "PreviewInfoHintWidget.h" +#include "PreviewRatingsWidget.h" namespace unity { @@ -198,8 +199,13 @@ void MoviePreview::SetupView() subtitle_->SetFont(style.subtitle_size_font().c_str()); app_data_layout->AddView(subtitle_.GetPointer(), 1); } - ///////////////////// + + rating_ = new PreviewRatingsWidget(); + rating_->SetMaximumHeight(style.GetRatingWidgetHeight()); + rating_->SetMinimumHeight(style.GetRatingWidgetHeight()); + rating_->SetRating(movie_preview_model->rating); + rating_->SetReviews(movie_preview_model->num_ratings); ///////////////////// // Description @@ -210,6 +216,12 @@ void MoviePreview::SetupView() preview_info_layout->SetSpaceBetweenChildren(12); preview_info->SetLayout(preview_info_layout); + if (!preview_model_->GetInfoHints().empty()) + { + PreviewInfoHintWidget* preview_info_hints = new PreviewInfoHintWidget(preview_model_, style.GetInfoHintIconSizeWidth(), false, true); + preview_info_layout->AddView(preview_info_hints, 0); + } + if (!preview_model_->description.Get().empty()) { description_ = new nux::StaticCairoText(""); @@ -220,12 +232,6 @@ void MoviePreview::SetupView() description_->SetText(preview_model_->description); preview_info_layout->AddView(description_.GetPointer()); } - - if (!preview_model_->GetInfoHints().empty()) - { - PreviewInfoHintWidget* preview_info_hints = new PreviewInfoHintWidget(preview_model_, style.GetInfoHintIconSizeWidth()); - preview_info_layout->AddView(preview_info_hints); - } ///////////////////// ///////////////////// @@ -236,6 +242,7 @@ void MoviePreview::SetupView() /////////////////// full_data_layout_->AddLayout(app_data_layout, 0); + full_data_layout_->AddView(rating_.GetPointer(), 0); full_data_layout_->AddView(preview_info, 1); full_data_layout_->AddView(actions_layout, 0); ///////////////////// @@ -254,7 +261,7 @@ long MoviePreview::ComputeContentSize() previews::Style& style = dash::previews::Style::Instance(); - nux::Geometry geo_art(geo.x, geo.y, style.GetAppImageAspectRatio() * geo.height, geo.height); + nux::Geometry geo_art(geo.x, geo.y, style.GetVideoImageAspectRatio() * geo.height, geo.height); if (geo.width - geo_art.width - style.GetPanelSplitWidth() - style.GetDetailsLeftMargin() - style.GetDetailsRightMargin() < style.GetDetailsPanelMinimumWidth()) geo_art.width = MAX(0, geo.width - style.GetPanelSplitWidth() - style.GetDetailsLeftMargin() - style.GetDetailsRightMargin() - style.GetDetailsPanelMinimumWidth()); diff --git a/dash/previews/MoviePreview.h b/dash/previews/MoviePreview.h index 82b690f3a..bc4b39872 100644 --- a/dash/previews/MoviePreview.h +++ b/dash/previews/MoviePreview.h @@ -40,6 +40,7 @@ namespace dash namespace previews { class CoverArt; +class PreviewRatingsWidget; class MoviePreview : public Preview { @@ -69,6 +70,7 @@ protected: nux::VLayout* full_data_layout_; nux::ObjectPtr<CoverArt> image_; + nux::ObjectPtr<PreviewRatingsWidget> rating_; nux::ObjectPtr<nux::StaticCairoText> title_; nux::ObjectPtr<nux::StaticCairoText> subtitle_; nux::ObjectPtr<nux::StaticCairoText> description_; diff --git a/dash/previews/PreviewInfoHintWidget.cpp b/dash/previews/PreviewInfoHintWidget.cpp index 6eda4b93e..b93c74e90 100644 --- a/dash/previews/PreviewInfoHintWidget.cpp +++ b/dash/previews/PreviewInfoHintWidget.cpp @@ -35,14 +35,21 @@ namespace dash { namespace previews { +namespace +{ nux::logging::Logger logger("unity.dash.previews.previewinfohintwidget"); +const int layout_spacing = 12; +} + NUX_IMPLEMENT_OBJECT_TYPE(PreviewInfoHintWidget); -PreviewInfoHintWidget::PreviewInfoHintWidget(dash::Preview::Ptr preview_model, int icon_size) - : View(NUX_TRACKER_LOCATION) - , icon_size_(icon_size) - , preview_model_(preview_model) +PreviewInfoHintWidget::PreviewInfoHintWidget(dash::Preview::Ptr preview_model, int icon_size, bool visible_icons, bool condensed_format) +: View(NUX_TRACKER_LOCATION) +, icon_size_(icon_size) +, condensed_format_(condensed_format) +, visible_icons_(visible_icons) +, preview_model_(preview_model) { SetupViews(); } @@ -51,6 +58,20 @@ 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) { } @@ -134,6 +155,9 @@ std::string StringFromVariant(GVariant* variant) void PreviewInfoHintWidget::SetupViews() { + RemoveLayout(); + info_hints_.clear(); + previews::Style& style = previews::Style::Instance(); nux::VLayout* layout = new nux::VLayout(); @@ -142,29 +166,40 @@ void PreviewInfoHintWidget::SetupViews() for (dash::Preview::InfoHintPtr info_hint : preview_model_->GetInfoHints()) { nux::HLayout* hint_layout = new nux::HLayout(); - hint_layout->SetSpaceBetweenChildren(16); + hint_layout->SetSpaceBetweenChildren(layout_spacing); - 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); + 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()) { - nux::StaticCairoText* info_name = new nux::StaticCairoText(info_hint->display_name, NUX_TRACKER_LOCATION); - info_name->SetFont(style.info_hint_font()); + std::string tmp_display_name = info_hint->display_name; + if (condensed_format_) { tmp_display_name += ":"; } + + info_name.Adopt(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->SetLines(-1); - info_name->SetMinimumWidth(style.GetInfoHintNameWidth()); - info_name->SetMaximumWidth(style.GetInfoHintNameWidth()); - - hint_layout->AddView(info_name, 0, nux::MINOR_POSITION_CENTER); + if (!condensed_format_) + { + info_name->SetMinimumWidth(style.GetInfoHintNameWidth()); + info_name->SetMaximumWidth(style.GetInfoHintNameWidth()); + } + hint_layout->AddView(info_name.GetPointer(), 0, nux::MINOR_POSITION_CENTER); } - - nux::StaticCairoText* info_value = new nux::StaticCairoText(StringFromVariant(info_hint->value), NUX_TRACKER_LOCATION); + + StaticCairoTextPtr info_value(new nux::StaticCairoText(StringFromVariant(info_hint->value), NUX_TRACKER_LOCATION)); info_value->SetFont(style.info_hint_font()); info_value->SetLines(-1); + hint_layout->AddView(info_value.GetPointer(), 1, nux::MINOR_POSITION_CENTER); - hint_layout->AddView(info_value, 1, nux::MINOR_POSITION_CENTER); + InfoHint info_hint_views(info_name, info_value); + info_hints_.push_back(info_hint_views); layout->AddLayout(hint_layout, 0); } @@ -172,6 +207,41 @@ void PreviewInfoHintWidget::SetupViews() SetLayout(layout); } + +long PreviewInfoHintWidget::ComputeContentSize() +{ + previews::Style& style = previews::Style::Instance(); + nux::Geometry const& geo = GetGeometry(); + + for (InfoHint const& info_hint : info_hints_) + { + int max_info_value_width = geo.width; + if (visible_icons_) + { + max_info_value_width -= icon_size_; + max_info_value_width -= layout_spacing; + } + if (info_hint.first) + { + 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; + } + + if (info_hint.second) + info_hint.second->SetMaximumWidth(max_info_value_width); + } + + return View::ComputeContentSize(); +} + + } // namespace previews } // namespace dash } // namespace unity diff --git a/dash/previews/PreviewInfoHintWidget.h b/dash/previews/PreviewInfoHintWidget.h index c23af7c43..2a77b4343 100644 --- a/dash/previews/PreviewInfoHintWidget.h +++ b/dash/previews/PreviewInfoHintWidget.h @@ -28,6 +28,10 @@ #include <UnityCore/Preview.h> #include "unity-shared/Introspectable.h" +namespace nux +{ +class StaticCairoText; +} namespace unity { @@ -42,12 +46,17 @@ public: typedef nux::ObjectPtr<PreviewInfoHintWidget> Ptr; NUX_DECLARE_OBJECT_TYPE(PreviewInfoHintWidget, nux::View); - PreviewInfoHintWidget(dash::Preview::Ptr preview_model, int icon_size); + PreviewInfoHintWidget(dash::Preview::Ptr preview_model, int icon_size, bool visible_icons = true, bool condensed_format = false); virtual ~PreviewInfoHintWidget(); + void SetVisibleIcons(bool visible); + void SetCondensedFormat(bool condensed); + // From debug::Introspectable std::string GetName() const; void AddProperties(GVariantBuilder* builder); + + long ComputeContentSize(); protected: virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); @@ -63,6 +72,12 @@ protected: protected: int icon_size_; + bool condensed_format_; + bool visible_icons_; + + typedef nux::ObjectPtr<nux::StaticCairoText> StaticCairoTextPtr; + typedef std::pair<StaticCairoTextPtr, StaticCairoTextPtr> InfoHint; + std::list<InfoHint> info_hints_; dash::Preview::Ptr preview_model_; typedef nux::ObjectPtr<nux::BaseTexture> BaseTexturePtr; diff --git a/dash/previews/StandaloneMoviePreview.cpp b/dash/previews/StandaloneMoviePreview.cpp new file mode 100644 index 000000000..8b6f9ff5d --- /dev/null +++ b/dash/previews/StandaloneMoviePreview.cpp @@ -0,0 +1,250 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * version 3 along with this program. If not, see + * <http://www.gnu.org/licenses/> + * + * Authored by: Nick Dedekind <nick.dedekind@canonical.com> + * + */ +#include <gtk/gtk.h> + +#include "Nux/Nux.h" +#include "Nux/VLayout.h" +#include "Nux/WindowThread.h" +#include "NuxGraphics/GraphicsEngine.h" +#include <Nux/Layout.h> +#include <NuxCore/Logger.h> +#include <UnityCore/Variant.h> +#include <UnityCore/ApplicationPreview.h> +#include <unity-protocol.h> + +#include "unity-shared/FontSettings.h" +#include "unity-shared/UnitySettings.h" +#include "unity-shared/PreviewStyle.h" +#include "unity-shared/DashStyle.h" +#include "unity-shared/ThumbnailGenerator.h" + +#include "Preview.h" +#include "PreviewContainer.h" + + +#define WIDTH 972 +#define HEIGHT 452 + +using namespace unity; +using namespace unity::dash; + +class DummyView : public nux::View +{ +public: + DummyView(nux::View* view) + : View(NUX_TRACKER_LOCATION) + { + SetAcceptKeyNavFocusOnMouseDown(false); + SetAcceptKeyNavFocusOnMouseEnter(false); + + nux::ROPConfig rop; + rop.Blend = true; + rop.SrcBlend = GL_ONE; + rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA; + bg_layer_.reset(new nux::ColorLayer(nux::Color(81, 26, 48), true, rop)); + + nux::Layout* layout = new nux::VLayout(); + layout->SetPadding(16); + layout->AddView(view, 1, nux::MINOR_POSITION_CENTER); + SetLayout(layout); + } + + // Keyboard navigation + bool AcceptKeyNavFocus() + { + return false; + } + +protected: + virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) + { + nux::Geometry const& base = GetGeometry(); + + gfx_engine.PushClippingRectangle(base); + nux::GetPainter().PaintBackground(gfx_engine, base); + + 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); + + bg_layer_->SetGeometry(GetGeometry()); + nux::GetPainter().RenderSinglePaintLayer(gfx_engine, GetGeometry(), bg_layer_.get()); + + gfx_engine.GetRenderStates().SetBlend(alpha, src, dest); + + gfx_engine.PopClippingRectangle(); + } + + virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw) + { + nux::Geometry const& base = GetGeometry(); + gfx_engine.PushClippingRectangle(base); + + if (!IsFullRedraw()) + nux::GetPainter().PushLayer(gfx_engine, GetGeometry(), bg_layer_.get()); + + if (GetCompositionLayout()) + GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw); + + if (!IsFullRedraw()) + nux::GetPainter().PopBackground(); + + gfx_engine.PopClippingRectangle(); + } + + typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr; + LayerPtr bg_layer_; +}; + +class TestRunner +{ +public: + TestRunner (); + ~TestRunner (); + + static void InitWindowThread (nux::NThread* thread, void* InitData); + void Init (); + void NavRight(); + void NavLeft(); + + previews::PreviewContainer::Ptr container_; + nux::Layout *layout_; + int nav_iter; +}; + +TestRunner::TestRunner () +{ + nav_iter = 0; +} + +TestRunner::~TestRunner () +{ +} + +void TestRunner::Init () +{ + container_ = new previews::PreviewContainer(NUX_TRACKER_LOCATION); + container_->navigate_right.connect(sigc::mem_fun(this, &TestRunner::NavRight)); + container_->navigate_left.connect(sigc::mem_fun(this, &TestRunner::NavLeft)); + container_->request_close.connect([&]() { exit(0); }); + + DummyView* dummyView = new DummyView(container_.GetPointer()); + layout_ = new nux::VLayout(NUX_TRACKER_LOCATION); + layout_->AddView(dummyView, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); + nux::GetWindowThread()->SetLayout (layout_); + + NavRight(); +} + +void TestRunner::NavRight() +{ + std::stringstream title; + title << "Up " << ++nav_iter; + + const char* subtitle = "2009"; + const char* description = "By tying thousands of balloons to his home, 78-year-old Carl sets out to fulfill his lifelong dream to see the wilds of South America. Russell, a wilderness explorer 70 years younger, inadvertently becomes a stowaway."; + + glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_movie_preview_new())); + + unity_protocol_movie_preview_set_rating(UNITY_PROTOCOL_MOVIE_PREVIEW(proto_obj.RawPtr()), 0.5); + unity_protocol_movie_preview_set_rating(UNITY_PROTOCOL_MOVIE_PREVIEW(proto_obj.RawPtr()), 17); + +// unity_protocol_preview_set_image_source_uri(proto_obj, "file:///home/nick/Videos/test-1.ogv"); + unity_protocol_preview_set_image_source_uri(proto_obj, "http://ia.media-imdb.com/images/M/MV5BMTMwODg0NDY1Nl5BMl5BanBnXkFtZTcwMjkwNTgyMg@@._V1._SY317_.jpg"); + unity_protocol_preview_set_title(proto_obj, title.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, "play", "Play", NULL, 0); + unity_protocol_preview_add_action(proto_obj, "upgradHD", "Upgrade to HD", NULL, 0); + unity_protocol_preview_add_info_hint(proto_obj, "director", "Director", NULL, g_variant_new("s", "Steve Martino, Mike Thurmeier")); + unity_protocol_preview_add_info_hint(proto_obj, "cast", "Cast", NULL, g_variant_new("s", "Ray Romano, Denis Leary and John Leguizamo")); + unity_protocol_preview_add_info_hint(proto_obj, "genre", "Genre", NULL, g_variant_new("s", "Animation")); + + 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::RIGHT); +} + +void TestRunner::NavLeft() +{ + std::stringstream title; + title << "Ice Age, Continental Drift" << --nav_iter; + + const char* subtitle = "2012, 88 min"; + const char* description = "Manny, Diego, and Sid embark upon another adventure after their continent is set adrift. Using an iceberg as a ship, they encounter sea creatures and battle pirates as they explore a new world."; + + glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_movie_preview_new())); + + unity_protocol_movie_preview_set_rating(UNITY_PROTOCOL_MOVIE_PREVIEW(proto_obj.RawPtr()), 0.5); + unity_protocol_movie_preview_set_rating(UNITY_PROTOCOL_MOVIE_PREVIEW(proto_obj.RawPtr()), 17); + + unity_protocol_preview_set_image_source_uri(proto_obj, "http://ia.media-imdb.com/images/M/MV5BMTM3NDM5MzY5Ml5BMl5BanBnXkFtZTcwNjExMDUwOA@@._V1._SY317_.jpg"); + unity_protocol_preview_set_title(proto_obj, title.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, "play", "Play", NULL, 0); + unity_protocol_preview_add_action(proto_obj, "upgradHD", "Upgrade to HD", NULL, 0); + unity_protocol_preview_add_info_hint(proto_obj, "director", "Director", NULL, g_variant_new("s", "Steve Martino, Mike Thurmeier")); + unity_protocol_preview_add_info_hint(proto_obj, "cast", "Cast", NULL, g_variant_new("s", "Ray Romano, Denis Leary and John Leguizamo")); + unity_protocol_preview_add_info_hint(proto_obj, "genre", "Genre", NULL, g_variant_new("s", "Animation")); + + 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); + +} + +void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData) +{ + TestRunner *self = (TestRunner *) InitData; + self->Init (); +} + +int main(int argc, char **argv) +{ + nux::WindowThread* wt = NULL; + + gtk_init (&argc, &argv); + + nux::NuxInitialize(0); + nux::logging::configure_logging(::getenv("UNITY_LOG_SEVERITY")); + // The instances for the pseudo-singletons. + unity::Settings settings; + unity::dash::previews::Style panel_style; + unity::dash::Style dash_style; + unity::ThumbnailGenerator thumbnail_generator; + + TestRunner *test_runner = new TestRunner (); + wt = nux::CreateGUIThread(TEXT("Unity Preview"), + WIDTH, HEIGHT, + 0, + &TestRunner::InitWindowThread, + test_runner); + + wt->Run (NULL); + delete wt; + return 0; +} + + |
