diff options
| -rw-r--r-- | dash/DashView.cpp | 6 | ||||
| -rw-r--r-- | dash/previews/ActionButton.cpp | 44 | ||||
| -rw-r--r-- | dash/previews/ActionButton.h | 3 | ||||
| -rw-r--r-- | dash/previews/Preview.cpp | 46 | ||||
| -rw-r--r-- | dash/previews/Preview.h | 3 | ||||
| -rw-r--r-- | dash/previews/PreviewContainer.cpp | 26 | ||||
| -rw-r--r-- | dash/previews/PreviewContainer.h | 3 | ||||
| -rw-r--r-- | dash/previews/PreviewInfoHintWidget.cpp | 77 | ||||
| -rw-r--r-- | dash/previews/PreviewInfoHintWidget.h | 9 | ||||
| -rw-r--r-- | unity-shared/CoverArt.cpp | 19 | ||||
| -rw-r--r-- | unity-shared/CoverArt.h | 3 |
11 files changed, 189 insertions, 50 deletions
diff --git a/dash/DashView.cpp b/dash/DashView.cpp index b9e73439a..085343d6f 100644 --- a/dash/DashView.cpp +++ b/dash/DashView.cpp @@ -238,7 +238,7 @@ void DashView::BuildPreview(Preview::Ptr model) preview_container_->SetParentObject(this); } preview_container_->Preview(model, previews::Navigation::NONE); // no swipe left or right - + preview_container_->scale = cv_->DPIScale(); preview_container_->SetGeometry(scopes_layout_->GetGeometry()); preview_displaying_ = true; @@ -265,6 +265,7 @@ void DashView::BuildPreview(Preview::Ptr model) { // got a new preview whilst already displaying, we probably clicked a navigation button. preview_container_->Preview(model, preview_navigation_mode_); // TODO + preview_container_->scale = cv_->DPIScale(); } if (G_LIKELY(preview_state_machine_.left_results() > 0 && preview_state_machine_.right_results() > 0)) @@ -585,6 +586,9 @@ void DashView::OnDPIChanged() search_bar_->scale = scale; scope_bar_->scale = scale; + + if (preview_container_) + preview_container_->scale = cv_->DPIScale(); } void DashView::UpdateDashViewSize() diff --git a/dash/previews/ActionButton.cpp b/dash/previews/ActionButton.cpp index 2bd21bcb8..ca2d527be 100644 --- a/dash/previews/ActionButton.cpp +++ b/dash/previews/ActionButton.cpp @@ -25,23 +25,25 @@ #include <Nux/HLayout.h> #include "unity-shared/IconTexture.h" #include "unity-shared/StaticCairoText.h" +#include "unity-shared/RawPixel.h" +namespace unity +{ namespace { -const int kMinButtonHeight = 34; -const int kMinButtonWidth = 48; +RawPixel kMinButtonHeight = 34_em; +RawPixel kMinButtonWidth = 48_em; -const int icon_size = 24; +RawPixel icon_size = 24_em; } -namespace unity -{ namespace dash { DECLARE_LOGGER(logger, "unity.dash.preview.action"); ActionButton::ActionButton(std::string const& action_hint, std::string const& label, std::string const& icon_hint, NUX_FILE_LINE_DECL) : nux::AbstractButton(NUX_FILE_LINE_PARAM) + , scale(1.0) , action_hint_(action_hint) , image_(nullptr) { @@ -49,6 +51,7 @@ ActionButton::ActionButton(std::string const& action_hint, std::string const& la SetAcceptKeyNavFocusOnMouseEnter(true); Init(); BuildLayout(label, icon_hint, ""); + scale.changed.connect(sigc::mem_fun(this, &ActionButton::UpdateScale)); } ActionButton::~ActionButton() @@ -94,8 +97,8 @@ void ActionButton::InitTheme() cr_focus_.reset(new nux::CairoWrapper(geo, sigc::mem_fun(this, &ActionButton::RedrawFocusOverlay))); } - SetMinimumHeight(kMinButtonHeight); - SetMinimumWidth(kMinButtonWidth); + SetMinimumHeight(kMinButtonHeight.CP(scale)); + SetMinimumWidth(kMinButtonWidth.CP(scale)); } void ActionButton::SetExtraHint(std::string const& extra_hint, std::string const& font_hint) @@ -123,13 +126,13 @@ void ActionButton::BuildLayout(std::string const& label, std::string const& icon if (!icon_hint_.empty()) { - image_ = new IconTexture(icon_hint, icon_size); + image_ = new IconTexture(icon_hint, icon_size.CP(scale)); image_->texture_updated.connect([this](nux::ObjectPtr<nux::BaseTexture> const&) { BuildLayout(label_, icon_hint_, extra_hint_); }); image_->SetInputEventSensitivity(false); - image_->SetMinMaxSize(icon_size, icon_size); + image_->SetMinMaxSize(icon_size.CP(scale), icon_size.CP(scale)); } } @@ -311,5 +314,28 @@ std::string ActionButton::GetExtraText() const return extra_hint_; } +void ActionButton::UpdateScale(double scale) +{ + SetMinimumHeight(kMinButtonHeight.CP(scale)); + SetMinimumWidth(kMinButtonWidth.CP(scale)); + + if (image_) + { + image_->SetSize(icon_size.CP(scale)); + image_->SetMinMaxSize(icon_size.CP(scale), icon_size.CP(scale)); + image_->ReLoadIcon(); + } + + if (static_text_) + static_text_->SetScale(scale); + + if (extra_text_) + extra_text_->SetScale(scale); + + QueueRelayout(); + QueueDraw(); +} + + } // namespace dash } // namespace unity diff --git a/dash/previews/ActionButton.h b/dash/previews/ActionButton.h index efcfbe37e..81478ff09 100644 --- a/dash/previews/ActionButton.h +++ b/dash/previews/ActionButton.h @@ -59,6 +59,9 @@ public: std::string GetLabel() const; std::string GetExtraText() const; + void UpdateScale(double scale); + nux::Property<double> scale; + protected: virtual long ComputeContentSize(); virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); diff --git a/dash/previews/Preview.cpp b/dash/previews/Preview.cpp index 49d5fbd4c..7e68662b7 100644 --- a/dash/previews/Preview.cpp +++ b/dash/previews/Preview.cpp @@ -38,6 +38,7 @@ #include "MusicPaymentPreview.h" #include "SocialPreview.h" #include "PreviewInfoHintWidget.h" +#include "ActionButton.h" namespace unity { @@ -100,14 +101,17 @@ NUX_IMPLEMENT_OBJECT_TYPE(Preview); Preview::Preview(dash::Preview::Ptr preview_model) : View(NUX_TRACKER_LOCATION) + , scale(1.0) , preview_model_(preview_model) , tab_iterator_(new TabIterator()) , full_data_layout_(nullptr) , image_(nullptr) , title_(nullptr) , subtitle_(nullptr) + , preview_container_(new PreviewContainer) { - preview_container_ = new PreviewContainer; + preview_container_->scale = scale(); + scale.changed.connect(sigc::mem_fun(this, &Preview::UpdateScale)); } Preview::~Preview() @@ -138,13 +142,13 @@ nux::Layout* Preview::BuildGridActionsLayout(dash::Preview::ActionPtrList action previews::Style& style = dash::previews::Style::Instance(); nux::VLayout* actions_layout_v = new nux::VLayout(); - actions_layout_v->SetSpaceBetweenChildren(style.GetSpaceBetweenActions()); + actions_layout_v->SetSpaceBetweenChildren(style.GetSpaceBetweenActions().CP(scale)); uint rows = actions.size() / 2 + ((actions.size() % 2 > 0) ? 1 : 0); uint action_iter = 0; for (uint i = 0; i < rows; i++) { nux::HLayout* actions_layout_h = new TabIteratorHLayout(tab_iterator_); - actions_layout_h->SetSpaceBetweenChildren(style.GetSpaceBetweenActions()); + actions_layout_h->SetSpaceBetweenChildren(style.GetSpaceBetweenActions().CP(scale)); for (uint j = 0; j < 2 && action_iter < actions.size(); j++, action_iter++) { @@ -172,7 +176,7 @@ nux::Layout* Preview::BuildVerticalActionsLayout(dash::Preview::ActionPtrList ac previews::Style& style = dash::previews::Style::Instance(); nux::VLayout* actions_layout_v = new TabIteratorVLayout(tab_iterator_); - actions_layout_v->SetSpaceBetweenChildren(style.GetSpaceBetweenActions()); + actions_layout_v->SetSpaceBetweenChildren(style.GetSpaceBetweenActions().CP(scale)); uint action_iter = 0; for (uint i = 0; i < actions.size(); i++) @@ -215,7 +219,7 @@ void Preview::UpdateCoverArtImage(CoverArt* cover_art) else cover_art->SetNoImageAvailable(); cover_art->SetFont(style.no_preview_image_font()); - + cover_art->mouse_click.connect(on_mouse_down); } @@ -279,6 +283,38 @@ sigc::signal<void> Preview::request_close() const return preview_container_->request_close; } +void Preview::UpdateScale(double scale) +{ + if (image_) + image_->scale = scale; + + if (title_) + title_->SetScale(scale); + if (subtitle_) + subtitle_->SetScale(scale); + if (description_) + description_->SetScale(scale); + + if (preview_container_) + preview_container_->scale = scale; + + if (preview_info_hints_) + preview_info_hints_->scale = scale; + + if (!action_buttons_.empty()) + { + for (nux::AbstractButton* button : action_buttons_) + { + ActionButton* bn = dynamic_cast<ActionButton*>(button); + if (bn) + bn->scale = scale; + } + } + + QueueRelayout(); + QueueDraw(); +} + } } } diff --git a/dash/previews/Preview.h b/dash/previews/Preview.h index c9615b0bb..07fba642b 100644 --- a/dash/previews/Preview.h +++ b/dash/previews/Preview.h @@ -74,6 +74,9 @@ public: unsigned long special_keys_state); virtual nux::Area* KeyNavIteration(nux::KeyNavDirection direction); + nux::Property<double> scale; + void UpdateScale(double scale); + protected: virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw) {} virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) {} diff --git a/dash/previews/PreviewContainer.cpp b/dash/previews/PreviewContainer.cpp index 9f27702a2..6ef3abc60 100644 --- a/dash/previews/PreviewContainer.cpp +++ b/dash/previews/PreviewContainer.cpp @@ -58,7 +58,8 @@ class PreviewContent : public nux::Layout, public debug::Introspectable { public: PreviewContent(PreviewContainer*const parent) - : parent_(parent) + : scale(1.0) + , parent_(parent) , progress_(0.0) , curve_progress_(0.0) , animating_(false) @@ -75,7 +76,18 @@ public: }); Style& style = previews::Style::Instance(); - spin_= style.GetSearchSpinIcon(32); + spin_= style.GetSearchSpinIcon(32_em); + + scale.changed.connect(sigc::mem_fun(this, &PreviewContent::UpdateScale)); + } + + void UpdateScale(double scale) + { + Style& style = previews::Style::Instance(); + spin_ = style.GetSearchSpinIcon((32_em).CP(scale)); + + for (auto* area : GetChildren()) + static_cast<previews::Preview*>(area)->scale = scale; } // From debug::Introspectable @@ -107,6 +119,7 @@ public: AddChild(preview.GetPointer()); AddView(preview.GetPointer()); preview->SetVisible(false); + preview->scale = scale(); } else { @@ -355,6 +368,7 @@ public: sigc::signal<void> start_navigation; sigc::signal<void> continue_navigation; sigc::signal<void> end_navigation; + nux::Property<double> scale; private: PreviewContainer*const parent_; @@ -394,6 +408,7 @@ NUX_IMPLEMENT_OBJECT_TYPE(PreviewContainer); PreviewContainer::PreviewContainer(NUX_FILE_LINE_DECL) : View(NUX_FILE_LINE_PARAM) + , scale(1.0) , preview_layout_(nullptr) , nav_disabled_(Navigation::NONE) , navigation_progress_speed_(0.0) @@ -408,6 +423,7 @@ PreviewContainer::PreviewContainer(NUX_FILE_LINE_DECL) key_down.connect(sigc::mem_fun(this, &PreviewContainer::OnKeyDown)); mouse_click.connect(sigc::mem_fun(this, &PreviewContainer::OnMouseDown)); + scale.changed.connect(sigc::mem_fun(this, &PreviewContainer::UpdateScale)); } PreviewContainer::~PreviewContainer() @@ -694,6 +710,12 @@ nux::Geometry PreviewContainer::GetLayoutGeometry() const return layout_content_->GetAbsoluteGeometry(); } +void PreviewContainer::UpdateScale(double scale) +{ + if (preview_layout_) + preview_layout_->scale = scale; +} + } // namespace previews } // namespace dash } // namespace unity diff --git a/dash/previews/PreviewContainer.h b/dash/previews/PreviewContainer.h index fd1f68d1c..eebaed07a 100644 --- a/dash/previews/PreviewContainer.h +++ b/dash/previews/PreviewContainer.h @@ -74,6 +74,9 @@ public: sigc::signal<void> navigate_right; sigc::signal<void> request_close; + nux::Property<double> scale; + void UpdateScale(double scale); + bool AcceptKeyNavFocus(); nux::Area* KeyNavIteration(nux::KeyNavDirection direction); diff --git a/dash/previews/PreviewInfoHintWidget.cpp b/dash/previews/PreviewInfoHintWidget.cpp index 69844b412..8a77062ae 100644 --- a/dash/previews/PreviewInfoHintWidget.cpp +++ b/dash/previews/PreviewInfoHintWidget.cpp @@ -41,17 +41,19 @@ namespace previews DECLARE_LOGGER(logger, "unity.dash.preview.infohintwidget"); namespace { -const int layout_spacing = 12; +const RawPixel layout_spacing = 12_em; } NUX_IMPLEMENT_OBJECT_TYPE(PreviewInfoHintWidget); PreviewInfoHintWidget::PreviewInfoHintWidget(dash::Preview::Ptr preview_model, int icon_size) : View(NUX_TRACKER_LOCATION) +, scale(1.0) , icon_size_(icon_size) , preview_model_(preview_model) { SetupViews(); + scale.changed.connect(sigc::mem_fun(this, &PreviewInfoHintWidget::UpdateScale)); } PreviewInfoHintWidget::~PreviewInfoHintWidget() @@ -150,43 +152,42 @@ void PreviewInfoHintWidget::SetupViews() auto on_mouse_down = [this](int x, int y, unsigned long button_flags, unsigned long key_flags) { this->preview_container_.OnMouseDown(x, y, button_flags, key_flags); }; - nux::VLayout* layout = new nux::VLayout(); - layout->SetSpaceBetweenChildren(6); + layout_ = new nux::VLayout(); + layout_->SetSpaceBetweenChildren((6_em).CP(scale)); for (dash::Preview::InfoHintPtr info_hint : preview_model_->GetInfoHints()) { - nux::HLayout* hint_layout = new nux::HLayout(); - hint_layout->SetSpaceBetweenChildren(layout_spacing); + hint_layout_ = new nux::HLayout(); + hint_layout_->SetSpaceBetweenChildren(layout_spacing.CP(scale)); - StaticCairoTextPtr info_name; if (!info_hint->display_name.empty()) { // The "%s" is used in the dash preview to display the "<hint>: <value>" infos std::string tmp_display_name = glib::String(g_strdup_printf (_("%s:"), info_hint->display_name.c_str())).Str(); - info_name = new StaticCairoText(tmp_display_name, true, NUX_TRACKER_LOCATION); - info_name->SetFont(style.info_hint_bold_font()); - info_name->SetLines(-1); - info_name->SetTextAlignment(StaticCairoText::NUX_ALIGN_RIGHT); - info_name->mouse_click.connect(on_mouse_down); - hint_layout->AddView(info_name.GetPointer(), 0, nux::MINOR_POSITION_CENTER); + info_name_ = new StaticCairoText(tmp_display_name, true, NUX_TRACKER_LOCATION); + info_name_->SetFont(style.info_hint_bold_font()); + info_name_->SetLines(-1); + info_name_->SetTextAlignment(StaticCairoText::NUX_ALIGN_RIGHT); + info_name_->mouse_click.connect(on_mouse_down); + hint_layout_->AddView(info_name_.GetPointer(), 0, nux::MINOR_POSITION_CENTER); } - StaticCairoTextPtr info_value(new StaticCairoText(StringFromVariant(info_hint->value), true, NUX_TRACKER_LOCATION)); - info_value->SetFont(style.info_hint_font()); - info_value->SetLines(-1); - info_value->mouse_click.connect(on_mouse_down); - hint_layout->AddView(info_value.GetPointer(), 1, nux::MINOR_POSITION_CENTER); + info_value_ = new StaticCairoText(StringFromVariant(info_hint->value), true, NUX_TRACKER_LOCATION); + info_value_->SetFont(style.info_hint_font()); + info_value_->SetLines(-1); + info_value_->mouse_click.connect(on_mouse_down); + hint_layout_->AddView(info_value_.GetPointer(), 1, nux::MINOR_POSITION_CENTER); - InfoHint info_hint_views(info_name, info_value); + InfoHint info_hint_views(info_name_, info_value_); info_hints_.push_back(info_hint_views); - layout->AddLayout(hint_layout, 0); + layout_->AddLayout(hint_layout_, 0); } mouse_click.connect(on_mouse_down); - SetLayout(layout); + SetLayout(layout_); } @@ -198,10 +199,10 @@ void PreviewInfoHintWidget::PreLayoutManagement() int info_hint_width = 0; for (InfoHint const& info_hint : info_hints_) { - int width = style.GetInfoHintNameMinimumWidth(); + RawPixel width = style.GetInfoHintNameMinimumWidth(); if (info_hint.first) { - width = info_hint.first->GetTextExtents().width; + width = (RawPixel)info_hint.first->GetTextExtents().width; if (width < style.GetInfoHintNameMinimumWidth()) width = style.GetInfoHintNameMinimumWidth(); @@ -215,27 +216,45 @@ void PreviewInfoHintWidget::PreLayoutManagement() } } - int info_value_width = geo.width; - info_value_width -= layout_spacing; - info_value_width -= info_hint_width; - info_value_width = MAX(0, info_value_width); + RawPixel info_value_width = geo.width; + info_value_width = info_value_width - layout_spacing; + info_value_width = info_value_width - info_hint_width; + info_value_width = std::max(0_em, info_value_width); for (InfoHint const& info_hint : info_hints_) { if (info_hint.first) { - info_hint.first->SetMinimumWidth(info_hint_width); - info_hint.first->SetMaximumWidth(info_hint_width); + info_hint.first->SetMinimumWidth(((RawPixel)info_hint_width).CP(scale)); + info_hint.first->SetMaximumWidth(((RawPixel)info_hint_width).CP(scale)); } if (info_hint.second) { - info_hint.second->SetMaximumWidth(info_value_width); + info_hint.second->SetMaximumWidth(info_value_width.CP(scale)); } } View::PreLayoutManagement(); } +void PreviewInfoHintWidget::UpdateScale(double scale) +{ + if (info_name_) + info_name_->SetScale(scale); + + if (info_value_) + info_value_->SetScale(scale); + + if (layout_) + layout_->SetSpaceBetweenChildren((6_em).CP(scale)); + + if (hint_layout_) + hint_layout_->SetSpaceBetweenChildren(layout_spacing.CP(scale)); + + QueueRelayout(); + QueueDraw(); +} + } // namespace previews } // namespace dash } // namespace unity diff --git a/dash/previews/PreviewInfoHintWidget.h b/dash/previews/PreviewInfoHintWidget.h index 80604d6a9..81b13cf20 100644 --- a/dash/previews/PreviewInfoHintWidget.h +++ b/dash/previews/PreviewInfoHintWidget.h @@ -58,6 +58,9 @@ public: sigc::signal<void> request_close() const { return preview_container_.request_close; } + void UpdateScale(double scale); + nux::Property<double> scale; + protected: virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw); @@ -82,6 +85,12 @@ protected: dash::Preview::Ptr preview_model_; typedef nux::ObjectPtr<nux::BaseTexture> BaseTexturePtr; + StaticCairoTextPtr info_name_; + StaticCairoTextPtr info_value_; + + nux::VLayout* layout_; + nux::HLayout* hint_layout_; + private: PreviewContainer preview_container_; }; diff --git a/unity-shared/CoverArt.cpp b/unity-shared/CoverArt.cpp index 99f003b8f..79463a122 100644 --- a/unity-shared/CoverArt.cpp +++ b/unity-shared/CoverArt.cpp @@ -42,7 +42,7 @@ DECLARE_LOGGER(logger, "unity.dash.previews.coverart"); namespace { -const int ICON_SIZE = 256; +const RawPixel ICON_SIZE = 256_em; const int IMAGE_TIMEOUT = 30; } @@ -50,6 +50,7 @@ NUX_IMPLEMENT_OBJECT_TYPE(CoverArt); CoverArt::CoverArt() : View(NUX_TRACKER_LOCATION) + , scale (1.0) , overlay_text_(nullptr) , thumb_handle_(0) , slot_handle_(0) @@ -58,6 +59,7 @@ CoverArt::CoverArt() , rotation_(0.0) { SetupViews(); + scale.changed.connect(sigc::mem_fun(this, &CoverArt::UpdateScale)); } CoverArt::~CoverArt() @@ -118,12 +120,12 @@ void CoverArt::SetImage(std::string const& image_hint) if (icon.IsType(G_TYPE_ICON)) { StartWaiting(); - slot_handle_ = IconLoader::GetDefault().LoadFromGIconString(image_hint, ICON_SIZE, ICON_SIZE, sigc::mem_fun(this, &CoverArt::IconLoaded)); + slot_handle_ = IconLoader::GetDefault().LoadFromGIconString(image_hint, ICON_SIZE.CP(scale), ICON_SIZE.CP(scale), sigc::mem_fun(this, &CoverArt::IconLoaded)); } else { StartWaiting(); - slot_handle_ = IconLoader::GetDefault().LoadFromIconName(image_hint, ICON_SIZE, ICON_SIZE, sigc::mem_fun(this, &CoverArt::IconLoaded)); + slot_handle_ = IconLoader::GetDefault().LoadFromIconName(image_hint, ICON_SIZE.CP(scale), ICON_SIZE.CP(scale), sigc::mem_fun(this, &CoverArt::IconLoaded)); } } else @@ -257,7 +259,8 @@ void CoverArt::IconLoaded(std::string const& texid, return; } - nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, pixbuf_width, pixbuf_height); + nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, ((RawPixel)pixbuf_width).CP(scale), + ((RawPixel)pixbuf_height).CP(scale)); cairo_t* cr = cairo_graphics.GetInternalContext(); cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); @@ -496,6 +499,14 @@ bool CoverArt::OnFrameTimeout() return false; } +void CoverArt::UpdateScale(double scale) +{ + if (overlay_text_) + overlay_text_->SetScale(scale); + + QueueDraw(); +} + } } } diff --git a/unity-shared/CoverArt.h b/unity-shared/CoverArt.h index add94f755..52929c730 100644 --- a/unity-shared/CoverArt.h +++ b/unity-shared/CoverArt.h @@ -58,6 +58,9 @@ public: void SetFont(std::string const& font); + void UpdateScale(double scale); + nux::Property<double> scale; + protected: virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw); virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw); |
