From 6cd7100eb841ed3e6327bdb52b55b67a3f0a8680 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Wed, 4 Jul 2012 15:14:45 +0100 Subject: Factory creation of previews. Created derived previews for Application/Movies/Music/Generic. (bzr r2419.4.8) --- unity-shared/CMakeLists.txt | 1 + unity-shared/PreviewStyle.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++ unity-shared/PreviewStyle.h | 59 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 unity-shared/PreviewStyle.cpp create mode 100644 unity-shared/PreviewStyle.h (limited to 'unity-shared') diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt index 608d312d5..49193fafa 100644 --- a/unity-shared/CMakeLists.txt +++ b/unity-shared/CMakeLists.txt @@ -45,6 +45,7 @@ set (UNITY_SHARED_SOURCES LineSeparator.cpp OverlayRenderer.cpp PanelStyle.cpp + PreviewStyle.cpp SearchBar.cpp SearchBarSpinner.cpp StaticCairoText.cpp diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp new file mode 100644 index 000000000..82eb4d811 --- /dev/null +++ b/unity-shared/PreviewStyle.cpp @@ -0,0 +1,59 @@ +// -*- 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: Nick Dedekind + * + */ +#include "PreviewStyle.h" + +namespace unity +{ +namespace dash +{ +namespace previews +{ + +Style::Style() +{ + +} + +Style::~Style() +{ + +} + +Style& Style::Instance() +{ + static Style style; + return style; +} + +int Style::NavigatorMinimumWidth() const +{ + return 42; +} + +int Style::NavigatorMaximumWidth() const +{ + return 42; +} + +} +} +} diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h new file mode 100644 index 000000000..715eee5b6 --- /dev/null +++ b/unity-shared/PreviewStyle.h @@ -0,0 +1,59 @@ +// -*- 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: Nick Dedekind + * + */ + +#ifndef PREVIEWSTYLE_H +#define PREVIEWSTYLE_H + +namespace unity +{ +namespace dash +{ +namespace previews +{ + +enum class Orientation { + UP, + DOWN, + LEFT, + RIGHT +}; + +class Style +{ +public: + static Style& Instance(); + + int NavigatorMinimumWidth() const; + int NavigatorMaximumWidth() const; + +protected: + Style(); + ~Style(); + + +}; + +} +} +} + +#endif //PREVIEWSTYLE_H -- cgit v1.2.3 From a4ce3fe462b96085cab99590c1ea9f9b21acace4 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Thu, 5 Jul 2012 11:51:38 +0100 Subject: PreviewContainer now hosts Previews (bzr r2419.4.10) --- unity-shared/PreviewStyle.cpp | 28 ++++++++++++++++++++++++---- unity-shared/PreviewStyle.h | 6 +++--- 2 files changed, 27 insertions(+), 7 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp index 82eb4d811..cfd1ecb71 100644 --- a/unity-shared/PreviewStyle.cpp +++ b/unity-shared/PreviewStyle.cpp @@ -20,6 +20,7 @@ * */ #include "PreviewStyle.h" +#include namespace unity { @@ -27,21 +28,40 @@ namespace dash { namespace previews { +namespace +{ +Style* style_instance = nullptr; + +nux::logging::Logger logger("unity.dash.previews.style"); + +} // namespace Style::Style() { - + if (style_instance) + { + LOG_ERROR(logger) << "More than one previews::Style created."; + } + else + { + style_instance = this; + } } Style::~Style() { - + if (style_instance == this) + style_instance = nullptr; } Style& Style::Instance() { - static Style style; - return style; + if (!style_instance) + { + LOG_ERROR(logger) << "No previews::Style created yet."; + } + + return *style_instance; } int Style::NavigatorMinimumWidth() const diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h index 715eee5b6..7624eb572 100644 --- a/unity-shared/PreviewStyle.h +++ b/unity-shared/PreviewStyle.h @@ -40,15 +40,15 @@ enum class Orientation { class Style { public: + Style(); + ~Style(); + static Style& Instance(); int NavigatorMinimumWidth() const; int NavigatorMaximumWidth() const; protected: - Style(); - ~Style(); - }; -- cgit v1.2.3 From 12c9d638cad745c1a8314b6d3893a6a0637662eb Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Thu, 5 Jul 2012 16:34:04 +0100 Subject: Draft Application Layout (bzr r2419.4.11) --- unity-shared/PreviewStyle.cpp | 21 +++++++++++++++++++++ unity-shared/PreviewStyle.h | 13 ++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'unity-shared') diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp index cfd1ecb71..fc2e97b00 100644 --- a/unity-shared/PreviewStyle.cpp +++ b/unity-shared/PreviewStyle.cpp @@ -74,6 +74,27 @@ int Style::NavigatorMaximumWidth() const return 42; } +std::string Style::app_name_font() const +{ + return "Ubuntu 20"; +} +std::string Style::version_size_font() const +{ + return "Ubuntu 12"; +} +std::string Style::app_last_update_font() const +{ + return "Ubuntu Light 10"; +} +std::string Style::app_copywrite_font() const +{ + return "Ubuntu Light 10"; +} +std::string Style::app_description_font() const +{ + return "Ubuntu Light 10"; +} + } } } diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h index 7624eb572..1626d9040 100644 --- a/unity-shared/PreviewStyle.h +++ b/unity-shared/PreviewStyle.h @@ -23,6 +23,8 @@ #ifndef PREVIEWSTYLE_H #define PREVIEWSTYLE_H + #include + namespace unity { namespace dash @@ -47,7 +49,16 @@ public: int NavigatorMinimumWidth() const; int NavigatorMaximumWidth() const; - + + //////////////////////////////// + // Application Preview + std::string app_name_font() const; + std::string version_size_font() const; + std::string app_last_update_font() const; + std::string app_copywrite_font() const; + std::string app_description_font() const; + //////////////////////////////// + protected: }; -- cgit v1.2.3 From dc057e2abd8d2ca2123f6bcdafaaeb0d5ab03352 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Fri, 6 Jul 2012 13:15:14 +0100 Subject: Fixed action button sizing issues and multi-line description text. (bzr r2419.4.12) --- unity-shared/DashStyle.cpp | 15 ++++++++++----- unity-shared/DashStyle.h | 4 ++-- unity-shared/StaticCairoText.cpp | 18 +++++++++++++++--- unity-shared/StaticCairoText.h | 1 + 4 files changed, 28 insertions(+), 10 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/DashStyle.cpp b/unity-shared/DashStyle.cpp index 36fd926e8..53dacf095 100644 --- a/unity-shared/DashStyle.cpp +++ b/unity-shared/DashStyle.cpp @@ -121,7 +121,7 @@ public: void Text(cairo_t* cr, nux::Color const& color, std::string const& label, - int font_size = -1, + int& font_size, double horizMargin = 4.0, Alignment alignment = Alignment::CENTER); @@ -1315,7 +1315,7 @@ void Style::Impl::GetTextExtents(int& width, void Style::Impl::Text(cairo_t* cr, nux::Color const& color, std::string const& label, - int text_size, + int& text_size, double horizMargin, Alignment alignment) { @@ -1353,6 +1353,10 @@ void Style::Impl::Text(cairo_t* cr, { pango_font_description_set_absolute_size(desc, text_size * PANGO_SCALE); } + else if (desc) + { + text_size = pango_font_description_get_size(desc) / PANGO_SCALE; + } PangoWeight weight; switch (regular_text_weight_) @@ -1528,7 +1532,7 @@ void Style::Impl::DrawOverlay(cairo_t* cr, } bool Style::Button(cairo_t* cr, nux::ButtonVisualState state, - std::string const& label, int font_size, + std::string const& label, int& font_size, Alignment alignment, bool zeromargin) { // sanity checks @@ -1622,7 +1626,7 @@ nux::AbstractPaintLayer* Style::FocusOverlay(int width, int height) bool Style::SquareButton(cairo_t* cr, nux::ButtonVisualState state, std::string const& label, bool curve_bottom, - int font_size, Alignment alignment, + int& font_size, Alignment alignment, bool zeromargin) { // sanity checks @@ -1833,10 +1837,11 @@ bool Style::MultiRangeSegment(cairo_t* cr, } cairo_set_source_rgba(cr, pimpl->button_label_border_color_[state]); cairo_stroke(cr); + int label_font_size = 10; pimpl->Text(cr, pimpl->button_label_text_color_[state], label, - 10); // 13px = 10pt + label_font_size); // 13px = 10pt return true; } diff --git a/unity-shared/DashStyle.h b/unity-shared/DashStyle.h index 440914d7d..977e5a19f 100644 --- a/unity-shared/DashStyle.h +++ b/unity-shared/DashStyle.h @@ -92,13 +92,13 @@ public: static Style& Instance(); virtual bool Button(cairo_t* cr, nux::ButtonVisualState state, - std::string const& label, int font_size=-1, + std::string const& label, int& font_size, Alignment alignment = Alignment::CENTER, bool zeromargin=false); virtual bool SquareButton(cairo_t* cr, nux::ButtonVisualState state, std::string const& label, bool curve_bottom, - int font_size=-1, + int& font_size, Alignment alignment = Alignment::CENTER, bool zeromargin=false); diff --git a/unity-shared/StaticCairoText.cpp b/unity-shared/StaticCairoText.cpp index c01a46d25..265afdc3a 100644 --- a/unity-shared/StaticCairoText.cpp +++ b/unity-shared/StaticCairoText.cpp @@ -58,7 +58,7 @@ struct StaticCairoText::Impl std::string GetEffectiveFont() const; Size GetTextExtents() const; - void DrawText(cairo_t* cr, int width, int height, Color const& color); + void DrawText(cairo_t* cr, int width, int height, int line_spacing, Color const& color); void UpdateTexture(); void OnFontChanged(); @@ -88,6 +88,7 @@ struct StaticCairoText::Impl int lines_; int actual_lines_; + float line_spacing_; }; StaticCairoText::Impl::Impl(StaticCairoText* parent, std::string const& text) @@ -104,6 +105,7 @@ StaticCairoText::Impl::Impl(StaticCairoText* parent, std::string const& text) // the desired height of the layout in Pango units if positive, or desired // number of lines if negative. , actual_lines_(0) + , line_spacing_(0.5) { GtkSettings* settings = gtk_settings_get_default(); // not ref'ed g_signal_connect(settings, "notify::gtk-font-name", @@ -190,6 +192,13 @@ void StaticCairoText::SetLines(int lines) QueueDraw(); } +void StaticCairoText::SetLineSpacing(float line_spacing) +{ + pimpl->line_spacing_ = line_spacing; + pimpl->UpdateTexture(); + QueueDraw(); +} + void StaticCairoText::PreLayoutManagement() { Geometry geo = GetGeometry(); @@ -400,9 +409,10 @@ Size StaticCairoText::Impl::GetTextExtents() const pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); pango_layout_set_ellipsize(layout, GetPangoEllipsizeMode()); pango_layout_set_alignment(layout, GetPangoAlignment()); - pango_layout_set_markup(layout, text_.c_str(), -1); pango_layout_set_height(layout, lines_); pango_layout_set_width(layout, maxwidth * PANGO_SCALE); + pango_layout_set_markup(layout, text_.c_str(), -1); + pango_layout_set_spacing(layout, line_spacing_ * PANGO_SCALE); pangoCtx = pango_layout_get_context(layout); // is not ref'ed pango_cairo_context_set_font_options(pangoCtx, @@ -442,6 +452,7 @@ Size StaticCairoText::Impl::GetTextExtents() const void StaticCairoText::Impl::DrawText(cairo_t* cr, int width, int height, + int line_spacing, Color const& color) { PangoLayout* layout = NULL; @@ -464,6 +475,7 @@ void StaticCairoText::Impl::DrawText(cairo_t* cr, pango_layout_set_markup(layout, text_.c_str(), -1); pango_layout_set_width(layout, width * PANGO_SCALE); pango_layout_set_height(layout, height * PANGO_SCALE); + pango_layout_set_spacing(layout, line_spacing * PANGO_SCALE); pango_layout_set_height(layout, lines_); pangoCtx = pango_layout_get_context(layout); // is not ref'ed @@ -510,7 +522,7 @@ void StaticCairoText::Impl::UpdateTexture() geo.width, geo.height); DrawText(cairo_graphics.GetInternalContext(), - geo.width, geo.height, text_color_); + geo.width, geo.height, line_spacing_, text_color_); texture2D_ = texture_ptr_from_cairo_graphics(cairo_graphics); } diff --git a/unity-shared/StaticCairoText.h b/unity-shared/StaticCairoText.h index 83580aeae..9fba1fe9d 100644 --- a/unity-shared/StaticCairoText.h +++ b/unity-shared/StaticCairoText.h @@ -75,6 +75,7 @@ public: void SetTextVerticalAlignment(AlignState state); void SetFont(std::string const& font); void SetLines(int maximum_lines); + void SetLineSpacing(float line_spacing); std::string GetText() const; Color GetTextColor() const; -- cgit v1.2.3 From 70300516f0b78ea0266fcd0768276a830959f8ec Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Mon, 9 Jul 2012 16:59:23 +0100 Subject: More UI/Layout work. (bzr r2419.4.14) --- unity-shared/ApplicationScreenshot.cpp | 125 +++++++++++++++ unity-shared/ApplicationScreenshot.h | 67 ++++++++ unity-shared/CMakeLists.txt | 2 + unity-shared/IconTexture.cpp | 2 +- unity-shared/IdleAnimator.cpp | 104 +++++++++++++ unity-shared/IdleAnimator.h | 59 +++++++ unity-shared/PreviewStyle.cpp | 13 ++ unity-shared/PreviewStyle.h | 3 + unity-shared/RatingsButton.cpp | 273 +++++++++++++++++++++++++++++++++ unity-shared/RatingsButton.h | 74 +++++++++ 10 files changed, 721 insertions(+), 1 deletion(-) create mode 100644 unity-shared/ApplicationScreenshot.cpp create mode 100644 unity-shared/ApplicationScreenshot.h create mode 100644 unity-shared/IdleAnimator.cpp create mode 100644 unity-shared/IdleAnimator.h create mode 100644 unity-shared/RatingsButton.cpp create mode 100644 unity-shared/RatingsButton.h (limited to 'unity-shared') diff --git a/unity-shared/ApplicationScreenshot.cpp b/unity-shared/ApplicationScreenshot.cpp new file mode 100644 index 000000000..da87210b2 --- /dev/null +++ b/unity-shared/ApplicationScreenshot.cpp @@ -0,0 +1,125 @@ +// -*- 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 + +namespace unity +{ +namespace dash +{ +namespace previews +{ + +namespace +{ +nux::logging::Logger logger("unity.dash.previews.applicationscreenshot"); +} + +NUX_IMPLEMENT_OBJECT_TYPE(ApplicationScreenshot); + +ApplicationScreenshot::ApplicationScreenshot(std::string const& image_hint) + : View(NUX_TRACKER_LOCATION) +{ + texture_screenshot_.Adopt(nux::CreateTexture2DFromFile(image_hint.c_str(), -1, true)); + SetupViews(); +} + +ApplicationScreenshot::~ApplicationScreenshot() +{ +} + +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); + + gfx_engine.PopClippingRectangle(); +} + +void ApplicationScreenshot::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw) +{ + nux::Geometry const& base = GetGeometry(); + gfx_engine.PushClippingRectangle(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; + + //DrawBorder(gfx_engine, imageDest, 0, nux::Color(0.15f, 0.15f, 0.15f)); + 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); + } + + gfx_engine.PopClippingRectangle(); +} + +std::string ApplicationScreenshot::GetName() const +{ + return "ApplicationScreenshot"; +} + +void ApplicationScreenshot::SetupViews() +{ +} + +} +} +} \ No newline at end of file diff --git a/unity-shared/ApplicationScreenshot.h b/unity-shared/ApplicationScreenshot.h new file mode 100644 index 000000000..e61e551e5 --- /dev/null +++ b/unity-shared/ApplicationScreenshot.h @@ -0,0 +1,67 @@ +// -*- 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 +#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(std::string const& image_hint); + virtual ~ApplicationScreenshot(); + + // From debug::Introspectable + std::string GetName() const; + +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_; + +}; + +} +} +} + +#endif // APPLICATIONSCREENSHOT_H \ No newline at end of file diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt index 49193fafa..4a0c11471 100644 --- a/unity-shared/CMakeLists.txt +++ b/unity-shared/CMakeLists.txt @@ -30,6 +30,7 @@ include_directories (. .. ../services ../UnityCore ${UNITY_SRC} ${CMAKE_BINARY_D set (UNITY_SHARED_SOURCES AbstractSeparator.cpp Animator.cpp + ApplicationScreenshot.cpp BGHash.cpp BackgroundEffectHelper.cpp DashStyle.cpp @@ -46,6 +47,7 @@ set (UNITY_SHARED_SOURCES OverlayRenderer.cpp PanelStyle.cpp PreviewStyle.cpp + RatingsButton.cpp SearchBar.cpp SearchBarSpinner.cpp StaticCairoText.cpp diff --git a/unity-shared/IconTexture.cpp b/unity-shared/IconTexture.cpp index f97e5eb43..45c4a06a8 100644 --- a/unity-shared/IconTexture.cpp +++ b/unity-shared/IconTexture.cpp @@ -181,7 +181,7 @@ void IconTexture::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) GfxContext.PushClippingRectangle(geo); - nux::GetPainter().PaintBackground(GfxContext, geo); + //nux::GetPainter().PaintBackground(GfxContext, geo); if (_texture_cached) { diff --git a/unity-shared/IdleAnimator.cpp b/unity-shared/IdleAnimator.cpp new file mode 100644 index 000000000..b134c11c4 --- /dev/null +++ b/unity-shared/IdleAnimator.cpp @@ -0,0 +1,104 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2011 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 warranty of + * MERCHANTABILITY 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 + * along with this program. If not, see . + * + * Authored by: Marco Trevisan (Treviño) + */ + +#include "IdleAnimator.h" + +namespace unity +{ + +IdleAnimator::IdleAnimator(unsigned int duration_) + : duration_(0) +{ + SetDuration(duration_); +} + +IdleAnimator::~IdleAnimator() +{ + Stop(); +} + + +void IdleAnimator::SetDuration(unsigned int duration) +{ + duration_ = duration * 1000; +} + +unsigned int IdleAnimator::GetRate() const +{ + if (rate_ != 0) + return 1000 / rate_; + + return rate_; +} + +unsigned int IdleAnimator::GetDuration() const +{ + return (one_time_duration_ > 0 ? one_time_duration_ : duration_) / 1000; +} + +bool IdleAnimator::IsRunning() const +{ + // short circuit to avoid unneeded calculations + struct timespec current; + clock_gettime(CLOCK_MONOTONIC, ¤t); + + // hover in animation + if (unity::TimeUtil::TimeDelta(¤t, &_times) < ANIM_DURATION_LONG) + return true; + + return false; +} + +void IdleAnimator::Start(unsigned int one_time_duration, double start_progress) +{ + DoStep(); +} + +void IdleAnimator::Start(double start_progress) +{ + Start(0, start_progress); +} + +void IdleAnimator::Stop() +{ + if (timeout_) + { + timeout_.reset(); + animation_updated.emit(progress_); + animation_ended.emit(); + animation_stopped.emit(progress_); + one_time_duration_ = 0; + } +} + +bool IdleAnimator::DoStep() +{ + // rely on the compiz event loop to come back to us in a nice throttling + if (IsRunning()) + { + auto idle = std::make_shared(glib::Source::Priority::DEFAULT); + sources_.Add(idle, ANIMATION_IDLE); + idle->Run([&]() { + EnsureAnimation(); + return false; + }); + } +} + +} //namespace diff --git a/unity-shared/IdleAnimator.h b/unity-shared/IdleAnimator.h new file mode 100644 index 000000000..fc230f6df --- /dev/null +++ b/unity-shared/IdleAnimator.h @@ -0,0 +1,59 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2011 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 warranty of + * MERCHANTABILITY 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 + * along with this program. If not, see . + * + * Authored by: Marco Trevisan (Treviño) + */ + +#ifndef UNITY_ANIMATOR_H_ +#define UNITY_ANIMATOR_H_ + +#include +#include + +namespace unity +{ +class IdleAnimator : boost::noncopyable +{ +public: + IdleAnimator(unsigned int duration); + ~IdleAnimator(); + + void SetDuration(unsigned int duration); + + unsigned int GetRate() const; + unsigned int GetDuration() const; + double GetProgress() const; + bool IsRunning() const; + + void Start(int source, int destination); + + sigc::signal animation_started; + sigc::signal animation_ended; + + sigc::signal animation_updated; + sigc::signal animation_stopped; + +private: + bool DoStep(); + unsigned int duration_; + + // Animation + struct timespec times; + glib::SourceManager sources_; +}; + +} +#endif diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp index fc2e97b00..63b4ba1f3 100644 --- a/unity-shared/PreviewStyle.cpp +++ b/unity-shared/PreviewStyle.cpp @@ -82,6 +82,10 @@ std::string Style::version_size_font() const { return "Ubuntu 12"; } +std::string Style::app_license_font() const +{ + return "Ubuntu Light 9.5"; +} std::string Style::app_last_update_font() const { return "Ubuntu Light 10"; @@ -95,6 +99,15 @@ std::string Style::app_description_font() const return "Ubuntu Light 10"; } +std::string Style::info_hint_font() const +{ + return "Ubuntu Light 10"; +} +std::string Style::user_rating_font() const +{ + return "Ubuntu Light 10"; +} + } } } diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h index 1626d9040..b0482ee8d 100644 --- a/unity-shared/PreviewStyle.h +++ b/unity-shared/PreviewStyle.h @@ -54,9 +54,12 @@ public: // 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; std::string app_description_font() const; + std::string info_hint_font() const; + std::string user_rating_font() const; //////////////////////////////// protected: diff --git a/unity-shared/RatingsButton.cpp b/unity-shared/RatingsButton.cpp new file mode 100644 index 000000000..112985394 --- /dev/null +++ b/unity-shared/RatingsButton.cpp @@ -0,0 +1,273 @@ +/* + * 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: Gordon Allott + * + */ + +#include + +#include +#include + +#include "RatingsButton.h" +#include "DashStyle.h" + +namespace +{ +const int num_stars = 5; +} + +namespace unity +{ +RatingsButton::RatingsButton(int star_size, int star_gap, NUX_FILE_LINE_DECL) + : nux::ToggleButton(NUX_FILE_LINE_PARAM) + , editable_(true) + , focused_star_(-1) + , star_size_(star_size) + , star_gap_(star_gap) +{ + SetAcceptKeyNavFocusOnMouseDown(false); + SetAcceptKeyNavFocusOnMouseEnter(true); + + mouse_up.connect(sigc::mem_fun(this, &RatingsButton::RecvMouseUp)); + mouse_move.connect(sigc::mem_fun(this, &RatingsButton::RecvMouseMove)); + mouse_drag.connect(sigc::mem_fun(this, &RatingsButton::RecvMouseDrag)); + + key_nav_focus_change.connect([&](nux::Area* area, bool has_focus, nux::KeyNavDirection direction) + { + if (has_focus && direction != nux::KEY_NAV_NONE) + focused_star_ = 0; + else if (!has_focus) + focused_star_ = -1; + + QueueDraw(); + }); + key_nav_focus_activate.connect([&](nux::Area*) { SetRating(static_cast(focused_star_+1)/num_stars); }); + key_down.connect(sigc::mem_fun(this, &RatingsButton::OnKeyDown)); +} + +RatingsButton::~RatingsButton() +{ +} + +void RatingsButton::SetEditable(bool editable) +{ + editable_ = editable; + if (!editable_) + focused_star_ = -1; + QueueDraw(); +} + +void RatingsButton::SetRating(float rating) +{ + rating_ = rating; + QueueDraw(); +} + +void RatingsButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) +{ + int rating = static_cast(rating_ * num_stars); + // FIXME: 9/26/2011 + // We should probably support an API for saying whether the ratings + // should or shouldn't support half stars...but our only consumer at + // the moment is the applications lens which according to design + // (Bug #839759) shouldn't. So for now just force rounding. + // int total_half_stars = rating % 2; + // int total_full_stars = rating / 2; + int total_full_stars = rating; + + nux::Geometry const& geo = GetGeometry(); + nux::Geometry geo_star(geo); + geo_star.width = star_size_; + + gPainter.PaintBackground(GfxContext, geo); + // set up our texture mode + nux::TexCoordXForm texxform; + texxform.SetWrap(nux::TEXWRAP_CLAMP_TO_BORDER, nux::TEXWRAP_CLAMP_TO_BORDER); + texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_SCALE_COORD); + texxform.SetFilter(nux::TEXFILTER_LINEAR, nux::TEXFILTER_LINEAR); + + // clear what is behind us + unsigned int alpha = 0, src = 0, dest = 0; + + GfxContext.GetRenderStates().GetBlend(alpha, src, dest); + GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + + nux::Color col = nux::color::Black; + col.alpha = 0; + GfxContext.QRP_Color(geo.x, + geo.y, + geo.width, + geo.height, + col); + + for (int index = 0; index < num_stars; ++index) + { + dash::Style& style = dash::Style::Instance(); + nux::BaseTexture* texture = style.GetStarSelectedIcon(); + if (index < total_full_stars) + { + if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_NORMAL) + texture = style.GetStarSelectedIcon(); + else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRELIGHT) + texture = style.GetStarSelectedIcon(); + else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED) + texture = style.GetStarSelectedIcon(); + } + else + { + if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_NORMAL) + texture = style.GetStarDeselectedIcon(); + else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRELIGHT) + texture = style.GetStarDeselectedIcon(); + else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED) + texture = style.GetStarDeselectedIcon(); + } + + GfxContext.QRP_1Tex(geo_star.x, + geo_star.y, + geo_star.width, + geo_star.height, + texture->GetDeviceTexture(), + texxform, + nux::Color(1.0f, 1.0f, 1.0f, 1.0f)); + + if (focused_star_ == index) + { + GfxContext.QRP_1Tex(geo_star.x, + geo_star.y, + geo_star.width, + geo_star.height, + style.GetStarHighlightIcon()->GetDeviceTexture(), + texxform, + nux::Color(1.0f, 1.0f, 1.0f, 0.5f)); + } + + geo_star.x += geo_star.width + star_gap_; + + } + + GfxContext.GetRenderStates().SetBlend(alpha, src, dest); + +} + +void RatingsButton::UpdateRatingToMouse(int x) +{ + int width = num_stars*star_size_ + (num_stars-1)*star_gap_; + float new_rating = (static_cast(x) / width); + + // FIXME: change to * 2 once we decide to support also half-stars + new_rating = ceil((num_stars * 1) * new_rating) / (num_stars * 1); + new_rating = (new_rating > 1) ? 1 : ((new_rating < 0) ? 0 : new_rating); + + UpdateRating(new_rating); +} + +void RatingsButton::RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags) +{ + if (!editable_) + return; + + UpdateRatingToMouse(x); +} + +void RatingsButton::RecvMouseDrag(int x, int y, int dx, int dy, + unsigned long button_flags, + unsigned long key_flags) +{ + if (!editable_) + return; + + UpdateRatingToMouse(x); +} + +void RatingsButton::RecvMouseMove(int x, int y, int dx, int dy, + unsigned long button_flags, + unsigned long key_flags) +{ + if (!editable_) + return; + + int width = num_stars*star_size_+ (num_stars-1)*star_gap_; + focused_star_ = std::max(0, std::min(static_cast(ceil((static_cast(x) / width) * num_stars) - 1), num_stars - 1)); + + if (!HasKeyFocus()) + nux::GetWindowCompositor().SetKeyFocusArea(this); + + QueueDraw(); +} + + +bool RatingsButton::InspectKeyEvent(unsigned int eventType, unsigned int keysym, const char* character) +{ + nux::KeyNavDirection direction = nux::KEY_NAV_NONE; + + switch (keysym) + { + case NUX_VK_LEFT: + direction = nux::KeyNavDirection::KEY_NAV_LEFT; + break; + case NUX_VK_RIGHT: + direction = nux::KeyNavDirection::KEY_NAV_RIGHT; + break; + default: + direction = nux::KeyNavDirection::KEY_NAV_NONE; + break; + } + + if (direction == nux::KeyNavDirection::KEY_NAV_NONE) + return false; + else if (direction == nux::KEY_NAV_LEFT && (focused_star_ <= 0)) + return false; + else if (direction == nux::KEY_NAV_RIGHT && (focused_star_ >= num_stars - 1)) + return false; + else + return true; +} + + +void RatingsButton::OnKeyDown(unsigned long event_type, unsigned long event_keysym, + unsigned long event_state, const TCHAR* character, + unsigned short key_repeat_count) +{ + switch (event_keysym) + { + case NUX_VK_LEFT: + --focused_star_; + break; + case NUX_VK_RIGHT: + ++focused_star_; + break; + default: + return; + } + + QueueDraw(); +} + +bool RatingsButton::AcceptKeyNavFocus() +{ + return true; +} + +void RatingsButton::UpdateRating(float rating) +{ + +} + +} // namespace unity diff --git a/unity-shared/RatingsButton.h b/unity-shared/RatingsButton.h new file mode 100644 index 000000000..b162bc0a9 --- /dev/null +++ b/unity-shared/RatingsButton.h @@ -0,0 +1,74 @@ +/* + * 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: Gordon Allott + * Nick Dedekind + * + */ + +#ifndef UNITYSHELL_RATINGSBUTTONWIDGET_H +#define UNITYSHELL_RATINGSBUTTONWIDGET_H + +#include + +#include +#include + +namespace unity +{ + +class RatingsButton : public nux::ToggleButton +{ +public: + RatingsButton(int star_size, int star_gap, NUX_FILE_LINE_PROTO); + virtual ~RatingsButton(); + + void SetEditable(bool editable); + virtual void SetRating(float rating); + +protected: + virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); + + // Key-nav + virtual bool AcceptKeyNavFocus(); + virtual bool InspectKeyEvent(unsigned int eventType, unsigned int keysym, const char* character); + + virtual void UpdateRating(float rating); + +private: + void OnKeyDown(unsigned long event_type, unsigned long event_keysym, + unsigned long event_state, const TCHAR* character, + unsigned short key_repeat_count); + + void RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags); + void RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); + void RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); + void UpdateRatingToMouse(int x); + + +protected: + bool editable_; + float rating_; + int focused_star_; + int star_size_; + int star_gap_; +}; + +} // namespace unity + +#endif // UNITYSHELL_RATINGSBUTTONWIDGET_H + -- cgit v1.2.3 From e2865bdadfe49033ac171b03a6592e9f24310731 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Fri, 13 Jul 2012 12:21:06 +0100 Subject: Show 'No image available' when no screenshot found (bzr r2419.4.18) --- unity-shared/ApplicationScreenshot.cpp | 74 +++++++++++++++++++++++++++++----- unity-shared/ApplicationScreenshot.h | 9 +++-- unity-shared/PreviewStyle.cpp | 4 ++ unity-shared/PreviewStyle.h | 1 + 4 files changed, 76 insertions(+), 12 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/ApplicationScreenshot.cpp b/unity-shared/ApplicationScreenshot.cpp index da87210b2..67ed0bac3 100644 --- a/unity-shared/ApplicationScreenshot.cpp +++ b/unity-shared/ApplicationScreenshot.cpp @@ -23,6 +23,7 @@ #include "ApplicationScreenshot.h" #include "unity-shared/IntrospectableWrappers.h" #include +#include namespace unity { @@ -38,31 +39,39 @@ nux::logging::Logger logger("unity.dash.previews.applicationscreenshot"); NUX_IMPLEMENT_OBJECT_TYPE(ApplicationScreenshot); -ApplicationScreenshot::ApplicationScreenshot(std::string const& image_hint) +ApplicationScreenshot::ApplicationScreenshot() : View(NUX_TRACKER_LOCATION) + , overlay_text_(nullptr) { - texture_screenshot_.Adopt(nux::CreateTexture2DFromFile(image_hint.c_str(), -1, true)); SetupViews(); } ApplicationScreenshot::~ApplicationScreenshot() { + if (overlay_text_) + overlay_text_->UnReference(); } -void ApplicationScreenshot::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) +void ApplicationScreenshot::SetImage(std::string const& image_hint) { - nux::Geometry const& base = GetGeometry(); + if (overlay_text_ && GetLayout()) + GetLayout()->RemoveChildObject(overlay_text_); - gfx_engine.PushClippingRectangle(base); - nux::GetPainter().PaintBackground(gfx_engine, base); + texture_screenshot_.Adopt(nux::CreateTexture2DFromFile(image_hint.c_str(), -1, true)); - gfx_engine.PopClippingRectangle(); + 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::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw) +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_) { @@ -83,7 +92,6 @@ void ApplicationScreenshot::DrawContent(nux::GraphicsEngine& gfx_engine, bool fo int border_width = 1; - //DrawBorder(gfx_engine, imageDest, 0, nux::Color(0.15f, 0.15f, 0.15f)); gfx_engine.QRP_Color(imageDest.x + (float(base.GetWidth() - imageDest.GetWidth()) / 2), imageDest.y + (float(base.GetHeight() - imageDest.GetHeight()) / 2), imageDest.GetWidth(), @@ -107,6 +115,38 @@ void ApplicationScreenshot::DrawContent(nux::GraphicsEngine& gfx_engine, bool fo 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(); } @@ -118,6 +158,22 @@ std::string ApplicationScreenshot::GetName() const 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); } } diff --git a/unity-shared/ApplicationScreenshot.h b/unity-shared/ApplicationScreenshot.h index e61e551e5..122a30c99 100644 --- a/unity-shared/ApplicationScreenshot.h +++ b/unity-shared/ApplicationScreenshot.h @@ -27,7 +27,6 @@ #include #include #include "unity-shared/StaticCairoText.h" -#include #include namespace unity @@ -43,12 +42,16 @@ public: typedef nux::ObjectPtr Ptr; NUX_DECLARE_OBJECT_TYPE(ApplicationScreenshot, nux::View); - ApplicationScreenshot(std::string const& image_hint); + 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); @@ -57,7 +60,7 @@ protected: private: nux::ObjectPtr texture_screenshot_; - + nux::StaticCairoText* overlay_text_; }; } diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp index 63b4ba1f3..d9c28394a 100644 --- a/unity-shared/PreviewStyle.cpp +++ b/unity-shared/PreviewStyle.cpp @@ -107,6 +107,10 @@ std::string Style::user_rating_font() const { return "Ubuntu Light 10"; } +std::string Style::no_preview_image_font() const +{ + return "Ubuntu Light 16"; +} } } diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h index b0482ee8d..75132f709 100644 --- a/unity-shared/PreviewStyle.h +++ b/unity-shared/PreviewStyle.h @@ -60,6 +60,7 @@ public: std::string app_description_font() const; std::string info_hint_font() const; std::string user_rating_font() const; + std::string no_preview_image_font() const; //////////////////////////////// protected: -- cgit v1.2.3 From 25612ee258bea3b9037473ec6fe82413afd7e060 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Fri, 13 Jul 2012 15:00:18 +0100 Subject: Added keyboard navigation (not perfect) (bzr r2419.4.19) --- unity-shared/RatingsButton.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'unity-shared') diff --git a/unity-shared/RatingsButton.cpp b/unity-shared/RatingsButton.cpp index 112985394..162a7b876 100644 --- a/unity-shared/RatingsButton.cpp +++ b/unity-shared/RatingsButton.cpp @@ -37,6 +37,7 @@ namespace unity RatingsButton::RatingsButton(int star_size, int star_gap, NUX_FILE_LINE_DECL) : nux::ToggleButton(NUX_FILE_LINE_PARAM) , editable_(true) + , rating_(0.0) , focused_star_(-1) , star_size_(star_size) , star_gap_(star_gap) @@ -245,6 +246,9 @@ void RatingsButton::OnKeyDown(unsigned long event_type, unsigned long event_keys unsigned long event_state, const TCHAR* character, unsigned short key_repeat_count) { + if (!editable_) + return; + switch (event_keysym) { case NUX_VK_LEFT: -- cgit v1.2.3 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 From 674e844bbcf864b91ea5dd0f27cd0b4cfba2db41 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Fri, 20 Jul 2012 14:28:26 +0100 Subject: Accion button icons. Style fixes. (bzr r2419.4.23) --- unity-shared/CMakeLists.txt | 1 + unity-shared/CoverArt.cpp | 12 ++-- unity-shared/PlacesVScrollBar.cpp | 142 ++++++++++++++++++++++++++++++++++++++ unity-shared/PlacesVScrollBar.h | 58 ++++++++++++++++ unity-shared/PreviewStyle.cpp | 61 +++++++++++++++- unity-shared/PreviewStyle.h | 17 ++++- unity-shared/RatingsButton.cpp | 1 + 7 files changed, 282 insertions(+), 10 deletions(-) create mode 100644 unity-shared/PlacesVScrollBar.cpp create mode 100644 unity-shared/PlacesVScrollBar.h (limited to 'unity-shared') diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt index cd4df5f15..96cb50ffe 100644 --- a/unity-shared/CMakeLists.txt +++ b/unity-shared/CMakeLists.txt @@ -48,6 +48,7 @@ set (UNITY_SHARED_SOURCES LineSeparator.cpp OverlayRenderer.cpp PanelStyle.cpp + PlacesVScrollBar.cpp PreviewStyle.cpp RatingsButton.cpp SearchBar.cpp diff --git a/unity-shared/CoverArt.cpp b/unity-shared/CoverArt.cpp index 0a9ac6419..c5c2caa53 100644 --- a/unity-shared/CoverArt.cpp +++ b/unity-shared/CoverArt.cpp @@ -93,11 +93,11 @@ void CoverArt::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) 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)); + gfx_engine.QRP_Color(base.x, + base.y, + base.GetWidth(), + base.GetHeight(), + nux::Color(0.03f, 0.03f, 0.03f, 0.0f)); texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_SCALE_COORD); texxform.SetWrap(nux::TEXWRAP_CLAMP_TO_BORDER, nux::TEXWRAP_CLAMP_TO_BORDER); @@ -126,7 +126,7 @@ void CoverArt::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) base.y, base.GetWidth(), base.GetHeight(), - nux::Color(0.15f, 0.15f, 0.15f, 0.15f)); + nux::Color(0.03f, 0.03f, 0.03f, 0.0f)); gPainter.Paint2DQuadWireframe(gfx_engine, base.x+1, diff --git a/unity-shared/PlacesVScrollBar.cpp b/unity-shared/PlacesVScrollBar.cpp new file mode 100644 index 000000000..0f8619fcc --- /dev/null +++ b/unity-shared/PlacesVScrollBar.cpp @@ -0,0 +1,142 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2011 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 warranty of + * MERCHANTABILITY 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 + * along with this program. If not, see . + * + * Authored by: Mirco Müller + */ + +#include + +#include "unity-shared/CairoTexture.h" +#include "PlacesVScrollBar.h" + +using unity::texture_from_cairo_graphics; + +namespace unity +{ +namespace dash +{ + +PlacesVScrollBar::PlacesVScrollBar(NUX_FILE_LINE_DECL) + : VScrollBar(NUX_FILE_LINE_PARAM), + _slider_texture(NULL) +{ + _scroll_up_button->SetMaximumHeight(15); + _scroll_up_button->SetMinimumHeight(15); + + _scroll_down_button->SetMaximumHeight(15); + _scroll_down_button->SetMinimumHeight(15); + + _slider->SetMinimumWidth(3); + _slider->SetMaximumWidth(3); + SetMinimumWidth(3); + SetMaximumWidth(3); +} + +PlacesVScrollBar::~PlacesVScrollBar() +{ + if (_slider_texture) + _slider_texture->UnReference(); +} + +void +PlacesVScrollBar::PreLayoutManagement() +{ + nux::VScrollBar::PreLayoutManagement(); +} + +long +PlacesVScrollBar::PostLayoutManagement(long LayoutResult) +{ + long ret = nux::VScrollBar::PostLayoutManagement(LayoutResult); + + UpdateTexture(); + return ret; +} + +void +PlacesVScrollBar::Draw(nux::GraphicsEngine& gfxContext, bool force_draw) +{ + nux::Color color = nux::color::White; + nux::Geometry const& base = GetGeometry(); + nux::TexCoordXForm texxform; + + gfxContext.PushClippingRectangle(base); + + nux::GetPainter().PaintBackground(gfxContext, base); + + // check if textures have been computed... if they haven't, exit function + if (!_slider_texture) + return; + + texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_SCALE_COORD); + + gfxContext.GetRenderStates().SetBlend(true); + gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER); + + if (content_height_ > container_height_) + { + nux::Geometry const& slider_geo = _slider->GetGeometry(); + + gfxContext.QRP_1Tex(slider_geo.x, + slider_geo.y, + slider_geo.width, + slider_geo.height, + _slider_texture->GetDeviceTexture(), + texxform, + color); + } + + gfxContext.GetRenderStates().SetBlend(false); + gfxContext.PopClippingRectangle(); + gfxContext.GetRenderStates().SetBlend(true); +} + +void PlacesVScrollBar::UpdateTexture() +{ + nux::CairoGraphics* cairoGraphics = NULL; + cairo_t* cr = NULL; + + // update texture of slider + int width = _slider->GetBaseWidth(); + int height = _slider->GetBaseHeight(); + cairoGraphics = new nux::CairoGraphics(CAIRO_FORMAT_ARGB32, width, height); + cr = cairoGraphics->GetContext(); + + cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); + cairo_paint(cr); + + cairo_set_operator(cr, CAIRO_OPERATOR_OVER); + cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f); + cairoGraphics->DrawRoundedRectangle(cr, + 1.0f, + 0.0, + 0.0, + 1.5, + 3.0, + (double) height - 3.0); + cairo_fill(cr); + + if (_slider_texture) + _slider_texture->UnReference(); + _slider_texture = texture_from_cairo_graphics(*cairoGraphics); + + cairo_destroy(cr); + delete cairoGraphics; +} + +} // namespace dash +} // namespace unity + diff --git a/unity-shared/PlacesVScrollBar.h b/unity-shared/PlacesVScrollBar.h new file mode 100644 index 000000000..de9a9dca7 --- /dev/null +++ b/unity-shared/PlacesVScrollBar.h @@ -0,0 +1,58 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2011 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 warranty of + * MERCHANTABILITY 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 + * along with this program. If not, see . + * + * Authored by: Mirco Müller + */ + +#ifndef PLACES_VSCROLLBAR_H +#define PLACES_VSCROLLBAR_H + +#include +#include +#include +#include +#include +#include + +namespace unity +{ +namespace dash +{ + +class PlacesVScrollBar : public nux::VScrollBar +{ +public: + PlacesVScrollBar(NUX_FILE_LINE_PROTO); + ~PlacesVScrollBar(); + +protected: + virtual void PreLayoutManagement(); + virtual long PostLayoutManagement(long LayoutResult); + + void Draw(nux::GraphicsEngine& gfxContext, + bool forceDraw); + +private: + void UpdateTexture(); + +private: + nux::BaseTexture* _slider_texture; +}; + +} // namespace dash +} // namespace unity + +#endif // PLACES_VSCROLLBAR_H diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp index 934fe8752..7febd4629 100644 --- a/unity-shared/PreviewStyle.cpp +++ b/unity-shared/PreviewStyle.cpp @@ -113,9 +113,64 @@ int Style::GetNavigatorWidth() const return 42; } -int Style::GetImageWidth() const +int Style::GetPreviewHeight() const { - return 400; + return 390; +} + +int Style::GetPreviewWidth() const +{ + return 796; +} + +int Style::GetDetailsTopMargin() const +{ + return 5; +} + +int Style::GetDetailsBottomMargin() const +{ + return 10; +} + +int Style::GetDetailsRightMargin() const +{ + return 10; +} + +int Style::GetDetailsLeftMargin() const +{ + return 10; +} + +int Style::GetPanelSplitWidth() const +{ + return 16; +} + +int Style::GetAppIconAreaWidth() const +{ + return 100; +} + +int Style::GetSpaceBetweenTitleAndSubtitle() const +{ + return 6; +} + +int Style::GetSpaceBetweenIconAndDetails() const +{ + return 18; +} + +int Style::GetTrackHeight() const +{ + return 28; +} + +int Style::GetSpaceBetweenActions() const +{ + return 10; } std::string Style::title_font() const @@ -128,7 +183,7 @@ std::string Style::subtitle_size_font() const } std::string Style::app_license_font() const { - return "Ubuntu Light 9.5"; + return "Ubuntu Light 10"; } std::string Style::app_last_update_font() const { diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h index 0570ece7f..2b1c175b1 100644 --- a/unity-shared/PreviewStyle.h +++ b/unity-shared/PreviewStyle.h @@ -57,7 +57,17 @@ public: static Style& Instance(); int GetNavigatorWidth() const; - int GetImageWidth() const; + int GetPreviewHeight() const; + int GetPreviewWidth() const; + + int GetDetailsTopMargin() const; + int GetDetailsBottomMargin() const; + int GetDetailsRightMargin() const; + int GetDetailsLeftMargin() const; + int GetPanelSplitWidth() const; + + int GetSpaceBetweenTitleAndSubtitle() const; + int GetSpaceBetweenActions() const; std::string title_font() const; @@ -72,11 +82,16 @@ public: std::string info_hint_font() const; std::string user_rating_font() const; std::string no_preview_image_font() const; + + int GetAppIconAreaWidth() const; + int GetSpaceBetweenIconAndDetails() const; //////////////////////////////// //////////////////////////////// // Music Preview std::string track_font() const; + + int GetTrackHeight() const; //////////////////////////////// diff --git a/unity-shared/RatingsButton.cpp b/unity-shared/RatingsButton.cpp index 162a7b876..b28dab690 100644 --- a/unity-shared/RatingsButton.cpp +++ b/unity-shared/RatingsButton.cpp @@ -95,6 +95,7 @@ void RatingsButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) nux::Geometry const& geo = GetGeometry(); nux::Geometry geo_star(geo); geo_star.width = star_size_; + geo_star.height = star_size_; gPainter.PaintBackground(GfxContext, geo); // set up our texture mode -- cgit v1.2.3 From a31c4115c2085b1cf8b83c617cc63ae69900eea5 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Fri, 20 Jul 2012 16:32:16 +0100 Subject: More style updates. Better action button stacking. (bzr r2419.4.24) --- unity-shared/PreviewStyle.cpp | 7 ++++++- unity-shared/PreviewStyle.h | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'unity-shared') diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp index 7febd4629..9e696349c 100644 --- a/unity-shared/PreviewStyle.cpp +++ b/unity-shared/PreviewStyle.cpp @@ -150,7 +150,7 @@ int Style::GetPanelSplitWidth() const int Style::GetAppIconAreaWidth() const { - return 100; + return 105; } int Style::GetSpaceBetweenTitleAndSubtitle() const @@ -168,6 +168,11 @@ int Style::GetTrackHeight() const return 28; } +int Style::GetActionButtonHeight() const +{ + return 36; +} + int Style::GetSpaceBetweenActions() const { return 10; diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h index 2b1c175b1..f9ce1e505 100644 --- a/unity-shared/PreviewStyle.h +++ b/unity-shared/PreviewStyle.h @@ -67,6 +67,8 @@ public: int GetPanelSplitWidth() const; int GetSpaceBetweenTitleAndSubtitle() const; + + int GetActionButtonHeight() const; int GetSpaceBetweenActions() const; -- cgit v1.2.3 From 0390b8edbc251f5039bf9514f2548f0b057c75ba Mon Sep 17 00:00:00 2001 From: Gord Allott Date: Tue, 24 Jul 2012 17:44:31 +0100 Subject: makes space for previews, hides filter bar, buggy hide search bar behaviour (bzr r2419.6.1) --- unity-shared/UBusMessages.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'unity-shared') diff --git a/unity-shared/UBusMessages.h b/unity-shared/UBusMessages.h index 603baa19f..65bec9786 100644 --- a/unity-shared/UBusMessages.h +++ b/unity-shared/UBusMessages.h @@ -81,6 +81,9 @@ #define UBUS_DASH_SIZE_CHANGED "DASH_SIZE_CHANGED" // FIXME - fix the nux focus api so we don't need this #define UBUS_RESULT_VIEW_KEYNAV_CHANGED "RESULT_VIEW_KEYNAV_CHANGED" +#define UBUS_RESULT_VIEW_EXPLICIT_SCROLL_POSITION "RESULT_VIEW_EXPLICIT_SCROLL_POSITION" + +#define UBUS_DASH_SET_SEARCH_VISIBILITY "DASH_SET_SEARCH_VISIBILITY" // Sends a string datatype containing the new icon name #define UBUS_HUD_ICON_CHANGED "HUD_ICON_CHANGED" -- cgit v1.2.3 From 9021f85e7d6252dc2ce59bced71fc3be67f127c9 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Wed, 25 Jul 2012 11:49:25 +0100 Subject: Removed factory creation of previews to keep unity-protocol-private hidden from non-UnityCore areas. (bzr r2419.4.26) --- unity-shared/PreviewStyle.cpp | 14 ++++++++++---- unity-shared/PreviewStyle.h | 6 +++++- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp index 9e696349c..59f3487bc 100644 --- a/unity-shared/PreviewStyle.cpp +++ b/unity-shared/PreviewStyle.cpp @@ -178,6 +178,11 @@ int Style::GetSpaceBetweenActions() const return 10; } +int Style::GetTrackBarHeight() const +{ + return 25; +} + std::string Style::title_font() const { return "Ubuntu 22"; @@ -186,19 +191,20 @@ std::string Style::subtitle_size_font() const { return "Ubuntu 12.5"; } -std::string Style::app_license_font() const +std::string Style::description_font() const { return "Ubuntu Light 10"; } -std::string Style::app_last_update_font() const + +std::string Style::app_license_font() const { return "Ubuntu Light 10"; } -std::string Style::app_copywrite_font() const +std::string Style::app_last_update_font() const { return "Ubuntu Light 10"; } -std::string Style::app_description_font() const +std::string Style::app_copywrite_font() const { return "Ubuntu Light 10"; } diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h index f9ce1e505..334353351 100644 --- a/unity-shared/PreviewStyle.h +++ b/unity-shared/PreviewStyle.h @@ -74,13 +74,13 @@ public: std::string title_font() const; std::string subtitle_size_font() const; + std::string description_font() const; //////////////////////////////// // Application Preview std::string app_license_font() const; std::string app_last_update_font() const; std::string app_copywrite_font() const; - std::string app_description_font() const; std::string info_hint_font() const; std::string user_rating_font() const; std::string no_preview_image_font() const; @@ -96,6 +96,10 @@ public: int GetTrackHeight() const; //////////////////////////////// + //////////////////////////////// + // Movie Preview + int GetTrackBarHeight() const; + //////////////////////////////// nux::BaseTexture* GetNavLeftIcon(); nux::BaseTexture* GetNavRightIcon(); -- cgit v1.2.3 From c4aad903b9c8a5ebf958b24d0d9ea98fbddbf28d Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Thu, 26 Jul 2012 10:38:46 +0100 Subject: Dynamic resizing of previews. Added escape key handler. (bzr r2419.4.27) --- unity-shared/PreviewStyle.cpp | 19 +++++++++++++++++-- unity-shared/PreviewStyle.h | 9 +++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp index 59f3487bc..5947166fe 100644 --- a/unity-shared/PreviewStyle.cpp +++ b/unity-shared/PreviewStyle.cpp @@ -113,12 +113,12 @@ int Style::GetNavigatorWidth() const return 42; } -int Style::GetPreviewHeight() const +int Style::GetPreviewPreferredHeight() const { return 390; } -int Style::GetPreviewWidth() const +int Style::GetPreviewPreferredWidth() const { return 796; } @@ -173,6 +173,11 @@ int Style::GetActionButtonHeight() const return 36; } +int Style::GetActionButtonMaximumWidth() const +{ + return 190; +} + int Style::GetSpaceBetweenActions() const { return 10; @@ -183,6 +188,16 @@ int Style::GetTrackBarHeight() const return 25; } +float Style::GetAppImageAspectRatio() const +{ + return 1.0; +} + +int Style::GetDetailsPanelMinimumWidth() const +{ + return 300; +} + std::string Style::title_font() const { return "Ubuntu 22"; diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h index 334353351..e81f5217c 100644 --- a/unity-shared/PreviewStyle.h +++ b/unity-shared/PreviewStyle.h @@ -57,8 +57,8 @@ public: static Style& Instance(); int GetNavigatorWidth() const; - int GetPreviewHeight() const; - int GetPreviewWidth() const; + int GetPreviewPreferredHeight() const; + int GetPreviewPreferredWidth() const; int GetDetailsTopMargin() const; int GetDetailsBottomMargin() const; @@ -70,6 +70,9 @@ public: int GetActionButtonHeight() const; int GetSpaceBetweenActions() const; + int GetActionButtonMaximumWidth() const; + + int GetDetailsPanelMinimumWidth() const; std::string title_font() const; @@ -85,6 +88,8 @@ public: std::string user_rating_font() const; std::string no_preview_image_font() const; + float GetAppImageAspectRatio() const; + int GetAppIconAreaWidth() const; int GetSpaceBetweenIconAndDetails() const; //////////////////////////////// -- cgit v1.2.3 From d860e6560df8e70b2a614ae476c6be1c50cc8b39 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Tue, 31 Jul 2012 11:10:16 +0100 Subject: Base+Derived DBusTestRunner. Added stub thumbnail generator standalone. (bzr r2419.5.1) --- unity-shared/RatingsButton.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'unity-shared') diff --git a/unity-shared/RatingsButton.h b/unity-shared/RatingsButton.h index b162bc0a9..1d33c9ddd 100644 --- a/unity-shared/RatingsButton.h +++ b/unity-shared/RatingsButton.h @@ -16,7 +16,6 @@ * ** * Authored by: Gordon Allott - * Nick Dedekind * */ @@ -28,6 +27,8 @@ #include #include + + namespace unity { -- cgit v1.2.3 From eabf711fcd463ce9310711032d7a0f32560310cf Mon Sep 17 00:00:00 2001 From: Brandon Schaefer Date: Thu, 2 Aug 2012 14:21:12 -0700 Subject: * Switcher is disabled now when the Wall plugin is active. (bzr r2529.8.1) --- unity-shared/PluginAdapter.h | 40 +++++++++++++++-------------- unity-shared/PluginAdapterCompiz.cpp | 44 ++++++++++++++++++-------------- unity-shared/PluginAdapterStandalone.cpp | 44 ++++++++++++++++++-------------- unity-shared/WindowManager.cpp | 40 +++++++++++++++++------------ unity-shared/WindowManager.h | 36 ++++++++++++++------------ 5 files changed, 113 insertions(+), 91 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/PluginAdapter.h b/unity-shared/PluginAdapter.h index 70d5e433c..8c9882bd1 100644 --- a/unity-shared/PluginAdapter.h +++ b/unity-shared/PluginAdapter.h @@ -92,11 +92,13 @@ public: void OnLeaveDesktop (); void TerminateScale(); - bool IsScaleActive(); - bool IsScaleActiveForGroup(); + bool IsScaleActive() const; + bool IsScaleActiveForGroup() const; void InitiateExpo(); - bool IsExpoActive(); + bool IsExpoActive() const; + + bool IsWallActive() const; void ShowGrabHandles(CompWindow* window, bool use_timer); void HideGrabHandles(CompWindow* window); @@ -109,22 +111,22 @@ public: void NotifyCompizEvent(const char* plugin, const char* event, CompOption::Vector& option); void NotifyNewDecorationState(guint32 xid); - guint32 GetActiveWindow(); + guint32 GetActiveWindow() const; void Decorate(guint32 xid); void Undecorate(guint32 xid); // WindowManager implementation - bool IsWindowMaximized(guint xid); + bool IsWindowMaximized(guint xid) const; bool IsWindowDecorated(guint xid); - bool IsWindowOnCurrentDesktop(guint xid); - bool IsWindowObscured(guint xid); - bool IsWindowMapped(guint xid); - bool IsWindowVisible(guint32 xid); - bool IsWindowOnTop(guint32 xid); - bool IsWindowClosable(guint32 xid); - bool IsWindowMinimizable(guint32 xid); - bool IsWindowMaximizable(guint32 xid); + bool IsWindowOnCurrentDesktop(guint xid) const; + bool IsWindowObscured(guint xid) const; + bool IsWindowMapped(guint xid) const; + bool IsWindowVisible(guint32 xid) const; + bool IsWindowOnTop(guint32 xid) const; + bool IsWindowClosable(guint32 xid) const; + bool IsWindowMinimizable(guint32 xid) const; + bool IsWindowMaximizable(guint32 xid) const; void Restore(guint32 xid); void RestoreAt(guint32 xid, int x, int y); @@ -140,12 +142,12 @@ public: void FocusWindowGroup(std::vector windows, FocusVisibility, int monitor = -1, bool only_top_win = true); bool ScaleWindowGroup(std::vector windows, int state, bool force); - bool IsScreenGrabbed(); - bool IsViewPortSwitchStarted(); + bool IsScreenGrabbed() const; + bool IsViewPortSwitchStarted() const; - unsigned long long GetWindowActiveNumber (guint32 xid); + unsigned long long GetWindowActiveNumber (guint32 xid) const; - bool MaximizeIfBigEnough(CompWindow* window); + bool MaximizeIfBigEnough(CompWindow* window) const; int GetWindowMonitor(guint32 xid) const; nux::Geometry GetWindowGeometry(guint32 xid) const; @@ -155,7 +157,7 @@ public: void CheckWindowIntersections(nux::Geometry const& region, bool &active, bool &any); - int WorkspaceCount(); + int WorkspaceCount() const; void SetCoverageAreaBeforeAutomaximize(float area); @@ -172,7 +174,7 @@ private: std::string MatchStringForXids(std::vector *windows); void InitiateScale(std::string const& match, int state = 0); - bool CheckWindowIntersection(nux::Geometry const& region, CompWindow* window); + bool CheckWindowIntersection(nux::Geometry const& region, CompWindow* window) const; void SetMwmWindowHints(Window xid, MotifWmHints* new_hints); CompScreen* m_Screen; diff --git a/unity-shared/PluginAdapterCompiz.cpp b/unity-shared/PluginAdapterCompiz.cpp index 567d37f49..9d4113bdc 100644 --- a/unity-shared/PluginAdapterCompiz.cpp +++ b/unity-shared/PluginAdapterCompiz.cpp @@ -298,7 +298,7 @@ MultiActionList::TerminateAll(CompOption::Vector& extraArgs) } unsigned long long -PluginAdapter::GetWindowActiveNumber (guint32 xid) +PluginAdapter::GetWindowActiveNumber (guint32 xid) const { Window win = xid; CompWindow* window; @@ -368,23 +368,29 @@ PluginAdapter::TerminateScale() } bool -PluginAdapter::IsScaleActive() +PluginAdapter::IsScaleActive() const { return m_Screen->grabExist("scale"); } bool -PluginAdapter::IsScaleActiveForGroup() +PluginAdapter::IsScaleActiveForGroup() const { return _spread_windows_state && m_Screen->grabExist("scale"); } bool -PluginAdapter::IsExpoActive() +PluginAdapter::IsExpoActive() const { return m_Screen->grabExist("expo"); } +bool +PluginAdapter::IsWallActive() const +{ + return m_Screen->grabExist("wall"); +} + void PluginAdapter::InitiateExpo() { @@ -395,13 +401,13 @@ PluginAdapter::InitiateExpo() // WindowManager implementation guint32 -PluginAdapter::GetActiveWindow() +PluginAdapter::GetActiveWindow() const { return m_Screen->activeWindow(); } bool -PluginAdapter::IsWindowMaximized(guint xid) +PluginAdapter::IsWindowMaximized(guint xid) const { Window win = xid; CompWindow* window; @@ -456,7 +462,7 @@ PluginAdapter::IsWindowDecorated(guint32 xid) } bool -PluginAdapter::IsWindowOnCurrentDesktop(guint32 xid) +PluginAdapter::IsWindowOnCurrentDesktop(guint32 xid) const { Window win = xid; CompWindow* window; @@ -472,7 +478,7 @@ PluginAdapter::IsWindowOnCurrentDesktop(guint32 xid) } bool -PluginAdapter::IsWindowObscured(guint32 xid) +PluginAdapter::IsWindowObscured(guint32 xid) const { Window win = xid; CompWindow* window; @@ -505,7 +511,7 @@ PluginAdapter::IsWindowObscured(guint32 xid) } bool -PluginAdapter::IsWindowMapped(guint32 xid) +PluginAdapter::IsWindowMapped(guint32 xid) const { Window win = xid; CompWindow* window; @@ -517,7 +523,7 @@ PluginAdapter::IsWindowMapped(guint32 xid) } bool -PluginAdapter::IsWindowVisible(guint32 xid) +PluginAdapter::IsWindowVisible(guint32 xid) const { Window win = xid; CompWindow* window; @@ -530,7 +536,7 @@ PluginAdapter::IsWindowVisible(guint32 xid) } bool -PluginAdapter::IsWindowOnTop(guint32 xid) +PluginAdapter::IsWindowOnTop(guint32 xid) const { Window win = xid; CompWindow* window = m_Screen->findWindow(win); @@ -569,7 +575,7 @@ PluginAdapter::IsWindowOnTop(guint32 xid) } bool -PluginAdapter::IsWindowClosable(guint32 xid) +PluginAdapter::IsWindowClosable(guint32 xid) const { Window win = xid; CompWindow* window; @@ -582,7 +588,7 @@ PluginAdapter::IsWindowClosable(guint32 xid) } bool -PluginAdapter::IsWindowMinimizable(guint32 xid) +PluginAdapter::IsWindowMinimizable(guint32 xid) const { Window win = xid; CompWindow* window; @@ -595,7 +601,7 @@ PluginAdapter::IsWindowMinimizable(guint32 xid) } bool -PluginAdapter::IsWindowMaximizable(guint32 xid) +PluginAdapter::IsWindowMaximizable(guint32 xid) const { Window win = xid; CompWindow* window; @@ -965,7 +971,7 @@ PluginAdapter::GetWorkAreaGeometry(guint32 xid) const } bool -PluginAdapter::CheckWindowIntersection(nux::Geometry const& region, CompWindow* window) +PluginAdapter::CheckWindowIntersection(nux::Geometry const& region, CompWindow* window) const { int intersect_types = CompWindowTypeNormalMask | CompWindowTypeDialogMask | CompWindowTypeModalDialogMask | CompWindowTypeUtilMask; @@ -1022,7 +1028,7 @@ PluginAdapter::CheckWindowIntersections (nux::Geometry const& region, bool &acti } int -PluginAdapter::WorkspaceCount() +PluginAdapter::WorkspaceCount() const { return m_Screen->vpSize().width() * m_Screen->vpSize().height(); } @@ -1105,19 +1111,19 @@ PluginAdapter::Undecorate(guint32 xid) } bool -PluginAdapter::IsScreenGrabbed() +PluginAdapter::IsScreenGrabbed() const { return m_Screen->grabbed(); } bool -PluginAdapter::IsViewPortSwitchStarted() +PluginAdapter::IsViewPortSwitchStarted() const { return _vp_switch_started; } /* Returns true if the window was maximized */ -bool PluginAdapter::MaximizeIfBigEnough(CompWindow* window) +bool PluginAdapter::MaximizeIfBigEnough(CompWindow* window) const { XClassHint classHint; Status status; diff --git a/unity-shared/PluginAdapterStandalone.cpp b/unity-shared/PluginAdapterStandalone.cpp index 45d0d5723..9ba893021 100644 --- a/unity-shared/PluginAdapterStandalone.cpp +++ b/unity-shared/PluginAdapterStandalone.cpp @@ -125,7 +125,7 @@ MultiActionList::TerminateAll(CompOption::Vector& extraArgs) } unsigned long long -PluginAdapter::GetWindowActiveNumber (guint32 xid) +PluginAdapter::GetWindowActiveNumber (guint32 xid) const { return 0; } @@ -157,19 +157,19 @@ PluginAdapter::TerminateScale() } bool -PluginAdapter::IsScaleActive() +PluginAdapter::IsScaleActive() const { return false; } bool -PluginAdapter::IsScaleActiveForGroup() +PluginAdapter::IsScaleActiveForGroup() const { return false; } bool -PluginAdapter::IsExpoActive() +PluginAdapter::IsExpoActive() const { return false; } @@ -179,15 +179,21 @@ PluginAdapter::InitiateExpo() { } +bool +PluginAdapter::IsWallActive() const +{ + return false; +} + // WindowManager implementation guint32 -PluginAdapter::GetActiveWindow() +PluginAdapter::GetActiveWindow() const { return 0; } bool -PluginAdapter::IsWindowMaximized(guint xid) +PluginAdapter::IsWindowMaximized(guint xid) const { return false; } @@ -199,49 +205,49 @@ PluginAdapter::IsWindowDecorated(guint32 xid) } bool -PluginAdapter::IsWindowOnCurrentDesktop(guint32 xid) +PluginAdapter::IsWindowOnCurrentDesktop(guint32 xid) const { return false; } bool -PluginAdapter::IsWindowObscured(guint32 xid) +PluginAdapter::IsWindowObscured(guint32 xid) const { return false; } bool -PluginAdapter::IsWindowMapped(guint32 xid) +PluginAdapter::IsWindowMapped(guint32 xid) const { return false; } bool -PluginAdapter::IsWindowVisible(guint32 xid) +PluginAdapter::IsWindowVisible(guint32 xid) const { return false; } bool -PluginAdapter::IsWindowOnTop(guint32 xid) +PluginAdapter::IsWindowOnTop(guint32 xid) const { return false; } bool -PluginAdapter::IsWindowClosable(guint32 xid) +PluginAdapter::IsWindowClosable(guint32 xid) const { return false; } bool -PluginAdapter::IsWindowMinimizable(guint32 xid) +PluginAdapter::IsWindowMinimizable(guint32 xid) const { return false; } bool -PluginAdapter::IsWindowMaximizable(guint32 xid) +PluginAdapter::IsWindowMaximizable(guint32 xid) const { return false; } @@ -347,7 +353,7 @@ PluginAdapter::GetWorkAreaGeometry(guint32 xid) const } bool -PluginAdapter::CheckWindowIntersection(nux::Geometry const& region, CompWindow* window) +PluginAdapter::CheckWindowIntersection(nux::Geometry const& region, CompWindow* window) const { return false; } @@ -358,7 +364,7 @@ PluginAdapter::CheckWindowIntersections (nux::Geometry const& region, bool &acti } int -PluginAdapter::WorkspaceCount() +PluginAdapter::WorkspaceCount() const { return 4; } @@ -379,19 +385,19 @@ PluginAdapter::Undecorate(guint32 xid) } bool -PluginAdapter::IsScreenGrabbed() +PluginAdapter::IsScreenGrabbed() const { return false; } bool -PluginAdapter::IsViewPortSwitchStarted() +PluginAdapter::IsViewPortSwitchStarted() const { return false; } /* Returns true if the window was maximized */ -bool PluginAdapter::MaximizeIfBigEnough(CompWindow* window) +bool PluginAdapter::MaximizeIfBigEnough(CompWindow* window) const { return true; } diff --git a/unity-shared/WindowManager.cpp b/unity-shared/WindowManager.cpp index 87d714477..5f5cd6519 100644 --- a/unity-shared/WindowManager.cpp +++ b/unity-shared/WindowManager.cpp @@ -23,22 +23,22 @@ static WindowManager* window_manager = NULL; class WindowManagerDummy : public WindowManager { - guint32 GetActiveWindow() + guint32 GetActiveWindow() const { return 0; } - unsigned long long GetWindowActiveNumber (guint32 xid) + unsigned long long GetWindowActiveNumber (guint32 xid) const { return 0; } - bool IsScreenGrabbed() + bool IsScreenGrabbed() const { return false; } - bool IsViewPortSwitchStarted() + bool IsViewPortSwitchStarted() const { return false; } @@ -48,7 +48,7 @@ class WindowManagerDummy : public WindowManager g_debug("%s", G_STRFUNC); } - bool IsWindowMaximized(guint32 xid) + bool IsWindowMaximized(guint32 xid) const { return false; } @@ -58,42 +58,42 @@ class WindowManagerDummy : public WindowManager return true; } - bool IsWindowOnCurrentDesktop(guint32 xid) + bool IsWindowOnCurrentDesktop(guint32 xid) const { return true; } - bool IsWindowObscured(guint32 xid) + bool IsWindowObscured(guint32 xid) const { return false; } - bool IsWindowMapped(guint32 xid) + bool IsWindowMapped(guint32 xid) const { return true; } - bool IsWindowVisible(guint32 xid) + bool IsWindowVisible(guint32 xid) const { return true; } - bool IsWindowOnTop(guint32 xid) + bool IsWindowOnTop(guint32 xid) const { return false; } - bool IsWindowClosable(guint32 xid) + bool IsWindowClosable(guint32 xid) const { return true; } - bool IsWindowMinimizable(guint32 xid) + bool IsWindowMinimizable(guint32 xid) const { return true; } - bool IsWindowMaximizable(guint32 xid) + bool IsWindowMaximizable(guint32 xid) const { return true; } @@ -182,7 +182,7 @@ class WindowManagerDummy : public WindowManager any = false; } - int WorkspaceCount () + int WorkspaceCount () const { return 1; } @@ -192,13 +192,13 @@ class WindowManagerDummy : public WindowManager g_debug("%s", G_STRFUNC); } - bool IsScaleActive() + bool IsScaleActive() const { g_debug("%s", G_STRFUNC); return false; } - bool IsScaleActiveForGroup() + bool IsScaleActiveForGroup() const { g_debug("%s", G_STRFUNC); return false; @@ -209,7 +209,13 @@ class WindowManagerDummy : public WindowManager g_debug("%s", G_STRFUNC); } - bool IsExpoActive() + bool IsExpoActive() const + { + g_debug("%s", G_STRFUNC); + return false; + } + + bool IsWallActive() const { g_debug("%s", G_STRFUNC); return false; diff --git a/unity-shared/WindowManager.h b/unity-shared/WindowManager.h index 1f828b45a..84ae82485 100644 --- a/unity-shared/WindowManager.h +++ b/unity-shared/WindowManager.h @@ -49,18 +49,18 @@ public: static WindowManager* Default(); static void SetDefault(WindowManager* manager); - virtual guint32 GetActiveWindow() = 0; + virtual guint32 GetActiveWindow() const = 0; - virtual bool IsWindowMaximized(guint32 xid) = 0; + virtual bool IsWindowMaximized(guint32 xid) const = 0; virtual bool IsWindowDecorated(guint32 xid) = 0; - virtual bool IsWindowOnCurrentDesktop(guint32 xid) = 0; - virtual bool IsWindowObscured(guint32 xid) = 0; - virtual bool IsWindowMapped(guint32 xid) = 0; - virtual bool IsWindowVisible(guint32 xid) = 0; - virtual bool IsWindowOnTop(guint32 xid) = 0; - virtual bool IsWindowClosable(guint32 xid) = 0; - virtual bool IsWindowMinimizable(guint32 xid) = 0; - virtual bool IsWindowMaximizable(guint32 xid) = 0; + virtual bool IsWindowOnCurrentDesktop(guint32 xid) const = 0; + virtual bool IsWindowObscured(guint32 xid) const = 0; + virtual bool IsWindowMapped(guint32 xid) const = 0; + virtual bool IsWindowVisible(guint32 xid) const = 0; + virtual bool IsWindowOnTop(guint32 xid) const = 0; + virtual bool IsWindowClosable(guint32 xid) const = 0; + virtual bool IsWindowMinimizable(guint32 xid) const = 0; + virtual bool IsWindowMaximizable(guint32 xid) const = 0; virtual void ShowDesktop() = 0; @@ -74,11 +74,13 @@ public: virtual void Lower(guint32 xid) = 0; virtual void TerminateScale() = 0; - virtual bool IsScaleActive() = 0; - virtual bool IsScaleActiveForGroup() = 0; + virtual bool IsScaleActive() const = 0; + virtual bool IsScaleActiveForGroup() const = 0; virtual void InitiateExpo() = 0; - virtual bool IsExpoActive() = 0; + virtual bool IsExpoActive() const = 0; + + virtual bool IsWallActive() const = 0; virtual void FocusWindowGroup(std::vector windows, FocusVisibility, int monitor = -1, bool only_top_win = true) = 0; virtual bool ScaleWindowGroup(std::vector windows, int state, bool force) = 0; @@ -86,8 +88,8 @@ public: virtual void Decorate(guint32 xid) {}; virtual void Undecorate(guint32 xid) {}; - virtual bool IsScreenGrabbed() = 0; - virtual bool IsViewPortSwitchStarted() = 0; + virtual bool IsScreenGrabbed() const = 0; + virtual bool IsViewPortSwitchStarted() const = 0; virtual void MoveResizeWindow(guint32 xid, nux::Geometry geometry) = 0; void StartMove(guint32 xid, int, int); @@ -98,13 +100,13 @@ public: virtual nux::Geometry GetScreenGeometry() const = 0; virtual nux::Geometry GetWorkAreaGeometry(guint32 xid = 0) const = 0; - virtual unsigned long long GetWindowActiveNumber(guint32 xid) = 0; + virtual unsigned long long GetWindowActiveNumber(guint32 xid) const = 0; virtual void SetWindowIconGeometry(Window window, nux::Geometry const& geo) = 0; virtual void CheckWindowIntersections (nux::Geometry const& region, bool &active, bool &any) = 0; - virtual int WorkspaceCount() = 0; + virtual int WorkspaceCount() const = 0; virtual bool saveInputFocus() = 0; virtual bool restoreInputFocus() = 0; -- cgit v1.2.3 From b1760bcc697345f0148a094574e6479def28e4ba Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Fri, 3 Aug 2012 12:04:20 +0100 Subject: Moved user thumbnailers into separate provider. (bzr r2419.4.31) --- unity-shared/CMakeLists.txt | 1 + unity-shared/ThumbnailGenerator.cpp | 134 +----------------------------- unity-shared/UserThumbnailProvider.cpp | 145 +++++++++++++++++++++++++++++++++ unity-shared/UserThumbnailProvider.h | 38 +++++++++ 4 files changed, 188 insertions(+), 130 deletions(-) create mode 100644 unity-shared/UserThumbnailProvider.cpp create mode 100644 unity-shared/UserThumbnailProvider.h (limited to 'unity-shared') diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt index c1927cb65..d1b06f000 100644 --- a/unity-shared/CMakeLists.txt +++ b/unity-shared/CMakeLists.txt @@ -64,6 +64,7 @@ set (UNITY_SHARED_SOURCES UnitySettings.cpp UnityWindowStyle.cpp UnityWindowView.cpp + UserThumbnailProvider.cpp WindowManager.cpp ubus-server.cpp ) diff --git a/unity-shared/ThumbnailGenerator.cpp b/unity-shared/ThumbnailGenerator.cpp index 04a502c6e..d0f5a3385 100644 --- a/unity-shared/ThumbnailGenerator.cpp +++ b/unity-shared/ThumbnailGenerator.cpp @@ -28,6 +28,7 @@ #include "TextureThumbnailProvider.h" #include "DefaultThumbnailProvider.h" +#include "UserThumbnailProvider.h" namespace unity { @@ -38,24 +39,8 @@ namespace ThumbnailGenerator* thumbnail_instance = nullptr; static unsigned int last_handle = 1; - class ThumbnailerProcess : public Thumbnailer - { - public: - ThumbnailerProcess(std::string const& name, std::string const& command_line) - : name(name) - , command_line(command_line) - {} - - std::string name; - std::string command_line; - - virtual std::string GetName() const { return name; } - - virtual bool Run(int size, std::string const& input_file, std::string& output_file, std::string& error_hint); - }; static std::map thumbnail_content_map; static std::map thumbnailers_; - static bool all_thumbnailers_initialized = false; pthread_mutex_t thumbnailers_mutex_ = PTHREAD_MUTEX_INITIALIZER; } @@ -71,9 +56,6 @@ public: std::string Generate(std::string& error_hint); - unsigned int GetHandle() const; - -protected: std::string const uri_; unsigned int size_; const unsigned int handle_; @@ -99,7 +81,6 @@ public: bool OnThumbnailComplete(); - static void LoadThumbnailers(); static Thumbnailer::Ptr GetThumbnailer(std::string const& content_type, std::string& error_hint); protected: @@ -157,7 +138,7 @@ unsigned int ThumbnailGeneratorImpl::GetThumbnail(std::string const& uri, int si Thumbnail::Ptr thumb(new Thumbnail(uri, size)); thumbnails_.push(thumb); - unsigned int handle = thumb->GetHandle(); + unsigned int handle = thumb->handle_; pthread_mutex_unlock (&thumbnails_mutex_); /********************************* @@ -200,7 +181,7 @@ void ThumbnailGeneratorImpl::Run_() pthread_mutex_lock (&thumbnails_mutex_); CompleteThumbnail complete_thumb; - complete_thumb.handle = thumb->GetHandle(); + complete_thumb.handle = thumb->handle_; complete_thumb.thubnail_uri = uri_result; complete_thumb.error_hint = error_hint; @@ -243,86 +224,8 @@ bool ThumbnailGeneratorImpl::OnThumbnailComplete() return false; } -void ThumbnailGeneratorImpl::LoadThumbnailers() -{ - if (all_thumbnailers_initialized) - return; - - GError* err = NULL; - GDir* thumbnailer_dir = g_dir_open("/usr/share/thumbnailers", 0, &err); - if (err != NULL) - return; - - const gchar* file; - while((file = g_dir_read_name(thumbnailer_dir)) != NULL) - { - std::string file_name(file); - if (file_name == "." || file_name == "..") - continue; - - pthread_mutex_lock (&thumbnailers_mutex_); - // Already have this one? - if (thumbnailers_.find(file_name) != thumbnailers_.end()) - { - pthread_mutex_unlock (&thumbnailers_mutex_); - continue; - } - pthread_mutex_unlock (&thumbnailers_mutex_); - - /********************************* - * READ SETTINGS - *********************************/ - - GKeyFile* key_file = g_key_file_new(); - - err=NULL; - if (!g_key_file_load_from_file (key_file, (std::string("/usr/share/thumbnailers/") + file_name).c_str(), G_KEY_FILE_NONE, &err)) - { - g_key_file_free(key_file); - g_error_free(err); - continue; - } - - err=NULL; - glib::String command_line(g_key_file_get_string (key_file, "Thumbnailer Entry", "Exec", &err)); - if (err != NULL) - { - g_key_file_free(key_file); - g_error_free(err); - continue; - } - - err=NULL; - gsize mime_count = 0; - gchar** mime_types = g_key_file_get_string_list (key_file, "Thumbnailer Entry", "MimeType", &mime_count, &err); - if (err != NULL) - { - g_key_file_free(key_file); - g_error_free(err); - continue; - } - - Thumbnailer::Ptr thumbnailer(new ThumbnailerProcess(file_name, command_line.Value())); - std::list mime_type_list; - for (gsize i = 0; i < mime_count && mime_types[i] != NULL; i++) - { - mime_type_list.push_front(mime_types[i]); - } - - ThumbnailGenerator::RegisterThumbnailer(mime_type_list, thumbnailer); - - g_strfreev(mime_types); - g_key_file_free(key_file); - } - - all_thumbnailers_initialized = true; - g_dir_close(thumbnailer_dir); -} - Thumbnailer::Ptr ThumbnailGeneratorImpl::GetThumbnailer(std::string const& content_type, std::string& error_hint) { - LoadThumbnailers(); - gchar** content_split = g_strsplit(content_type.c_str(), "/", -1); std::vector content_list; @@ -387,6 +290,7 @@ ThumbnailGenerator::ThumbnailGenerator() { thumbnail_instance = this; + UserThumbnailProvider::Initialise(); TextureThumbnailProvider::Initialise(); DefaultThumbnailProvider::Initialise(); } @@ -471,36 +375,6 @@ std::string Thumbnail::Generate(std::string& error_hint) return output_file; } -unsigned int Thumbnail::GetHandle() const -{ - return handle_; -} - -bool ThumbnailerProcess::Run(int size, std::string const& input_file, std::string& output_file, std::string& error_hint) -{ - std::string tmp_command_line = command_line; - - size_t pos = tmp_command_line.find("%s"); - std::stringstream ss; ss << size; - if (pos != std::string::npos) { tmp_command_line.replace(pos, 2, ss.str()); } - pos = tmp_command_line.find("%u"); - if (pos != std::string::npos) { tmp_command_line.replace(pos, 2, input_file); } - - pos = tmp_command_line.find("%o"); - if (pos != std::string::npos) { tmp_command_line.replace(pos, 2, output_file); } - - gint exit_status = 0; - GError* err = NULL; - g_spawn_command_line_sync(tmp_command_line.c_str(), NULL, NULL, &exit_status, &err); - if (err != NULL) - { - error_hint = err->message; - g_error_free (err); - return false; - } - - return true; -} } // namespace unity \ No newline at end of file diff --git a/unity-shared/UserThumbnailProvider.cpp b/unity-shared/UserThumbnailProvider.cpp new file mode 100644 index 000000000..310a74f6f --- /dev/null +++ b/unity-shared/UserThumbnailProvider.cpp @@ -0,0 +1,145 @@ +/* + * 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: Nick Dedekind + * + */ + +#include +#include "UnityCore/GLibWrapper.h" +#include "UserThumbnailProvider.h" +#include "ThumbnailGenerator.h" + +namespace unity +{ + +namespace UserThumbnailProvider +{ + +class UserThumbnailer : public Thumbnailer +{ +public: + UserThumbnailer(std::string const& name, std::string const& command_line) + : name(name) + , command_line(command_line) + {} + + std::string name; + std::string command_line; + + virtual std::string GetName() const { return name; } + + virtual bool Run(int size, std::string const& input_file, std::string& output_file, std::string& error_hint); +}; + +bool UserThumbnailer::Run(int size, std::string const& input_file, std::string& output_file, std::string& error_hint) +{ + std::string tmp_command_line = command_line; + + // replace size + size_t pos = tmp_command_line.find("%s"); + std::stringstream ss; ss << size; + if (pos != std::string::npos) { tmp_command_line.replace(pos, 2, ss.str()); } + + // replace input file name + pos = tmp_command_line.find("%u"); + if (pos != std::string::npos) { tmp_command_line.replace(pos, 2, input_file); } + + // replace output file name + pos = tmp_command_line.find("%o"); + if (pos != std::string::npos) { tmp_command_line.replace(pos, 2, output_file); } + + gint exit_status = 0; + GError* err = NULL; + g_spawn_command_line_sync(tmp_command_line.c_str(), NULL, NULL, &exit_status, &err); + if (err != NULL) + { + error_hint = err->message; + g_error_free (err); + return false; + } + + return true; +} + +void Initialise() +{ + GError* err = NULL; + GDir* thumbnailer_dir = g_dir_open("/usr/share/thumbnailers", 0, &err); + if (err != NULL) + return; + + const gchar* file; + while((file = g_dir_read_name(thumbnailer_dir)) != NULL) + { + std::string file_name(file); + if (file_name == "." || file_name == "..") + continue; + + /********************************* + * READ SETTINGS + *********************************/ + + GKeyFile* key_file = g_key_file_new(); + + err=NULL; + if (!g_key_file_load_from_file (key_file, (std::string("/usr/share/thumbnailers/") + file_name).c_str(), G_KEY_FILE_NONE, &err)) + { + g_key_file_free(key_file); + g_error_free(err); + continue; + } + + err=NULL; + glib::String command_line(g_key_file_get_string (key_file, "Thumbnailer Entry", "Exec", &err)); + if (err != NULL) + { + g_key_file_free(key_file); + g_error_free(err); + continue; + } + + err=NULL; + gsize mime_count = 0; + gchar** mime_types = g_key_file_get_string_list (key_file, "Thumbnailer Entry", "MimeType", &mime_count, &err); + if (err != NULL) + { + g_key_file_free(key_file); + g_error_free(err); + continue; + } + + Thumbnailer::Ptr thumbnailer(new UserThumbnailer(file_name, command_line.Value())); + std::list mime_type_list; + for (gsize i = 0; i < mime_count && mime_types[i] != NULL; i++) + { + mime_type_list.push_front(mime_types[i]); + } + + ThumbnailGenerator::RegisterThumbnailer(mime_type_list, thumbnailer); + + g_strfreev(mime_types); + g_key_file_free(key_file); + } + + g_dir_close(thumbnailer_dir); +} + +} // namespace DefaultThumbnailProvider +} // namespace unity + + diff --git a/unity-shared/UserThumbnailProvider.h b/unity-shared/UserThumbnailProvider.h new file mode 100644 index 000000000..a3058307c --- /dev/null +++ b/unity-shared/UserThumbnailProvider.h @@ -0,0 +1,38 @@ +/* + * 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: Nick Dedekind + * + */ + +#ifndef UNITYSHARED_USERTHUMBNAILPROVIDER_H +#define UNITYSHARED_USERTHUMBNAILPROVIDER_H + +#include + +namespace unity +{ + +namespace UserThumbnailProvider +{ + void Initialise(); +}; + +} // namespace unity + +#endif // UNITYSHARED_USERTHUMBNAILPROVIDER_H + -- cgit v1.2.3 From 92c7152d1fedd96cd198430fff80b21812a50c8d Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Mon, 6 Aug 2012 16:39:20 +0100 Subject: Added thumbnail management (bzr r2419.4.33) --- unity-shared/CoverArt.cpp | 109 ++++--------- unity-shared/CoverArt.h | 8 +- unity-shared/DashStyle.cpp | 15 +- unity-shared/DashStyle.h | 4 +- unity-shared/DefaultThumbnailProvider.cpp | 2 +- unity-shared/ThumbnailGenerator.cpp | 257 ++++++++++++++++++++++++------ unity-shared/ThumbnailGenerator.h | 26 ++- unity-shared/UserThumbnailProvider.cpp | 7 + 8 files changed, 283 insertions(+), 145 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/CoverArt.cpp b/unity-shared/CoverArt.cpp index 010f86f02..a158e4acc 100644 --- a/unity-shared/CoverArt.cpp +++ b/unity-shared/CoverArt.cpp @@ -25,7 +25,6 @@ #include "unity-shared/IntrospectableWrappers.h" #include #include -#include "ThumbnailGenerator.h" #include "DashStyle.h" #include "IconLoader.h" @@ -53,9 +52,6 @@ CoverArt::CoverArt() , rotation_(0.0) { SetupViews(); - - ThumbnailGenerator::Instance().ready.connect(sigc::mem_fun(this, &CoverArt::OnThumbnailGenerated)); - ThumbnailGenerator::Instance().error.connect(sigc::mem_fun(this, &CoverArt::OnThumbnailError)); } CoverArt::~CoverArt() @@ -68,6 +64,9 @@ CoverArt::~CoverArt() IconLoader::GetDefault().DisconnectHandle(slot_handle_); slot_handle_ = 0; } + + if (notifier_) + notifier_->Cancel(); } void CoverArt::SetImage(std::string const& image_hint) @@ -81,9 +80,20 @@ void CoverArt::SetImage(std::string const& image_hint) if (GetLayout()) GetLayout()->RemoveChildObject(overlay_text_); - GIcon* icon = g_icon_new_for_string(image_hint.c_str(), NULL); + GIcon* icon = g_icon_new_for_string(image_hint.c_str(), NULL); + glib::Object image_file; if (g_strrstr(image_hint.c_str(), "://")) + { + /* try to open the source file for reading */ + image_file = g_file_new_for_uri (image_hint.c_str()); + } + 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; @@ -92,17 +102,15 @@ void CoverArt::SetImage(std::string const& image_hint) GFileInputStream *stream; GError *error = NULL; - GFile *file; - /* try to open the source file for reading */ - file = g_file_new_for_uri (image_hint.c_str()); - stream = g_file_read (file, NULL, &error); - g_object_unref (file); + stream = g_file_read (image_file, NULL, &error); if (error != NULL) { g_error_free (error); - QueueDraw(); + + if (icon != NULL) + g_object_unref(icon); return; } @@ -111,7 +119,6 @@ void CoverArt::SetImage(std::string const& image_hint) g_object_unref (stream); texture_screenshot_.Adopt(nux::CreateTexture2DFromPixbuf(pixbuf, true)); - g_object_unref(pixbuf); if (!texture_screenshot_ && GetLayout()) { @@ -120,53 +127,15 @@ void CoverArt::SetImage(std::string const& image_hint) } QueueDraw(); } + else if (G_IS_ICON(icon)) + { + StartWaiting(); + slot_handle_ = IconLoader::GetDefault().LoadFromGIconString(image_hint, 128, sigc::mem_fun(this, &CoverArt::IconLoaded)); + } else { - GFile *file = g_file_new_for_path (image_hint.c_str()); - if (g_file_query_exists(file, NULL)) - { - // for files on disk, we stretch to maximum aspect ratio. - stretch_image_ = true; - spinner_timeout_.reset(); - waiting_ = false; - - GFileInputStream *stream; - GError *error = NULL; - - /* try to open the source file for reading */ - stream = g_file_read (file, NULL, &error); - g_object_unref (file); - - if (error != NULL) - { - g_error_free (error); - QueueDraw(); - return; - } - - /* stream image into pixel-buffer. */ - glib::Object 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_ && GetLayout()) - { - GetLayout()->AddView(overlay_text_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL, 100.0, nux::LayoutPosition(1)); - ComputeContentSize(); - } - QueueDraw(); - } - else if (G_IS_ICON(icon)) - { - StartWaiting(); - slot_handle_ = IconLoader::GetDefault().LoadFromGIconString(image_hint, 128, sigc::mem_fun(this, &CoverArt::IconLoaded)); - } - else - { - StartWaiting(); - slot_handle_ = IconLoader::GetDefault().LoadFromIconName(image_hint, 128, sigc::mem_fun(this, &CoverArt::IconLoaded)); - } + StartWaiting(); + slot_handle_ = IconLoader::GetDefault().LoadFromIconName(image_hint, 128, sigc::mem_fun(this, &CoverArt::IconLoaded)); } if (icon != NULL) @@ -176,7 +145,10 @@ void CoverArt::SetImage(std::string const& image_hint) void CoverArt::GenerateImage(std::string const& uri) { StartWaiting(); - thumb_handle_ = ThumbnailGenerator::Instance().GetThumbnail(uri, 512); + notifier_ = ThumbnailGenerator::Instance().GetThumbnail(uri, 512); + + notifier_->ready.connect(sigc::mem_fun(this, &CoverArt::OnThumbnailGenerated)); + notifier_->error.connect(sigc::mem_fun(this, &CoverArt::OnThumbnailError)); } void CoverArt::StartWaiting() @@ -296,14 +268,7 @@ void CoverArt::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) base.GetWidth(), base.GetHeight(), nux::Color(0.03f, 0.03f, 0.03f, 0.0f)); - - gPainter.Paint2DQuadWireframe(gfx_engine, - base.x+1, - base.y, - base.GetWidth(), - base.GetHeight(), - nux::Color(0.5f, 0.5, 0.5, 0.15f)); - + if (waiting_) { nux::TexCoordXForm texxform; @@ -395,19 +360,14 @@ void CoverArt::SetFont(std::string const& font) overlay_text_->SetFont(font); } -void CoverArt::OnThumbnailGenerated(unsigned int thumb_handle, std::string const& uri) +void CoverArt::OnThumbnailGenerated(std::string const& uri) { - if (thumb_handle_ != thumb_handle) - return; - SetImage(uri); + notifier_.Release(); } -void CoverArt::OnThumbnailError(unsigned int thumb_handle, std::string const& error_hint) +void CoverArt::OnThumbnailError(std::string const& error_hint) { - if (thumb_handle_ != thumb_handle) - return; - LOG_WARNING(logger) << "Failed to generate thumbnail: " << error_hint; spinner_timeout_.reset(); frame_timeout_.reset(); @@ -421,6 +381,7 @@ void CoverArt::OnThumbnailError(unsigned int thumb_handle, std::string const& er ComputeContentSize(); } QueueDraw(); + notifier_.Release(); } diff --git a/unity-shared/CoverArt.h b/unity-shared/CoverArt.h index 792655a8f..a4a61b84c 100644 --- a/unity-shared/CoverArt.h +++ b/unity-shared/CoverArt.h @@ -28,8 +28,9 @@ #include #include #include -#include "unity-shared/StaticCairoText.h" #include +#include "unity-shared/StaticCairoText.h" +#include "ThumbnailGenerator.h" namespace unity { @@ -63,8 +64,8 @@ protected: void SetupViews(); - void OnThumbnailGenerated(unsigned int thumb_handle, std::string const& uri); - void OnThumbnailError(unsigned int thumb_handle, std::string const& error_hint); + void OnThumbnailGenerated(std::string const& uri); + void OnThumbnailError(std::string const& error_hint); bool OnFrameTimeout(); void IconLoaded(std::string const& texid, unsigned size, glib::Object const& pixbuf); @@ -79,6 +80,7 @@ private: unsigned int thumb_handle_; int slot_handle_; bool stretch_image_; + ThumbnailNotifier::Ptr notifier_; // Spinner bool waiting_; diff --git a/unity-shared/DashStyle.cpp b/unity-shared/DashStyle.cpp index 4676b02a6..789659139 100644 --- a/unity-shared/DashStyle.cpp +++ b/unity-shared/DashStyle.cpp @@ -123,7 +123,7 @@ public: void Text(cairo_t* cr, nux::Color const& color, std::string const& label, - int& font_size, + int font_size = -1, double horizMargin = 4.0, Alignment alignment = Alignment::CENTER); @@ -1317,7 +1317,7 @@ void Style::Impl::GetTextExtents(int& width, void Style::Impl::Text(cairo_t* cr, nux::Color const& color, std::string const& label, - int& text_size, + int text_size, double horizMargin, Alignment alignment) { @@ -1355,10 +1355,6 @@ void Style::Impl::Text(cairo_t* cr, { pango_font_description_set_absolute_size(desc, text_size * PANGO_SCALE); } - else if (desc) - { - text_size = pango_font_description_get_size(desc) / PANGO_SCALE; - } PangoWeight weight; switch (regular_text_weight_) @@ -1534,7 +1530,7 @@ void Style::Impl::DrawOverlay(cairo_t* cr, } bool Style::Button(cairo_t* cr, nux::ButtonVisualState state, - std::string const& label, int& font_size, + std::string const& label, int font_size, Alignment alignment, bool zeromargin) { // sanity checks @@ -1628,7 +1624,7 @@ nux::AbstractPaintLayer* Style::FocusOverlay(int width, int height) bool Style::SquareButton(cairo_t* cr, nux::ButtonVisualState state, std::string const& label, bool curve_bottom, - int& font_size, Alignment alignment, + int font_size, Alignment alignment, bool zeromargin) { // sanity checks @@ -1839,11 +1835,10 @@ bool Style::MultiRangeSegment(cairo_t* cr, } cairo_set_source_rgba(cr, pimpl->button_label_border_color_[state]); cairo_stroke(cr); - int label_font_size = 10; pimpl->Text(cr, pimpl->button_label_text_color_[state], label, - label_font_size); // 13px = 10pt + 10); // 13px = 10pt return true; } diff --git a/unity-shared/DashStyle.h b/unity-shared/DashStyle.h index 977e5a19f..440914d7d 100644 --- a/unity-shared/DashStyle.h +++ b/unity-shared/DashStyle.h @@ -92,13 +92,13 @@ public: static Style& Instance(); virtual bool Button(cairo_t* cr, nux::ButtonVisualState state, - std::string const& label, int& font_size, + std::string const& label, int font_size=-1, Alignment alignment = Alignment::CENTER, bool zeromargin=false); virtual bool SquareButton(cairo_t* cr, nux::ButtonVisualState state, std::string const& label, bool curve_bottom, - int& font_size, + int font_size=-1, Alignment alignment = Alignment::CENTER, bool zeromargin=false); diff --git a/unity-shared/DefaultThumbnailProvider.cpp b/unity-shared/DefaultThumbnailProvider.cpp index 2c6210f66..7545b21e5 100644 --- a/unity-shared/DefaultThumbnailProvider.cpp +++ b/unity-shared/DefaultThumbnailProvider.cpp @@ -58,7 +58,7 @@ bool DefaultThumbnailer::Run(int size, std::string const& input_file, std::strin return ""; } - glib::Object icon(g_file_info_get_icon(file_info)); + GIcon* icon = g_file_info_get_icon(file_info); // [transfer none] output_file = g_icon_to_string(icon); return true; diff --git a/unity-shared/ThumbnailGenerator.cpp b/unity-shared/ThumbnailGenerator.cpp index d0f5a3385..f4183401e 100644 --- a/unity-shared/ThumbnailGenerator.cpp +++ b/unity-shared/ThumbnailGenerator.cpp @@ -22,13 +22,15 @@ #include #include #include "UnityCore/GLibSource.h" -#include "UnityCore/GLibWrapper.h" +#include "UnityCore/DesktopUtilities.h" #include "ThumbnailGenerator.h" -#include +#include +#include #include "TextureThumbnailProvider.h" #include "DefaultThumbnailProvider.h" #include "UserThumbnailProvider.h" +#include "config.h" namespace unity { @@ -37,20 +39,28 @@ namespace { nux::logging::Logger logger("unity.thumbnailgenerator"); ThumbnailGenerator* thumbnail_instance = nullptr; - static unsigned int last_handle = 1; - static std::map thumbnail_content_map; + const unsigned int CLEANUP_DURATION = 10*1000; + const unsigned int CLEANUP_PREVIEW_AGE = 60*1000; + + static std::multimap thumbnail_content_map; static std::map thumbnailers_; pthread_mutex_t thumbnailers_mutex_ = PTHREAD_MUTEX_INITIALIZER; + + static std::string get_preview_dir() + { + return DesktopUtilities::GetUserDataDirectory().append("/previews"); + } } + class Thumbnail { public: typedef std::shared_ptr Ptr; - Thumbnail(std::string const& uri, unsigned int size); + Thumbnail(std::string const& uri, unsigned int size, ThumbnailNotifier::Ptr notifier); virtual ~Thumbnail(); @@ -58,9 +68,27 @@ public: std::string const uri_; unsigned int size_; - const unsigned int handle_; + ThumbnailNotifier::Ptr notifier_; }; +NUX_IMPLEMENT_OBJECT_TYPE(ThumbnailNotifier); + +ThumbnailNotifier::ThumbnailNotifier() +: cancel_(g_cancellable_new()) +{ + +} + +void ThumbnailNotifier::Cancel() +{ + g_cancellable_cancel(cancel_); +} + +bool ThumbnailNotifier::IsCancelled() const +{ + return g_cancellable_is_cancelled(cancel_); +} + class ThumbnailGeneratorImpl { public: @@ -75,15 +103,20 @@ public: pthread_join(thumbnail_thread_, NULL); } - void Run_(); - - unsigned int GetThumbnail(std::string const& uri, int size); + ThumbnailNotifier::Ptr GetThumbnail(std::string const& uri, int size); + void DoCleanup(); bool OnThumbnailComplete(); - static Thumbnailer::Ptr GetThumbnailer(std::string const& content_type, std::string& error_hint); + static std::list GetThumbnailers(std::string const& content_type, std::string& error_hint); + + void RunGenerate(); + void RunManagement(); + +private: + void StartCleanupTimer(); -protected: +private: ThumbnailGenerator* parent_; glib::Source::UniquePtr idle_; @@ -99,26 +132,65 @@ protected: volatile bool thumbnail_thread_is_running_; pthread_t thumbnail_thread_; + volatile bool management_thread_is_running_; + pthread_t management_thread_; + + glib::Source::UniquePtr cleanup_timer_; + std::queue thumbnails_; struct CompleteThumbnail { - unsigned int handle; std::string thubnail_uri; std::string error_hint; + ThumbnailNotifier::Ptr notifier; }; std::list complete_thumbnails_; }; -static void* -thumbnail_thread_start (void* data) +static void* thumbnail_thread_start (void* data) { - ((ThumbnailGeneratorImpl*)data)->Run_(); + ((ThumbnailGeneratorImpl*)data)->RunGenerate(); return NULL; } -unsigned int ThumbnailGeneratorImpl::GetThumbnail(std::string const& uri, int size) +bool CheckCache(std::string const& uri_in, std::string& filename_out) +{ + // Check Cache. + std::hash hash_fn; + std::stringstream ss_chache_thum; + ss_chache_thum << get_preview_dir() << "/" << hash_fn(uri_in) << ".png"; + filename_out = ss_chache_thum.str(); + + glib::Object cache_file(g_file_new_for_path(filename_out.c_str())); + return g_file_query_exists(cache_file, NULL); +} + +ThumbnailNotifier::Ptr ThumbnailGeneratorImpl::GetThumbnail(std::string const& uri, int size) { + std::string cache_filename; + if (CheckCache(uri, cache_filename)) + { + pthread_mutex_lock (&thumbnails_mutex_); + + CompleteThumbnail complete_thumb; + complete_thumb.thubnail_uri = cache_filename; + complete_thumb.notifier = new ThumbnailNotifier(); + complete_thumbnails_.push_back(complete_thumb); + + // Delay the thumbnail update until after this method has returned with the notifier + if (!idle_return_) + { + idle_return_.reset(new glib::Idle(sigc::mem_fun(this, &ThumbnailGeneratorImpl::OnThumbnailComplete), glib::Source::Priority::LOW)); + } + + pthread_mutex_unlock (&thumbnails_mutex_); + + StartCleanupTimer(); + + return complete_thumb.notifier; + } + pthread_mutex_lock (&thumbnails_mutex_); /********************************* * MUTEX LOCKED @@ -128,7 +200,6 @@ unsigned int ThumbnailGeneratorImpl::GetThumbnail(std::string const& uri, int si { idle_.reset(new glib::Idle([&]() { - thumbnail_thread_is_running_ = true; pthread_create (&thumbnail_thread_, NULL, thumbnail_thread_start, this); idle_.reset(); @@ -136,19 +207,29 @@ unsigned int ThumbnailGeneratorImpl::GetThumbnail(std::string const& uri, int si }, glib::Source::Priority::LOW)); } - Thumbnail::Ptr thumb(new Thumbnail(uri, size)); + ThumbnailNotifier::Ptr notifier(new ThumbnailNotifier()); + Thumbnail::Ptr thumb(new Thumbnail(uri, size, notifier)); thumbnails_.push(thumb); - unsigned int handle = thumb->handle_; pthread_mutex_unlock (&thumbnails_mutex_); /********************************* * MUTEX UNLOCKED *********************************/ - return handle; + + StartCleanupTimer(); + + + return notifier; +} + +void ThumbnailGeneratorImpl::StartCleanupTimer() +{ + if (!cleanup_timer_) + cleanup_timer_.reset(new glib::Timeout(CLEANUP_DURATION, [&]() { DoCleanup(); return false; })); } -void ThumbnailGeneratorImpl::Run_() +void ThumbnailGeneratorImpl::RunGenerate() { for (;;) { @@ -164,16 +245,19 @@ void ThumbnailGeneratorImpl::Run_() pthread_exit (NULL); } + Thumbnail::Ptr thumb(thumbnails_.front()); + thumbnails_.pop(); + pthread_mutex_unlock (&thumbnails_mutex_); /********************************* * MUTEX UNLOCKED *********************************/ - Thumbnail::Ptr thumb(thumbnails_.front()); + if (thumb->notifier_->IsCancelled()) + continue; + std::string error_hint; std::string uri_result = thumb->Generate(error_hint); - thumbnails_.pop(); - /********************************* * MUTEX LOCKED @@ -181,9 +265,9 @@ void ThumbnailGeneratorImpl::Run_() pthread_mutex_lock (&thumbnails_mutex_); CompleteThumbnail complete_thumb; - complete_thumb.handle = thumb->handle_; complete_thumb.thubnail_uri = uri_result; complete_thumb.error_hint = error_hint; + complete_thumb.notifier = thumb->notifier_; complete_thumbnails_.push_back(complete_thumb); @@ -216,16 +300,21 @@ bool ThumbnailGeneratorImpl::OnThumbnailComplete() pthread_mutex_unlock (&thumbnails_mutex_); + if (complete_thumbnail.notifier->IsCancelled()) + continue; + if (complete_thumbnail.error_hint == "") - parent_->ready.emit(complete_thumbnail.handle, complete_thumbnail.thubnail_uri); + complete_thumbnail.notifier->ready.emit(complete_thumbnail.thubnail_uri); else - parent_->error.emit(complete_thumbnail.handle, complete_thumbnail.error_hint); + complete_thumbnail.notifier->error.emit(complete_thumbnail.error_hint); } return false; } -Thumbnailer::Ptr ThumbnailGeneratorImpl::GetThumbnailer(std::string const& content_type, std::string& error_hint) +std::list ThumbnailGeneratorImpl::GetThumbnailers(std::string const& content_type, std::string& error_hint) { + std::list thumbnailer_list; + gchar** content_split = g_strsplit(content_type.c_str(), "/", -1); std::vector content_list; @@ -258,27 +347,79 @@ Thumbnailer::Ptr ThumbnailGeneratorImpl::GetThumbnailer(std::string const& conte /********************************* * FIND THUMBNAILER *********************************/ - pthread_mutex_lock (&thumbnailers_mutex_); // have already got this content type? - auto iter_content = thumbnail_content_map.find(ss_content_type.str()); - if (iter_content != thumbnail_content_map.end()) - { - pthread_mutex_unlock (&thumbnailers_mutex_); + auto range = thumbnail_content_map.equal_range(ss_content_type.str()); + for (; range.first != range.second; range.first++) + { // find the thumbnailer. - auto iter_tumbnailers = thumbnailers_.find(iter_content->second); + auto iter_tumbnailers = thumbnailers_.find(range.first->second); if (iter_tumbnailers != thumbnailers_.end()) - return iter_tumbnailers->second; + { + thumbnailer_list.push_back(iter_tumbnailers->second); + } } pthread_mutex_unlock (&thumbnailers_mutex_); } - error_hint = "thumbnailer not found."; + return thumbnailer_list; +} + +static void* management_thread_start (void* data) +{ + ((ThumbnailGeneratorImpl*)data)->RunManagement(); return NULL; } +void ThumbnailGeneratorImpl::DoCleanup() +{ + cleanup_timer_.reset(); + + if (!management_thread_is_running_) + { + management_thread_is_running_ = true; + pthread_create (&management_thread_, NULL, management_thread_start, this); + } +} + +void ThumbnailGeneratorImpl::RunManagement() +{ + guint64 time = std::time(NULL) - CLEANUP_PREVIEW_AGE; + std::string thumbnail_folder_name = get_preview_dir(); + + GError* err = NULL; + GDir* thumbnailer_dir = g_dir_open(thumbnail_folder_name.c_str(), 0, &err); + if (err != NULL) + return; + + const gchar* file_basename = NULL;; + while ((file_basename = g_dir_read_name(thumbnailer_dir)) != NULL) + { + std::string filename = g_build_filename (thumbnail_folder_name.c_str(), file_basename, NULL); + + glib::Object file(g_file_new_for_path(filename.c_str())); + + GError *err = NULL; + glib::Object file_info(g_file_query_info(file, G_FILE_ATTRIBUTE_TIME_CREATED, G_FILE_QUERY_INFO_NONE, NULL, &err)); + if (err != NULL) + { + g_error_free (err); + return; + } + + guint64 mtime = g_file_info_get_attribute_uint64(file_info, G_FILE_ATTRIBUTE_TIME_CREATED); + + if (mtime < time) + { + g_unlink(filename.c_str()); + } + } + + thumbnail_thread_is_running_ = false; +} + ThumbnailGenerator::ThumbnailGenerator() : pimpl(new ThumbnailGeneratorImpl(this)) { @@ -312,7 +453,7 @@ ThumbnailGenerator& ThumbnailGenerator::Instance() return *thumbnail_instance; } -unsigned int ThumbnailGenerator::GetThumbnail(std::string const& uri, int size) +ThumbnailNotifier::Ptr ThumbnailGenerator::GetThumbnail(std::string const& uri, int size) { return pimpl->GetThumbnail(uri, size); } @@ -325,16 +466,21 @@ void ThumbnailGenerator::RegisterThumbnailer(std::list mime_types, for (std::string mime_type : mime_types) { - thumbnail_content_map[mime_type] = thumbnailer->GetName(); + thumbnail_content_map.insert(std::pair(mime_type, thumbnailer->GetName())); } pthread_mutex_unlock (&thumbnailers_mutex_); } -Thumbnail::Thumbnail(std::string const& uri, unsigned int size) +void ThumbnailGenerator::DoCleanup() +{ + pimpl->DoCleanup(); +} + +Thumbnail::Thumbnail(std::string const& uri, unsigned int size, ThumbnailNotifier::Ptr notifier) : uri_(uri) , size_(size) -, handle_(last_handle++) +, notifier_(notifier) { } @@ -342,10 +488,8 @@ Thumbnail::~Thumbnail() { } -std::string Thumbnail::Generate(std::string& error_hint) +std::string Thumbnail::Generate(std::string& error_hint) { - std::string output_file; - glib::Object file(::g_file_new_for_uri(uri_.c_str())); GError *err = NULL; @@ -357,22 +501,31 @@ std::string Thumbnail::Generate(std::string& error_hint) return ""; } + mkdir(get_preview_dir().c_str(), S_IRWXU); + std::string file_type = g_file_info_get_attribute_string(file_info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); - Thumbnailer::Ptr thumbnailer = ThumbnailGeneratorImpl::GetThumbnailer(file_type, error_hint); - if (!thumbnailer) - return ""; + std::list thumbnailers = ThumbnailGeneratorImpl::GetThumbnailers(file_type, error_hint); std::hash hash_fn; - std::stringstream ss_output; ss_output << "/home/nick/test_thumbnails/" << hash_fn(uri_) << ".png"; - output_file = ss_output.str(); + std::stringstream ss_output; + ss_output << get_preview_dir() << "/"; + ss_output << hash_fn(uri_) << ".png"; - if (!thumbnailer->Run(size_, uri_, output_file, error_hint)) + std::string output_file; + for (Thumbnailer::Ptr const& thumbnailer : thumbnailers) { - return ""; - } + output_file = ss_output.str(); - return output_file; + if (thumbnailer->Run(size_, uri_, output_file, error_hint)) + { + error_hint.clear(); + return output_file; + } + } + if (error_hint == "") + error_hint = "Could not find thumbnailer"; + return ""; } diff --git a/unity-shared/ThumbnailGenerator.h b/unity-shared/ThumbnailGenerator.h index 7ea5c348e..f786f3d22 100644 --- a/unity-shared/ThumbnailGenerator.h +++ b/unity-shared/ThumbnailGenerator.h @@ -23,6 +23,7 @@ #define UNITYSHARED_THUMBNAILGENERATOR_H #include +#include "UnityCore/GLibWrapper.h" namespace unity { @@ -37,7 +38,27 @@ public: virtual bool Run(int size, std::string const& input_file, std::string& output_file, std::string& error_hint) = 0; }; +class ThumbnailNotifier : public nux::Object +{ +public: + typedef nux::ObjectPtr Ptr; + NUX_DECLARE_OBJECT_TYPE(ThumbnailNotifier, Object); + + ThumbnailNotifier(); + + void Cancel(); + bool IsCancelled() const; + + sigc::signal ready; + sigc::signal error; + +private: + glib::Object cancel_; +}; + + class ThumbnailGeneratorImpl; + class ThumbnailGenerator { public: @@ -48,10 +69,9 @@ public: static void RegisterThumbnailer(std::list mime_types, Thumbnailer::Ptr thumbnailer); - unsigned int GetThumbnail(std::string const& uri, int size); + ThumbnailNotifier::Ptr GetThumbnail(std::string const& uri, int size); - sigc::signal ready; - sigc::signal error; + void DoCleanup(); protected: std::unique_ptr pimpl; diff --git a/unity-shared/UserThumbnailProvider.cpp b/unity-shared/UserThumbnailProvider.cpp index 310a74f6f..2b8511480 100644 --- a/unity-shared/UserThumbnailProvider.cpp +++ b/unity-shared/UserThumbnailProvider.cpp @@ -72,6 +72,13 @@ bool UserThumbnailer::Run(int size, std::string const& input_file, std::string& g_error_free (err); return false; } + else if (exit_status != 0) + { + std::stringstream ss; + ss << "Failed to create thumbnail. Program exited with exit_status=" << exit_status; + error_hint = ss.str(); + return false; + } return true; } -- cgit v1.2.3 From fb22988a2e398d3c3bc76de6e8940a4d4c49b916 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Tue, 7 Aug 2012 13:27:24 +0100 Subject: Fixed preview info hint name width (bzr r2419.4.41) --- unity-shared/PreviewStyle.cpp | 5 +++++ unity-shared/PreviewStyle.h | 2 ++ 2 files changed, 7 insertions(+) (limited to 'unity-shared') diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp index 5947166fe..4935241ca 100644 --- a/unity-shared/PreviewStyle.cpp +++ b/unity-shared/PreviewStyle.cpp @@ -198,6 +198,11 @@ int Style::GetDetailsPanelMinimumWidth() const return 300; } +int Style::GetInfoHintNameWidth() const +{ + return 100; +} + std::string Style::title_font() const { return "Ubuntu 22"; diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h index e81f5217c..88466f138 100644 --- a/unity-shared/PreviewStyle.h +++ b/unity-shared/PreviewStyle.h @@ -74,6 +74,8 @@ public: int GetDetailsPanelMinimumWidth() const; + int GetInfoHintNameWidth() const; + std::string title_font() const; std::string subtitle_size_font() const; -- cgit v1.2.3 From 527087c37011d0be73223561f903bb15e5d1d98f Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Tue, 7 Aug 2012 15:20:06 +0100 Subject: Merger Proposal fixes. (bzr r2419.4.42) --- unity-shared/PreviewStyle.cpp | 20 ++++++++++++++++++++ unity-shared/PreviewStyle.h | 5 +++++ 2 files changed, 25 insertions(+) (limited to 'unity-shared') diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp index 4935241ca..aa21b642c 100644 --- a/unity-shared/PreviewStyle.cpp +++ b/unity-shared/PreviewStyle.cpp @@ -198,11 +198,31 @@ int Style::GetDetailsPanelMinimumWidth() const return 300; } +int Style::GetInfoHintIconSizeWidth() const +{ + return 24; +} + int Style::GetInfoHintNameWidth() const { return 100; } +float Style::GetDescriptionLineSpacing() const +{ + return 2.0; +} + +int Style::GetDescriptionLineCount() const +{ + return 20; +} + +int Style::GetRatingWidgetHeight() const +{ + return 36; +} + std::string Style::title_font() const { return "Ubuntu 22"; diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h index 88466f138..321d748ab 100644 --- a/unity-shared/PreviewStyle.h +++ b/unity-shared/PreviewStyle.h @@ -74,8 +74,13 @@ public: int GetDetailsPanelMinimumWidth() const; + int GetInfoHintIconSizeWidth() const; int GetInfoHintNameWidth() const; + float GetDescriptionLineSpacing() const; + int GetDescriptionLineCount() const; + + int GetRatingWidgetHeight() const; std::string title_font() const; std::string subtitle_size_font() const; -- cgit v1.2.3 From 12d82b0f19c9bb3bb041ed4dd0da9ff6b9236d65 Mon Sep 17 00:00:00 2001 From: Gord Allott Date: Tue, 7 Aug 2012 15:34:04 +0100 Subject: removed a lot of the old code for handling background animations we aren't doing anymore (bzr r2419.6.12) --- unity-shared/UBusMessages.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/UBusMessages.h b/unity-shared/UBusMessages.h index 65bec9786..2126fd7df 100644 --- a/unity-shared/UBusMessages.h +++ b/unity-shared/UBusMessages.h @@ -81,9 +81,9 @@ #define UBUS_DASH_SIZE_CHANGED "DASH_SIZE_CHANGED" // FIXME - fix the nux focus api so we don't need this #define UBUS_RESULT_VIEW_KEYNAV_CHANGED "RESULT_VIEW_KEYNAV_CHANGED" -#define UBUS_RESULT_VIEW_EXPLICIT_SCROLL_POSITION "RESULT_VIEW_EXPLICIT_SCROLL_POSITION" -#define UBUS_DASH_SET_SEARCH_VISIBILITY "DASH_SET_SEARCH_VISIBILITY" +// for communicating positions to the preview state machine (ii) +#define UBUS_DASH_SPLIT_COORD_CHANGED "DASH_SPLIT_COORD_CHANGED" // Sends a string datatype containing the new icon name #define UBUS_HUD_ICON_CHANGED "HUD_ICON_CHANGED" -- cgit v1.2.3 From 03fa642aecd3c5b73d20357b5cf5c8fea9cad430 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Tue, 7 Aug 2012 16:46:38 +0100 Subject: Added new preview assets and IconTexture for their correct display. (bzr r2419.4.43) --- unity-shared/CoverArt.cpp | 9 +++--- unity-shared/IconTexture.cpp | 75 ++++++++++++++++++++++++++++++++++++------- unity-shared/IconTexture.h | 8 +++++ unity-shared/PreviewStyle.cpp | 23 ++++++++++--- unity-shared/PreviewStyle.h | 4 +++ 5 files changed, 98 insertions(+), 21 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/CoverArt.cpp b/unity-shared/CoverArt.cpp index a158e4acc..5985a32df 100644 --- a/unity-shared/CoverArt.cpp +++ b/unity-shared/CoverArt.cpp @@ -248,11 +248,10 @@ void CoverArt::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) texxform.u1 = imageDest.width; texxform.v1 = imageDest.height; - int border_width = 1; - gfx_engine.QRP_1Tex(base.x + (float(base.GetWidth() - imageDest.GetWidth()) / 2) + border_width, - base.y + (float(base.GetHeight() - imageDest.GetHeight()) / 2) + border_width, - imageDest.width - (border_width * 2), - imageDest.height - (border_width * 2), + gfx_engine.QRP_1Tex(base.x + (float(base.GetWidth() - imageDest.GetWidth()) / 2), + base.y + (float(base.GetHeight() - imageDest.GetHeight()) / 2), + imageDest.width, + imageDest.height, texture_screenshot_.GetPointer()->GetDeviceTexture(), texxform, nux::color::White); diff --git a/unity-shared/IconTexture.cpp b/unity-shared/IconTexture.cpp index f97e5eb43..c324a2e29 100644 --- a/unity-shared/IconTexture.cpp +++ b/unity-shared/IconTexture.cpp @@ -51,7 +51,8 @@ IconTexture::IconTexture(nux::BaseTexture* texture, guint width, guint height) _texture_size(width, height), _loading(false), _opacity(1.0f), - _handle(0) + _handle(0), + _draw_mode(DrawMode::NORMAL) { SetMinMaxSize(width, height); } @@ -63,7 +64,8 @@ IconTexture::IconTexture(std::string const& icon_name, unsigned int size, bool d _size(size), _loading(false), _opacity(1.0f), - _handle(0) + _handle(0), + _draw_mode(DrawMode::NORMAL) { if (!icon_name.empty () && !defer_icon_loading) LoadIcon(); @@ -187,16 +189,60 @@ void IconTexture::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) { nux::Color col(1.0f * _opacity, 1.0f * _opacity, 1.0f * _opacity, _opacity); nux::TexCoordXForm texxform; - texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD); - texxform.SetWrap(nux::TEXWRAP_CLAMP_TO_BORDER, nux::TEXWRAP_CLAMP_TO_BORDER); - - GfxContext.QRP_1Tex(geo.x + ((geo.width - _texture_size.width) / 2), - geo.y + ((geo.height - _texture_size.height) / 2), - _texture_size.width, - _texture_size.height, - _texture_cached->GetDeviceTexture(), - texxform, - col); + + if (_draw_mode == DrawMode::STRETCH_WITH_ASPECT) + { + nux::Geometry imageDest = geo; + + float geo_apsect = float(geo.GetWidth()) / geo.GetHeight(); + float image_aspect = float(_texture_cached->GetWidth()) / _texture_cached->GetHeight(); + + if (image_aspect > geo_apsect) + { + imageDest.SetHeight(float(imageDest.GetWidth()) / image_aspect); + } + if (image_aspect < geo_apsect) + { + imageDest.SetWidth(image_aspect * imageDest.GetHeight()); + } + else + { + imageDest = nux::Geometry(0, 0, _texture_cached->GetWidth(), _texture_cached->GetHeight()); + } + + 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; + + int border_width = 1; + GfxContext.QRP_1Tex(geo.x + (float(geo.GetWidth() - imageDest.GetWidth()) / 2) + border_width, + geo.y + (float(geo.GetHeight() - imageDest.GetHeight()) / 2) + border_width, + imageDest.width - (border_width * 2), + imageDest.height - (border_width * 2), + _texture_cached.GetPointer()->GetDeviceTexture(), + texxform, + nux::color::White); + } + else + { + texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD); + texxform.SetWrap(nux::TEXWRAP_CLAMP_TO_BORDER, nux::TEXWRAP_CLAMP_TO_BORDER); + + GfxContext.QRP_1Tex(geo.x + ((geo.width - _texture_size.width) / 2), + geo.y + ((geo.height - _texture_size.height) / 2), + _texture_size.width, + _texture_size.height, + _texture_cached->GetDeviceTexture(), + texxform, + col); + } + + } GfxContext.PopClippingRectangle(); @@ -259,4 +305,9 @@ bool IconTexture::AcceptKeyNavFocus() return _accept_key_nav_focus; } +void IconTexture::SetDrawMode(DrawMode mode) +{ + _draw_mode = mode; + QueueDraw(); +} } diff --git a/unity-shared/IconTexture.h b/unity-shared/IconTexture.h index 88428733c..83364a1f7 100644 --- a/unity-shared/IconTexture.h +++ b/unity-shared/IconTexture.h @@ -54,6 +54,13 @@ public: nux::BaseTexture* texture(); + enum class DrawMode + { + NORMAL, + STRETCH_WITH_ASPECT + }; + void SetDrawMode(DrawMode mode); + sigc::signal texture_updated; protected: @@ -83,6 +90,7 @@ private: bool _loading; float _opacity; int _handle; + DrawMode _draw_mode; }; } diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp index aa21b642c..be43aac33 100644 --- a/unity-shared/PreviewStyle.cpp +++ b/unity-shared/PreviewStyle.cpp @@ -62,10 +62,10 @@ 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") + , 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) { } ~Impl() {} @@ -113,6 +113,11 @@ int Style::GetNavigatorWidth() const return 42; } +int Style::GetNavigatorIconSize() const +{ + return 24; +} + int Style::GetPreviewPreferredHeight() const { return 390; @@ -168,6 +173,11 @@ int Style::GetTrackHeight() const return 28; } +int Style::GetMusicDurationWidth() const +{ + return 40; +} + int Style::GetActionButtonHeight() const { return 36; @@ -223,6 +233,11 @@ int Style::GetRatingWidgetHeight() const return 36; } +int Style::GetStatusIconSize() const +{ + return 12; +} + std::string Style::title_font() const { return "Ubuntu 22"; diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h index 321d748ab..38c965c88 100644 --- a/unity-shared/PreviewStyle.h +++ b/unity-shared/PreviewStyle.h @@ -57,6 +57,8 @@ public: static Style& Instance(); int GetNavigatorWidth() const; + int GetNavigatorIconSize() const; + int GetPreviewPreferredHeight() const; int GetPreviewPreferredWidth() const; @@ -111,6 +113,8 @@ public: //////////////////////////////// // Movie Preview int GetTrackBarHeight() const; + int GetMusicDurationWidth() const; + int GetStatusIconSize() const; //////////////////////////////// nux::BaseTexture* GetNavLeftIcon(); -- cgit v1.2.3 From 82388cb34832d16274979c61ed0ae51487a744f3 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Tue, 7 Aug 2012 17:28:24 +0100 Subject: Fixed preview svg thumbnail rendering (bzr r2419.4.44) --- unity-shared/CoverArt.cpp | 109 +++++++++++++++++++++--------- unity-shared/TextureThumbnailProvider.cpp | 11 ++- 2 files changed, 87 insertions(+), 33 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/CoverArt.cpp b/unity-shared/CoverArt.cpp index 5985a32df..0b41a3af9 100644 --- a/unity-shared/CoverArt.cpp +++ b/unity-shared/CoverArt.cpp @@ -23,6 +23,7 @@ #include "CoverArt.h" #include "unity-shared/IntrospectableWrappers.h" +#include "unity-shared/CairoTexture.h" #include #include #include "DashStyle.h" @@ -38,6 +39,8 @@ namespace previews namespace { nux::logging::Logger logger("unity.dash.previews.coverart"); + +const int icon_width = 256; } NUX_IMPLEMENT_OBJECT_TYPE(CoverArt); @@ -130,12 +133,12 @@ void CoverArt::SetImage(std::string const& image_hint) else if (G_IS_ICON(icon)) { StartWaiting(); - slot_handle_ = IconLoader::GetDefault().LoadFromGIconString(image_hint, 128, sigc::mem_fun(this, &CoverArt::IconLoaded)); + slot_handle_ = IconLoader::GetDefault().LoadFromGIconString(image_hint, icon_width, sigc::mem_fun(this, &CoverArt::IconLoaded)); } else { StartWaiting(); - slot_handle_ = IconLoader::GetDefault().LoadFromIconName(image_hint, 128, sigc::mem_fun(this, &CoverArt::IconLoaded)); + slot_handle_ = IconLoader::GetDefault().LoadFromIconName(image_hint, icon_width, sigc::mem_fun(this, &CoverArt::IconLoaded)); } if (icon != NULL) @@ -179,25 +182,75 @@ void CoverArt::StartWaiting() void CoverArt::IconLoaded(std::string const& texid, unsigned size, glib::Object const& pixbuf) { - if (GetLayout()) - GetLayout()->RemoveChildObject(overlay_text_); + int height = size; - slot_handle_ = 0; - stretch_image_ = false; - texture_screenshot_.Release(); - waiting_ = false; - spinner_timeout_.reset(); + int pixbuf_width, pixbuf_height; + pixbuf_width = gdk_pixbuf_get_width(pixbuf); + pixbuf_height = gdk_pixbuf_get_height(pixbuf); + if (G_UNLIKELY(!pixbuf_height || !pixbuf_width)) + { + pixbuf_width = (pixbuf_width) ? pixbuf_width : 1; // no zeros please + pixbuf_height = (pixbuf_height) ? pixbuf_height: 1; // no zeros please + } - if (pixbuf) + if (pixbuf_width == pixbuf_height) { - texture_screenshot_.Adopt(nux::CreateTextureFromPixbuf(pixbuf)); - + // quick path for square icons + texture_screenshot_.Adopt(nux::CreateTexture2DFromPixbuf(pixbuf, true)); QueueDraw(); } - else if (GetLayout()) + else { - GetLayout()->AddView(overlay_text_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL, 100.0, nux::LayoutPosition(1)); - ComputeContentSize(); + // slow path for non square icons that must be resized to fit in the square + // texture + + float aspect = static_cast(pixbuf_height) / pixbuf_width; // already sanitized width/height so can not be 0.0 + if (aspect < 1.0f) + { + pixbuf_width = icon_width; + pixbuf_height = pixbuf_width * aspect; + + if (pixbuf_height > height) + { + // scaled too big, scale down + pixbuf_height = height; + pixbuf_width = pixbuf_height / aspect; + } + } + else + { + pixbuf_height = height; + pixbuf_width = pixbuf_height / aspect; + } + + if (gdk_pixbuf_get_height(pixbuf) == pixbuf_height) + { + // we changed our mind, fast path is good + texture_screenshot_.Adopt(nux::CreateTexture2DFromPixbuf(pixbuf, true)); + QueueDraw(); + return; + } + + nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, pixbuf_width, pixbuf_height); + cairo_t* cr = cairo_graphics.GetInternalContext(); + + cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); + cairo_paint(cr); + + float scale = float(pixbuf_height) / gdk_pixbuf_get_height(pixbuf); + + //cairo_translate(cr, + // static_cast((width - (pixbuf_width * scale)) * 0.5), + // static_cast((height - (pixbuf_height * scale)) * 0.5)); + + cairo_scale(cr, scale, scale); + + cairo_set_operator(cr, CAIRO_OPERATOR_OVER); + gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); + cairo_paint(cr); + + texture_screenshot_.Adopt(texture_from_cairo_graphics(cairo_graphics)); + QueueDraw(); } } @@ -208,10 +261,9 @@ void CoverArt::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) gfx_engine.PushClippingRectangle(base); nux::GetPainter().PaintBackground(gfx_engine, base); - if (texture_screenshot_) - { - nux::Geometry imageDest = base; - nux::TexCoordXForm texxform; + 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, @@ -219,6 +271,11 @@ void CoverArt::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) base.GetHeight(), nux::Color(0.03f, 0.03f, 0.03f, 0.0f)); + if (texture_screenshot_) + { + nux::Geometry imageDest = base; + nux::TexCoordXForm texxform; + if (stretch_image_ || base.GetWidth() < texture_screenshot_->GetWidth() || base.height < texture_screenshot_->GetHeight()) { float base_apsect = float(base.GetWidth()) / base.GetHeight(); @@ -258,16 +315,6 @@ void CoverArt::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) } 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.03f, 0.03f, 0.03f, 0.0f)); - if (waiting_) { nux::TexCoordXForm texxform; @@ -309,9 +356,9 @@ void CoverArt::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) frame_timeout_.reset(new glib::Timeout(22, sigc::mem_fun(this, &CoverArt::OnFrameTimeout))); } } - - gfx_engine.GetRenderStates().SetBlend(alpha, src, dest); } + + gfx_engine.GetRenderStates().SetBlend(alpha, src, dest); gfx_engine.PopClippingRectangle(); } diff --git a/unity-shared/TextureThumbnailProvider.cpp b/unity-shared/TextureThumbnailProvider.cpp index a32b8cd92..128daf8bf 100644 --- a/unity-shared/TextureThumbnailProvider.cpp +++ b/unity-shared/TextureThumbnailProvider.cpp @@ -63,8 +63,15 @@ bool GdkTextureThumbnailer::Run(int size, std::string const& input_file, std::st return false; } - glib::Object source_pixbuf(gdk_pixbuf_new_from_stream (G_INPUT_STREAM (stream), - NULL, &error)); + glib::Object source_pixbuf(::gdk_pixbuf_new_from_stream_at_scale(G_INPUT_STREAM (stream), + -1, + size, + TRUE, + NULL, + NULL)); + + // glib::Object source_pixbuf(gdk_pixbuf_new_from_stream (G_INPUT_STREAM (stream), + // NULL, &error)); g_object_unref (stream); if (error != NULL) -- cgit v1.2.3 From 8e00d4dc94d87a1b3351e7ef5f62c56c46ac46a6 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Tue, 7 Aug 2012 17:58:09 +0100 Subject: Fixed icon cover-art timeout bug (bzr r2419.4.46) --- unity-shared/CoverArt.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/CoverArt.cpp b/unity-shared/CoverArt.cpp index 0b41a3af9..af5dff168 100644 --- a/unity-shared/CoverArt.cpp +++ b/unity-shared/CoverArt.cpp @@ -73,7 +73,11 @@ CoverArt::~CoverArt() } void CoverArt::SetImage(std::string const& image_hint) -{ +{ + spinner_timeout_.reset(); + frame_timeout_.reset(); + waiting_ = false; + if (slot_handle_ > 0) { IconLoader::GetDefault().DisconnectHandle(slot_handle_); @@ -100,8 +104,6 @@ void CoverArt::SetImage(std::string const& image_hint) { // for files on disk, we stretch to maximum aspect ratio. stretch_image_ = true; - spinner_timeout_.reset(); - waiting_ = false; GFileInputStream *stream; GError *error = NULL; @@ -156,6 +158,9 @@ void CoverArt::GenerateImage(std::string const& uri) void CoverArt::StartWaiting() { + if (waiting_) + return; + waiting_ = true; rotate_matrix_.Rotate_z(0.0f); @@ -182,6 +187,13 @@ void CoverArt::StartWaiting() void CoverArt::IconLoaded(std::string const& texid, unsigned size, glib::Object const& pixbuf) { + // Finished waiting + spinner_timeout_.reset(); + frame_timeout_.reset(); + waiting_ = false; + + stretch_image_ = false; + int height = size; int pixbuf_width, pixbuf_height; -- cgit v1.2.3 From e5ced20c8b6674892502b8be9f8454ae02e9daed Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Wed, 8 Aug 2012 10:38:10 +0100 Subject: Improved movie previews. (bzr r2419.4.47) --- unity-shared/PreviewStyle.cpp | 16 ++++++++++++++++ unity-shared/PreviewStyle.h | 3 +++ 2 files changed, 19 insertions(+) (limited to 'unity-shared') diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp index be43aac33..8dd27c8df 100644 --- a/unity-shared/PreviewStyle.cpp +++ b/unity-shared/PreviewStyle.cpp @@ -238,14 +238,21 @@ int Style::GetStatusIconSize() const return 12; } +float Style::GetVideoImageAspectRatio() const +{ + return float(540)/380; +} + std::string Style::title_font() const { return "Ubuntu 22"; } + std::string Style::subtitle_size_font() const { return "Ubuntu 12.5"; } + std::string Style::description_font() const { return "Ubuntu Light 10"; @@ -255,10 +262,12 @@ std::string Style::app_license_font() const { return "Ubuntu Light 10"; } + std::string Style::app_last_update_font() const { return "Ubuntu Light 10"; } + std::string Style::app_copywrite_font() const { return "Ubuntu Light 10"; @@ -268,10 +277,17 @@ std::string Style::info_hint_font() const { return "Ubuntu Light 10"; } + +std::string Style::info_hint_bold_font() const +{ + return "Ubuntu Bold 10"; +} + std::string Style::user_rating_font() const { return "Ubuntu Light 10"; } + std::string Style::no_preview_image_font() const { return "Ubuntu Light 16"; diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h index 38c965c88..a63a5b3de 100644 --- a/unity-shared/PreviewStyle.h +++ b/unity-shared/PreviewStyle.h @@ -94,6 +94,7 @@ public: std::string app_last_update_font() const; std::string app_copywrite_font() const; std::string info_hint_font() const; + std::string info_hint_bold_font() const; std::string user_rating_font() const; std::string no_preview_image_font() const; @@ -112,6 +113,8 @@ public: //////////////////////////////// // Movie Preview + float GetVideoImageAspectRatio() const; + int GetTrackBarHeight() const; int GetMusicDurationWidth() const; int GetStatusIconSize() const; -- cgit v1.2.3 From 1e65a8a4820325a78c36c25a56826eb5255113c9 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Wed, 8 Aug 2012 10:42:33 +0100 Subject: Increased thumbnail age limit. (bzr r2419.4.48) --- unity-shared/ThumbnailGenerator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/ThumbnailGenerator.cpp b/unity-shared/ThumbnailGenerator.cpp index f4183401e..e6d03ec14 100644 --- a/unity-shared/ThumbnailGenerator.cpp +++ b/unity-shared/ThumbnailGenerator.cpp @@ -40,8 +40,8 @@ namespace nux::logging::Logger logger("unity.thumbnailgenerator"); ThumbnailGenerator* thumbnail_instance = nullptr; - const unsigned int CLEANUP_DURATION = 10*1000; - const unsigned int CLEANUP_PREVIEW_AGE = 60*1000; + const unsigned int CLEANUP_DURATION = 60*1000; // 1 minute + const unsigned int CLEANUP_PREVIEW_AGE = 6*60*60*1000; // 6 hours static std::multimap thumbnail_content_map; static std::map thumbnailers_; -- cgit v1.2.3 From f7dfaa9d167401ec0f681a8d508b113e85ca3140 Mon Sep 17 00:00:00 2001 From: Gord Allott Date: Wed, 8 Aug 2012 17:56:18 +0100 Subject: fixed bunch of small bugs woo (bzr r2419.6.13) --- unity-shared/UBusMessages.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/UBusMessages.h b/unity-shared/UBusMessages.h index 2126fd7df..777217e0c 100644 --- a/unity-shared/UBusMessages.h +++ b/unity-shared/UBusMessages.h @@ -82,8 +82,14 @@ // FIXME - fix the nux focus api so we don't need this #define UBUS_RESULT_VIEW_KEYNAV_CHANGED "RESULT_VIEW_KEYNAV_CHANGED" -// for communicating positions to the preview state machine (ii) -#define UBUS_DASH_SPLIT_COORD_CHANGED "DASH_SPLIT_COORD_CHANGED" +// for communicating positions to the preview state machine (iii) +// (split y coord in absolute geometry, results to the left, results to the right) +#define UBUS_DASH_PREVIEW_INFO_PAYLOAD "DASH_PREVIEW_INFO_PAYLOAD" + +// called when previews wish to navigate left/right or close (is) +// -1 = left, 0 = close, 1 = right, +// string is the uri string that last result activated was +#define UBUS_DASH_PREVIEW_NAVIGATION_REQUEST "DASH_PREVIEW_NAVIGATION_REQUEST" // Sends a string datatype containing the new icon name #define UBUS_HUD_ICON_CHANGED "HUD_ICON_CHANGED" -- cgit v1.2.3 From 8f916207583699241f72d3465d6b0b2da303cf51 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Thu, 9 Aug 2012 15:04:39 +0100 Subject: Fixed typo in thumbnail generator log string (bzr r2419.4.51) --- unity-shared/ThumbnailGenerator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'unity-shared') diff --git a/unity-shared/ThumbnailGenerator.cpp b/unity-shared/ThumbnailGenerator.cpp index e6d03ec14..e94d0d5af 100644 --- a/unity-shared/ThumbnailGenerator.cpp +++ b/unity-shared/ThumbnailGenerator.cpp @@ -447,7 +447,7 @@ ThumbnailGenerator& ThumbnailGenerator::Instance() { if (!thumbnail_instance) { - LOG_ERROR(logger) << "No panel::Style created yet."; + LOG_ERROR(logger) << "No thumbnail generator created yet."; } return *thumbnail_instance; -- cgit v1.2.3 From 36d5f5bd7de1457d455d9d6239766909586d0b4c Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Thu, 9 Aug 2012 16:03:58 +0100 Subject: Added check for null pixbuffers in CoverArt iconloader. (bzr r2419.4.53) --- unity-shared/CoverArt.cpp | 56 ++++++++++++++++++++++++++++------------------- unity-shared/CoverArt.h | 1 + 2 files changed, 35 insertions(+), 22 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/CoverArt.cpp b/unity-shared/CoverArt.cpp index af5dff168..5854fdbfe 100644 --- a/unity-shared/CoverArt.cpp +++ b/unity-shared/CoverArt.cpp @@ -84,9 +84,6 @@ void CoverArt::SetImage(std::string const& image_hint) slot_handle_ = 0; } - if (GetLayout()) - GetLayout()->RemoveChildObject(overlay_text_); - GIcon* icon = g_icon_new_for_string(image_hint.c_str(), NULL); glib::Object image_file; @@ -125,22 +122,27 @@ void CoverArt::SetImage(std::string const& image_hint) texture_screenshot_.Adopt(nux::CreateTexture2DFromPixbuf(pixbuf, true)); - if (!texture_screenshot_ && GetLayout()) + if (!texture_screenshot_) { - GetLayout()->AddView(overlay_text_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL, 100.0, nux::LayoutPosition(1)); - ComputeContentSize(); + SetNoImageAvailable(); } QueueDraw(); } - else if (G_IS_ICON(icon)) - { - StartWaiting(); - slot_handle_ = IconLoader::GetDefault().LoadFromGIconString(image_hint, icon_width, sigc::mem_fun(this, &CoverArt::IconLoaded)); - } else { - StartWaiting(); - slot_handle_ = IconLoader::GetDefault().LoadFromIconName(image_hint, icon_width, sigc::mem_fun(this, &CoverArt::IconLoaded)); + if (GetLayout()) + GetLayout()->RemoveChildObject(overlay_text_); + + if (G_IS_ICON(icon)) + { + StartWaiting(); + slot_handle_ = IconLoader::GetDefault().LoadFromGIconString(image_hint, icon_width, sigc::mem_fun(this, &CoverArt::IconLoaded)); + } + else + { + StartWaiting(); + slot_handle_ = IconLoader::GetDefault().LoadFromIconName(image_hint, icon_width, sigc::mem_fun(this, &CoverArt::IconLoaded)); + } } if (icon != NULL) @@ -171,29 +173,39 @@ void CoverArt::StartWaiting() texture_screenshot_.Release(); waiting_ = false; - if (GetLayout()) - { - GetLayout()->RemoveChildObject(overlay_text_); - GetLayout()->AddView(overlay_text_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL, 100.0, nux::LayoutPosition(1)); - ComputeContentSize(); - } - - QueueDraw(); + SetNoImageAvailable(); return false; })); QueueDraw(); } +void CoverArt::SetNoImageAvailable() +{ + if (GetLayout()) + { + GetLayout()->RemoveChildObject(overlay_text_); + GetLayout()->AddView(overlay_text_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL, 100.0, nux::LayoutPosition(1)); + ComputeContentSize(); + + QueueDraw(); + } +} + void CoverArt::IconLoaded(std::string const& texid, unsigned size, glib::Object const& pixbuf) { // Finished waiting spinner_timeout_.reset(); frame_timeout_.reset(); waiting_ = false; - stretch_image_ = false; + if (!pixbuf) + { + SetNoImageAvailable(); + return; + } + int height = size; int pixbuf_width, pixbuf_height; diff --git a/unity-shared/CoverArt.h b/unity-shared/CoverArt.h index a4a61b84c..13b33cb25 100644 --- a/unity-shared/CoverArt.h +++ b/unity-shared/CoverArt.h @@ -71,6 +71,7 @@ protected: void IconLoaded(std::string const& texid, unsigned size, glib::Object const& pixbuf); void StartWaiting(); + void SetNoImageAvailable(); private: nux::ObjectPtr texture_screenshot_; -- cgit v1.2.3 From e5fabcfdf958791e637471cc7559a23f94955f5c Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Fri, 10 Aug 2012 09:47:30 +0100 Subject: Fixed indentation (bzr r2419.4.56) --- unity-shared/CoverArt.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/CoverArt.cpp b/unity-shared/CoverArt.cpp index 5854fdbfe..4b5e21e03 100644 --- a/unity-shared/CoverArt.cpp +++ b/unity-shared/CoverArt.cpp @@ -289,11 +289,11 @@ void CoverArt::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) 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.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_) { -- cgit v1.2.3 From 67afba9fb1e1db24d17f30e2af094613ab283f08 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Fri, 10 Aug 2012 11:11:50 +0100 Subject: Switched thumbnail generation idle sources to timers (bzr r2419.4.58) --- unity-shared/ThumbnailGenerator.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'unity-shared') 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; } -- cgit v1.2.3 From 9af4d7cc86fa9c394bbb15d8570ff5a25c90f41f Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Fri, 10 Aug 2012 11:18:03 +0100 Subject: Use IconLoader for loading image from file; sorts out file io blocking. (bzr r2419.4.59) --- unity-shared/CoverArt.cpp | 69 ++++++++++++++++++++------------------------- unity-shared/CoverArt.h | 1 + unity-shared/IconLoader.cpp | 21 ++++++++++---- 3 files changed, 46 insertions(+), 45 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/CoverArt.cpp b/unity-shared/CoverArt.cpp index 4b5e21e03..14f4d8e12 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 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 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); @@ -278,6 +253,22 @@ void CoverArt::IconLoaded(std::string const& texid, unsigned size, glib::Object< } } +void CoverArt::TextureLoaded(std::string const& texid, unsigned size, glib::Object const& pixbuf) +{ + // Finished waiting + spinner_timeout_.reset(); + frame_timeout_.reset(); + waiting_ = false; + stretch_image_ = false; + + 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(); 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 const& pixbuf); + void TextureLoaded(std::string const& texid, unsigned size, glib::Object 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 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(~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); } } -- cgit v1.2.3 From b522f72dbd3822f601f7ab1259e95886782d2443 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Fri, 10 Aug 2012 13:53:53 +0100 Subject: Stretch full texture (bzr r2419.4.60) --- unity-shared/CoverArt.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/CoverArt.cpp b/unity-shared/CoverArt.cpp index 14f4d8e12..d73687f64 100644 --- a/unity-shared/CoverArt.cpp +++ b/unity-shared/CoverArt.cpp @@ -259,7 +259,7 @@ void CoverArt::TextureLoaded(std::string const& texid, unsigned size, glib::Obje spinner_timeout_.reset(); frame_timeout_.reset(); waiting_ = false; - stretch_image_ = false; + stretch_image_ = true; if (!pixbuf) { @@ -278,7 +278,7 @@ 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, -- cgit v1.2.3 From f4a0ee054ea8806e8216e3152910c46c051204b0 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Fri, 10 Aug 2012 13:55:06 +0100 Subject: Added preview wait spinner. (bzr r2419.4.61) --- unity-shared/PreviewStyle.cpp | 90 +++++++++++++++++++++---------------------- unity-shared/PreviewStyle.h | 1 + 2 files changed, 46 insertions(+), 45 deletions(-) (limited to 'unity-shared') 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 BaseTexturePtr; +template 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 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 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 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; -- cgit v1.2.3 From bb5fe89b31703e61a1d150c1a68881a27279d019 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Fri, 10 Aug 2012 16:04:03 +0100 Subject: New design of preview info hints. (bzr r2419.4.62) --- unity-shared/CoverArt.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/CoverArt.cpp b/unity-shared/CoverArt.cpp index d73687f64..c6949d499 100644 --- a/unity-shared/CoverArt.cpp +++ b/unity-shared/CoverArt.cpp @@ -237,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((width - (pixbuf_width * scale)) * 0.5), - // static_cast((height - (pixbuf_height * scale)) * 0.5)); - cairo_scale(cr, scale, scale); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); -- cgit v1.2.3 From 4af96d27e4489a8c61dbf26db116cca66b3a8f0d Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Fri, 10 Aug 2012 16:05:10 +0100 Subject: Maximum aspect ratio sourced height for previews. (bzr r2419.4.63) --- unity-shared/PreviewStyle.cpp | 16 ++++++++-------- unity-shared/PreviewStyle.h | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp index 41cbbbd10..56e55bb4a 100644 --- a/unity-shared/PreviewStyle.cpp +++ b/unity-shared/PreviewStyle.cpp @@ -148,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(796)/390; } int Style::GetDetailsTopMargin() const @@ -243,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; diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h index 44c5f1832..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; -- cgit v1.2.3 From d614ab24da6a392d53cdd1cad4fdd7081bdecd9d Mon Sep 17 00:00:00 2001 From: Daniel van Vugt Date: Tue, 14 Aug 2012 14:50:24 +0800 Subject: Fix uninitialized variable warnings, causing build failure (LP: #1036514) You'd only see these errors if you build lp:unity with: -DUSE_MODERN_COMPIZ_GL=ON Fixes LP: #1036514 (bzr r2558.1.1) --- unity-shared/IconRenderer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/IconRenderer.cpp b/unity-shared/IconRenderer.cpp index ed1fa65e6..2c37cc89c 100644 --- a/unity-shared/IconRenderer.cpp +++ b/unity-shared/IconRenderer.cpp @@ -757,8 +757,8 @@ void IconRenderer::RenderElement(nux::GraphicsEngine& GfxContext, CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0)); CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0)); - int VertexLocation; - int TextureCoord0Location; + int VertexLocation = -1; + int TextureCoord0Location = -1; int FragmentColor = 0; int ColorifyColor = 0; int DesatFactor = 0; -- cgit v1.2.3 From 701288c91a6ff396cef7e1631e10e6c432ac0a84 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Wed, 15 Aug 2012 12:23:55 +0100 Subject: Added preview and thumbnail generator unit tests. (bzr r2419.4.67) --- unity-shared/RatingsButton.cpp | 12 ++++++------ unity-shared/RatingsButton.h | 3 +-- unity-shared/ThumbnailGenerator.cpp | 11 ++++++++--- 3 files changed, 15 insertions(+), 11 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/RatingsButton.cpp b/unity-shared/RatingsButton.cpp index b28dab690..c479c65ff 100644 --- a/unity-shared/RatingsButton.cpp +++ b/unity-shared/RatingsButton.cpp @@ -80,6 +80,11 @@ void RatingsButton::SetRating(float rating) QueueDraw(); } +float RatingsButton::GetRating() const +{ + return rating_; +} + void RatingsButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) { int rating = static_cast(rating_ * num_stars); @@ -177,7 +182,7 @@ void RatingsButton::UpdateRatingToMouse(int x) new_rating = ceil((num_stars * 1) * new_rating) / (num_stars * 1); new_rating = (new_rating > 1) ? 1 : ((new_rating < 0) ? 0 : new_rating); - UpdateRating(new_rating); + SetRating(new_rating); } void RatingsButton::RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags) @@ -270,9 +275,4 @@ bool RatingsButton::AcceptKeyNavFocus() return true; } -void RatingsButton::UpdateRating(float rating) -{ - -} - } // namespace unity diff --git a/unity-shared/RatingsButton.h b/unity-shared/RatingsButton.h index 1d33c9ddd..9364c0f2c 100644 --- a/unity-shared/RatingsButton.h +++ b/unity-shared/RatingsButton.h @@ -40,6 +40,7 @@ public: void SetEditable(bool editable); virtual void SetRating(float rating); + virtual float GetRating() const; protected: virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); @@ -48,8 +49,6 @@ protected: virtual bool AcceptKeyNavFocus(); virtual bool InspectKeyEvent(unsigned int eventType, unsigned int keysym, const char* character); - virtual void UpdateRating(float rating); - private: void OnKeyDown(unsigned long event_type, unsigned long event_keysym, unsigned long event_state, const TCHAR* character, diff --git a/unity-shared/ThumbnailGenerator.cpp b/unity-shared/ThumbnailGenerator.cpp index 0245f5f03..d13be2b9e 100644 --- a/unity-shared/ThumbnailGenerator.cpp +++ b/unity-shared/ThumbnailGenerator.cpp @@ -96,6 +96,7 @@ public: : parent_(parent) , thumbnails_mutex_(PTHREAD_MUTEX_INITIALIZER) , thumbnail_thread_is_running_(false) + , thumbnail_thread_(0) {} ~ThumbnailGeneratorImpl() @@ -198,7 +199,6 @@ ThumbnailNotifier::Ptr ThumbnailGeneratorImpl::GetThumbnail(std::string const& u if (!thread_create_timer_ && thumbnail_thread_is_running_ == false) { - thread_create_timer_.reset(new glib::Timeout(0, [&]() { thumbnail_thread_is_running_ = true; @@ -441,7 +441,8 @@ ThumbnailGenerator::ThumbnailGenerator() ThumbnailGenerator::~ThumbnailGenerator() { - + if (this == thumbnail_instance) + thumbnail_instance = NULL; } ThumbnailGenerator& ThumbnailGenerator::Instance() @@ -497,7 +498,9 @@ std::string Thumbnail::Generate(std::string& error_hint) glib::Object file_info(g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, &err)); if (err != NULL) { - error_hint = err->message; + std::stringstream error_stream; + error_stream << "Could not retrieve file info for '" << uri_ << "'"; + error_hint = error_stream.str(); g_error_free (err); return ""; } @@ -518,6 +521,8 @@ std::string Thumbnail::Generate(std::string& error_hint) { output_file = ss_output.str(); + LOG_TRACE(logger) << "Attempting to generate thumbnail using '" << thumbnailer->GetName() << "' thumbnail provider"; + if (thumbnailer->Run(size_, uri_, output_file, error_hint)) { error_hint.clear(); -- cgit v1.2.3 From 49559f88f8b8fa3eaba9d60cc186eddad46768a9 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Wed, 15 Aug 2012 17:21:08 +0100 Subject: Update text cached texture when maximum size changes. Fixes LP: #1037187 (bzr r2568.1.1) --- unity-shared/StaticCairoText.cpp | 41 +++++++++++++++++++++++++++++++++------- unity-shared/StaticCairoText.h | 3 +++ 2 files changed, 37 insertions(+), 7 deletions(-) (limited to 'unity-shared') diff --git a/unity-shared/StaticCairoText.cpp b/unity-shared/StaticCairoText.cpp index 8f055cbd7..0f51dfb14 100644 --- a/unity-shared/StaticCairoText.cpp +++ b/unity-shared/StaticCairoText.cpp @@ -67,7 +67,7 @@ struct StaticCairoText::Impl StaticCairoText* parent_; bool accept_key_nav_focus_; - bool need_new_extent_cache_; + mutable bool need_new_extent_cache_; // The three following are all set in get text extents. mutable Size cached_extent_; mutable Size cached_base_; @@ -309,6 +309,29 @@ void StaticCairoText::SetText(std::string const& text) } } +void StaticCairoText::SetMaximumSize(int w, int h) +{ + if (w != GetMaximumWidth()) + { + pimpl->need_new_extent_cache_ = true; + View::SetMaximumSize(w, h); + pimpl->UpdateTexture(); + return; + } + + View::SetMaximumSize(w, h); +} + +void StaticCairoText::SetMaximumWidth(int w) +{ + if (w != GetMaximumWidth()) + { + pimpl->need_new_extent_cache_ = true; + View::SetMaximumWidth(w); + pimpl->UpdateTexture(); + } +} + std::string StaticCairoText::GetText() const { return pimpl->text_; @@ -333,12 +356,15 @@ void StaticCairoText::SetTextColor(Color const& textColor) void StaticCairoText::SetFont(std::string const& font) { - pimpl->font_ = font; - pimpl->need_new_extent_cache_ = true; - Size s = GetTextExtents(); - SetMinimumHeight(s.height); - NeedRedraw(); - sigFontChanged.emit(this); + if (pimpl->font_ != font) + { + pimpl->font_ = font; + pimpl->need_new_extent_cache_ = true; + Size s = GetTextExtents(); + SetMinimumHeight(s.height); + NeedRedraw(); + sigFontChanged.emit(this); + } } int StaticCairoText::GetLineCount() const @@ -440,6 +466,7 @@ Size StaticCairoText::Impl::GetTextExtents() const result.height = std::ceil(static_cast(logRect.height) / PANGO_SCALE); cached_extent_ = result; baseline_ = pango_layout_get_baseline(layout) / PANGO_SCALE; + need_new_extent_cache_ = false; // clean up pango_font_description_free(desc); diff --git a/unity-shared/StaticCairoText.h b/unity-shared/StaticCairoText.h index 9fba1fe9d..d3ddf1a8f 100644 --- a/unity-shared/StaticCairoText.h +++ b/unity-shared/StaticCairoText.h @@ -92,6 +92,9 @@ public: void SetAcceptKeyNavFocus(bool accept); + void SetMaximumSize(int w, int h); + void SetMaximumWidth(int w); + protected: // Key navigation virtual bool AcceptKeyNavFocus(); -- cgit v1.2.3 From 7171f7c5620d273111c43dfd2fefb1889354df52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 15 Aug 2012 19:22:33 +0200 Subject: Use SignalManager::Add