Merge branch 'master' into beta

This commit is contained in:
David Capello 2020-12-22 15:48:15 -03:00
commit 91628daa9d
9 changed files with 97 additions and 51 deletions

View File

@ -369,6 +369,8 @@ MoveTiles = Move Tiles
NewBrush = New Brush
NewFile = New File
NewFile_FromClipboard = New File from Clipboard
NewFile_Sprite = Sprite
NewFile_BackgroundLayer = Background
NewFrame = New Frame
NewFrame_NewEmptyFrame = New Empty Frame
NewFrame_DuplicateCels = Duplicate Cels w/Layer Mode

View File

@ -232,12 +232,11 @@ void NewFileCommand::onExecute(Context* ctx)
if (sprite->colorMode() != ColorMode::GRAYSCALE)
get_default_palette()->copyColorsTo(sprite->palette(frame_t(0)));
// If the background color isn't transparent, we have to
// convert the `Layer 1' in a `Background'
if (bgColor.getType() != app::Color::MaskType) {
Layer* layer = sprite->root()->firstLayer();
if (layer && layer->isImage()) {
Layer* layer = sprite->root()->firstLayer();
if (layer && layer->isImage()) {
// If the background color isn't transparent, we have to
// convert the `Layer 1' in a `Background'
if (bgColor.getType() != app::Color::MaskType) {
LayerImage* layerImage = static_cast<LayerImage*>(layer);
layerImage->configureAsBackground();
@ -258,11 +257,8 @@ void NewFileCommand::onExecute(Context* ctx)
set_current_palette(&oldPal, false);
}
}
#ifdef ENABLE_UI
else if (clipboardImage) {
Layer* layer = sprite->root()->firstLayer();
if (layer && layer->isImage()) {
else if (clipboardImage) {
LayerImage* layerImage = static_cast<LayerImage*>(layer);
// layerImage->configureAsBackground();
@ -277,13 +273,19 @@ void NewFileCommand::onExecute(Context* ctx)
}
sprite->setPalette(&clipboardPalette, false);
}
}
#endif // ENABLE_UI
if (layer->isBackground())
layer->setName(Strings::commands_NewFile_BackgroundLayer());
else
layer->setName(fmt::format("{} {}", Strings::commands_NewLayer_Layer(), 1));
}
// Show the sprite to the user
std::unique_ptr<Doc> doc(new Doc(sprite.get()));
sprite.release();
doc->setFilename(fmt::format("Sprite-{:04d}", ++g_spriteCounter));
doc->setFilename(fmt::format("{}-{:04d}",
Strings::commands_NewFile_Sprite(), ++g_spriteCounter));
doc->setContext(ctx);
doc.release();
}

View File

@ -9,20 +9,20 @@
#include "config.h"
#endif
#include <cstdarg>
#include <cstdio>
#include <vector>
#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/memory.h"
#include "base/string.h"
#include "ui/system.h"
#include "ui/ui.h"
#include <cstdarg>
#include <cstdio>
#include <memory>
namespace app {
@ -42,7 +42,6 @@ public:
});
m_view.attachToView(&m_textbox);
m_button.setMinSize(gfx::Size(60*ui::guiscale(), 0));
ui::Grid* grid = new ui::Grid(1, false);
grid->addChildInCell(&m_view, 1, 1, HORIZONTAL | VERTICAL);
@ -52,16 +51,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);
@ -71,22 +68,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;
@ -94,7 +108,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)
@ -118,7 +132,7 @@ Console::Console(Context* ctx)
if (m_console || m_consoleCounter > 1)
return;
m_console = new ConsoleWindow;
m_console.reset(new ConsoleWindow);
}
Console::~Console()
@ -129,14 +143,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, ...)
@ -178,4 +190,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

@ -642,6 +642,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

@ -1603,7 +1603,7 @@ void Editor::updateToolByTipProximity(ui::PointerType pointerType)
}
}
void Editor::updateToolLoopModifiersIndicators()
void Editor::updateToolLoopModifiersIndicators(const bool firstFromMouseDown)
{
int modifiers = int(tools::ToolLoopModifiers::kNone);
const bool autoSelectLayer = isAutoSelectLayer();
@ -1636,7 +1636,13 @@ void Editor::updateToolLoopModifiersIndicators()
modifiers |= int(tools::ToolLoopModifiers::kSquareAspect);
if (int(action & KeyAction::DrawFromCenter))
modifiers |= int(tools::ToolLoopModifiers::kFromCenter);
if (int(action & KeyAction::RotateShape))
// We prefer to activate the rotation only when the user press
// the Alt key again in the ToolLoop (and not before starting
// the loop). So Alt+Shift+selection tool will subtract the
// selection but will not start the rotation until we release
// and press the Alt key again.
if ((int(action & KeyAction::RotateShape)) && !firstFromMouseDown)
modifiers |= int(tools::ToolLoopModifiers::kRotateShape);
}
@ -1885,7 +1891,16 @@ bool Editor::onProcessMessage(Message* msg)
->pressButton(pointer_from_msg(this, mouseMsg));
EditorStatePtr holdState(m_state);
return m_state->onMouseDown(this, mouseMsg);
bool state = m_state->onMouseDown(this, mouseMsg);
// Re-update the tool modifiers if the state has changed
// (e.g. we are on DrawingState now). This is required for the
// Line tool to be able to Shift+press mouse buttons to start
// drawing lines with the angle snapped.
if (m_state != holdState)
updateToolLoopModifiersIndicators(true);
return state;
}
break;

View File

@ -341,7 +341,10 @@ namespace app {
void setStateInternal(const EditorStatePtr& newState);
void updateQuicktool();
void updateToolByTipProximity(ui::PointerType pointerType);
void updateToolLoopModifiersIndicators();
// firstFromMouseDown=true when we call this function from the
// first MouseDown message (instead of KeyDown).
void updateToolLoopModifiersIndicators(const bool firstFromMouseDown = false);
void drawBackground(ui::Graphics* g);
void drawSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& rc);

View File

@ -402,7 +402,7 @@ void LayerImage::displaceFrames(frame_t fromThis, frame_t delta)
LayerGroup::LayerGroup(Sprite* sprite)
: Layer(ObjectType::LayerGroup, sprite)
{
setName("Layer Set");
setName("Group");
}
LayerGroup::~LayerGroup()

View File

@ -704,11 +704,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;