lua: Several app.useTool() calls can be used in one transaction now (fix aseprite/api#18)

This commit is contained in:
David Capello 2019-06-28 16:33:11 -03:00
parent ff6538a68e
commit e9d8392a46
2 changed files with 19 additions and 20 deletions

View File

@ -10,6 +10,6 @@
// Increment this value if the scripting API is modified between two // Increment this value if the scripting API is modified between two
// released Aseprite versions. // released Aseprite versions.
#define API_VERSION 3 #define API_VERSION 4
#endif #endif

View File

@ -33,7 +33,7 @@
#include "app/tools/tool.h" #include "app/tools/tool.h"
#include "app/tools/tool_box.h" #include "app/tools/tool_box.h"
#include "app/tools/tool_loop.h" #include "app/tools/tool_loop.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/color_bar.h" #include "app/ui/color_bar.h"
#include "app/ui/context_bar.h" #include "app/ui/context_bar.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
@ -361,7 +361,7 @@ class ToolLoopImpl : public ToolLoopBase {
Mask* m_mask; Mask* m_mask;
gfx::Point m_maskOrigin; gfx::Point m_maskOrigin;
bool m_canceled; bool m_canceled;
Transaction m_transaction; Tx m_tx;
ExpandCelCanvas* m_expandCelCanvas; ExpandCelCanvas* m_expandCelCanvas;
Image* m_floodfillSrcImage; Image* m_floodfillSrcImage;
bool m_saveLastPoint; bool m_saveLastPoint;
@ -383,14 +383,14 @@ public:
button, fgColor, bgColor) button, fgColor, bgColor)
, m_context(context) , m_context(context)
, m_canceled(false) , m_canceled(false)
, m_transaction(m_context, , m_tx(m_context,
m_tool->getText().c_str(), m_tool->getText().c_str(),
((getInk()->isSelection() || ((getInk()->isSelection() ||
getInk()->isEyedropper() || getInk()->isEyedropper() ||
getInk()->isScrollMovement() || getInk()->isScrollMovement() ||
getInk()->isSlice() || getInk()->isSlice() ||
getInk()->isZoom()) ? DoesntModifyDocument: getInk()->isZoom()) ? DoesntModifyDocument:
ModifyDocument)) ModifyDocument))
, m_expandCelCanvas(nullptr) , m_expandCelCanvas(nullptr)
, m_floodfillSrcImage(nullptr) , m_floodfillSrcImage(nullptr)
, m_saveLastPoint(saveLastPoint) , m_saveLastPoint(saveLastPoint)
@ -428,7 +428,7 @@ public:
m_expandCelCanvas = new ExpandCelCanvas( m_expandCelCanvas = new ExpandCelCanvas(
site, site.layer(), site, site.layer(),
m_docPref.tiled.mode(), m_docPref.tiled.mode(),
m_transaction, m_tx,
ExpandCelCanvas::Flags( ExpandCelCanvas::Flags(
ExpandCelCanvas::NeedsSource | ExpandCelCanvas::NeedsSource |
// If the tool is freehand-like, we can use the modified // If the tool is freehand-like, we can use the modified
@ -468,7 +468,7 @@ public:
(!m_document->isMaskVisible() || (!m_document->isMaskVisible() ||
(int(getModifiers()) & int(tools::ToolLoopModifiers::kReplaceSelection)))) { (int(getModifiers()) & int(tools::ToolLoopModifiers::kReplaceSelection)))) {
Mask emptyMask; Mask emptyMask;
m_transaction.execute(new cmd::SetMask(m_document, &emptyMask)); m_tx(new cmd::SetMask(m_document, &emptyMask));
} }
m_celOrigin = m_expandCelCanvas->getCel()->position(); m_celOrigin = m_expandCelCanvas->getCel()->position();
@ -491,10 +491,9 @@ public:
if (!m_canceled) { if (!m_canceled) {
// Freehand changes the last point // Freehand changes the last point
if (m_saveLastPoint) { if (m_saveLastPoint) {
m_transaction.execute( m_tx(new cmd::SetLastPoint(
new cmd::SetLastPoint( m_document,
m_document, getController()->getLastPoint()));
getController()->getLastPoint()));
} }
// Paint ink // Paint ink
@ -521,7 +520,7 @@ public:
redraw = true; redraw = true;
} }
m_transaction.commit(); m_tx.commit();
} }
else { else {
redraw = true; redraw = true;
@ -569,7 +568,7 @@ public:
bool useMask() override { return m_useMask; } bool useMask() override { return m_useMask; }
Mask* getMask() override { return m_mask; } Mask* getMask() override { return m_mask; }
void setMask(Mask* newMask) override { void setMask(Mask* newMask) override {
m_transaction.execute(new cmd::SetMask(m_document, newMask)); m_tx(new cmd::SetMask(m_document, newMask));
} }
gfx::Point getMaskOrigin() override { return m_maskOrigin; } gfx::Point getMaskOrigin() override { return m_maskOrigin; }
bool getFilled() override { return m_filled; } bool getFilled() override { return m_filled; }
@ -599,7 +598,7 @@ public:
color.getBlue(), color.getBlue(),
color.getAlpha())); color.getAlpha()));
m_transaction.execute(new cmd::AddSlice(m_sprite, slice)); m_tx(new cmd::AddSlice(m_sprite, slice));
return; return;
} }
} }