mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-16 05:42:32 +00:00
theme: Possibility to specify default screen/ui scaling
This commit is contained in:
parent
a9c1b26db3
commit
d00db433fe
@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<theme name="Default">
|
<theme name="Default"
|
||||||
|
screenscaling="2"
|
||||||
|
uiscaling="1">
|
||||||
<authors>
|
<authors>
|
||||||
<author name="David Capello" url="http://davidcapello.com/" />
|
<author name="David Capello" url="http://davidcapello.com/" />
|
||||||
<author name="Ilija Melentijevic" url="http://ilkke.blogspot.com/" />
|
<author name="Ilija Melentijevic" url="http://ilkke.blogspot.com/" />
|
||||||
|
@ -239,14 +239,7 @@ public:
|
|||||||
gridScope()->Change.connect(base::Bind<void>(&OptionsWindow::onChangeGridScope, this));
|
gridScope()->Change.connect(base::Bind<void>(&OptionsWindow::onChangeGridScope, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Screen/UI Scale
|
selectScalingItems();
|
||||||
screenScale()->setSelectedItemIndex(
|
|
||||||
screenScale()->findItemIndexByValue(
|
|
||||||
base::convert_to<std::string>(m_pref.general.screenScale())));
|
|
||||||
|
|
||||||
uiScale()->setSelectedItemIndex(
|
|
||||||
uiScale()->findItemIndexByValue(
|
|
||||||
base::convert_to<std::string>(m_pref.general.uiScale())));
|
|
||||||
|
|
||||||
if ((int(she::instance()->capabilities()) &
|
if ((int(she::instance()->capabilities()) &
|
||||||
int(she::Capabilities::GpuAccelerationSwitch)) == int(she::Capabilities::GpuAccelerationSwitch)) {
|
int(she::Capabilities::GpuAccelerationSwitch)) == int(she::Capabilities::GpuAccelerationSwitch)) {
|
||||||
@ -444,16 +437,30 @@ public:
|
|||||||
"||&OK", warnings.c_str());
|
"||&OK", warnings.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reset_screen) {
|
if (reset_screen)
|
||||||
ui::Manager* manager = ui::Manager::getDefault();
|
updateScreenScaling();
|
||||||
she::Display* display = manager->getDisplay();
|
|
||||||
she::instance()->setGpuAcceleration(newGpuAccel);
|
|
||||||
display->setScale(newScreenScale);
|
|
||||||
manager->setDisplay(display);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void selectScalingItems() {
|
||||||
|
// Screen/UI Scale
|
||||||
|
screenScale()->setSelectedItemIndex(
|
||||||
|
screenScale()->findItemIndexByValue(
|
||||||
|
base::convert_to<std::string>(m_pref.general.screenScale())));
|
||||||
|
|
||||||
|
uiScale()->setSelectedItemIndex(
|
||||||
|
uiScale()->findItemIndexByValue(
|
||||||
|
base::convert_to<std::string>(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() {
|
void onNativeCursorChange() {
|
||||||
bool state =
|
bool state =
|
||||||
// If the platform supports native cursors...
|
// If the platform supports native cursors...
|
||||||
@ -688,13 +695,34 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onSelectTheme() {
|
void onSelectTheme() {
|
||||||
ThemeItem* item = dynamic_cast<ThemeItem*>(themeList()->getSelectedChild());
|
try {
|
||||||
if (item &&
|
ThemeItem* item = dynamic_cast<ThemeItem*>(themeList()->getSelectedChild());
|
||||||
item->themeName() != m_pref.theme.selected()) {
|
if (item &&
|
||||||
m_pref.theme.selected(item->themeName());
|
item->themeName() != m_pref.theme.selected()) {
|
||||||
|
auto theme = static_cast<skin::SkinTheme*>(ui::get_theme());
|
||||||
|
|
||||||
ui::set_theme(ui::get_theme(),
|
// Change theme name from preferences
|
||||||
ui::guiscale());
|
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()->selectChild(item);
|
||||||
extensionsList()->layout();
|
extensionsList()->layout();
|
||||||
}
|
}
|
||||||
catch (std::exception& ex) {
|
catch (const std::exception& ex) {
|
||||||
Console::showException(ex);
|
Console::showException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -810,7 +838,7 @@ private:
|
|||||||
item->uninstall();
|
item->uninstall();
|
||||||
deleteExtensionItem(item);
|
deleteExtensionItem(item);
|
||||||
}
|
}
|
||||||
catch (std::exception& ex) {
|
catch (const std::exception& ex) {
|
||||||
Console::showException(ex);
|
Console::showException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,6 +184,8 @@ SkinTheme::SkinTheme()
|
|||||||
, m_standardCursors(ui::kCursorTypes, nullptr)
|
, m_standardCursors(ui::kCursorTypes, nullptr)
|
||||||
, m_defaultFont(nullptr)
|
, m_defaultFont(nullptr)
|
||||||
, m_miniFont(nullptr)
|
, m_miniFont(nullptr)
|
||||||
|
, m_preferredScreenScaling(-1)
|
||||||
|
, m_preferredUIScaling(-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,6 +312,22 @@ void SkinTheme::loadXml()
|
|||||||
XmlDocumentRef doc = open_xml(xml_filename);
|
XmlDocumentRef doc = open_xml(xml_filename);
|
||||||
TiXmlHandle handle(doc.get());
|
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
|
// Load fonts
|
||||||
{
|
{
|
||||||
TiXmlElement* xmlFont = handle
|
TiXmlElement* xmlFont = handle
|
||||||
|
@ -48,6 +48,8 @@ namespace app {
|
|||||||
~SkinTheme();
|
~SkinTheme();
|
||||||
|
|
||||||
const std::string& path() { return m_path; }
|
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* getDefaultFont() const override { return m_defaultFont; }
|
||||||
she::Font* getWidgetFont(const ui::Widget* widget) const override;
|
she::Font* getWidgetFont(const ui::Widget* widget) const override;
|
||||||
@ -156,6 +158,8 @@ namespace app {
|
|||||||
std::map<std::string, she::Font*> m_themeFonts;
|
std::map<std::string, she::Font*> m_themeFonts;
|
||||||
she::Font* m_defaultFont;
|
she::Font* m_defaultFont;
|
||||||
she::Font* m_miniFont;
|
she::Font* m_miniFont;
|
||||||
|
int m_preferredScreenScaling;
|
||||||
|
int m_preferredUIScaling;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace skin
|
} // namespace skin
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// SHE library
|
// 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.
|
// This file is released under the terms of the MIT license.
|
||||||
// Read LICENSE.txt for more information.
|
// Read LICENSE.txt for more information.
|
||||||
@ -100,6 +100,7 @@ int SkiaDisplay::scale() const
|
|||||||
|
|
||||||
void SkiaDisplay::setScale(int scale)
|
void SkiaDisplay::setScale(int scale)
|
||||||
{
|
{
|
||||||
|
ASSERT(scale > 0);
|
||||||
m_window.setScale(scale);
|
m_window.setScale(scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user