diff --git a/src/app/console.cpp b/src/app/console.cpp index f8db98928..b3ef4ab45 100644 --- a/src/app/console.cpp +++ b/src/app/console.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2019 Igara Studio S.A. +// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -9,21 +9,22 @@ #include "config.h" #endif -#include -#include -#include - -#include "base/bind.h" -#include "base/memory.h" -#include "base/string.h" -#include "ui/ui.h" +#include "app/console.h" #include "app/app.h" -#include "app/console.h" #include "app/context.h" #include "app/modules/gui.h" #include "app/ui/status_bar.h" +#include "base/bind.h" +#include "base/memory.h" +#include "base/string.h" #include "ui/system.h" +#include "ui/ui.h" + + +#include +#include +#include namespace app { @@ -44,7 +45,6 @@ public: })); m_view.attachToView(&m_textbox); - m_button.setMinSize(gfx::Size(60*ui::guiscale(), 0)); Grid* grid = new Grid(1, false); grid->addChildInCell(&m_view, 1, 1, HORIZONTAL | VERTICAL); @@ -54,16 +54,14 @@ public: m_textbox.setFocusMagnet(true); m_button.setFocusMagnet(true); m_view.setExpansive(true); + + initTheme(); } void addMessage(const std::string& msg) { if (!m_hasText) { m_hasText = true; - - remapWindow(); - setBounds(gfx::Rect(0, 0, ui::display_w()*9/10, ui::display_h()*6/10)); - centerWindow(); - invalidate(); + centerConsole(); } m_textbox.setText(m_textbox.text() + msg); @@ -73,22 +71,39 @@ public: return (m_hasText && isVisible()); } + void centerConsole() { + initTheme(); + remapWindow(); + setBounds(gfx::Rect(0, 0, ui::display_w()*9/10, ui::display_h()*6/10)); + centerWindow(); + invalidate(); + } + private: bool onProcessMessage(ui::Message* msg) override { - if (msg->type() == ui::kKeyDownMessage) { + switch (msg->type()) { + + case ui::kKeyDownMessage: #if defined __APPLE__ - if (msg->onlyCmdPressed()) + if (msg->onlyCmdPressed()) #else - if (msg->onlyCtrlPressed()) + if (msg->onlyCtrlPressed()) #endif - { - if (static_cast(msg)->scancode() == kKeyC) - set_clipboard_text(m_textbox.text()); - } + { + if (static_cast(msg)->scancode() == kKeyC) + set_clipboard_text(m_textbox.text()); + } + break; } return Window::onProcessMessage(msg); } + void onInitTheme(InitThemeEvent& ev) override { + Window::onInitTheme(ev); + + m_button.setMinSize(gfx::Size(60*ui::guiscale(), 0)); + } + View m_view; TextBox m_textbox; Button m_button; @@ -96,7 +111,7 @@ private: }; int Console::m_consoleCounter = 0; -Console::ConsoleWindow* Console::m_console = nullptr; +std::unique_ptr Console::m_console = nullptr; Console::Console(Context* ctx) : m_withUI(false) @@ -120,7 +135,7 @@ Console::Console(Context* ctx) if (m_console || m_consoleCounter > 1) return; - m_console = new ConsoleWindow; + m_console.reset(new ConsoleWindow); } Console::~Console() @@ -131,14 +146,12 @@ Console::~Console() --m_consoleCounter; if (m_console && m_console->isConsoleVisible()) { - m_console->manager()->attractFocus(m_console); + m_console->manager()->attractFocus(m_console.get()); m_console->openWindowInForeground(); } - if (m_consoleCounter == 0) { - delete m_console; // window - m_console = nullptr; - } + if (m_consoleCounter == 0) + m_console.reset(); } void Console::printf(const char* format, ...) @@ -180,4 +193,11 @@ void Console::showException(const std::exception& e) console.printf("A problem has occurred.\n\nDetails:\n%s\n", e.what()); } +// static +void Console::notifyNewDisplayConfiguration() +{ + if (m_console) + m_console->centerConsole(); +} + } // namespace app diff --git a/src/app/console.h b/src/app/console.h index afa94ec45..218374a1f 100644 --- a/src/app/console.h +++ b/src/app/console.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018 Igara Studio S.A. +// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of @@ -10,6 +10,7 @@ #pragma once #include +#include namespace app { class Context; @@ -22,13 +23,14 @@ namespace app { void printf(const char *format, ...); static void showException(const std::exception& e); + static void notifyNewDisplayConfiguration(); private: class ConsoleWindow; bool m_withUI; static int m_consoleCounter; - static ConsoleWindow* m_console; + static std::unique_ptr m_console; }; } // namespace app diff --git a/src/app/modules/gui.cpp b/src/app/modules/gui.cpp index 030633b97..5b1931944 100644 --- a/src/app/modules/gui.cpp +++ b/src/app/modules/gui.cpp @@ -641,6 +641,10 @@ void CustomizedGuiManager::onNewDisplayConfiguration() { Manager::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? + Console::notifyNewDisplayConfiguration(); } std::string CustomizedGuiManager::loadLayout(Widget* widget) diff --git a/src/ui/theme.cpp b/src/ui/theme.cpp index c5a1c4754..cb59726f3 100644 --- a/src/ui/theme.cpp +++ b/src/ui/theme.cpp @@ -703,11 +703,10 @@ void set_theme(Theme* theme, const int uiscale) details::reinitThemeForAllWidgets(); // Reinitialize all widget using the new theme/uiscale - Manager* manager = Manager::getDefault(); - if (manager) + if (Manager* manager = Manager::getDefault()) { manager->initTheme(); - - manager->invalidate(); + manager->invalidate(); + } } old_ui_scale = current_ui_scale;