mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-06 12:39:57 +00:00
Fix strange scenarios/crashes using NewBrushCommand on multiple editors
We cannot use current_editor in SelectBoxDelegate implementations. For example: NewBrushCommand cannot use the current_editor in NewBrushCommand::onQuickboxEnd() because multiple editors can be in SelectBoxState, and it looks like we can select the brush box in a non-current editor if it's the first click to set that editor as the current one.
This commit is contained in:
parent
a2e33ffbca
commit
c674c474f6
@ -43,15 +43,15 @@ protected:
|
||||
void onExecute(Context* context) override;
|
||||
|
||||
// SelectBoxDelegate impl
|
||||
void onQuickboxEnd(const gfx::Rect& rect, ui::MouseButtons buttons) override;
|
||||
void onQuickboxCancel() override;
|
||||
void onQuickboxEnd(Editor* editor, const gfx::Rect& rect, ui::MouseButtons buttons) override;
|
||||
void onQuickboxCancel(Editor* editor) override;
|
||||
|
||||
std::string onGetContextBarHelp() override {
|
||||
return "Select brush bounds | Right-click to cut";
|
||||
}
|
||||
|
||||
private:
|
||||
void createBrush(const Mask* mask);
|
||||
void createBrush(const Site& site, const Mask* mask);
|
||||
void selectPencilTool();
|
||||
};
|
||||
|
||||
@ -92,7 +92,8 @@ void NewBrushCommand::onExecute(Context* context)
|
||||
}
|
||||
// Create a brush from the active selection
|
||||
else {
|
||||
createBrush(context->activeDocument()->mask());
|
||||
createBrush(context->activeSite(),
|
||||
context->activeDocument()->mask());
|
||||
selectPencilTool();
|
||||
|
||||
// Deselect mask
|
||||
@ -102,11 +103,11 @@ void NewBrushCommand::onExecute(Context* context)
|
||||
}
|
||||
}
|
||||
|
||||
void NewBrushCommand::onQuickboxEnd(const gfx::Rect& rect, ui::MouseButtons buttons)
|
||||
void NewBrushCommand::onQuickboxEnd(Editor* editor, const gfx::Rect& rect, ui::MouseButtons buttons)
|
||||
{
|
||||
Mask mask;
|
||||
mask.replace(rect);
|
||||
createBrush(&mask);
|
||||
createBrush(editor->getSite(), &mask);
|
||||
selectPencilTool();
|
||||
|
||||
// If the right-button was used, we clear the selected area.
|
||||
@ -128,18 +129,17 @@ void NewBrushCommand::onQuickboxEnd(const gfx::Rect& rect, ui::MouseButtons butt
|
||||
App::instance()->getMainWindow()->getContextBar()
|
||||
->updateForCurrentTool();
|
||||
|
||||
current_editor->backToPreviousState();
|
||||
editor->backToPreviousState();
|
||||
}
|
||||
|
||||
void NewBrushCommand::onQuickboxCancel()
|
||||
void NewBrushCommand::onQuickboxCancel(Editor* editor)
|
||||
{
|
||||
current_editor->backToPreviousState();
|
||||
editor->backToPreviousState();
|
||||
}
|
||||
|
||||
void NewBrushCommand::createBrush(const Mask* mask)
|
||||
void NewBrushCommand::createBrush(const Site& site, const Mask* mask)
|
||||
{
|
||||
doc::ImageRef image(new_image_from_mask(
|
||||
UIContext::instance()->activeSite(), mask));
|
||||
doc::ImageRef image(new_image_from_mask(site, mask));
|
||||
if (!image)
|
||||
return;
|
||||
|
||||
|
@ -110,9 +110,9 @@ bool SelectBoxState::onMouseUp(Editor* editor, MouseMessage* msg)
|
||||
|
||||
if (m_delegate) {
|
||||
if (m_selectingButtons == msg->buttons())
|
||||
m_delegate->onQuickboxEnd(getBoxBounds(), msg->buttons());
|
||||
m_delegate->onQuickboxEnd(editor, getBoxBounds(), msg->buttons());
|
||||
else
|
||||
m_delegate->onQuickboxCancel();
|
||||
m_delegate->onQuickboxCancel(editor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,8 +29,8 @@ namespace app {
|
||||
|
||||
// Called only in QUICKBOX mode, when the user released the mouse
|
||||
// button.
|
||||
virtual void onQuickboxEnd(const gfx::Rect& rect, ui::MouseButtons buttons) { }
|
||||
virtual void onQuickboxCancel() { }
|
||||
virtual void onQuickboxEnd(Editor* editor, const gfx::Rect& rect, ui::MouseButtons buttons) { }
|
||||
virtual void onQuickboxCancel(Editor* editor) { }
|
||||
|
||||
// Help text to be shown in the ContextBar
|
||||
virtual std::string onGetContextBarHelp() { return ""; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user