diff --git a/data/extensions/aseprite-theme/theme.xml b/data/extensions/aseprite-theme/theme.xml index 2ee2d78c4..c7ae0594e 100644 --- a/data/extensions/aseprite-theme/theme.xml +++ b/data/extensions/aseprite-theme/theme.xml @@ -1,5 +1,7 @@ - + diff --git a/src/app/commands/cmd_options.cpp b/src/app/commands/cmd_options.cpp index ccfaceb58..9481c0cb2 100644 --- a/src/app/commands/cmd_options.cpp +++ b/src/app/commands/cmd_options.cpp @@ -239,14 +239,7 @@ public: gridScope()->Change.connect(base::Bind(&OptionsWindow::onChangeGridScope, this)); } - // Screen/UI Scale - screenScale()->setSelectedItemIndex( - screenScale()->findItemIndexByValue( - base::convert_to(m_pref.general.screenScale()))); - - uiScale()->setSelectedItemIndex( - uiScale()->findItemIndexByValue( - base::convert_to(m_pref.general.uiScale()))); + selectScalingItems(); if ((int(she::instance()->capabilities()) & int(she::Capabilities::GpuAccelerationSwitch)) == int(she::Capabilities::GpuAccelerationSwitch)) { @@ -444,16 +437,30 @@ public: "||&OK", warnings.c_str()); } - if (reset_screen) { - ui::Manager* manager = ui::Manager::getDefault(); - she::Display* display = manager->getDisplay(); - she::instance()->setGpuAcceleration(newGpuAccel); - display->setScale(newScreenScale); - manager->setDisplay(display); - } + if (reset_screen) + updateScreenScaling(); } private: + void selectScalingItems() { + // Screen/UI Scale + screenScale()->setSelectedItemIndex( + screenScale()->findItemIndexByValue( + base::convert_to(m_pref.general.screenScale()))); + + uiScale()->setSelectedItemIndex( + uiScale()->findItemIndexByValue( + base::convert_to(m_pref.general.uiScale()))); + } + + void updateScreenScaling() { + ui::Manager* manager = ui::Manager::getDefault(); + she::Display* display = manager->getDisplay(); + she::instance()->setGpuAcceleration(m_pref.general.gpuAcceleration()); + display->setScale(m_pref.general.screenScale()); + manager->setDisplay(display); + } + void onNativeCursorChange() { bool state = // If the platform supports native cursors... @@ -688,13 +695,34 @@ private: } void onSelectTheme() { - ThemeItem* item = dynamic_cast(themeList()->getSelectedChild()); - if (item && - item->themeName() != m_pref.theme.selected()) { - m_pref.theme.selected(item->themeName()); + try { + ThemeItem* item = dynamic_cast(themeList()->getSelectedChild()); + if (item && + item->themeName() != m_pref.theme.selected()) { + auto theme = static_cast(ui::get_theme()); - ui::set_theme(ui::get_theme(), - ui::guiscale()); + // Change theme name from preferences + m_pref.theme.selected(item->themeName()); + + // Preferred UI Scaling factor by the theme + if (theme->preferredUIScaling() > 0) + m_pref.general.uiScale(theme->preferredUIScaling()); + + ui::set_theme(theme, m_pref.general.uiScale()); + + // Preferred Screen Scaling by the theme + const int newScreenScale = theme->preferredScreenScaling(); + if (newScreenScale > 0 && + newScreenScale != m_pref.general.screenScale()) { + m_pref.general.screenScale(newScreenScale); + updateScreenScaling(); + } + + selectScalingItems(); + } + } + catch (const std::exception& ex) { + Console::showException(ex); } } @@ -781,7 +809,7 @@ private: extensionsList()->selectChild(item); extensionsList()->layout(); } - catch (std::exception& ex) { + catch (const std::exception& ex) { Console::showException(ex); } } @@ -810,7 +838,7 @@ private: item->uninstall(); deleteExtensionItem(item); } - catch (std::exception& ex) { + catch (const std::exception& ex) { Console::showException(ex); } } diff --git a/src/app/ui/skin/skin_theme.cpp b/src/app/ui/skin/skin_theme.cpp index d7faf4d8b..cb12a6bb1 100644 --- a/src/app/ui/skin/skin_theme.cpp +++ b/src/app/ui/skin/skin_theme.cpp @@ -184,6 +184,8 @@ SkinTheme::SkinTheme() , m_standardCursors(ui::kCursorTypes, nullptr) , m_defaultFont(nullptr) , m_miniFont(nullptr) + , m_preferredScreenScaling(-1) + , m_preferredUIScaling(-1) { } @@ -310,6 +312,22 @@ void SkinTheme::loadXml() XmlDocumentRef doc = open_xml(xml_filename); TiXmlHandle handle(doc.get()); + // Load Preferred scaling + m_preferredScreenScaling = -1; + m_preferredUIScaling = -1; + { + TiXmlElement* xmlTheme = handle + .FirstChild("theme").ToElement(); + if (xmlTheme) { + const char* screenScaling = xmlTheme->Attribute("screenscaling"); + const char* uiScaling = xmlTheme->Attribute("uiscaling"); + if (screenScaling) + m_preferredScreenScaling = std::strtol(screenScaling, nullptr, 10); + if (uiScaling) + m_preferredUIScaling = std::strtol(uiScaling, nullptr, 10); + } + } + // Load fonts { TiXmlElement* xmlFont = handle diff --git a/src/app/ui/skin/skin_theme.h b/src/app/ui/skin/skin_theme.h index 5508c7c23..34908249e 100644 --- a/src/app/ui/skin/skin_theme.h +++ b/src/app/ui/skin/skin_theme.h @@ -48,6 +48,8 @@ namespace app { ~SkinTheme(); const std::string& path() { return m_path; } + int preferredScreenScaling() { return m_preferredScreenScaling; } + int preferredUIScaling() { return m_preferredUIScaling; } she::Font* getDefaultFont() const override { return m_defaultFont; } she::Font* getWidgetFont(const ui::Widget* widget) const override; @@ -156,6 +158,8 @@ namespace app { std::map m_themeFonts; she::Font* m_defaultFont; she::Font* m_miniFont; + int m_preferredScreenScaling; + int m_preferredUIScaling; }; } // namespace skin diff --git a/src/she/skia/skia_display.cpp b/src/she/skia/skia_display.cpp index 9bb1f130c..8114317c6 100644 --- a/src/she/skia/skia_display.cpp +++ b/src/she/skia/skia_display.cpp @@ -1,5 +1,5 @@ // SHE library -// Copyright (C) 2012-2016 David Capello +// Copyright (C) 2012-2017 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -100,6 +100,7 @@ int SkiaDisplay::scale() const void SkiaDisplay::setScale(int scale) { + ASSERT(scale > 0); m_window.setScale(scale); }