From 5d31314cdb23f314391e5eaebd7cea84f5179ac7 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 2 Feb 2021 15:59:28 -0300 Subject: [PATCH] Adapt code to the new os::Display -> os::Window refactor --- laf | 2 +- src/app/app.cpp | 12 ++-- src/app/color_spaces.cpp | 6 +- src/app/commands/cmd_fullscreen_mode.cpp | 14 ++-- src/app/commands/cmd_options.cpp | 16 ++--- src/app/commands/screenshot.cpp | 12 ++-- src/app/console.cpp | 2 +- src/app/doc.cpp | 8 +-- src/app/file_selector.cpp | 6 +- src/app/file_system.cpp | 7 +- src/app/modules/gui.cpp | 88 ++++++++++++------------ src/app/modules/gui.h | 4 +- src/app/ui/editor/brush_preview.cpp | 3 +- src/app/ui/editor/editor.cpp | 3 +- src/app/ui/editor/zooming_state.cpp | 5 +- src/app/ui/main_window.cpp | 14 ++-- src/app/util/clipboard_native.cpp | 12 ++-- src/ui/LICENSE.txt | 2 +- src/ui/graphics.cpp | 8 +-- src/ui/manager.cpp | 42 +++++------ src/ui/manager.h | 11 ++- src/ui/move_region.cpp | 12 ++-- src/ui/overlay_manager.cpp | 10 +-- src/ui/system.cpp | 40 +++++------ src/ui/system.h | 6 +- src/ui/widget.cpp | 8 +-- 26 files changed, 176 insertions(+), 177 deletions(-) diff --git a/laf b/laf index 858e39c5e..417ace741 160000 --- a/laf +++ b/laf @@ -1 +1 @@ -Subproject commit 858e39c5eee871d940bba47edaf81c19b5976474 +Subproject commit 417ace74134d994db8223d91b6b13518cb4519f0 diff --git a/src/app/app.cpp b/src/app/app.cpp index 1d7f7b6f9..92a0b91f6 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2020 Igara Studio S.A. +// Copyright (C) 2018-2021 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -60,10 +60,10 @@ #include "base/split_string.h" #include "doc/sprite.h" #include "fmt/format.h" -#include "os/display.h" #include "os/error.h" #include "os/surface.h" #include "os/system.h" +#include "os/window.h" #include "render/render.h" #include "ui/intern.h" #include "ui/ui.h" @@ -359,7 +359,7 @@ void App::run() if (isGui()) { #ifdef _WIN32 // How to interpret one finger on Windows tablets. - ui::Manager::getDefault()->getDisplay() + ui::Manager::getDefault()->nativeWindow() ->setInterpretOneFingerGestureAsMouseMovement( preferences().experimental.oneFingerAsMouseMovement()); #endif @@ -367,7 +367,7 @@ void App::run() #if !defined(_WIN32) && !defined(__APPLE__) // Setup app icon for Linux window managers try { - os::Display* display = os::instance()->defaultDisplay(); + os::Window* window = os::instance()->defaultWindow(); os::SurfaceList icons; for (const int size : { 32, 64, 128 }) { @@ -380,7 +380,7 @@ void App::run() } } - display->setIcons(icons); + window->setIcons(icons); } catch (const std::exception&) { // Just ignore the exception, we couldn't change the app icon, no @@ -666,7 +666,7 @@ void App::updateDisplayTitleBar() } title += defaultTitle; - os::instance()->defaultDisplay()->setTitle(title); + os::instance()->defaultWindow()->setTitle(title); } InputChain& App::inputChain() diff --git a/src/app/color_spaces.cpp b/src/app/color_spaces.cpp index 625f1d2df..b34080e6b 100644 --- a/src/app/color_spaces.cpp +++ b/src/app/color_spaces.cpp @@ -1,5 +1,5 @@ // 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 // the End-User License Agreement for Aseprite. @@ -14,8 +14,8 @@ #include "app/modules/editors.h" #include "app/pref/preferences.h" #include "app/ui/editor/editor.h" -#include "os/display.h" #include "os/system.h" +#include "os/window.h" namespace app { @@ -35,7 +35,7 @@ void initialize_color_spaces(Preferences& pref) os::ColorSpaceRef get_screen_color_space() { - return os::instance()->defaultDisplay()->colorSpace(); + return os::instance()->defaultWindow()->colorSpace(); } os::ColorSpaceRef get_current_color_space() diff --git a/src/app/commands/cmd_fullscreen_mode.cpp b/src/app/commands/cmd_fullscreen_mode.cpp index ad6980911..3a78293c0 100644 --- a/src/app/commands/cmd_fullscreen_mode.cpp +++ b/src/app/commands/cmd_fullscreen_mode.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2020 Igara Studio S.A. +// Copyright (C) 2020-2021 Igara Studio S.A. // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -14,8 +14,8 @@ #include "app/commands/command.h" #include "app/commands/commands.h" #include "app/context.h" -#include "os/display.h" #include "os/system.h" +#include "os/window.h" namespace app { @@ -43,13 +43,13 @@ void FullscreenModeCommand::onExecute(Context* ctx) if (!manager) return; - os::Display* display = manager->getDisplay(); - ASSERT(display); - if (!display) + os::Window* window = manager->nativeWindow(); + ASSERT(window); + if (!window) return; - display->setFullscreen( - !display->isFullscreen()); + window->setFullscreen( + !window->isFullscreen()); } Command* CommandFactory::createFullscreenModeCommand() diff --git a/src/app/commands/cmd_options.cpp b/src/app/commands/cmd_options.cpp index e33383442..bcf5369ed 100644 --- a/src/app/commands/cmd_options.cpp +++ b/src/app/commands/cmd_options.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2020 Igara Studio S.A. +// Copyright (C) 2018-2021 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -38,8 +38,8 @@ #include "base/version.h" #include "doc/image.h" #include "fmt/format.h" -#include "os/display.h" #include "os/system.h" +#include "os/window.h" #include "render/render.h" #include "ui/ui.h" @@ -645,7 +645,7 @@ public: if (j == winCs) { name = gfxCs->name(); - os::instance()->setDisplaysColorSpace(cs); + os::instance()->setWindowsColorSpace(cs); break; } ++j; @@ -655,7 +655,7 @@ public: break; } } - update_displays_color_profile_from_preferences(); + update_windows_color_profile_from_preferences(); // Change sprite grid bounds if (m_context && m_context->activeDocument()) { @@ -725,7 +725,7 @@ public: m_pref.tablet.api(tabletStr); m_pref.experimental.loadWintabDriver(wintabState); - manager()->getDisplay() + manager()->nativeWindow() ->setInterpretOneFingerGestureAsMouseMovement( oneFingerAsMouseMovement()->isSelected()); @@ -845,10 +845,10 @@ private: void updateScreenScaling() { ui::Manager* manager = ui::Manager::getDefault(); - os::Display* display = manager->getDisplay(); + os::Window* window = manager->nativeWindow(); os::instance()->setGpuAcceleration(m_pref.general.gpuAcceleration()); - display->setScale(m_pref.general.screenScale()); - manager->setDisplay(display); + window->setScale(m_pref.general.screenScale()); + manager->setNativeWindow(window); } void onApply() { diff --git a/src/app/commands/screenshot.cpp b/src/app/commands/screenshot.cpp index 010c82c69..e0c5d975c 100644 --- a/src/app/commands/screenshot.cpp +++ b/src/app/commands/screenshot.cpp @@ -1,5 +1,5 @@ // 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 // the End-User License Agreement for Aseprite. @@ -25,8 +25,8 @@ #include "doc/layer.h" #include "doc/sprite.h" #include "fmt/format.h" -#include "os/display.h" #include "os/surface.h" +#include "os/window.h" #include "ui/alert.h" #include "ui/manager.h" #include "ui/scale.h" @@ -69,8 +69,8 @@ void ScreenshotCommand::onExecute(Context* ctx) app::ResourceFinder rf(false); rf.includeDesktopDir(""); - os::Display* display = ui::Manager::getDefault()->getDisplay(); - os::Surface* surface = display->surface(); + os::Window* window = ui::Manager::getDefault()->nativeWindow(); + os::Surface* surface = window->surface(); std::string fn; if (params().save()) { @@ -89,7 +89,7 @@ void ScreenshotCommand::onExecute(Context* ctx) surface->width(), surface->height(), 0, // Mask color - display->colorSpace()->gfxColorSpace()); + window->colorSpace()->gfxColorSpace()); doc::Sprite* spr = doc::Sprite::MakeStdSprite(spec); static_cast(spr->firstLayer())->configureAsBackground(); @@ -122,7 +122,7 @@ void ScreenshotCommand::onExecute(Context* ctx) // Get image again (cmd::convert_color_profile() might have changed it) img = cel->image(); - const int scale = display->scale(); + const int scale = window->scale(); base::buffer rgbBuffer(3*w*h*scale*scale); int c = 0; doc::LockImageBits bits(img); diff --git a/src/app/console.cpp b/src/app/console.cpp index 67b39d7e3..78c1951da 100644 --- a/src/app/console.cpp +++ b/src/app/console.cpp @@ -123,7 +123,7 @@ Console::Console(Context* ctx) (App::instance() && App::instance()->isGui() && Manager::getDefault() && - Manager::getDefault()->getDisplay()); + Manager::getDefault()->nativeWindow()); if (!m_withUI) return; diff --git a/src/app/doc.cpp b/src/app/doc.cpp index f867f1f55..840994009 100644 --- a/src/app/doc.cpp +++ b/src/app/doc.cpp @@ -30,11 +30,11 @@ #include "doc/mask.h" #include "doc/mask_boundaries.h" #include "doc/palette.h" +#include "doc/slice.h" #include "doc/sprite.h" #include "doc/tag.h" -#include "doc/slice.h" -#include "os/display.h" #include "os/system.h" +#include "os/window.h" #include "ui/system.h" #include @@ -612,8 +612,8 @@ void Doc::updateOSColorSpace(bool appWideSignal) auto system = os::instance(); if (system) { m_osColorSpace = system->makeColorSpace(sprite()->colorSpace()); - if (!m_osColorSpace && system->defaultDisplay()) - m_osColorSpace = system->defaultDisplay()->colorSpace(); + if (!m_osColorSpace && system->defaultWindow()) + m_osColorSpace = system->defaultWindow()->colorSpace(); } if (appWideSignal && diff --git a/src/app/file_selector.cpp b/src/app/file_selector.cpp index d7e8f0119..b5975356a 100644 --- a/src/app/file_selector.cpp +++ b/src/app/file_selector.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2020 Igara Studio S.A. +// Copyright (C) 2020-2021 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -14,9 +14,9 @@ #include "app/app.h" #include "app/pref/preferences.h" #include "app/ui/file_selector.h" -#include "os/display.h" #include "os/native_dialogs.h" #include "os/system.h" +#include "os/window.h" namespace app { @@ -59,7 +59,7 @@ bool show_file_selector( if (!defExtension.empty()) dlg->setDefaultExtension(defExtension); - bool res = dlg->show(os::instance()->defaultDisplay()); + bool res = dlg->show(os::instance()->defaultWindow()); if (res) { if (type == FileSelectorType::OpenMultiple) dlg->getMultipleFileNames(output); diff --git a/src/app/file_system.cpp b/src/app/file_system.cpp index 2b4eb95c9..70ad2d357 100644 --- a/src/app/file_system.cpp +++ b/src/app/file_system.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2021 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -19,9 +19,9 @@ #include "base/fs.h" #include "base/string.h" -#include "os/display.h" #include "os/surface.h" #include "os/system.h" +#include "os/window.h" #include #include @@ -455,7 +455,8 @@ const FileItemList& FileItem::children() ULONG c, fetched; // Get the interface to enumerate subitems - hr = pFolder->EnumObjects(reinterpret_cast(os::instance()->defaultDisplay()->nativeHandle()), + hr = pFolder->EnumObjects( + reinterpret_cast(os::instance()->defaultWindow()->nativeHandle()), SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &pEnum); if (hr == S_OK && pEnum != NULL) { diff --git a/src/app/modules/gui.cpp b/src/app/modules/gui.cpp index 8934679f3..25d33ef2d 100644 --- a/src/app/modules/gui.cpp +++ b/src/app/modules/gui.cpp @@ -42,10 +42,10 @@ #include "base/memory.h" #include "base/string.h" #include "doc/sprite.h" -#include "os/display.h" #include "os/error.h" #include "os/surface.h" #include "os/system.h" +#include "os/window.h" #include "ui/intern.h" #include "ui/ui.h" @@ -97,7 +97,7 @@ protected: 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 Theme* gui_theme = nullptr; @@ -109,7 +109,7 @@ static void load_gui_config(int& w, int& h, bool& maximized, std::string& windowLayout); static void save_gui_config(); -static bool create_main_display(bool gpuAccel, +static bool create_main_window(bool gpuAccel, bool& maximized, std::string& lastError) { @@ -125,44 +125,44 @@ static bool create_main_display(bool gpuAccel, try { 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))); } } - catch (const os::DisplayCreationException& e) { + catch (const os::WindowCreationException& e) { lastError = e.what(); } - if (!main_display) { + if (!main_window) { for (int c=0; try_resolutions[c].width; ++c) { try { - main_display = - os::instance()->makeDisplay( + main_window = + os::instance()->makeWindow( try_resolutions[c].width, try_resolutions[c].height, (scale == 0 ? try_resolutions[c].scale: scale)); break; } - catch (const os::DisplayCreationException& e) { + catch (const os::WindowCreationException& e) { lastError = e.what(); } } } - if (main_display) { + if (main_window) { // Change the scale value only in the first run (this will be // saved when the program is closed). if (scale == 0) - Preferences::instance().general.screenScale(main_display->scale()); + Preferences::instance().general.screenScale(main_window->scale()); if (!windowLayout.empty()) { - main_display->setLayout(windowLayout); - if (main_display->isMinimized()) - main_display->maximize(); + main_window->setLayout(windowLayout); + if (main_window->isMinimized()) + main_window->maximize(); } } - return (main_display != nullptr); + return (main_window != nullptr); } // Initializes GUI. @@ -173,40 +173,40 @@ int init_module_gui() std::string lastError = "Unknown error"; bool gpuAccel = pref.general.gpuAcceleration(); - if (!create_main_display(gpuAccel, maximized, lastError)) { - // If we've created the display with hardware acceleration, + if (!create_main_window(gpuAccel, maximized, lastError)) { + // If we've created the native window with hardware acceleration, // now we try to do it without hardware acceleration. if (gpuAccel && (int(os::instance()->capabilities()) & 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 pref.general.gpuAcceleration(false); } } } - if (!main_display) { + if (!main_window) { 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; } // Create the default-manager manager = new CustomizedGuiManager(); - manager->setDisplay(main_display.get()); + manager->setNativeWindow(main_window.get()); // Setup the GUI theme for all widgets gui_theme = new SkinTheme; ui::set_theme(gui_theme, pref.general.uiScale()); if (maximized) - main_display->maximize(); + main_window->maximize(); // Handle live resize too redraw the entire manager, dispatch the UI - // messages, and flip the display. - main_display->handleResize = - [](os::Display* display) { + // messages, and flip the window. + main_window->handleResize = + [](os::Window* window) { manager->invalidate(); Message* msg = new Message(kResizeDisplayMessage); @@ -221,7 +221,7 @@ int init_module_gui() // Set graphics options for next time save_gui_config(); - update_displays_color_profile_from_preferences(); + update_windows_color_profile_from_preferences(); return 0; } @@ -238,10 +238,10 @@ void exit_module_gui() delete gui_theme; // 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(); @@ -253,10 +253,10 @@ void update_displays_color_profile_from_preferences() switch (windowProfile) { case gen::WindowColorProfile::MONITOR: - system->setDisplaysColorSpace(nullptr); + system->setWindowsColorSpace(nullptr); break; case gen::WindowColorProfile::SRGB: - system->setDisplaysColorSpace( + system->setWindowsColorSpace( system->makeColorSpace(gfx::ColorSpace::MakeSRGB())); break; case gen::WindowColorProfile::SPECIFIC: { @@ -270,7 +270,7 @@ void update_displays_color_profile_from_preferences() auto gfxCs = cs->gfxColorSpace(); if (gfxCs->type() == gfx::ColorSpace::ICC && gfxCs->name() == name) { - system->setDisplaysColorSpace(cs); + system->setWindowsColorSpace(cs); break; } } @@ -282,7 +282,7 @@ void update_displays_color_profile_from_preferences() static void load_gui_config(int& w, int& h, bool& maximized, std::string& windowLayout) { - gfx::Size defSize = os::instance()->defaultNewDisplaySize(); + gfx::Size defSize = os::instance()->defaultNewWindowSize(); w = get_config_int("GfxMode", "Width", defSize.w); 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() { - os::Display* display = manager->getDisplay(); - if (display) { - set_config_bool("GfxMode", "Maximized", display->isMaximized()); - set_config_int("GfxMode", "Width", display->originalWidth()); - set_config_int("GfxMode", "Height", display->originalHeight()); + os::Window* window = manager->nativeWindow(); + if (window) { + set_config_bool("GfxMode", "Maximized", window->isMaximized()); + set_config_int("GfxMode", "Width", window->originalWidth()); + set_config_int("GfxMode", "Height", window->originalHeight()); - std::string windowLayout = display->getLayout(); + std::string windowLayout = window->getLayout(); if (!windowLayout.empty()) set_config_string("GfxMode", "WindowLayout", windowLayout.c_str()); } @@ -575,8 +575,8 @@ bool CustomizedGuiManager::onProcessDevModeKeyDown(KeyMessage* msg) if (msg->ctrlPressed() && msg->scancode() == kKeyF1) { try { - os::Display* display = getDisplay(); - int screenScale = display->scale(); + os::Window* window = nativeWindow(); + int screenScale = window->scale(); int uiScale = ui::guiscale(); if (msg->shiftPressed()) { @@ -611,9 +611,9 @@ bool CustomizedGuiManager::onProcessDevModeKeyDown(KeyMessage* msg) if (uiScale != ui::guiscale()) { ui::set_theme(ui::get_theme(), uiScale); } - if (screenScale != display->scale()) { - display->setScale(screenScale); - setDisplay(display); + if (screenScale != window->scale()) { + window->setScale(screenScale); + setWindow(window); } } catch (const std::exception& ex) { @@ -659,7 +659,7 @@ void CustomizedGuiManager::onNewDisplayConfiguration() save_gui_config(); // 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(); } diff --git a/src/app/modules/gui.h b/src/app/modules/gui.h index 4dabeacef..85cf1c969 100644 --- a/src/app/modules/gui.h +++ b/src/app/modules/gui.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2019 Igara Studio S.A. +// Copyright (C) 2018-2021 Igara Studio S.A. // Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of @@ -35,7 +35,7 @@ namespace app { int init_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 load_window_pos(ui::Widget* window, const char* section, diff --git a/src/app/ui/editor/brush_preview.cpp b/src/app/ui/editor/brush_preview.cpp index 28193d0d6..cfee3160b 100644 --- a/src/app/ui/editor/brush_preview.cpp +++ b/src/app/ui/editor/brush_preview.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2021 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -39,7 +39,6 @@ #include "doc/layer.h" #include "doc/primitives.h" #include "gfx/rect_io.h" -#include "os/display.h" #include "render/render.h" #include "ui/manager.h" #include "ui/system.h" diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp index c3d5f290e..1c2b173ac 100644 --- a/src/app/ui/editor/editor.cpp +++ b/src/app/ui/editor/editor.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2020 Igara Studio S.A. +// Copyright (C) 2018-2021 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -61,7 +61,6 @@ #include "doc/slice.h" #include "fmt/format.h" #include "os/color_space.h" -#include "os/display.h" #include "os/surface.h" #include "os/system.h" #include "render/rasterize.h" diff --git a/src/app/ui/editor/zooming_state.cpp b/src/app/ui/editor/zooming_state.cpp index 1e30485e4..fa99a0e33 100644 --- a/src/app/ui/editor/zooming_state.cpp +++ b/src/app/ui/editor/zooming_state.cpp @@ -1,4 +1,5 @@ // Aseprite +// Copyright (C) 2021 Igara Studio S.A. // Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of @@ -16,7 +17,7 @@ #include "app/ui/status_bar.h" #include "doc/sprite.h" #include "gfx/rect.h" -#include "os/display.h" +#include "os/window.h" #include "ui/manager.h" #include "ui/message.h" #include "ui/system.h" @@ -66,7 +67,7 @@ bool ZoomingState::onMouseUp(Editor* editor, MouseMessage* msg) bool ZoomingState::onMouseMove(Editor* editor, MouseMessage* msg) { 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) { m_moved = true; diff --git a/src/app/ui/main_window.cpp b/src/app/ui/main_window.cpp index a12cb6943..defb46db6 100644 --- a/src/app/ui/main_window.cpp +++ b/src/app/ui/main_window.cpp @@ -39,8 +39,8 @@ #include "app/ui/workspace_tabs.h" #include "app/ui_context.h" #include "base/fs.h" -#include "os/display.h" #include "os/system.h" +#include "os/window.h" #include "ui/message.h" #include "ui/splitter.h" #include "ui/system.h" @@ -78,9 +78,9 @@ public: ui::set_theme(ui::get_theme(), newUIScale); Manager* manager = Manager::getDefault(); - os::Display* display = manager->getDisplay(); - display->setScale(newScreenScale); - manager->setDisplay(display); + os::Window* window = manager->nativeWindow(); + window->setScale(newScreenScale); + manager->setNativeWindow(window); } }; @@ -370,9 +370,9 @@ void MainWindow::onResize(ui::ResizeEvent& ev) { app::gen::MainWindow::onResize(ev); - os::Display* display = manager()->getDisplay(); - if ((display) && - (display->scale()*ui::guiscale() > 2) && + os::Window* window = manager()->nativeWindow(); + if ((window) && + (window->scale()*ui::guiscale() > 2) && (!m_scalePanic) && (ui::display_w()/ui::guiscale() < 320 || ui::display_h()/ui::guiscale() < 260)) { diff --git a/src/app/util/clipboard_native.cpp b/src/app/util/clipboard_native.cpp index 9aac591e9..764a84eaa 100644 --- a/src/app/util/clipboard_native.cpp +++ b/src/app/util/clipboard_native.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2020 Igara Studio S.A. +// Copyright (C) 2020-2021 Igara Studio S.A. // Copyright (C) 2016-2018 David Capello // // This program is distributed under the terms of @@ -22,8 +22,8 @@ #include "doc/palette_io.h" #include "doc/tileset_io.h" #include "gfx/size.h" -#include "os/display.h" #include "os/system.h" +#include "os/window.h" #include "ui/alert.h" #include @@ -37,8 +37,8 @@ using namespace base::serialization::little_endian; namespace { clip::format custom_image_format = 0; - void* native_display_handle() { - return os::instance()->defaultDisplay()->nativeHandle(); + void* native_window_handle() { + return os::instance()->defaultWindow()->nativeHandle(); } void custom_error_handler(clip::ErrorCode code) { @@ -70,7 +70,7 @@ bool Clipboard::setNativeBitmap(const doc::Image* image, const doc::Palette* palette, const doc::Tileset* tileset) { - clip::lock l(native_display_handle()); + clip::lock l(native_window_handle()); if (!l.locked()) return false; @@ -177,7 +177,7 @@ bool Clipboard::getNativeBitmap(doc::Image** image, *palette = nullptr; *tileset = nullptr; - clip::lock l(native_display_handle()); + clip::lock l(native_window_handle()); if (!l.locked()) return false; diff --git a/src/ui/LICENSE.txt b/src/ui/LICENSE.txt index da9a44fa3..3b086de25 100644 --- a/src/ui/LICENSE.txt +++ b/src/ui/LICENSE.txt @@ -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 Permission is hereby granted, free of charge, to any person obtaining diff --git a/src/ui/graphics.cpp b/src/ui/graphics.cpp index fccb68d91..44eb97de7 100644 --- a/src/ui/graphics.cpp +++ b/src/ui/graphics.cpp @@ -1,5 +1,5 @@ // 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 // // This file is released under the terms of the MIT license. @@ -19,11 +19,11 @@ #include "gfx/rect.h" #include "gfx/region.h" #include "gfx/size.h" -#include "os/display.h" #include "os/draw_text.h" #include "os/font.h" #include "os/surface.h" #include "os/system.h" +#include "os/window.h" #include "ui/manager.h" #include "ui/scale.h" #include "ui/theme.h" @@ -45,7 +45,7 @@ Graphics::~Graphics() { // If we were drawing in the screen surface, we mark these regions // 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); } @@ -612,7 +612,7 @@ void Graphics::dirty(const gfx::Rect& bounds) // ScreenGraphics ScreenGraphics::ScreenGraphics() - : Graphics(AddRef(os::instance()->defaultDisplay()->surface()), 0, 0) + : Graphics(AddRef(os::instance()->defaultWindow()->surface()), 0, 0) { setFont(AddRef(get_theme()->getDefaultFont())); } diff --git a/src/ui/manager.cpp b/src/ui/manager.cpp index 1f610b38f..be97a457f 100644 --- a/src/ui/manager.cpp +++ b/src/ui/manager.cpp @@ -1,5 +1,5 @@ // 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 // // This file is released under the terms of the MIT license. @@ -22,11 +22,11 @@ #include "base/concurrent_queue.h" #include "base/scoped_value.h" #include "base/time.h" -#include "os/display.h" #include "os/event.h" #include "os/event_queue.h" #include "os/surface.h" #include "os/system.h" +#include "os/window.h" #include "ui/intern.h" #include "ui/ui.h" @@ -162,7 +162,7 @@ bool Manager::widgetAssociatedToManager(Widget* widget) Manager::Manager() : Widget(kManagerWidget) - , m_display(nullptr) + , m_window(nullptr) , m_eventQueue(nullptr) , m_lockedWindow(nullptr) , m_mouseButton(kButtonNone) @@ -226,13 +226,13 @@ Manager::~Manager() } } -void Manager::setDisplay(os::Display* display) +void Manager::setNativeWindow(os::Window* window) { base::ScopedValue lock( auto_window_adjustment, false, auto_window_adjustment); - m_display = display; + m_window = window; m_eventQueue = os::instance()->eventQueue(); onNewDisplayConfiguration(); @@ -255,7 +255,7 @@ void Manager::run() void Manager::flipDisplay() { - if (!m_display) + if (!m_window) return; OverlayManager* overlays = OverlayManager::instance(); @@ -271,7 +271,7 @@ void Manager::flipDisplay() gfx::Region(gfx::Rect(0, 0, ui::display_w(), ui::display_h()))); if (!m_dirtyRegion.isEmpty()) { - m_display->invalidateRegion(m_dirtyRegion); + m_window->invalidateRegion(m_dirtyRegion); m_dirtyRegion.clear(); } } @@ -385,7 +385,7 @@ void Manager::generateMessagesFromOSEvents() break; } - case os::Event::CloseDisplay: { + case os::Event::CloseWindow: { Message* msg = new Message(kCloseDisplayMessage); msg->setRecipient(this); msg->setPropagateToChildren(true); @@ -393,7 +393,7 @@ void Manager::generateMessagesFromOSEvents() break; } - case os::Event::ResizeDisplay: { + case os::Event::ResizeWindow: { Message* msg = new Message(kResizeDisplayMessage); msg->setRecipient(this); msg->setPropagateToChildren(true); @@ -888,7 +888,7 @@ void Manager::setCapture(Widget* widget) widget->enableFlags(HAS_CAPTURE); capture_widget = widget; - m_display->captureMouse(); + m_window->captureMouse(); } // Sets the focus to the "magnetic" widget inside the window @@ -928,7 +928,7 @@ void Manager::freeCapture() capture_widget->disableFlags(HAS_CAPTURE); capture_widget = nullptr; - m_display->releaseMouse(); + m_window->releaseMouse(); } } @@ -1309,8 +1309,8 @@ void Manager::onInitTheme(InitThemeEvent& ev) gfx::Rect bounds = window->bounds(); bounds *= newUIScale; bounds /= oldUIScale; - bounds.x = base::clamp(bounds.x, 0, m_display->width() - bounds.w); - bounds.y = base::clamp(bounds.y, 0, m_display->height() - bounds.h); + bounds.x = base::clamp(bounds.x, 0, m_window->width() - bounds.w); + bounds.y = base::clamp(bounds.y, 0, m_window->height() - bounds.h); window->setBounds(bounds); } } @@ -1324,16 +1324,16 @@ LayoutIO* Manager::onGetLayoutIO() void Manager::onNewDisplayConfiguration() { - if (m_display) { - int w = m_display->width() / m_display->scale(); - int h = m_display->height() / m_display->scale(); + if (m_window) { + int w = m_window->width() / m_window->scale(); + int h = m_window->height() / m_window->scale(); if ((bounds().w != w || bounds().h != h)) { setBounds(gfx::Rect(0, 0, w, h)); } } - _internal_set_mouse_display(m_display); + _internal_set_mouse_window(m_window); invalidate(); flushRedraw(); } @@ -1500,7 +1500,7 @@ bool Manager::sendMessageToWidget(Message* msg, Widget* widget) // Restore overlays in the region that we're going to paint. OverlayManager::instance()->restoreOverlappedAreas(paintMsg->rect()); - os::Surface* surface = m_display->surface(); + os::Surface* surface = m_window->surface(); surface->saveClip(); 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()); } - if (m_display) { - m_display->invalidateRegion( + if (m_window) { + m_window->invalidateRegion( 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); diff --git a/src/ui/manager.h b/src/ui/manager.h index 4554548ad..8e8ecf520 100644 --- a/src/ui/manager.h +++ b/src/ui/manager.h @@ -1,5 +1,5 @@ // 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 // // This file is released under the terms of the MIT license. @@ -17,8 +17,8 @@ #include "ui/widget.h" namespace os { - class Display; class EventQueue; + class Window; } namespace ui { @@ -35,9 +35,8 @@ namespace ui { Manager(); ~Manager(); - os::Display* getDisplay() { return m_display; } - - void setDisplay(os::Display* display); + os::Window* nativeWindow() { return m_window; } + void setNativeWindow(os::Window* window); // Executes the main message loop. void run(); @@ -168,7 +167,7 @@ namespace ui { static gfx::Region m_dirtyRegion; WidgetsList m_garbage; - os::Display* m_display; + os::Window* m_window; os::EventQueue* m_eventQueue; gfx::Region m_invalidRegion; // Invalid region (we didn't receive paint messages yet for this). diff --git a/src/ui/move_region.cpp b/src/ui/move_region.cpp index cf6972814..bd5b65a0e 100644 --- a/src/ui/move_region.cpp +++ b/src/ui/move_region.cpp @@ -1,5 +1,5 @@ // 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 // // This file is released under the terms of the MIT license. @@ -11,9 +11,9 @@ #include "ui/manager.h" -#include "os/display.h" #include "os/surface.h" #include "os/system.h" +#include "os/window.h" #include "ui/overlay_manager.h" #include @@ -24,9 +24,9 @@ using namespace gfx; void move_region(Manager* manager, const Region& region, int dx, int dy) { - os::Display* display = manager->getDisplay(); - ASSERT(display); - if (!display) + os::Window* window = manager->nativeWindow(); + ASSERT(window); + if (!window) return; 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); overlays->restoreOverlappedAreas(bounds); - os::Surface* surface = display->surface(); + os::Surface* surface = window->surface(); os::SurfaceLock lock(surface); // Fast path, move one rectangle. diff --git a/src/ui/overlay_manager.cpp b/src/ui/overlay_manager.cpp index bc87fc186..5bf0fd4bf 100644 --- a/src/ui/overlay_manager.cpp +++ b/src/ui/overlay_manager.cpp @@ -1,5 +1,5 @@ // 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 // // This file is released under the terms of the MIT license. @@ -11,8 +11,8 @@ #include "ui/overlay_manager.h" -#include "os/display.h" #include "os/surface.h" +#include "os/window.h" #include "ui/manager.h" #include "ui/overlay.h" @@ -86,11 +86,11 @@ void OverlayManager::drawOverlays() if (!manager) return; - os::Surface* displaySurface = manager->getDisplay()->surface(); - os::SurfaceLock lock(displaySurface); + os::Surface* windowSurface = manager->nativeWindow()->surface(); + os::SurfaceLock lock(windowSurface); for (auto& overlay : *this) - overlay->captureOverlappedArea(displaySurface); + overlay->captureOverlappedArea(windowSurface); for (auto& overlay : *this) overlay->drawOverlay(); diff --git a/src/ui/system.cpp b/src/ui/system.cpp index ffb6137ae..217ee7ec8 100644 --- a/src/ui/system.cpp +++ b/src/ui/system.cpp @@ -1,5 +1,5 @@ // 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 // // This file is released under the terms of the MIT license. @@ -13,11 +13,11 @@ #include "base/thread.h" #include "gfx/point.h" -#include "os/display.h" #include "os/event.h" #include "os/event_queue.h" #include "os/surface.h" #include "os/system.h" +#include "os/window.h" #include "ui/clipboard_delegate.h" #include "ui/cursor.h" #include "ui/intern.h" @@ -40,7 +40,7 @@ base::thread::native_id_type main_gui_thread; static CursorType mouse_cursor_type = kOutsideDisplay; static const Cursor* mouse_cursor_custom = 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 bool use_native_mouse_cursor = true; 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 if (support_native_custom_cursor && - mouse_display) { + mouse_window) { if (cursor) { - result = mouse_display->setNativeMouseCursor( + result = mouse_window->setNativeMouseCursor( // The surface is already scaled by guiscale() cursor->getSurface().get(), cursor->getFocus(), // 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) { - result = mouse_display->setNativeMouseCursor(os::kArrowCursor); + result = mouse_window->setNativeMouseCursor(os::kArrowCursor); } 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 - if (mouse_display) { - bool ok = mouse_display->setNativeMouseCursor(nativeCursor); + if (mouse_window) { + bool ok = mouse_window->setNativeMouseCursor(nativeCursor); // It looks like the specific native cursor is not supported, // so we can should use the internal overlay (even when we @@ -207,7 +207,7 @@ UISystem::~UISystem() details::exitWidgets(); - _internal_set_mouse_display(nullptr); + _internal_set_mouse_window(nullptr); if (!update_custom_native_cursor(nullptr)) update_mouse_overlay(nullptr); @@ -215,27 +215,27 @@ UISystem::~UISystem() g_instance = nullptr; } -void _internal_set_mouse_display(os::Display* display) +void _internal_set_mouse_window(os::Window* window) { CursorType cursor = get_mouse_cursor(); set_mouse_cursor(kNoCursor); - mouse_display = display; - if (display) + mouse_window = window; + if (window) set_mouse_cursor(cursor); // Restore mouse cursor } int display_w() { - if (mouse_display) - return mouse_display->width() / mouse_display->scale(); + if (mouse_window) + return mouse_window->width() / mouse_window->scale(); else return 1; } int display_h() { - if (mouse_display) - return mouse_display->height() / mouse_display->scale(); + if (mouse_window) + return mouse_window->height() / mouse_window->scale(); else return 1; } @@ -331,8 +331,8 @@ const gfx::Point& get_mouse_position() void set_mouse_position(const gfx::Point& newPos) { - if (mouse_display) - mouse_display->setMousePosition(newPos); + if (mouse_window) + mouse_window->setMousePosition(newPos); _internal_set_mouse_position(newPos); } diff --git a/src/ui/system.h b/src/ui/system.h index 6fb5497fd..79c8842c3 100644 --- a/src/ui/system.h +++ b/src/ui/system.h @@ -1,5 +1,5 @@ // 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 // // This file is released under the terms of the MIT license. @@ -16,7 +16,7 @@ #include #include -namespace os { class Display; } +namespace os { class Window; } namespace ui { @@ -61,7 +61,7 @@ namespace ui { void hide_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_set_mouse_position(const gfx::Point& newPos); diff --git a/src/ui/widget.cpp b/src/ui/widget.cpp index 5549ff0a7..61d88cee7 100644 --- a/src/ui/widget.cpp +++ b/src/ui/widget.cpp @@ -16,10 +16,10 @@ #include "base/clamp.h" #include "base/memory.h" #include "base/string.h" -#include "os/display.h" #include "os/font.h" #include "os/surface.h" #include "os/system.h" +#include "os/window.h" #include "ui/init_theme_event.h" #include "ui/intern.h" #include "ui/layout_io.h" @@ -28,9 +28,9 @@ #include "ui/message.h" #include "ui/move_region.h" #include "ui/paint_event.h" -#include "ui/size_hint_event.h" #include "ui/resize_event.h" #include "ui/save_layout_event.h" +#include "ui/size_hint_event.h" #include "ui/system.h" #include "ui/theme.h" #include "ui/view.h" @@ -1158,7 +1158,7 @@ public: 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 lockDst(dst); m_surface->blitTo( @@ -1178,7 +1178,7 @@ GraphicsPtr Widget::getGraphics(const gfx::Rect& clip) { GraphicsPtr graphics; 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 // buffer only if the default surface is the screen.