Adapt code to the new os::Display -> os::Window refactor

This commit is contained in:
David Capello 2021-02-02 15:59:28 -03:00
parent 017a7320f9
commit 5d31314cdb
26 changed files with 176 additions and 177 deletions

2
laf

@ -1 +1 @@
Subproject commit 858e39c5eee871d940bba47edaf81c19b5976474 Subproject commit 417ace74134d994db8223d91b6b13518cb4519f0

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -60,10 +60,10 @@
#include "base/split_string.h" #include "base/split_string.h"
#include "doc/sprite.h" #include "doc/sprite.h"
#include "fmt/format.h" #include "fmt/format.h"
#include "os/display.h"
#include "os/error.h" #include "os/error.h"
#include "os/surface.h" #include "os/surface.h"
#include "os/system.h" #include "os/system.h"
#include "os/window.h"
#include "render/render.h" #include "render/render.h"
#include "ui/intern.h" #include "ui/intern.h"
#include "ui/ui.h" #include "ui/ui.h"
@ -359,7 +359,7 @@ void App::run()
if (isGui()) { if (isGui()) {
#ifdef _WIN32 #ifdef _WIN32
// How to interpret one finger on Windows tablets. // How to interpret one finger on Windows tablets.
ui::Manager::getDefault()->getDisplay() ui::Manager::getDefault()->nativeWindow()
->setInterpretOneFingerGestureAsMouseMovement( ->setInterpretOneFingerGestureAsMouseMovement(
preferences().experimental.oneFingerAsMouseMovement()); preferences().experimental.oneFingerAsMouseMovement());
#endif #endif
@ -367,7 +367,7 @@ void App::run()
#if !defined(_WIN32) && !defined(__APPLE__) #if !defined(_WIN32) && !defined(__APPLE__)
// Setup app icon for Linux window managers // Setup app icon for Linux window managers
try { try {
os::Display* display = os::instance()->defaultDisplay(); os::Window* window = os::instance()->defaultWindow();
os::SurfaceList icons; os::SurfaceList icons;
for (const int size : { 32, 64, 128 }) { for (const int size : { 32, 64, 128 }) {
@ -380,7 +380,7 @@ void App::run()
} }
} }
display->setIcons(icons); window->setIcons(icons);
} }
catch (const std::exception&) { catch (const std::exception&) {
// Just ignore the exception, we couldn't change the app icon, no // Just ignore the exception, we couldn't change the app icon, no
@ -666,7 +666,7 @@ void App::updateDisplayTitleBar()
} }
title += defaultTitle; title += defaultTitle;
os::instance()->defaultDisplay()->setTitle(title); os::instance()->defaultWindow()->setTitle(title);
} }
InputChain& App::inputChain() InputChain& App::inputChain()

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2018-2021 Igara Studio S.A.
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -14,8 +14,8 @@
#include "app/modules/editors.h" #include "app/modules/editors.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "os/display.h"
#include "os/system.h" #include "os/system.h"
#include "os/window.h"
namespace app { namespace app {
@ -35,7 +35,7 @@ void initialize_color_spaces(Preferences& pref)
os::ColorSpaceRef get_screen_color_space() os::ColorSpaceRef get_screen_color_space()
{ {
return os::instance()->defaultDisplay()->colorSpace(); return os::instance()->defaultWindow()->colorSpace();
} }
os::ColorSpaceRef get_current_color_space() os::ColorSpaceRef get_current_color_space()

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2020 Igara Studio S.A. // Copyright (C) 2020-2021 Igara Studio S.A.
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -14,8 +14,8 @@
#include "app/commands/command.h" #include "app/commands/command.h"
#include "app/commands/commands.h" #include "app/commands/commands.h"
#include "app/context.h" #include "app/context.h"
#include "os/display.h"
#include "os/system.h" #include "os/system.h"
#include "os/window.h"
namespace app { namespace app {
@ -43,13 +43,13 @@ void FullscreenModeCommand::onExecute(Context* ctx)
if (!manager) if (!manager)
return; return;
os::Display* display = manager->getDisplay(); os::Window* window = manager->nativeWindow();
ASSERT(display); ASSERT(window);
if (!display) if (!window)
return; return;
display->setFullscreen( window->setFullscreen(
!display->isFullscreen()); !window->isFullscreen());
} }
Command* CommandFactory::createFullscreenModeCommand() Command* CommandFactory::createFullscreenModeCommand()

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -38,8 +38,8 @@
#include "base/version.h" #include "base/version.h"
#include "doc/image.h" #include "doc/image.h"
#include "fmt/format.h" #include "fmt/format.h"
#include "os/display.h"
#include "os/system.h" #include "os/system.h"
#include "os/window.h"
#include "render/render.h" #include "render/render.h"
#include "ui/ui.h" #include "ui/ui.h"
@ -645,7 +645,7 @@ public:
if (j == winCs) { if (j == winCs) {
name = gfxCs->name(); name = gfxCs->name();
os::instance()->setDisplaysColorSpace(cs); os::instance()->setWindowsColorSpace(cs);
break; break;
} }
++j; ++j;
@ -655,7 +655,7 @@ public:
break; break;
} }
} }
update_displays_color_profile_from_preferences(); update_windows_color_profile_from_preferences();
// Change sprite grid bounds // Change sprite grid bounds
if (m_context && m_context->activeDocument()) { if (m_context && m_context->activeDocument()) {
@ -725,7 +725,7 @@ public:
m_pref.tablet.api(tabletStr); m_pref.tablet.api(tabletStr);
m_pref.experimental.loadWintabDriver(wintabState); m_pref.experimental.loadWintabDriver(wintabState);
manager()->getDisplay() manager()->nativeWindow()
->setInterpretOneFingerGestureAsMouseMovement( ->setInterpretOneFingerGestureAsMouseMovement(
oneFingerAsMouseMovement()->isSelected()); oneFingerAsMouseMovement()->isSelected());
@ -845,10 +845,10 @@ private:
void updateScreenScaling() { void updateScreenScaling() {
ui::Manager* manager = ui::Manager::getDefault(); ui::Manager* manager = ui::Manager::getDefault();
os::Display* display = manager->getDisplay(); os::Window* window = manager->nativeWindow();
os::instance()->setGpuAcceleration(m_pref.general.gpuAcceleration()); os::instance()->setGpuAcceleration(m_pref.general.gpuAcceleration());
display->setScale(m_pref.general.screenScale()); window->setScale(m_pref.general.screenScale());
manager->setDisplay(display); manager->setNativeWindow(window);
} }
void onApply() { void onApply() {

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2019-2021 Igara Studio S.A.
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -25,8 +25,8 @@
#include "doc/layer.h" #include "doc/layer.h"
#include "doc/sprite.h" #include "doc/sprite.h"
#include "fmt/format.h" #include "fmt/format.h"
#include "os/display.h"
#include "os/surface.h" #include "os/surface.h"
#include "os/window.h"
#include "ui/alert.h" #include "ui/alert.h"
#include "ui/manager.h" #include "ui/manager.h"
#include "ui/scale.h" #include "ui/scale.h"
@ -69,8 +69,8 @@ void ScreenshotCommand::onExecute(Context* ctx)
app::ResourceFinder rf(false); app::ResourceFinder rf(false);
rf.includeDesktopDir(""); rf.includeDesktopDir("");
os::Display* display = ui::Manager::getDefault()->getDisplay(); os::Window* window = ui::Manager::getDefault()->nativeWindow();
os::Surface* surface = display->surface(); os::Surface* surface = window->surface();
std::string fn; std::string fn;
if (params().save()) { if (params().save()) {
@ -89,7 +89,7 @@ void ScreenshotCommand::onExecute(Context* ctx)
surface->width(), surface->width(),
surface->height(), surface->height(),
0, // Mask color 0, // Mask color
display->colorSpace()->gfxColorSpace()); window->colorSpace()->gfxColorSpace());
doc::Sprite* spr = doc::Sprite::MakeStdSprite(spec); doc::Sprite* spr = doc::Sprite::MakeStdSprite(spec);
static_cast<doc::LayerImage*>(spr->firstLayer())->configureAsBackground(); static_cast<doc::LayerImage*>(spr->firstLayer())->configureAsBackground();
@ -122,7 +122,7 @@ void ScreenshotCommand::onExecute(Context* ctx)
// Get image again (cmd::convert_color_profile() might have changed it) // Get image again (cmd::convert_color_profile() might have changed it)
img = cel->image(); img = cel->image();
const int scale = display->scale(); const int scale = window->scale();
base::buffer rgbBuffer(3*w*h*scale*scale); base::buffer rgbBuffer(3*w*h*scale*scale);
int c = 0; int c = 0;
doc::LockImageBits<RgbTraits> bits(img); doc::LockImageBits<RgbTraits> bits(img);

View File

@ -123,7 +123,7 @@ Console::Console(Context* ctx)
(App::instance() && (App::instance() &&
App::instance()->isGui() && App::instance()->isGui() &&
Manager::getDefault() && Manager::getDefault() &&
Manager::getDefault()->getDisplay()); Manager::getDefault()->nativeWindow());
if (!m_withUI) if (!m_withUI)
return; return;

View File

@ -30,11 +30,11 @@
#include "doc/mask.h" #include "doc/mask.h"
#include "doc/mask_boundaries.h" #include "doc/mask_boundaries.h"
#include "doc/palette.h" #include "doc/palette.h"
#include "doc/slice.h"
#include "doc/sprite.h" #include "doc/sprite.h"
#include "doc/tag.h" #include "doc/tag.h"
#include "doc/slice.h"
#include "os/display.h"
#include "os/system.h" #include "os/system.h"
#include "os/window.h"
#include "ui/system.h" #include "ui/system.h"
#include <limits> #include <limits>
@ -612,8 +612,8 @@ void Doc::updateOSColorSpace(bool appWideSignal)
auto system = os::instance(); auto system = os::instance();
if (system) { if (system) {
m_osColorSpace = system->makeColorSpace(sprite()->colorSpace()); m_osColorSpace = system->makeColorSpace(sprite()->colorSpace());
if (!m_osColorSpace && system->defaultDisplay()) if (!m_osColorSpace && system->defaultWindow())
m_osColorSpace = system->defaultDisplay()->colorSpace(); m_osColorSpace = system->defaultWindow()->colorSpace();
} }
if (appWideSignal && if (appWideSignal &&

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2020 Igara Studio S.A. // Copyright (C) 2020-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -14,9 +14,9 @@
#include "app/app.h" #include "app/app.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "app/ui/file_selector.h" #include "app/ui/file_selector.h"
#include "os/display.h"
#include "os/native_dialogs.h" #include "os/native_dialogs.h"
#include "os/system.h" #include "os/system.h"
#include "os/window.h"
namespace app { namespace app {
@ -59,7 +59,7 @@ bool show_file_selector(
if (!defExtension.empty()) if (!defExtension.empty())
dlg->setDefaultExtension(defExtension); dlg->setDefaultExtension(defExtension);
bool res = dlg->show(os::instance()->defaultDisplay()); bool res = dlg->show(os::instance()->defaultWindow());
if (res) { if (res) {
if (type == FileSelectorType::OpenMultiple) if (type == FileSelectorType::OpenMultiple)
dlg->getMultipleFileNames(output); dlg->getMultipleFileNames(output);

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2019-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -19,9 +19,9 @@
#include "base/fs.h" #include "base/fs.h"
#include "base/string.h" #include "base/string.h"
#include "os/display.h"
#include "os/surface.h" #include "os/surface.h"
#include "os/system.h" #include "os/system.h"
#include "os/window.h"
#include <algorithm> #include <algorithm>
#include <cstdio> #include <cstdio>
@ -455,7 +455,8 @@ const FileItemList& FileItem::children()
ULONG c, fetched; ULONG c, fetched;
// Get the interface to enumerate subitems // Get the interface to enumerate subitems
hr = pFolder->EnumObjects(reinterpret_cast<HWND>(os::instance()->defaultDisplay()->nativeHandle()), hr = pFolder->EnumObjects(
reinterpret_cast<HWND>(os::instance()->defaultWindow()->nativeHandle()),
SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &pEnum); SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &pEnum);
if (hr == S_OK && pEnum != NULL) { if (hr == S_OK && pEnum != NULL) {

View File

@ -42,10 +42,10 @@
#include "base/memory.h" #include "base/memory.h"
#include "base/string.h" #include "base/string.h"
#include "doc/sprite.h" #include "doc/sprite.h"
#include "os/display.h"
#include "os/error.h" #include "os/error.h"
#include "os/surface.h" #include "os/surface.h"
#include "os/system.h" #include "os/system.h"
#include "os/window.h"
#include "ui/intern.h" #include "ui/intern.h"
#include "ui/ui.h" #include "ui/ui.h"
@ -97,7 +97,7 @@ protected:
void saveLayout(Widget* widget, const std::string& str) override; void saveLayout(Widget* widget, const std::string& str) override;
}; };
static os::DisplayRef main_display = nullptr; static os::WindowRef main_window = nullptr;
static CustomizedGuiManager* manager = nullptr; static CustomizedGuiManager* manager = nullptr;
static Theme* gui_theme = nullptr; static Theme* gui_theme = nullptr;
@ -109,7 +109,7 @@ static void load_gui_config(int& w, int& h, bool& maximized,
std::string& windowLayout); std::string& windowLayout);
static void save_gui_config(); static void save_gui_config();
static bool create_main_display(bool gpuAccel, static bool create_main_window(bool gpuAccel,
bool& maximized, bool& maximized,
std::string& lastError) std::string& lastError)
{ {
@ -125,44 +125,44 @@ static bool create_main_display(bool gpuAccel,
try { try {
if (w > 0 && h > 0) { if (w > 0 && h > 0) {
main_display = os::instance()->makeDisplay( main_window = os::instance()->makeWindow(
w, h, (scale == 0 ? 2: base::clamp(scale, 1, 4))); w, h, (scale == 0 ? 2: base::clamp(scale, 1, 4)));
} }
} }
catch (const os::DisplayCreationException& e) { catch (const os::WindowCreationException& e) {
lastError = e.what(); lastError = e.what();
} }
if (!main_display) { if (!main_window) {
for (int c=0; try_resolutions[c].width; ++c) { for (int c=0; try_resolutions[c].width; ++c) {
try { try {
main_display = main_window =
os::instance()->makeDisplay( os::instance()->makeWindow(
try_resolutions[c].width, try_resolutions[c].width,
try_resolutions[c].height, try_resolutions[c].height,
(scale == 0 ? try_resolutions[c].scale: scale)); (scale == 0 ? try_resolutions[c].scale: scale));
break; break;
} }
catch (const os::DisplayCreationException& e) { catch (const os::WindowCreationException& e) {
lastError = e.what(); lastError = e.what();
} }
} }
} }
if (main_display) { if (main_window) {
// Change the scale value only in the first run (this will be // Change the scale value only in the first run (this will be
// saved when the program is closed). // saved when the program is closed).
if (scale == 0) if (scale == 0)
Preferences::instance().general.screenScale(main_display->scale()); Preferences::instance().general.screenScale(main_window->scale());
if (!windowLayout.empty()) { if (!windowLayout.empty()) {
main_display->setLayout(windowLayout); main_window->setLayout(windowLayout);
if (main_display->isMinimized()) if (main_window->isMinimized())
main_display->maximize(); main_window->maximize();
} }
} }
return (main_display != nullptr); return (main_window != nullptr);
} }
// Initializes GUI. // Initializes GUI.
@ -173,40 +173,40 @@ int init_module_gui()
std::string lastError = "Unknown error"; std::string lastError = "Unknown error";
bool gpuAccel = pref.general.gpuAcceleration(); bool gpuAccel = pref.general.gpuAcceleration();
if (!create_main_display(gpuAccel, maximized, lastError)) { if (!create_main_window(gpuAccel, maximized, lastError)) {
// If we've created the display with hardware acceleration, // If we've created the native window with hardware acceleration,
// now we try to do it without hardware acceleration. // now we try to do it without hardware acceleration.
if (gpuAccel && if (gpuAccel &&
(int(os::instance()->capabilities()) & (int(os::instance()->capabilities()) &
int(os::Capabilities::GpuAccelerationSwitch)) == int(os::Capabilities::GpuAccelerationSwitch)) { int(os::Capabilities::GpuAccelerationSwitch)) == int(os::Capabilities::GpuAccelerationSwitch)) {
if (create_main_display(false, maximized, lastError)) { if (create_main_window(false, maximized, lastError)) {
// Disable hardware acceleration // Disable hardware acceleration
pref.general.gpuAcceleration(false); pref.general.gpuAcceleration(false);
} }
} }
} }
if (!main_display) { if (!main_window) {
os::error_message( os::error_message(
("Unable to create a user-interface display.\nDetails: "+lastError+"\n").c_str()); ("Unable to create a user-interface window.\nDetails: "+lastError+"\n").c_str());
return -1; return -1;
} }
// Create the default-manager // Create the default-manager
manager = new CustomizedGuiManager(); manager = new CustomizedGuiManager();
manager->setDisplay(main_display.get()); manager->setNativeWindow(main_window.get());
// Setup the GUI theme for all widgets // Setup the GUI theme for all widgets
gui_theme = new SkinTheme; gui_theme = new SkinTheme;
ui::set_theme(gui_theme, pref.general.uiScale()); ui::set_theme(gui_theme, pref.general.uiScale());
if (maximized) if (maximized)
main_display->maximize(); main_window->maximize();
// Handle live resize too redraw the entire manager, dispatch the UI // Handle live resize too redraw the entire manager, dispatch the UI
// messages, and flip the display. // messages, and flip the window.
main_display->handleResize = main_window->handleResize =
[](os::Display* display) { [](os::Window* window) {
manager->invalidate(); manager->invalidate();
Message* msg = new Message(kResizeDisplayMessage); Message* msg = new Message(kResizeDisplayMessage);
@ -221,7 +221,7 @@ int init_module_gui()
// Set graphics options for next time // Set graphics options for next time
save_gui_config(); save_gui_config();
update_displays_color_profile_from_preferences(); update_windows_color_profile_from_preferences();
return 0; return 0;
} }
@ -238,10 +238,10 @@ void exit_module_gui()
delete gui_theme; delete gui_theme;
// This should be the last unref() of the display to delete it. // This should be the last unref() of the display to delete it.
main_display.reset(); main_window.reset();
} }
void update_displays_color_profile_from_preferences() void update_windows_color_profile_from_preferences()
{ {
auto system = os::instance(); auto system = os::instance();
@ -253,10 +253,10 @@ void update_displays_color_profile_from_preferences()
switch (windowProfile) { switch (windowProfile) {
case gen::WindowColorProfile::MONITOR: case gen::WindowColorProfile::MONITOR:
system->setDisplaysColorSpace(nullptr); system->setWindowsColorSpace(nullptr);
break; break;
case gen::WindowColorProfile::SRGB: case gen::WindowColorProfile::SRGB:
system->setDisplaysColorSpace( system->setWindowsColorSpace(
system->makeColorSpace(gfx::ColorSpace::MakeSRGB())); system->makeColorSpace(gfx::ColorSpace::MakeSRGB()));
break; break;
case gen::WindowColorProfile::SPECIFIC: { case gen::WindowColorProfile::SPECIFIC: {
@ -270,7 +270,7 @@ void update_displays_color_profile_from_preferences()
auto gfxCs = cs->gfxColorSpace(); auto gfxCs = cs->gfxColorSpace();
if (gfxCs->type() == gfx::ColorSpace::ICC && if (gfxCs->type() == gfx::ColorSpace::ICC &&
gfxCs->name() == name) { gfxCs->name() == name) {
system->setDisplaysColorSpace(cs); system->setWindowsColorSpace(cs);
break; break;
} }
} }
@ -282,7 +282,7 @@ void update_displays_color_profile_from_preferences()
static void load_gui_config(int& w, int& h, bool& maximized, static void load_gui_config(int& w, int& h, bool& maximized,
std::string& windowLayout) std::string& windowLayout)
{ {
gfx::Size defSize = os::instance()->defaultNewDisplaySize(); gfx::Size defSize = os::instance()->defaultNewWindowSize();
w = get_config_int("GfxMode", "Width", defSize.w); w = get_config_int("GfxMode", "Width", defSize.w);
h = get_config_int("GfxMode", "Height", defSize.h); h = get_config_int("GfxMode", "Height", defSize.h);
@ -292,13 +292,13 @@ static void load_gui_config(int& w, int& h, bool& maximized,
static void save_gui_config() static void save_gui_config()
{ {
os::Display* display = manager->getDisplay(); os::Window* window = manager->nativeWindow();
if (display) { if (window) {
set_config_bool("GfxMode", "Maximized", display->isMaximized()); set_config_bool("GfxMode", "Maximized", window->isMaximized());
set_config_int("GfxMode", "Width", display->originalWidth()); set_config_int("GfxMode", "Width", window->originalWidth());
set_config_int("GfxMode", "Height", display->originalHeight()); set_config_int("GfxMode", "Height", window->originalHeight());
std::string windowLayout = display->getLayout(); std::string windowLayout = window->getLayout();
if (!windowLayout.empty()) if (!windowLayout.empty())
set_config_string("GfxMode", "WindowLayout", windowLayout.c_str()); set_config_string("GfxMode", "WindowLayout", windowLayout.c_str());
} }
@ -575,8 +575,8 @@ bool CustomizedGuiManager::onProcessDevModeKeyDown(KeyMessage* msg)
if (msg->ctrlPressed() && if (msg->ctrlPressed() &&
msg->scancode() == kKeyF1) { msg->scancode() == kKeyF1) {
try { try {
os::Display* display = getDisplay(); os::Window* window = nativeWindow();
int screenScale = display->scale(); int screenScale = window->scale();
int uiScale = ui::guiscale(); int uiScale = ui::guiscale();
if (msg->shiftPressed()) { if (msg->shiftPressed()) {
@ -611,9 +611,9 @@ bool CustomizedGuiManager::onProcessDevModeKeyDown(KeyMessage* msg)
if (uiScale != ui::guiscale()) { if (uiScale != ui::guiscale()) {
ui::set_theme(ui::get_theme(), uiScale); ui::set_theme(ui::get_theme(), uiScale);
} }
if (screenScale != display->scale()) { if (screenScale != window->scale()) {
display->setScale(screenScale); window->setScale(screenScale);
setDisplay(display); setWindow(window);
} }
} }
catch (const std::exception& ex) { catch (const std::exception& ex) {
@ -659,7 +659,7 @@ void CustomizedGuiManager::onNewDisplayConfiguration()
save_gui_config(); save_gui_config();
// TODO Should we provide a more generic way for all ui::Window to // TODO Should we provide a more generic way for all ui::Window to
// detect the ui::Display (or UI Screen Scaling) change? // detect the os::Window (or UI Screen Scaling) change?
Console::notifyNewDisplayConfiguration(); Console::notifyNewDisplayConfiguration();
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2018-2019 Igara Studio S.A. // Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2017 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -35,7 +35,7 @@ namespace app {
int init_module_gui(); int init_module_gui();
void exit_module_gui(); void exit_module_gui();
void update_displays_color_profile_from_preferences(); void update_windows_color_profile_from_preferences();
void update_screen_for_document(const Doc* document); void update_screen_for_document(const Doc* document);
void load_window_pos(ui::Widget* window, const char* section, void load_window_pos(ui::Widget* window, const char* section,

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2019-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -39,7 +39,6 @@
#include "doc/layer.h" #include "doc/layer.h"
#include "doc/primitives.h" #include "doc/primitives.h"
#include "gfx/rect_io.h" #include "gfx/rect_io.h"
#include "os/display.h"
#include "render/render.h" #include "render/render.h"
#include "ui/manager.h" #include "ui/manager.h"
#include "ui/system.h" #include "ui/system.h"

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -61,7 +61,6 @@
#include "doc/slice.h" #include "doc/slice.h"
#include "fmt/format.h" #include "fmt/format.h"
#include "os/color_space.h" #include "os/color_space.h"
#include "os/display.h"
#include "os/surface.h" #include "os/surface.h"
#include "os/system.h" #include "os/system.h"
#include "render/rasterize.h" #include "render/rasterize.h"

View File

@ -1,4 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2021 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2017 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -16,7 +17,7 @@
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
#include "doc/sprite.h" #include "doc/sprite.h"
#include "gfx/rect.h" #include "gfx/rect.h"
#include "os/display.h" #include "os/window.h"
#include "ui/manager.h" #include "ui/manager.h"
#include "ui/message.h" #include "ui/message.h"
#include "ui/system.h" #include "ui/system.h"
@ -66,7 +67,7 @@ bool ZoomingState::onMouseUp(Editor* editor, MouseMessage* msg)
bool ZoomingState::onMouseMove(Editor* editor, MouseMessage* msg) bool ZoomingState::onMouseMove(Editor* editor, MouseMessage* msg)
{ {
gfx::Point pt = (msg->position() - m_startPos); gfx::Point pt = (msg->position() - m_startPos);
int threshold = 8 * guiscale() * editor->manager()->getDisplay()->scale(); int threshold = 8 * guiscale() * editor->manager()->nativeWindow()->scale();
if (m_moved || std::sqrt(pt.x*pt.x + pt.y*pt.y) > threshold) { if (m_moved || std::sqrt(pt.x*pt.x + pt.y*pt.y) > threshold) {
m_moved = true; m_moved = true;

View File

@ -39,8 +39,8 @@
#include "app/ui/workspace_tabs.h" #include "app/ui/workspace_tabs.h"
#include "app/ui_context.h" #include "app/ui_context.h"
#include "base/fs.h" #include "base/fs.h"
#include "os/display.h"
#include "os/system.h" #include "os/system.h"
#include "os/window.h"
#include "ui/message.h" #include "ui/message.h"
#include "ui/splitter.h" #include "ui/splitter.h"
#include "ui/system.h" #include "ui/system.h"
@ -78,9 +78,9 @@ public:
ui::set_theme(ui::get_theme(), newUIScale); ui::set_theme(ui::get_theme(), newUIScale);
Manager* manager = Manager::getDefault(); Manager* manager = Manager::getDefault();
os::Display* display = manager->getDisplay(); os::Window* window = manager->nativeWindow();
display->setScale(newScreenScale); window->setScale(newScreenScale);
manager->setDisplay(display); manager->setNativeWindow(window);
} }
}; };
@ -370,9 +370,9 @@ void MainWindow::onResize(ui::ResizeEvent& ev)
{ {
app::gen::MainWindow::onResize(ev); app::gen::MainWindow::onResize(ev);
os::Display* display = manager()->getDisplay(); os::Window* window = manager()->nativeWindow();
if ((display) && if ((window) &&
(display->scale()*ui::guiscale() > 2) && (window->scale()*ui::guiscale() > 2) &&
(!m_scalePanic) && (!m_scalePanic) &&
(ui::display_w()/ui::guiscale() < 320 || (ui::display_w()/ui::guiscale() < 320 ||
ui::display_h()/ui::guiscale() < 260)) { ui::display_h()/ui::guiscale() < 260)) {

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2020 Igara Studio S.A. // Copyright (C) 2020-2021 Igara Studio S.A.
// Copyright (C) 2016-2018 David Capello // Copyright (C) 2016-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -22,8 +22,8 @@
#include "doc/palette_io.h" #include "doc/palette_io.h"
#include "doc/tileset_io.h" #include "doc/tileset_io.h"
#include "gfx/size.h" #include "gfx/size.h"
#include "os/display.h"
#include "os/system.h" #include "os/system.h"
#include "os/window.h"
#include "ui/alert.h" #include "ui/alert.h"
#include <sstream> #include <sstream>
@ -37,8 +37,8 @@ using namespace base::serialization::little_endian;
namespace { namespace {
clip::format custom_image_format = 0; clip::format custom_image_format = 0;
void* native_display_handle() { void* native_window_handle() {
return os::instance()->defaultDisplay()->nativeHandle(); return os::instance()->defaultWindow()->nativeHandle();
} }
void custom_error_handler(clip::ErrorCode code) { void custom_error_handler(clip::ErrorCode code) {
@ -70,7 +70,7 @@ bool Clipboard::setNativeBitmap(const doc::Image* image,
const doc::Palette* palette, const doc::Palette* palette,
const doc::Tileset* tileset) const doc::Tileset* tileset)
{ {
clip::lock l(native_display_handle()); clip::lock l(native_window_handle());
if (!l.locked()) if (!l.locked())
return false; return false;
@ -177,7 +177,7 @@ bool Clipboard::getNativeBitmap(doc::Image** image,
*palette = nullptr; *palette = nullptr;
*tileset = nullptr; *tileset = nullptr;
clip::lock l(native_display_handle()); clip::lock l(native_window_handle());
if (!l.locked()) if (!l.locked())
return false; return false;

View File

@ -1,4 +1,4 @@
Copyright (c) 2018-2020 Igara Studio S.A. Copyright (c) 2018-2021 Igara Studio S.A.
Copyright (c) 2001-2018 David Capello Copyright (c) 2001-2018 David Capello
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining

View File

@ -1,5 +1,5 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2019-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -19,11 +19,11 @@
#include "gfx/rect.h" #include "gfx/rect.h"
#include "gfx/region.h" #include "gfx/region.h"
#include "gfx/size.h" #include "gfx/size.h"
#include "os/display.h"
#include "os/draw_text.h" #include "os/draw_text.h"
#include "os/font.h" #include "os/font.h"
#include "os/surface.h" #include "os/surface.h"
#include "os/system.h" #include "os/system.h"
#include "os/window.h"
#include "ui/manager.h" #include "ui/manager.h"
#include "ui/scale.h" #include "ui/scale.h"
#include "ui/theme.h" #include "ui/theme.h"
@ -45,7 +45,7 @@ Graphics::~Graphics()
{ {
// If we were drawing in the screen surface, we mark these regions // If we were drawing in the screen surface, we mark these regions
// as dirty for the final flip. // as dirty for the final flip.
if (m_surface == os::instance()->defaultDisplay()->surface()) if (m_surface == os::instance()->defaultWindow()->surface())
Manager::getDefault()->dirtyRect(m_dirtyBounds); Manager::getDefault()->dirtyRect(m_dirtyBounds);
} }
@ -612,7 +612,7 @@ void Graphics::dirty(const gfx::Rect& bounds)
// ScreenGraphics // ScreenGraphics
ScreenGraphics::ScreenGraphics() ScreenGraphics::ScreenGraphics()
: Graphics(AddRef(os::instance()->defaultDisplay()->surface()), 0, 0) : Graphics(AddRef(os::instance()->defaultWindow()->surface()), 0, 0)
{ {
setFont(AddRef(get_theme()->getDefaultFont())); setFont(AddRef(get_theme()->getDefaultFont()));
} }

View File

@ -1,5 +1,5 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -22,11 +22,11 @@
#include "base/concurrent_queue.h" #include "base/concurrent_queue.h"
#include "base/scoped_value.h" #include "base/scoped_value.h"
#include "base/time.h" #include "base/time.h"
#include "os/display.h"
#include "os/event.h" #include "os/event.h"
#include "os/event_queue.h" #include "os/event_queue.h"
#include "os/surface.h" #include "os/surface.h"
#include "os/system.h" #include "os/system.h"
#include "os/window.h"
#include "ui/intern.h" #include "ui/intern.h"
#include "ui/ui.h" #include "ui/ui.h"
@ -162,7 +162,7 @@ bool Manager::widgetAssociatedToManager(Widget* widget)
Manager::Manager() Manager::Manager()
: Widget(kManagerWidget) : Widget(kManagerWidget)
, m_display(nullptr) , m_window(nullptr)
, m_eventQueue(nullptr) , m_eventQueue(nullptr)
, m_lockedWindow(nullptr) , m_lockedWindow(nullptr)
, m_mouseButton(kButtonNone) , m_mouseButton(kButtonNone)
@ -226,13 +226,13 @@ Manager::~Manager()
} }
} }
void Manager::setDisplay(os::Display* display) void Manager::setNativeWindow(os::Window* window)
{ {
base::ScopedValue<bool> lock( base::ScopedValue<bool> lock(
auto_window_adjustment, false, auto_window_adjustment, false,
auto_window_adjustment); auto_window_adjustment);
m_display = display; m_window = window;
m_eventQueue = os::instance()->eventQueue(); m_eventQueue = os::instance()->eventQueue();
onNewDisplayConfiguration(); onNewDisplayConfiguration();
@ -255,7 +255,7 @@ void Manager::run()
void Manager::flipDisplay() void Manager::flipDisplay()
{ {
if (!m_display) if (!m_window)
return; return;
OverlayManager* overlays = OverlayManager::instance(); OverlayManager* overlays = OverlayManager::instance();
@ -271,7 +271,7 @@ void Manager::flipDisplay()
gfx::Region(gfx::Rect(0, 0, ui::display_w(), ui::display_h()))); gfx::Region(gfx::Rect(0, 0, ui::display_w(), ui::display_h())));
if (!m_dirtyRegion.isEmpty()) { if (!m_dirtyRegion.isEmpty()) {
m_display->invalidateRegion(m_dirtyRegion); m_window->invalidateRegion(m_dirtyRegion);
m_dirtyRegion.clear(); m_dirtyRegion.clear();
} }
} }
@ -385,7 +385,7 @@ void Manager::generateMessagesFromOSEvents()
break; break;
} }
case os::Event::CloseDisplay: { case os::Event::CloseWindow: {
Message* msg = new Message(kCloseDisplayMessage); Message* msg = new Message(kCloseDisplayMessage);
msg->setRecipient(this); msg->setRecipient(this);
msg->setPropagateToChildren(true); msg->setPropagateToChildren(true);
@ -393,7 +393,7 @@ void Manager::generateMessagesFromOSEvents()
break; break;
} }
case os::Event::ResizeDisplay: { case os::Event::ResizeWindow: {
Message* msg = new Message(kResizeDisplayMessage); Message* msg = new Message(kResizeDisplayMessage);
msg->setRecipient(this); msg->setRecipient(this);
msg->setPropagateToChildren(true); msg->setPropagateToChildren(true);
@ -888,7 +888,7 @@ void Manager::setCapture(Widget* widget)
widget->enableFlags(HAS_CAPTURE); widget->enableFlags(HAS_CAPTURE);
capture_widget = widget; capture_widget = widget;
m_display->captureMouse(); m_window->captureMouse();
} }
// Sets the focus to the "magnetic" widget inside the window // Sets the focus to the "magnetic" widget inside the window
@ -928,7 +928,7 @@ void Manager::freeCapture()
capture_widget->disableFlags(HAS_CAPTURE); capture_widget->disableFlags(HAS_CAPTURE);
capture_widget = nullptr; capture_widget = nullptr;
m_display->releaseMouse(); m_window->releaseMouse();
} }
} }
@ -1309,8 +1309,8 @@ void Manager::onInitTheme(InitThemeEvent& ev)
gfx::Rect bounds = window->bounds(); gfx::Rect bounds = window->bounds();
bounds *= newUIScale; bounds *= newUIScale;
bounds /= oldUIScale; bounds /= oldUIScale;
bounds.x = base::clamp(bounds.x, 0, m_display->width() - bounds.w); bounds.x = base::clamp(bounds.x, 0, m_window->width() - bounds.w);
bounds.y = base::clamp(bounds.y, 0, m_display->height() - bounds.h); bounds.y = base::clamp(bounds.y, 0, m_window->height() - bounds.h);
window->setBounds(bounds); window->setBounds(bounds);
} }
} }
@ -1324,16 +1324,16 @@ LayoutIO* Manager::onGetLayoutIO()
void Manager::onNewDisplayConfiguration() void Manager::onNewDisplayConfiguration()
{ {
if (m_display) { if (m_window) {
int w = m_display->width() / m_display->scale(); int w = m_window->width() / m_window->scale();
int h = m_display->height() / m_display->scale(); int h = m_window->height() / m_window->scale();
if ((bounds().w != w || if ((bounds().w != w ||
bounds().h != h)) { bounds().h != h)) {
setBounds(gfx::Rect(0, 0, w, h)); setBounds(gfx::Rect(0, 0, w, h));
} }
} }
_internal_set_mouse_display(m_display); _internal_set_mouse_window(m_window);
invalidate(); invalidate();
flushRedraw(); flushRedraw();
} }
@ -1500,7 +1500,7 @@ bool Manager::sendMessageToWidget(Message* msg, Widget* widget)
// Restore overlays in the region that we're going to paint. // Restore overlays in the region that we're going to paint.
OverlayManager::instance()->restoreOverlappedAreas(paintMsg->rect()); OverlayManager::instance()->restoreOverlappedAreas(paintMsg->rect());
os::Surface* surface = m_display->surface(); os::Surface* surface = m_window->surface();
surface->saveClip(); surface->saveClip();
if (surface->clipRect(paintMsg->rect())) { if (surface->clipRect(paintMsg->rect())) {
@ -1519,10 +1519,10 @@ bool Manager::sendMessageToWidget(Message* msg, Widget* widget)
surface->fillRect(gfx::rgba(0, 0, 255), paintMsg->rect()); surface->fillRect(gfx::rgba(0, 0, 255), paintMsg->rect());
} }
if (m_display) { if (m_window) {
m_display->invalidateRegion( m_window->invalidateRegion(
gfx::Region(gfx::Rect(0, 0, display_w(), display_h()))); gfx::Region(gfx::Rect(0, 0, display_w(), display_h())));
// TODO m_display->update() ?? // TODO m_window->update() ??
} }
base::this_thread::sleep_for(0.002); base::this_thread::sleep_for(0.002);

View File

@ -1,5 +1,5 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-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.
@ -17,8 +17,8 @@
#include "ui/widget.h" #include "ui/widget.h"
namespace os { namespace os {
class Display;
class EventQueue; class EventQueue;
class Window;
} }
namespace ui { namespace ui {
@ -35,9 +35,8 @@ namespace ui {
Manager(); Manager();
~Manager(); ~Manager();
os::Display* getDisplay() { return m_display; } os::Window* nativeWindow() { return m_window; }
void setNativeWindow(os::Window* window);
void setDisplay(os::Display* display);
// Executes the main message loop. // Executes the main message loop.
void run(); void run();
@ -168,7 +167,7 @@ namespace ui {
static gfx::Region m_dirtyRegion; static gfx::Region m_dirtyRegion;
WidgetsList m_garbage; WidgetsList m_garbage;
os::Display* m_display; os::Window* m_window;
os::EventQueue* m_eventQueue; os::EventQueue* m_eventQueue;
gfx::Region m_invalidRegion; // Invalid region (we didn't receive paint messages yet for this). gfx::Region m_invalidRegion; // Invalid region (we didn't receive paint messages yet for this).

View File

@ -1,5 +1,5 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -11,9 +11,9 @@
#include "ui/manager.h" #include "ui/manager.h"
#include "os/display.h"
#include "os/surface.h" #include "os/surface.h"
#include "os/system.h" #include "os/system.h"
#include "os/window.h"
#include "ui/overlay_manager.h" #include "ui/overlay_manager.h"
#include <vector> #include <vector>
@ -24,9 +24,9 @@ using namespace gfx;
void move_region(Manager* manager, const Region& region, int dx, int dy) void move_region(Manager* manager, const Region& region, int dx, int dy)
{ {
os::Display* display = manager->getDisplay(); os::Window* window = manager->nativeWindow();
ASSERT(display); ASSERT(window);
if (!display) if (!window)
return; return;
auto overlays = ui::OverlayManager::instance(); auto overlays = ui::OverlayManager::instance();
@ -34,7 +34,7 @@ void move_region(Manager* manager, const Region& region, int dx, int dy)
bounds |= gfx::Rect(bounds).offset(dx, dy); bounds |= gfx::Rect(bounds).offset(dx, dy);
overlays->restoreOverlappedAreas(bounds); overlays->restoreOverlappedAreas(bounds);
os::Surface* surface = display->surface(); os::Surface* surface = window->surface();
os::SurfaceLock lock(surface); os::SurfaceLock lock(surface);
// Fast path, move one rectangle. // Fast path, move one rectangle.

View File

@ -1,5 +1,5 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello // Copyright (C) 2001-2016 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -11,8 +11,8 @@
#include "ui/overlay_manager.h" #include "ui/overlay_manager.h"
#include "os/display.h"
#include "os/surface.h" #include "os/surface.h"
#include "os/window.h"
#include "ui/manager.h" #include "ui/manager.h"
#include "ui/overlay.h" #include "ui/overlay.h"
@ -86,11 +86,11 @@ void OverlayManager::drawOverlays()
if (!manager) if (!manager)
return; return;
os::Surface* displaySurface = manager->getDisplay()->surface(); os::Surface* windowSurface = manager->nativeWindow()->surface();
os::SurfaceLock lock(displaySurface); os::SurfaceLock lock(windowSurface);
for (auto& overlay : *this) for (auto& overlay : *this)
overlay->captureOverlappedArea(displaySurface); overlay->captureOverlappedArea(windowSurface);
for (auto& overlay : *this) for (auto& overlay : *this)
overlay->drawOverlay(); overlay->drawOverlay();

View File

@ -1,5 +1,5 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -13,11 +13,11 @@
#include "base/thread.h" #include "base/thread.h"
#include "gfx/point.h" #include "gfx/point.h"
#include "os/display.h"
#include "os/event.h" #include "os/event.h"
#include "os/event_queue.h" #include "os/event_queue.h"
#include "os/surface.h" #include "os/surface.h"
#include "os/system.h" #include "os/system.h"
#include "os/window.h"
#include "ui/clipboard_delegate.h" #include "ui/clipboard_delegate.h"
#include "ui/cursor.h" #include "ui/cursor.h"
#include "ui/intern.h" #include "ui/intern.h"
@ -40,7 +40,7 @@ base::thread::native_id_type main_gui_thread;
static CursorType mouse_cursor_type = kOutsideDisplay; static CursorType mouse_cursor_type = kOutsideDisplay;
static const Cursor* mouse_cursor_custom = nullptr; static const Cursor* mouse_cursor_custom = nullptr;
static const Cursor* mouse_cursor = nullptr; static const Cursor* mouse_cursor = nullptr;
static os::Display* mouse_display = nullptr; static os::Window* mouse_window = nullptr;
static OverlayRef mouse_cursor_overlay = nullptr; static OverlayRef mouse_cursor_overlay = nullptr;
static bool use_native_mouse_cursor = true; static bool use_native_mouse_cursor = true;
static bool support_native_custom_cursor = false; static bool support_native_custom_cursor = false;
@ -83,20 +83,20 @@ static bool update_custom_native_cursor(const Cursor* cursor)
// Check if we can use a custom native mouse in this platform // Check if we can use a custom native mouse in this platform
if (support_native_custom_cursor && if (support_native_custom_cursor &&
mouse_display) { mouse_window) {
if (cursor) { if (cursor) {
result = mouse_display->setNativeMouseCursor( result = mouse_window->setNativeMouseCursor(
// The surface is already scaled by guiscale() // The surface is already scaled by guiscale()
cursor->getSurface().get(), cursor->getSurface().get(),
cursor->getFocus(), cursor->getFocus(),
// We scale the cursor by the os::Display scale // We scale the cursor by the os::Display scale
mouse_display->scale() * mouse_cursor_scale); mouse_window->scale() * mouse_cursor_scale);
} }
else if (mouse_cursor_type == kOutsideDisplay) { else if (mouse_cursor_type == kOutsideDisplay) {
result = mouse_display->setNativeMouseCursor(os::kArrowCursor); result = mouse_window->setNativeMouseCursor(os::kArrowCursor);
} }
else { else {
result = mouse_display->setNativeMouseCursor(os::kNoCursor); result = mouse_window->setNativeMouseCursor(os::kNoCursor);
} }
} }
@ -146,8 +146,8 @@ static void update_mouse_cursor()
} }
// Set native cursor // Set native cursor
if (mouse_display) { if (mouse_window) {
bool ok = mouse_display->setNativeMouseCursor(nativeCursor); bool ok = mouse_window->setNativeMouseCursor(nativeCursor);
// It looks like the specific native cursor is not supported, // It looks like the specific native cursor is not supported,
// so we can should use the internal overlay (even when we // so we can should use the internal overlay (even when we
@ -207,7 +207,7 @@ UISystem::~UISystem()
details::exitWidgets(); details::exitWidgets();
_internal_set_mouse_display(nullptr); _internal_set_mouse_window(nullptr);
if (!update_custom_native_cursor(nullptr)) if (!update_custom_native_cursor(nullptr))
update_mouse_overlay(nullptr); update_mouse_overlay(nullptr);
@ -215,27 +215,27 @@ UISystem::~UISystem()
g_instance = nullptr; g_instance = nullptr;
} }
void _internal_set_mouse_display(os::Display* display) void _internal_set_mouse_window(os::Window* window)
{ {
CursorType cursor = get_mouse_cursor(); CursorType cursor = get_mouse_cursor();
set_mouse_cursor(kNoCursor); set_mouse_cursor(kNoCursor);
mouse_display = display; mouse_window = window;
if (display) if (window)
set_mouse_cursor(cursor); // Restore mouse cursor set_mouse_cursor(cursor); // Restore mouse cursor
} }
int display_w() int display_w()
{ {
if (mouse_display) if (mouse_window)
return mouse_display->width() / mouse_display->scale(); return mouse_window->width() / mouse_window->scale();
else else
return 1; return 1;
} }
int display_h() int display_h()
{ {
if (mouse_display) if (mouse_window)
return mouse_display->height() / mouse_display->scale(); return mouse_window->height() / mouse_window->scale();
else else
return 1; return 1;
} }
@ -331,8 +331,8 @@ const gfx::Point& get_mouse_position()
void set_mouse_position(const gfx::Point& newPos) void set_mouse_position(const gfx::Point& newPos)
{ {
if (mouse_display) if (mouse_window)
mouse_display->setMousePosition(newPos); mouse_window->setMousePosition(newPos);
_internal_set_mouse_position(newPos); _internal_set_mouse_position(newPos);
} }

View File

@ -1,5 +1,5 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2019-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -16,7 +16,7 @@
#include <functional> #include <functional>
#include <string> #include <string>
namespace os { class Display; } namespace os { class Window; }
namespace ui { namespace ui {
@ -61,7 +61,7 @@ namespace ui {
void hide_mouse_cursor(); void hide_mouse_cursor();
void show_mouse_cursor(); void show_mouse_cursor();
void _internal_set_mouse_display(os::Display* display); void _internal_set_mouse_window(os::Window* window);
void _internal_no_mouse_position(); void _internal_no_mouse_position();
void _internal_set_mouse_position(const gfx::Point& newPos); void _internal_set_mouse_position(const gfx::Point& newPos);

View File

@ -16,10 +16,10 @@
#include "base/clamp.h" #include "base/clamp.h"
#include "base/memory.h" #include "base/memory.h"
#include "base/string.h" #include "base/string.h"
#include "os/display.h"
#include "os/font.h" #include "os/font.h"
#include "os/surface.h" #include "os/surface.h"
#include "os/system.h" #include "os/system.h"
#include "os/window.h"
#include "ui/init_theme_event.h" #include "ui/init_theme_event.h"
#include "ui/intern.h" #include "ui/intern.h"
#include "ui/layout_io.h" #include "ui/layout_io.h"
@ -28,9 +28,9 @@
#include "ui/message.h" #include "ui/message.h"
#include "ui/move_region.h" #include "ui/move_region.h"
#include "ui/paint_event.h" #include "ui/paint_event.h"
#include "ui/size_hint_event.h"
#include "ui/resize_event.h" #include "ui/resize_event.h"
#include "ui/save_layout_event.h" #include "ui/save_layout_event.h"
#include "ui/size_hint_event.h"
#include "ui/system.h" #include "ui/system.h"
#include "ui/theme.h" #include "ui/theme.h"
#include "ui/view.h" #include "ui/view.h"
@ -1158,7 +1158,7 @@ public:
void operator()(Graphics* graphics) { void operator()(Graphics* graphics) {
{ {
os::Surface* dst = os::instance()->defaultDisplay()->surface(); os::Surface* dst = os::instance()->defaultWindow()->surface();
os::SurfaceLock lockSrc(m_surface.get()); os::SurfaceLock lockSrc(m_surface.get());
os::SurfaceLock lockDst(dst); os::SurfaceLock lockDst(dst);
m_surface->blitTo( m_surface->blitTo(
@ -1178,7 +1178,7 @@ GraphicsPtr Widget::getGraphics(const gfx::Rect& clip)
{ {
GraphicsPtr graphics; GraphicsPtr graphics;
os::SurfaceRef surface; os::SurfaceRef surface;
os::Surface* defaultSurface = os::instance()->defaultDisplay()->surface(); os::Surface* defaultSurface = os::instance()->defaultWindow()->surface();
// In case of double-buffering, we need to create the temporary // In case of double-buffering, we need to create the temporary
// buffer only if the default surface is the screen. // buffer only if the default surface is the screen.