Fix bug with Console when the UI Screen Scaling is changed

This commit is contained in:
David Capello 2020-12-11 15:52:14 -03:00
parent c0ac9208ff
commit 81d9e8afec
4 changed files with 61 additions and 36 deletions

View File

@ -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 <cstdarg>
#include <cstdio>
#include <vector>
#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 <cstdarg>
#include <cstdio>
#include <memory>
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<KeyMessage*>(msg)->scancode() == kKeyC)
set_clipboard_text(m_textbox.text());
}
{
if (static_cast<KeyMessage*>(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::ConsoleWindow> 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

View File

@ -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 <exception>
#include <memory>
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<Console::ConsoleWindow> m_console;
};
} // namespace app

View File

@ -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)

View File

@ -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;