From d81520d95b182dcada788d6ee736a0f40964d0cd Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Tue, 17 Jul 2012 16:28:47 +0100 Subject: Added music preview. (bzr r2419.4.21) --- unity-shared/ApplicationScreenshot.cpp | 181 -------------------------------- unity-shared/ApplicationScreenshot.h | 70 ------------- unity-shared/CMakeLists.txt | 2 +- unity-shared/CoverArt.cpp | 182 +++++++++++++++++++++++++++++++++ unity-shared/CoverArt.h | 71 +++++++++++++ unity-shared/PreviewStyle.cpp | 121 ++++++++++++++++++++-- unity-shared/PreviewStyle.h | 34 +++++- 7 files changed, 397 insertions(+), 264 deletions(-) delete mode 100644 unity-shared/ApplicationScreenshot.cpp delete mode 100644 unity-shared/ApplicationScreenshot.h create mode 100644 unity-shared/CoverArt.cpp create mode 100644 unity-shared/CoverArt.h (limited to 'unity-shared') diff --git a/unity-shared/ApplicationScreenshot.cpp b/unity-shared/ApplicationScreenshot.cpp deleted file mode 100644 index 67ed0bac3..000000000 --- a/unity-shared/ApplicationScreenshot.cpp +++ /dev/null @@ -1,181 +0,0 @@ -// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- -/* - * Copyright 2011 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser 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 applicable version of the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of both the GNU Lesser General Public - * License version 3 along with this program. If not, see - * - * - * Authored by: Andrea Cimitan - * - */ - -#include "ApplicationScreenshot.h" -#include "unity-shared/IntrospectableWrappers.h" -#include -#include - -namespace unity -{ -namespace dash -{ -namespace previews -{ - -namespace -{ -nux::logging::Logger logger("unity.dash.previews.applicationscreenshot"); -} - -NUX_IMPLEMENT_OBJECT_TYPE(ApplicationScreenshot); - -ApplicationScreenshot::ApplicationScreenshot() - : View(NUX_TRACKER_LOCATION) - , overlay_text_(nullptr) -{ - SetupViews(); -} - -ApplicationScreenshot::~ApplicationScreenshot() -{ - if (overlay_text_) - overlay_text_->UnReference(); -} - -void ApplicationScreenshot::SetImage(std::string const& image_hint) -{ - if (overlay_text_ && GetLayout()) - GetLayout()->RemoveChildObject(overlay_text_); - - texture_screenshot_.Adopt(nux::CreateTexture2DFromFile(image_hint.c_str(), -1, true)); - - if (!texture_screenshot_ && GetLayout()) - { - GetLayout()->AddView(overlay_text_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL, 100.0, nux::LayoutPosition(1)); - } - QueueDraw(); -} - -void ApplicationScreenshot::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) -{ - nux::Geometry const& base = GetGeometry(); - - gfx_engine.PushClippingRectangle(base); - nux::GetPainter().PaintBackground(gfx_engine, base); - - if (texture_screenshot_) - { - nux::Geometry imageDest = base; - nux::TexCoordXForm texxform; - - float base_apsect = float(base.GetWidth()) / base.GetHeight(); - float image_aspect = float(texture_screenshot_->GetWidth()) / texture_screenshot_->GetHeight(); - - if (image_aspect > base_apsect) - { - imageDest.SetHeight(float(imageDest.GetWidth())/image_aspect); - } - if (image_aspect < base_apsect) - { - imageDest.SetWidth(image_aspect*imageDest.GetHeight()); - } - - int border_width = 1; - - gfx_engine.QRP_Color(imageDest.x + (float(base.GetWidth() - imageDest.GetWidth()) / 2), - imageDest.y + (float(base.GetHeight() - imageDest.GetHeight()) / 2), - imageDest.GetWidth(), - imageDest.GetHeight(), - nux::Color(0.15f, 0.15f, 0.15f)); - - texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_SCALE_COORD); - texxform.SetWrap(nux::TEXWRAP_CLAMP_TO_BORDER, nux::TEXWRAP_CLAMP_TO_BORDER); - texxform.SetFilter(nux::TEXFILTER_LINEAR, nux::TEXFILTER_LINEAR); - - texxform.u0 = 0; - texxform.v0 = 0; - texxform.u1 = imageDest.width; - texxform.v1 = imageDest.height; - - gfx_engine.QRP_1Tex(imageDest.x + (float(base.GetWidth() - imageDest.GetWidth()) / 2) + border_width, - imageDest.y + (float(base.GetHeight() - imageDest.GetHeight()) / 2) + border_width, - imageDest.width - (border_width * 2), - imageDest.height - (border_width * 2), - texture_screenshot_.GetPointer()->GetDeviceTexture(), - texxform, - nux::color::White); - } - else - { - unsigned int alpha, src, dest = 0; - gfx_engine.GetRenderStates().GetBlend(alpha, src, dest); - gfx_engine.GetRenderStates().SetBlend(true); - - gfx_engine.QRP_Color(base.x, - base.y, - base.GetWidth(), - base.GetHeight(), - nux::Color(0.15f, 0.15f, 0.15f, 0.15f)); - - gPainter.Paint2DQuadWireframe(gfx_engine, - base.x+1, - base.y, - base.GetWidth(), - base.GetHeight(), - nux::Color(0.5f, 0.5, 0.5, 0.15f)); - - gfx_engine.GetRenderStates().SetBlend(alpha, src, dest); - } - - gfx_engine.PopClippingRectangle(); -} - -void ApplicationScreenshot::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw) -{ - nux::Geometry const& base = GetGeometry(); - gfx_engine.PushClippingRectangle(base); - - if (GetLayout()) - GetLayout()->ProcessDraw(gfx_engine, force_draw); - - gfx_engine.PopClippingRectangle(); -} - -std::string ApplicationScreenshot::GetName() const -{ - return "ApplicationScreenshot"; -} - -void ApplicationScreenshot::SetupViews() -{ - nux::VLayout* layout = new nux::VLayout(); - layout->AddSpace(0, 1); - layout->AddSpace(0, 1); - SetLayout(layout); - - overlay_text_ = new nux::StaticCairoText("", NUX_TRACKER_LOCATION); - overlay_text_->Reference(); - overlay_text_->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_CENTRE); - overlay_text_->SetFont("Ubuntu 14"); - overlay_text_->SetLines(-3); - overlay_text_->SetText("No Image Available"); -} - -void ApplicationScreenshot::SetFont(std::string const& font) -{ - overlay_text_->SetFont(font); -} - -} -} -} \ No newline at end of file diff --git a/unity-shared/ApplicationScreenshot.h b/unity-shared/ApplicationScreenshot.h deleted file mode 100644 index 122a30c99..000000000 --- a/unity-shared/ApplicationScreenshot.h +++ /dev/null @@ -1,70 +0,0 @@ -// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- -/* - * Copyright 2011 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser 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 applicable version of the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of both the GNU Lesser General Public - * License version 3 along with this program. If not, see - * - * - * Authored by: Andrea Cimitan - * - */ - -#ifndef APPLICATIONSCREENSHOT_H -#define APPLICATIONSCREENSHOT_H - -#include -#include -#include -#include "unity-shared/StaticCairoText.h" -#include - -namespace unity -{ -namespace dash -{ -namespace previews -{ - -class ApplicationScreenshot : public nux::View -{ -public: - typedef nux::ObjectPtr Ptr; - NUX_DECLARE_OBJECT_TYPE(ApplicationScreenshot, nux::View); - - ApplicationScreenshot(); - virtual ~ApplicationScreenshot(); - - void SetImage(std::string const& image_hint); - - // From debug::Introspectable - std::string GetName() const; - - void SetFont(std::string const& font); - -protected: - virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw); - virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw); - - void SetupViews(); - -private: - nux::ObjectPtr texture_screenshot_; - nux::StaticCairoText* overlay_text_; -}; - -} -} -} - -#endif // APPLICATIONSCREENSHOT_H \ No newline at end of file diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt index 272bd3d25..cd4df5f15 100644 --- a/unity-shared/CMakeLists.txt +++ b/unity-shared/CMakeLists.txt @@ -31,8 +31,8 @@ include_directories (. .. ../services ../UnityCore ${UNITY_SRC} ${CMAKE_BINARY_D set (UNITY_SHARED_SOURCES AbstractSeparator.cpp Animator.cpp - ApplicationScreenshot.cpp BGHash.cpp + CoverArt.cpp BackgroundEffectHelper.cpp DashStyle.cpp FontSettings.cpp diff --git a/unity-shared/CoverArt.cpp b/unity-shared/CoverArt.cpp new file mode 100644 index 000000000..0a9ac6419 --- /dev/null +++ b/unity-shared/CoverArt.cpp @@ -0,0 +1,182 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright 2011 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser 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 applicable version of the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of both the GNU Lesser General Public + * License version 3 along with this program. If not, see + * + * + * Authored by: Andrea Cimitan + * Nick Dedekind + * + */ + +#include "CoverArt.h" +#include "unity-shared/IntrospectableWrappers.h" +#include +#include + +namespace unity +{ +namespace dash +{ +namespace previews +{ + +namespace +{ +nux::logging::Logger logger("unity.dash.previews.coverart"); +} + +NUX_IMPLEMENT_OBJECT_TYPE(CoverArt); + +CoverArt::CoverArt() + : View(NUX_TRACKER_LOCATION) + , overlay_text_(nullptr) +{ + SetupViews(); +} + +CoverArt::~CoverArt() +{ + if (overlay_text_) + overlay_text_->UnReference(); +} + +void CoverArt::SetImage(std::string const& image_hint) +{ + if (overlay_text_ && GetLayout()) + GetLayout()->RemoveChildObject(overlay_text_); + + texture_screenshot_.Adopt(nux::CreateTexture2DFromFile(image_hint.c_str(), -1, true)); + + if (!texture_screenshot_ && GetLayout()) + { + GetLayout()->AddView(overlay_text_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL, 100.0, nux::LayoutPosition(1)); + } + QueueDraw(); +} + +void CoverArt::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) +{ + nux::Geometry const& base = GetGeometry(); + + gfx_engine.PushClippingRectangle(base); + nux::GetPainter().PaintBackground(gfx_engine, base); + + if (texture_screenshot_) + { + nux::Geometry imageDest = base; + nux::TexCoordXForm texxform; + + float base_apsect = float(base.GetWidth()) / base.GetHeight(); + float image_aspect = float(texture_screenshot_->GetWidth()) / texture_screenshot_->GetHeight(); + + if (image_aspect > base_apsect) + { + imageDest.SetHeight(float(imageDest.GetWidth())/image_aspect); + } + if (image_aspect < base_apsect) + { + imageDest.SetWidth(image_aspect*imageDest.GetHeight()); + } + + int border_width = 1; + + gfx_engine.QRP_Color(imageDest.x + (float(base.GetWidth() - imageDest.GetWidth()) / 2), + imageDest.y + (float(base.GetHeight() - imageDest.GetHeight()) / 2), + imageDest.GetWidth(), + imageDest.GetHeight(), + nux::Color(0.15f, 0.15f, 0.15f)); + + texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_SCALE_COORD); + texxform.SetWrap(nux::TEXWRAP_CLAMP_TO_BORDER, nux::TEXWRAP_CLAMP_TO_BORDER); + texxform.SetFilter(nux::TEXFILTER_LINEAR, nux::TEXFILTER_LINEAR); + + texxform.u0 = 0; + texxform.v0 = 0; + texxform.u1 = imageDest.width; + texxform.v1 = imageDest.height; + + gfx_engine.QRP_1Tex(imageDest.x + (float(base.GetWidth() - imageDest.GetWidth()) / 2) + border_width, + imageDest.y + (float(base.GetHeight() - imageDest.GetHeight()) / 2) + border_width, + imageDest.width - (border_width * 2), + imageDest.height - (border_width * 2), + texture_screenshot_.GetPointer()->GetDeviceTexture(), + texxform, + nux::color::White); + } + else + { + unsigned int alpha, src, dest = 0; + gfx_engine.GetRenderStates().GetBlend(alpha, src, dest); + gfx_engine.GetRenderStates().SetBlend(true); + + gfx_engine.QRP_Color(base.x, + base.y, + base.GetWidth(), + base.GetHeight(), + nux::Color(0.15f, 0.15f, 0.15f, 0.15f)); + + gPainter.Paint2DQuadWireframe(gfx_engine, + base.x+1, + base.y, + base.GetWidth(), + base.GetHeight(), + nux::Color(0.5f, 0.5, 0.5, 0.15f)); + + gfx_engine.GetRenderStates().SetBlend(alpha, src, dest); + } + + gfx_engine.PopClippingRectangle(); +} + +void CoverArt::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw) +{ + nux::Geometry const& base = GetGeometry(); + gfx_engine.PushClippingRectangle(base); + + if (GetLayout()) + GetLayout()->ProcessDraw(gfx_engine, force_draw); + + gfx_engine.PopClippingRectangle(); +} + +std::string CoverArt::GetName() const +{ + return "CoverArt"; +} + +void CoverArt::SetupViews() +{ + nux::VLayout* layout = new nux::VLayout(); + layout->AddSpace(0, 1); + layout->AddSpace(0, 1); + SetLayout(layout); + + overlay_text_ = new nux::StaticCairoText("", NUX_TRACKER_LOCATION); + overlay_text_->Reference(); + overlay_text_->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_CENTRE); + overlay_text_->SetFont("Ubuntu 14"); + overlay_text_->SetLines(-3); + overlay_text_->SetText("No Image Available"); +} + +void CoverArt::SetFont(std::string const& font) +{ + overlay_text_->SetFont(font); +} + +} +} +} \ No newline at end of file diff --git a/unity-shared/CoverArt.h b/unity-shared/CoverArt.h new file mode 100644 index 000000000..dad9969ae --- /dev/null +++ b/unity-shared/CoverArt.h @@ -0,0 +1,71 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright 2011 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser 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 applicable version of the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of both the GNU Lesser General Public + * License version 3 along with this program. If not, see + * + * + * Authored by: Andrea Cimitan + * Nick Dedekind + * + */ + +#ifndef COVERART_H +#define COVERART_H + +#include +#include +#include +#include "unity-shared/StaticCairoText.h" +#include + +namespace unity +{ +namespace dash +{ +namespace previews +{ + +class CoverArt : public nux::View +{ +public: + typedef nux::ObjectPtr Ptr; + NUX_DECLARE_OBJECT_TYPE(CoverArt, nux::View); + + CoverArt(); + virtual ~CoverArt(); + + void SetImage(std::string const& image_hint); + + // From debug::Introspectable + std::string GetName() const; + + void SetFont(std::string const& font); + +protected: + virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw); + virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw); + + void SetupViews(); + +private: + nux::ObjectPtr texture_screenshot_; + nux::StaticCairoText* overlay_text_; +}; + +} +} +} + +#endif // APPLICATIONSCREENSHOT_H \ No newline at end of file diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp index d9c28394a..934fe8752 100644 --- a/unity-shared/PreviewStyle.cpp +++ b/unity-shared/PreviewStyle.cpp @@ -19,9 +19,14 @@ * Authored by: Nick Dedekind * */ + #include "PreviewStyle.h" #include +#include +#include +#include "config.h" + namespace unity { namespace dash @@ -34,9 +39,48 @@ Style* style_instance = nullptr; nux::logging::Logger logger("unity.dash.previews.style"); +typedef nux::ObjectPtr BaseTexturePtr; + +class LazyLoadTexture +{ +public: + LazyLoadTexture(std::string const& filename, int size = -1); + nux::BaseTexture* texture(); +private: + void LoadTexture(); +private: + std::string filename_; + int size_; + BaseTexturePtr texture_; +}; + } // namespace + +class Style::Impl +{ +public: + Impl(Style* owner) + : owner_(owner) + , preview_nav_left_texture_("/prev.svg") + , preview_nav_right_texture_("/next.svg") + , preview_play_texture_("/play.svg") + , preview_pause_texture_("/pause.svg") + { + } + ~Impl() {} + + Style* owner_; + + LazyLoadTexture preview_nav_left_texture_; + LazyLoadTexture preview_nav_right_texture_; + LazyLoadTexture preview_play_texture_; + LazyLoadTexture preview_pause_texture_; +}; + + Style::Style() +: pimpl(new Impl(this)) { if (style_instance) { @@ -64,23 +108,23 @@ Style& Style::Instance() return *style_instance; } -int Style::NavigatorMinimumWidth() const +int Style::GetNavigatorWidth() const { return 42; } -int Style::NavigatorMaximumWidth() const +int Style::GetImageWidth() const { - return 42; + return 400; } -std::string Style::app_name_font() const +std::string Style::title_font() const { - return "Ubuntu 20"; + return "Ubuntu 22"; } -std::string Style::version_size_font() const +std::string Style::subtitle_size_font() const { - return "Ubuntu 12"; + return "Ubuntu 12.5"; } std::string Style::app_license_font() const { @@ -112,6 +156,69 @@ std::string Style::no_preview_image_font() const return "Ubuntu Light 16"; } +std::string Style::track_font() const +{ + return "Ubuntu Light 10"; +} + + + +nux::BaseTexture* Style::GetNavLeftIcon() +{ + return pimpl->preview_nav_left_texture_.texture(); } + +nux::BaseTexture* Style::GetNavRightIcon() +{ + return pimpl->preview_nav_right_texture_.texture(); } + +nux::BaseTexture* Style::GetPlayIcon() +{ + return pimpl->preview_play_texture_.texture(); } + +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() +{ + std::string full_path = PKGDATADIR + filename_; + glib::Object 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 +} // namespace unity diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h index 75132f709..0570ece7f 100644 --- a/unity-shared/PreviewStyle.h +++ b/unity-shared/PreviewStyle.h @@ -23,7 +23,16 @@ #ifndef PREVIEWSTYLE_H #define PREVIEWSTYLE_H - #include +#include +#include + +#include +#include + +namespace nux +{ + class BaseTexture; +} namespace unity { @@ -47,13 +56,15 @@ public: static Style& Instance(); - int NavigatorMinimumWidth() const; - int NavigatorMaximumWidth() const; + int GetNavigatorWidth() const; + int GetImageWidth() const; + + + std::string title_font() const; + std::string subtitle_size_font() const; //////////////////////////////// // Application Preview - std::string app_name_font() const; - std::string version_size_font() const; std::string app_license_font() const; std::string app_last_update_font() const; std::string app_copywrite_font() const; @@ -62,8 +73,21 @@ public: std::string user_rating_font() const; std::string no_preview_image_font() const; //////////////////////////////// + + //////////////////////////////// + // Music Preview + std::string track_font() const; + //////////////////////////////// + + + nux::BaseTexture* GetNavLeftIcon(); + nux::BaseTexture* GetNavRightIcon(); + nux::BaseTexture* GetPlayIcon(); + nux::BaseTexture* GetPauseIcon(); protected: + class Impl; + std::unique_ptr pimpl; }; -- cgit v1.2.3