mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-23 18:39:55 +00:00
Fix several issues with UI Scaling > 100% (fix #1456)
This commit is contained in:
parent
87f3b578e5
commit
73999c5415
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -146,10 +146,9 @@ void App::initialize(const AppOptions& options)
|
||||
{
|
||||
m_isGui = options.startUI() && !options.previewCLI();
|
||||
m_isShell = options.startShell();
|
||||
if (m_isGui)
|
||||
m_uiSystem.reset(new ui::UISystem);
|
||||
|
||||
m_coreModules = new CoreModules;
|
||||
if (m_isGui)
|
||||
m_uiSystem.reset(new ui::UISystem(preferences().general.uiScale()));
|
||||
|
||||
bool createLogInDesktop = false;
|
||||
switch (options.verboseLevel()) {
|
||||
|
@ -183,8 +183,7 @@ int init_module_gui()
|
||||
manager->setDisplay(main_display);
|
||||
|
||||
// Setup the GUI theme for all widgets
|
||||
gui_theme = new SkinTheme();
|
||||
gui_theme->setScale(Preferences::instance().general.uiScale());
|
||||
gui_theme = new SkinTheme;
|
||||
ui::set_theme(gui_theme);
|
||||
|
||||
if (maximized)
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2016 David Capello
|
||||
// Copyright (C) 2016-2017 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -11,8 +11,8 @@
|
||||
#include "app/ui/color_selector.h"
|
||||
|
||||
#include "ui/message.h"
|
||||
#include "ui/scale.h"
|
||||
#include "ui/size_hint_event.h"
|
||||
#include "ui/theme.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -15,7 +15,7 @@
|
||||
#include "base/hex.h"
|
||||
#include "gfx/border.h"
|
||||
#include "ui/message.h"
|
||||
#include "ui/theme.h"
|
||||
#include "ui/scale.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
@ -52,7 +52,7 @@ HexColorEntry::HexColorEntry()
|
||||
|
||||
initTheme();
|
||||
|
||||
setBorder(gfx::Border(2*guiscale(), 0, 0, 0));
|
||||
setBorder(gfx::Border(2*ui::guiscale(), 0, 0, 0));
|
||||
setChildSpacing(0);
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "she/font.h"
|
||||
#include "she/system.h"
|
||||
#include "ui/scale.h"
|
||||
|
||||
namespace app {
|
||||
namespace skin {
|
||||
@ -52,10 +53,10 @@ she::Font* FontData::getFont(int size, bool useCache)
|
||||
|
||||
switch (m_type) {
|
||||
case she::FontType::kSpriteSheet:
|
||||
font = she::instance()->loadSpriteSheetFont(m_filename.c_str());
|
||||
font = she::instance()->loadSpriteSheetFont(m_filename.c_str(), ui::guiscale());
|
||||
break;
|
||||
case she::FontType::kTrueType:
|
||||
font = she::instance()->loadTrueTypeFont(m_filename.c_str(), size);
|
||||
font = she::instance()->loadTrueTypeFont(m_filename.c_str(), size*ui::guiscale());
|
||||
if (font)
|
||||
font->setAntialias(m_antialias);
|
||||
break;
|
||||
|
@ -274,6 +274,8 @@ void SkinTheme::loadSheet(const std::string& skinId)
|
||||
m_sheet = nullptr;
|
||||
}
|
||||
m_sheet = she::instance()->loadRgbaSurface(rf.filename().c_str());
|
||||
if (m_sheet)
|
||||
m_sheet->applyScale(guiscale());
|
||||
}
|
||||
catch (...) {
|
||||
throw base::Exception("Error loading %s file", sheet_filename.c_str());
|
||||
@ -282,6 +284,8 @@ void SkinTheme::loadSheet(const std::string& skinId)
|
||||
|
||||
void SkinTheme::loadXml(const std::string& skinId)
|
||||
{
|
||||
const int scale = guiscale();
|
||||
|
||||
// Load the skin XML
|
||||
std::string xml_filename(themeFileName(skinId, "theme.xml"));
|
||||
ResourceFinder rf;
|
||||
@ -376,10 +380,10 @@ void SkinTheme::loadXml(const std::string& skinId)
|
||||
while (xmlPart) {
|
||||
// Get the tool-icon rectangle
|
||||
const char* part_id = xmlPart->Attribute("id");
|
||||
int x = strtol(xmlPart->Attribute("x"), NULL, 10);
|
||||
int y = strtol(xmlPart->Attribute("y"), NULL, 10);
|
||||
int w = xmlPart->Attribute("w") ? strtol(xmlPart->Attribute("w"), NULL, 10): 0;
|
||||
int h = xmlPart->Attribute("h") ? strtol(xmlPart->Attribute("h"), NULL, 10): 0;
|
||||
int x = scale*strtol(xmlPart->Attribute("x"), nullptr, 10);
|
||||
int y = scale*strtol(xmlPart->Attribute("y"), nullptr, 10);
|
||||
int w = (xmlPart->Attribute("w") ? scale*strtol(xmlPart->Attribute("w"), nullptr, 10): 0);
|
||||
int h = (xmlPart->Attribute("h") ? scale*strtol(xmlPart->Attribute("h"), nullptr, 10): 0);
|
||||
|
||||
LOG(VERBOSE) << "THEME: Loading part " << part_id << "\n";
|
||||
|
||||
@ -389,16 +393,15 @@ void SkinTheme::loadXml(const std::string& skinId)
|
||||
|
||||
if (w > 0 && h > 0) {
|
||||
part->setSpriteBounds(gfx::Rect(x, y, w, h));
|
||||
part->setBitmap(0,
|
||||
sliceSheet(part->bitmap(0), gfx::Rect(x, y, w, h)));
|
||||
part->setBitmap(0, sliceSheet(part->bitmap(0), gfx::Rect(x, y, w, h)));
|
||||
}
|
||||
else if (xmlPart->Attribute("w1")) { // 3x3-1 part (NW, N, NE, E, SE, S, SW, W)
|
||||
int w1 = strtol(xmlPart->Attribute("w1"), NULL, 10);
|
||||
int w2 = strtol(xmlPart->Attribute("w2"), NULL, 10);
|
||||
int w3 = strtol(xmlPart->Attribute("w3"), NULL, 10);
|
||||
int h1 = strtol(xmlPart->Attribute("h1"), NULL, 10);
|
||||
int h2 = strtol(xmlPart->Attribute("h2"), NULL, 10);
|
||||
int h3 = strtol(xmlPart->Attribute("h3"), NULL, 10);
|
||||
int w1 = scale*strtol(xmlPart->Attribute("w1"), nullptr, 10);
|
||||
int w2 = scale*strtol(xmlPart->Attribute("w2"), nullptr, 10);
|
||||
int w3 = scale*strtol(xmlPart->Attribute("w3"), nullptr, 10);
|
||||
int h1 = scale*strtol(xmlPart->Attribute("h1"), nullptr, 10);
|
||||
int h2 = scale*strtol(xmlPart->Attribute("h2"), nullptr, 10);
|
||||
int h3 = scale*strtol(xmlPart->Attribute("h3"), nullptr, 10);
|
||||
|
||||
part->setSpriteBounds(gfx::Rect(x, y, w1+w2+w3, h1+h2+h3));
|
||||
part->setSlicesBounds(gfx::Rect(w1, h1, w2, h2));
|
||||
@ -416,8 +419,8 @@ void SkinTheme::loadXml(const std::string& skinId)
|
||||
// Is it a mouse cursor?
|
||||
if (std::strncmp(part_id, "cursor_", 7) == 0) {
|
||||
std::string cursorName = std::string(part_id).substr(7);
|
||||
int focusx = std::strtol(xmlPart->Attribute("focusx"), NULL, 10);
|
||||
int focusy = std::strtol(xmlPart->Attribute("focusy"), NULL, 10);
|
||||
int focusx = scale*std::strtol(xmlPart->Attribute("focusx"), NULL, 10);
|
||||
int focusy = scale*std::strtol(xmlPart->Attribute("focusy"), NULL, 10);
|
||||
|
||||
LOG(VERBOSE) << "THEME: Loading cursor '" << cursorName << "'\n";
|
||||
|
||||
@ -430,9 +433,7 @@ void SkinTheme::loadXml(const std::string& skinId)
|
||||
// TODO share the Surface with the SkinPart
|
||||
she::Surface* slice = sliceSheet(nullptr, gfx::Rect(x, y, w, h));
|
||||
Cursor* cursor =
|
||||
new Cursor(slice,
|
||||
gfx::Point(focusx*guiscale(),
|
||||
focusy*guiscale()));
|
||||
new Cursor(slice, gfx::Point(focusx, focusy));
|
||||
m_cursors[cursorName] = cursor;
|
||||
|
||||
for (int c=0; c<kCursorTypes; ++c) {
|
||||
@ -482,11 +483,11 @@ void SkinTheme::loadXml(const std::string& skinId)
|
||||
const char* r = xmlStyle->Attribute("margin-right");
|
||||
const char* b = xmlStyle->Attribute("margin-bottom");
|
||||
gfx::Border margin = ui::Style::UndefinedBorder();
|
||||
if (m || l) margin.left(std::strtol(l ? l: m, nullptr, 10));
|
||||
if (m || t) margin.top(std::strtol(t ? t: m, nullptr, 10));
|
||||
if (m || r) margin.right(std::strtol(r ? r: m, nullptr, 10));
|
||||
if (m || b) margin.bottom(std::strtol(b ? b: m, nullptr, 10));
|
||||
style->setMargin(margin*guiscale());
|
||||
if (m || l) margin.left(scale*std::strtol(l ? l: m, nullptr, 10));
|
||||
if (m || t) margin.top(scale*std::strtol(t ? t: m, nullptr, 10));
|
||||
if (m || r) margin.right(scale*std::strtol(r ? r: m, nullptr, 10));
|
||||
if (m || b) margin.bottom(scale*std::strtol(b ? b: m, nullptr, 10));
|
||||
style->setMargin(margin);
|
||||
}
|
||||
|
||||
// Border
|
||||
@ -497,11 +498,11 @@ void SkinTheme::loadXml(const std::string& skinId)
|
||||
const char* r = xmlStyle->Attribute("border-right");
|
||||
const char* b = xmlStyle->Attribute("border-bottom");
|
||||
gfx::Border border = ui::Style::UndefinedBorder();
|
||||
if (m || l) border.left(std::strtol(l ? l: m, nullptr, 10));
|
||||
if (m || t) border.top(std::strtol(t ? t: m, nullptr, 10));
|
||||
if (m || r) border.right(std::strtol(r ? r: m, nullptr, 10));
|
||||
if (m || b) border.bottom(std::strtol(b ? b: m, nullptr, 10));
|
||||
style->setBorder(border*guiscale());
|
||||
if (m || l) border.left(scale*std::strtol(l ? l: m, nullptr, 10));
|
||||
if (m || t) border.top(scale*std::strtol(t ? t: m, nullptr, 10));
|
||||
if (m || r) border.right(scale*std::strtol(r ? r: m, nullptr, 10));
|
||||
if (m || b) border.bottom(scale*std::strtol(b ? b: m, nullptr, 10));
|
||||
style->setBorder(border);
|
||||
}
|
||||
|
||||
// Padding
|
||||
@ -512,11 +513,11 @@ void SkinTheme::loadXml(const std::string& skinId)
|
||||
const char* r = xmlStyle->Attribute("padding-right");
|
||||
const char* b = xmlStyle->Attribute("padding-bottom");
|
||||
gfx::Border padding = ui::Style::UndefinedBorder();
|
||||
if (m || l) padding.left(std::strtol(l ? l: m, nullptr, 10));
|
||||
if (m || t) padding.top(std::strtol(t ? t: m, nullptr, 10));
|
||||
if (m || r) padding.right(std::strtol(r ? r: m, nullptr, 10));
|
||||
if (m || b) padding.bottom(std::strtol(b ? b: m, nullptr, 10));
|
||||
style->setPadding(padding*guiscale());
|
||||
if (m || l) padding.left(scale*std::strtol(l ? l: m, nullptr, 10));
|
||||
if (m || t) padding.top(scale*std::strtol(t ? t: m, nullptr, 10));
|
||||
if (m || r) padding.right(scale*std::strtol(r ? r: m, nullptr, 10));
|
||||
if (m || b) padding.bottom(scale*std::strtol(b ? b: m, nullptr, 10));
|
||||
style->setPadding(padding);
|
||||
}
|
||||
|
||||
// Font
|
||||
@ -607,7 +608,7 @@ void SkinTheme::loadXml(const std::string& skinId)
|
||||
gfx::Point offset(0, 0);
|
||||
if (x) offset.x = std::strtol(x, nullptr, 10);
|
||||
if (y) offset.y = std::strtol(y, nullptr, 10);
|
||||
layer.setOffset(offset);
|
||||
layer.setOffset(offset*scale);
|
||||
}
|
||||
|
||||
// Sprite sheet
|
||||
@ -669,7 +670,6 @@ she::Surface* SkinTheme::sliceSheet(she::Surface* sur, const gfx::Rect& bounds)
|
||||
m_sheet->blitTo(sur, bounds.x, bounds.y, 0, 0, bounds.w, bounds.h);
|
||||
}
|
||||
|
||||
sur->applyScale(guiscale());
|
||||
return sur;
|
||||
}
|
||||
|
||||
@ -698,7 +698,7 @@ void SkinTheme::initWidget(Widget* widget)
|
||||
#define BORDER4(L,T,R,B) \
|
||||
widget->setBorder(gfx::Border((L), (T), (R), (B)))
|
||||
|
||||
int scale = guiscale();
|
||||
const int scale = guiscale();
|
||||
|
||||
switch (widget->type()) {
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "gfx/color.h"
|
||||
#include "gfx/fwd.h"
|
||||
#include "ui/manager.h"
|
||||
#include "ui/scale.h"
|
||||
#include "ui/theme.h"
|
||||
|
||||
#include "theme.xml.h"
|
||||
@ -106,11 +107,9 @@ namespace app {
|
||||
}
|
||||
|
||||
int getDimensionById(const std::string& id) const {
|
||||
// Warning! Don't use ui::guiscale(), as CurrentTheme::get()
|
||||
// is still nullptr when we use this getDimensionById()
|
||||
auto it = m_dimensions_by_id.find(id);
|
||||
if (it != m_dimensions_by_id.end())
|
||||
return it->second * this->guiscale();
|
||||
return it->second * ui::guiscale();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -39,7 +39,7 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
// Do not create a she::System, as we don't need it for testing purposes.
|
||||
//she::ScopedHandle<she::System> system(she::create_system());
|
||||
ui::UISystem uiSystem;
|
||||
ui::UISystem uiSystem(1);
|
||||
ui::Manager uiManager;
|
||||
#endif
|
||||
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "ui/button.h"
|
||||
#include "ui/grid.h"
|
||||
#include "ui/label.h"
|
||||
#include "ui/scale.h"
|
||||
#include "ui/separator.h"
|
||||
#include "ui/slider.h"
|
||||
#include "ui/theme.h"
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "ui/manager.h"
|
||||
#include "ui/menu.h"
|
||||
#include "ui/message.h"
|
||||
#include "ui/scale.h"
|
||||
#include "ui/size_hint_event.h"
|
||||
#include "ui/system.h"
|
||||
#include "ui/theme.h"
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "she/surface.h"
|
||||
#include "she/system.h"
|
||||
#include "ui/manager.h"
|
||||
#include "ui/scale.h"
|
||||
#include "ui/theme.h"
|
||||
|
||||
#include <cctype>
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "ui/manager.h"
|
||||
#include "ui/message.h"
|
||||
#include "ui/popup_window.h"
|
||||
#include "ui/scale.h"
|
||||
#include "ui/size_hint_event.h"
|
||||
#include "ui/slider.h"
|
||||
#include "ui/system.h"
|
||||
|
19
src/ui/scale.h
Normal file
19
src/ui/scale.h
Normal file
@ -0,0 +1,19 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2017 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifndef UI_SCALE_H_INCLUDED
|
||||
#define UI_SCALE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
namespace ui {
|
||||
|
||||
// This value is a factor to multiply every screen size/coordinate.
|
||||
// Every icon/graphics/font should be scaled to this factor.
|
||||
int guiscale();
|
||||
|
||||
} // namespace ui
|
||||
|
||||
#endif
|
@ -13,9 +13,10 @@
|
||||
#include "ui/load_layout_event.h"
|
||||
#include "ui/manager.h"
|
||||
#include "ui/message.h"
|
||||
#include "ui/size_hint_event.h"
|
||||
#include "ui/resize_event.h"
|
||||
#include "ui/save_layout_event.h"
|
||||
#include "ui/scale.h"
|
||||
#include "ui/size_hint_event.h"
|
||||
#include "ui/system.h"
|
||||
#include "ui/theme.h"
|
||||
|
||||
|
@ -25,6 +25,10 @@
|
||||
|
||||
namespace ui {
|
||||
|
||||
// Global UI Screen Scaling factor
|
||||
|
||||
static int g_guiscale = 1;
|
||||
|
||||
// Current mouse cursor type.
|
||||
|
||||
static CursorType mouse_cursor_type = kOutsideDisplay;
|
||||
@ -165,8 +169,9 @@ static void update_mouse_cursor()
|
||||
}
|
||||
}
|
||||
|
||||
UISystem::UISystem()
|
||||
UISystem::UISystem(int scale)
|
||||
{
|
||||
g_guiscale = scale;
|
||||
mouse_cursor_type = kOutsideDisplay;
|
||||
support_native_custom_cursor =
|
||||
((she::instance() &&
|
||||
@ -191,6 +196,11 @@ UISystem::~UISystem()
|
||||
update_mouse_overlay(nullptr);
|
||||
}
|
||||
|
||||
int guiscale()
|
||||
{
|
||||
return g_guiscale;
|
||||
}
|
||||
|
||||
void _internal_set_mouse_display(she::Display* display)
|
||||
{
|
||||
CursorType cursor = get_mouse_cursor();
|
||||
|
@ -22,7 +22,7 @@ namespace ui {
|
||||
|
||||
class UISystem {
|
||||
public:
|
||||
UISystem();
|
||||
UISystem(int uiscale);
|
||||
~UISystem();
|
||||
};
|
||||
|
||||
|
@ -119,7 +119,6 @@ int PaintWidgetPartInfo::getStyleFlagsForWidget(const Widget* widget)
|
||||
}
|
||||
|
||||
Theme::Theme()
|
||||
: m_guiscale(1)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -52,9 +52,6 @@ namespace ui {
|
||||
|
||||
void regenerate();
|
||||
|
||||
int guiscale() const { return m_guiscale; }
|
||||
void setScale(int value) { m_guiscale = value; }
|
||||
|
||||
virtual she::Font* getDefaultFont() const = 0;
|
||||
virtual she::Font* getWidgetFont(const Widget* widget) const = 0;
|
||||
|
||||
@ -145,19 +142,11 @@ namespace ui {
|
||||
const Style* style,
|
||||
gfx::Size& sizeHint,
|
||||
gfx::Border& borderHint);
|
||||
|
||||
int m_guiscale;
|
||||
};
|
||||
|
||||
void set_theme(Theme* theme);
|
||||
Theme* get_theme();
|
||||
|
||||
// This value is a factor to multiply every screen size/coordinate.
|
||||
// Every icon/graphics/font should be scaled to this factor.
|
||||
inline int guiscale() {
|
||||
return (get_theme() ? get_theme()->guiscale(): 1);
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
|
||||
#endif
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "ui/manager.h"
|
||||
#include "ui/message.h"
|
||||
#include "ui/paint_event.h"
|
||||
#include "ui/scale.h"
|
||||
#include "ui/size_hint_event.h"
|
||||
#include "ui/system.h"
|
||||
#include "ui/textbox.h"
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include "ui/register_message.h"
|
||||
#include "ui/resize_event.h"
|
||||
#include "ui/save_layout_event.h"
|
||||
#include "ui/scale.h"
|
||||
#include "ui/scroll_bar.h"
|
||||
#include "ui/separator.h"
|
||||
#include "ui/size_hint_event.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user