diff options
| author | Marco Trevisan (TreviƱo) <mail@3v1n0.net> | 2014-09-04 22:11:33 +0000 |
|---|---|---|
| committer | CI bot <ps-jenkins@lists.canonical.com> | 2014-09-04 22:11:33 +0000 |
| commit | 4a2c7025275d21415867c1534f718489622d738c (patch) | |
| tree | 06b0e10c47bfc07709c2b42e37b880754d7f34f2 | |
| parent | fd08bcca0b5d445186bab1bcf21c4b35bc987b0c (diff) | |
| parent | f16d816cbc51d9e82dd59db869d99192326564ee (diff) | |
SearchBar, ActionButtons, IconRenderer: include the font scaling when scaling textual items
User font scaling settings should be applied to all the items containing text. Fixed some elements missing support. Fixes: 1332947, 1361713, 1362162, 1362346 Approved by: Andrea Azzarone, PS Jenkins bot (bzr r3866)
| -rw-r--r-- | dash/FilterBasicButton.cpp | 9 | ||||
| -rw-r--r-- | dash/previews/ActionButton.cpp | 7 | ||||
| -rw-r--r-- | launcher/Launcher.cpp | 2 | ||||
| -rw-r--r-- | launcher/Tooltip.cpp | 9 | ||||
| -rwxr-xr-x | unity-shared/DashStyle.cpp | 19 | ||||
| -rw-r--r-- | unity-shared/IconRenderer.cpp | 72 | ||||
| -rw-r--r-- | unity-shared/IconRenderer.h | 2 | ||||
| -rw-r--r-- | unity-shared/SearchBar.cpp | 10 | ||||
| -rw-r--r-- | unity-shared/UnitySettings.cpp | 10 |
9 files changed, 77 insertions, 63 deletions
diff --git a/dash/FilterBasicButton.cpp b/dash/FilterBasicButton.cpp index a16ed9270..d66980663 100644 --- a/dash/FilterBasicButton.cpp +++ b/dash/FilterBasicButton.cpp @@ -20,6 +20,7 @@ */ #include "unity-shared/DashStyle.h" +#include "unity-shared/UnitySettings.h" #include "FilterBasicButton.h" namespace unity @@ -70,6 +71,7 @@ FilterBasicButton::FilterBasicButton(std::string const& label, nux::TextureArea* }); scale.changed.connect(sigc::mem_fun(this, &FilterBasicButton::UpdateScale)); + Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &FilterBasicButton::InitTheme))); } void FilterBasicButton::InitTheme() @@ -81,11 +83,12 @@ void FilterBasicButton::InitTheme() normal_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &FilterBasicButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_NORMAL))); focus_.reset(new nux::CairoWrapper(geo, sigc::mem_fun(this, &FilterBasicButton::RedrawFocusOverlay))); - SetMinimumWidth(MIN_BUTTON_WIDTH.CP(scale)); + double font_scaling = Settings::Instance().font_scaling() * scale; + SetMinimumWidth(MIN_BUTTON_WIDTH.CP(font_scaling)); ApplyMinWidth(); - SetMinimumHeight(BUTTON_HEIGHT.CP(scale)); - SetMaximumHeight(BUTTON_HEIGHT.CP(scale)); + SetMinimumHeight(BUTTON_HEIGHT.CP(font_scaling)); + SetMaximumHeight(BUTTON_HEIGHT.CP(font_scaling)); } void FilterBasicButton::RedrawTheme(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state) diff --git a/dash/previews/ActionButton.cpp b/dash/previews/ActionButton.cpp index 981c625bb..04351b17f 100644 --- a/dash/previews/ActionButton.cpp +++ b/dash/previews/ActionButton.cpp @@ -24,6 +24,7 @@ #include <Nux/HLayout.h> #include "unity-shared/IconTexture.h" #include "unity-shared/StaticCairoText.h" +#include "unity-shared/UnitySettings.h" namespace unity { @@ -49,6 +50,7 @@ ActionButton::ActionButton(std::string const& action_hint, std::string const& la Init(); BuildLayout(label, icon_hint, ""); scale.changed.connect(sigc::mem_fun(this, &ActionButton::UpdateScale)); + Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &ActionButton::InitTheme))); } ActionButton::~ActionButton() @@ -91,8 +93,9 @@ void ActionButton::InitTheme() cr_normal_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &ActionButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_NORMAL))); cr_focus_.reset(new nux::CairoWrapper(geo, sigc::mem_fun(this, &ActionButton::RedrawFocusOverlay))); - SetMinimumHeight(MIN_BUTTON_HEIGHT.CP(scale)); - SetMinimumWidth(MIN_BUTTON_WIDTH.CP(scale)); + double font_scaling = Settings::Instance().font_scaling() * scale; + SetMinimumHeight(MIN_BUTTON_HEIGHT.CP(font_scaling)); + SetMinimumWidth(MIN_BUTTON_WIDTH.CP(font_scaling)); } void ActionButton::SetExtraHint(std::string const& extra_hint, std::string const& font_hint) diff --git a/launcher/Launcher.cpp b/launcher/Launcher.cpp index 2420f4dc7..0062c106d 100644 --- a/launcher/Launcher.cpp +++ b/launcher/Launcher.cpp @@ -1517,8 +1517,6 @@ void Launcher::SetLauncherMinimizeWindow(bool click_to_minimize) void Launcher::SetIconSize(int tile_size, int icon_size) { - ui::IconRenderer::DestroyShortcutTextures(); - icon_size_ = tile_size; icon_renderer_->SetTargetSize(icon_size_.CP(cv_), RawPixel(icon_size).CP(cv_), SPACE_BETWEEN_ICONS.CP(cv_)); AbstractLauncherIcon::icon_size = icon_size_; diff --git a/launcher/Tooltip.cpp b/launcher/Tooltip.cpp index 833da1cdb..42570f5a3 100644 --- a/launcher/Tooltip.cpp +++ b/launcher/Tooltip.cpp @@ -144,11 +144,12 @@ void Tooltip::PreLayoutManagement() _tooltip_text->SetMinimumWidth(text_min_width); _tooltip_text->SetMinimumHeight(text_height); + int space_height = _padding.CP(cv_) + CORNER_RADIUS.CP(cv_); if (text_height < ANCHOR_HEIGHT.CP(cv_)) - { - _top_space->SetMinMaxSize(1, (ANCHOR_HEIGHT.CP(cv_) - text_height) / 2 + _padding.CP(cv_) + CORNER_RADIUS.CP(cv_)); - _bottom_space->SetMinMaxSize(1, (ANCHOR_HEIGHT.CP(cv_) - text_height) / 2 + 1 + _padding.CP(cv_) + CORNER_RADIUS.CP(cv_)); - } + space_height += (ANCHOR_HEIGHT.CP(cv_) - text_height) / 2; + + _top_space->SetMinMaxSize(1, space_height); + _bottom_space->SetMinMaxSize(1, space_height + 1); CairoBaseWindow::PreLayoutManagement(); } diff --git a/unity-shared/DashStyle.cpp b/unity-shared/DashStyle.cpp index 5f4989814..23fa9601e 100755 --- a/unity-shared/DashStyle.cpp +++ b/unity-shared/DashStyle.cpp @@ -383,9 +383,9 @@ void Style::Impl::Refresh() ::pango_layout_context_changed(layout); PangoRectangle log_rect; - ::pango_layout_get_extents(layout, NULL, &log_rect); - text_width_ = log_rect.width / PANGO_SCALE; - text_height_ = log_rect.height / PANGO_SCALE; + ::pango_layout_get_pixel_extents(layout, NULL, &log_rect); + text_width_ = log_rect.width; + text_height_ = log_rect.height; owner_->changed.emit(); @@ -1396,10 +1396,10 @@ void Style::Impl::GetTextExtents(int& width, pango_cairo_context_set_resolution(pangoCtx, 96.0 * Settings::Instance().font_scaling()); pango_layout_context_changed(layout); - pango_layout_get_extents(layout, &inkRect, NULL); + pango_layout_get_pixel_extents(layout, &inkRect, NULL); - width = inkRect.width / PANGO_SCALE; - height = inkRect.height / PANGO_SCALE; + width = inkRect.width; + height = inkRect.height; // clean up pango_font_description_free(desc); @@ -1444,11 +1444,8 @@ void Style::Impl::Text(cairo_t* cr, if (text_size > 0) { - pango_font_description_set_absolute_size(desc, text_size * PANGO_SCALE); - } - else if (desc) - { - text_size = pango_font_description_get_size(desc) / PANGO_SCALE; + text_size = pango_units_from_double(Settings::Instance().font_scaling() * text_size); + pango_font_description_set_absolute_size(desc, text_size); } PangoWeight weight; diff --git a/unity-shared/IconRenderer.cpp b/unity-shared/IconRenderer.cpp index 57c034c79..844ffe88a 100644 --- a/unity-shared/IconRenderer.cpp +++ b/unity-shared/IconRenderer.cpp @@ -31,6 +31,8 @@ #include "unity-shared/CairoTexture.h" #include "unity-shared/DecorationStyle.h" #include "unity-shared/TextureCache.h" +#include "unity-shared/UnitySettings.h" +#include "unity-shared/WindowManager.h" #include "GraphicsUtils.h" #include <gtk/gtk.h> @@ -212,7 +214,6 @@ struct IconRenderer::TexturesPool return instance; } - nux::ObjectPtr<nux::BaseTexture> RenderLabelTexture(char label, int icon_size, nux::Color const& bg_color); nux::ObjectPtr<nux::IOpenGLBaseTexture> offscreen_progress_texture; nux::ObjectPtr<nux::IOpenGLShaderProgram> shader_program_uv_persp_correction; #ifndef USE_GLES @@ -226,8 +227,6 @@ struct IconRenderer::TexturesPool int ColorifyColor; int DesatFactor; - std::map<char, BaseTexturePtr> labels; - private: TexturesPool(); @@ -251,14 +250,18 @@ struct IconRenderer::LocalTextures LocalTextures(IconRenderer* parent) : parent_(parent) { - theme_conn_ = decoration::Style::Get()->theme.changed.connect([this] (std::string const&) { + connections_.Add(decoration::Style::Get()->theme.changed.connect([this] (std::string const&) { auto& cache = TextureCache::GetDefault(); for (auto const& tex_data : texture_files_) cache.Invalidate(tex_data.name, tex_data.size, tex_data.size); ReloadIconSizedTextures(parent_->icon_size, parent_->image_size); - }); + })); + + auto clear_labels = sigc::hide(sigc::mem_fun(this, &LocalTextures::ClearLabels)); + connections_.Add(Settings::Instance().font_scaling.changed.connect(clear_labels)); + connections_.Add(WindowManager::Default().average_color.changed.connect(clear_labels)); } void ReloadIconSizedTextures(int icon_size, int image_size) @@ -300,6 +303,22 @@ struct IconRenderer::LocalTextures *tex_data.tex_ptr = cache.FindTexture(tex_data.name, tex_data.size, tex_data.size, texture_loader); } + nux::BaseTexture* RenderLabelTexture(char label, int icon_size, nux::Color const&); + + BaseTexturePtr const& GetLabelTexture(char label, int icon_size, nux::Color const& color) + { + labels_.push_back(TextureCache::GetDefault().FindTexture(std::string(1, label), icon_size, icon_size, [this, &color] (std::string const& label, int size, int) { + return RenderLabelTexture(label[0], size, color); + })); + + return labels_.back(); + } + + void ClearLabels() + { + labels_.clear(); + } + BaseTexturePtr icon_background; BaseTexturePtr icon_selected_background; BaseTexturePtr icon_edge; @@ -317,7 +336,8 @@ private: IconRenderer* parent_; struct TextureData { BaseTexturePtr* tex_ptr; std::string name; int size; }; std::vector<TextureData> texture_files_; - connection::Wrapper theme_conn_; + std::vector<BaseTexturePtr> labels_; + connection::Manager connections_; }; IconRenderer::IconRenderer() @@ -337,6 +357,7 @@ void IconRenderer::SetTargetSize(int tile_size, int image_size_, int spacing_) icon_size = tile_size; image_size = image_size_; local_textures_->ReloadIconSizedTextures(icon_size, image_size); + local_textures_->ClearLabels(); } spacing = spacing_; @@ -767,20 +788,8 @@ void IconRenderer::RenderIcon(nux::GraphicsEngine& GfxContext, RenderArg const& // draw superkey-shortcut label if (arg.draw_shortcut && arg.shortcut_label) { - char shortcut = (char) arg.shortcut_label; - - BaseTexturePtr label; - auto label_it = textures_->labels.find(shortcut); - - if (label_it != textures_->labels.end()) - { - label = label_it->second; - } - else - { - label = textures_->RenderLabelTexture(shortcut, icon_size, shortcut_color); - textures_->labels[shortcut] = label; - } + char shortcut = static_cast<char>(arg.shortcut_label); + auto const& label = local_textures_->GetLabelTexture(shortcut, icon_size, shortcut_color); RenderElement(GfxContext, arg, @@ -793,7 +802,7 @@ void IconRenderer::RenderIcon(nux::GraphicsEngine& GfxContext, RenderArg const& } } -nux::ObjectPtr<nux::BaseTexture> IconRenderer::TexturesPool::RenderLabelTexture(char label, int icon_size, nux::Color const& bg_color) +nux::BaseTexture* IconRenderer::LocalTextures::RenderLabelTexture(char label, int icon_size, nux::Color const& bg_color) { nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, icon_size, icon_size); cairo_t* cr = cg.GetInternalContext(); @@ -817,27 +826,27 @@ nux::ObjectPtr<nux::BaseTexture> IconRenderer::TexturesPool::RenderLabelTexture( cairo_set_source_rgba(cr, bg_color.red, bg_color.green, bg_color.blue, 0.20f); cairo_fill(cr); - const double text_ratio = 0.75; - double text_size = label_size * text_ratio; glib::Object<PangoLayout> layout(pango_cairo_create_layout(cr)); g_object_get(gtk_settings_get_default(), "gtk-font-name", &font_name, NULL); std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font_name), pango_font_description_free); - pango_font_description_set_absolute_size(desc.get(), text_size * PANGO_SCALE); + const double text_ratio = 0.75; + int text_size = pango_units_from_double(label_size * text_ratio * Settings::Instance().font_scaling()); + pango_font_description_set_absolute_size(desc.get(), text_size); pango_layout_set_font_description(layout, desc.get()); pango_layout_set_text(layout, &label, 1); - nux::Size extents; - pango_layout_get_pixel_size(layout, &extents.width, &extents.height); + PangoRectangle ink_rect; + pango_layout_get_pixel_extents(layout, &ink_rect, nullptr); // position and paint text cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f); - double x = label_x - std::round((extents.width - label_w) / 2.0f); - double y = label_y - std::round((extents.height - label_h) / 2.0f); + double x = label_x - std::round((ink_rect.width - label_w) / 2.0f) - ink_rect.x; + double y = label_y - std::round((ink_rect.height - label_h) / 2.0f) - ink_rect.y; cairo_move_to(cr, x, y); pango_cairo_show_layout(cr, layout); - return texture_ptr_from_cairo_graphics(cg); + return texture_from_cairo_graphics(cg); } void IconRenderer::RenderElement(nux::GraphicsEngine& GfxContext, @@ -1179,11 +1188,6 @@ void IconRenderer::RenderProgressToTexture(nux::GraphicsEngine& GfxContext, unity::graphics::PopOffscreenRenderTarget(); } -void IconRenderer::DestroyShortcutTextures() -{ - TexturesPool::Get()->labels.clear(); -} - void IconRenderer::GetInverseScreenPerspectiveMatrix(nux::Matrix4& ViewMatrix, nux::Matrix4& PerspectiveMatrix, int ViewportWidth, int ViewportHeight, diff --git a/unity-shared/IconRenderer.h b/unity-shared/IconRenderer.h index 733f9a1cf..50ab20e29 100644 --- a/unity-shared/IconRenderer.h +++ b/unity-shared/IconRenderer.h @@ -44,8 +44,6 @@ public: void SetTargetSize(int tile_size, int image_size, int spacing); - static void DestroyShortcutTextures(); - protected: void RenderElement(nux::GraphicsEngine& GfxContext, RenderArg const& arg, diff --git a/unity-shared/SearchBar.cpp b/unity-shared/SearchBar.cpp index 9718c91ae..b9bf13452 100644 --- a/unity-shared/SearchBar.cpp +++ b/unity-shared/SearchBar.cpp @@ -72,7 +72,7 @@ const RawPixel BOT_ARROW_MAX_HEIGHT = 8_em; const RawPixel FILTER_HORIZONTAL_MARGIN = 8_em; // Fonts -const std::string HINT_LABEL_FONT_SIZE = "20px"; +const std::string HINT_LABEL_FONT_SIZE = "15"; // == 20px const std::string HINT_LABEL_FONT_STYLE = "Italic"; const std::string HINT_LABEL_DEFAULT_FONT = "Ubuntu " + HINT_LABEL_FONT_STYLE + " " + HINT_LABEL_FONT_SIZE; @@ -269,6 +269,7 @@ SearchBar::SearchBar(bool show_filter_hint, NUX_FILE_LINE_DECL) im_preedit.SetGetterFunction(sigc::mem_fun(this, &SearchBar::get_im_preedit)); showing_filters.changed.connect(sigc::mem_fun(this, &SearchBar::OnShowingFiltersChanged)); scale.changed.connect(sigc::mem_fun(this, &SearchBar::UpdateScale)); + Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &SearchBar::UpdateSearchBarSize))); can_refine_search.changed.connect([this] (bool can_refine) { if (show_filter_hint_) @@ -295,7 +296,8 @@ void SearchBar::UpdateSearchBarSize() entry_layout_->SetSpaceBetweenChildren(SPACE_BETWEEN_SPINNER_AND_TEXT.CP(scale())); - pango_entry_->SetFontSize(PANGO_ENTRY_FONT_SIZE.CP(scale())); + double font_scaling = scale() * Settings::Instance().font_scaling(); + pango_entry_->SetFontSize(PANGO_ENTRY_FONT_SIZE.CP(font_scaling)); if (show_filter_hint_) { @@ -335,7 +337,7 @@ void SearchBar::UpdateSearchBarSize() layered_layout_->SetMinimumHeight(entry_min); layered_layout_->SetMaximumHeight(entry_min); - int search_bar_height = style.GetSearchBarHeight().CP(scale); + int search_bar_height = style.GetSearchBarHeight().CP(font_scaling); SetMinimumHeight(search_bar_height); SetMaximumHeight(search_bar_height); } @@ -365,7 +367,7 @@ void SearchBar::OnFontChanged() if (desc) { pango_entry_->SetFontFamily(pango_font_description_get_family(desc)); - pango_entry_->SetFontSize(PANGO_ENTRY_FONT_SIZE); + pango_entry_->SetFontSize(PANGO_ENTRY_FONT_SIZE.CP(scale * Settings::Instance().font_scaling())); pango_entry_->SetFontOptions(gdk_screen_get_font_options(gdk_screen_get_default())); font_desc << pango_font_description_get_family(desc) << " " << HINT_LABEL_FONT_STYLE << " " << HINT_LABEL_FONT_SIZE; diff --git a/unity-shared/UnitySettings.cpp b/unity-shared/UnitySettings.cpp index 090fc86d1..7498d7fb3 100644 --- a/unity-shared/UnitySettings.cpp +++ b/unity-shared/UnitySettings.cpp @@ -20,6 +20,7 @@ #include <glib.h> #include <NuxCore/Logger.h> +#include <UnityCore/GLibSource.h> #include <UnityCore/Variant.h> #include "DecorationStyle.h" @@ -60,6 +61,7 @@ const std::string GNOME_TEXT_SCALE_FACTOR = "text-scaling-factor"; const int DEFAULT_LAUNCHER_WIDTH = 64; const int MINIMUM_DESKTOP_HEIGHT = 800; +const int GNOME_SETTINGS_CHANGED_WAIT_SECONDS = 1; const double DEFAULT_DPI = 96.0f; } @@ -302,6 +304,7 @@ public: void UpdateAppsScaling(double scale) { changing_gnome_settings_ = true; + changing_gnome_settings_timeout_.reset(); unsigned integer_scaling = std::max<unsigned>(1, scale); double point_scaling = scale / static_cast<double>(integer_scaling); double text_scale_factor = parent_->font_scaling() * point_scaling; @@ -310,7 +313,11 @@ public: g_settings_set_int(gnome_ui_settings_, GNOME_CURSOR_SIZE.c_str(), cursor_size); g_settings_set_uint(gnome_ui_settings_, GNOME_SCALE_FACTOR.c_str(), integer_scaling); g_settings_set_double(gnome_ui_settings_, GNOME_TEXT_SCALE_FACTOR.c_str(), text_scale_factor); - changing_gnome_settings_ = false; + + changing_gnome_settings_timeout_.reset(new glib::TimeoutSeconds(GNOME_SETTINGS_CHANGED_WAIT_SECONDS, [this] { + changing_gnome_settings_ = false; + return false; + }, glib::Source::Priority::LOW)); } Settings* parent_; @@ -319,6 +326,7 @@ public: glib::Object<GSettings> ui_settings_; glib::Object<GSettings> ubuntu_ui_settings_; glib::Object<GSettings> gnome_ui_settings_; + glib::Source::UniquePtr changing_gnome_settings_timeout_; glib::SignalManager signals_; std::vector<EMConverter::Ptr> em_converters_; std::vector<int> launcher_widths_; |
