mirror of https://github.com/aseprite/aseprite.git
Compare commits
3 Commits
145556a2ac
...
9d1076825e
Author | SHA1 | Date |
---|---|---|
|
9d1076825e | |
|
80fa065bd5 | |
|
1e556678ba |
|
@ -13,6 +13,8 @@
|
|||
#include "app/console.h"
|
||||
#include "app/context.h"
|
||||
#include "app/context_observer.h"
|
||||
#include "app/doc.h"
|
||||
#include "app/doc_undo.h"
|
||||
#include "app/script/docobj.h"
|
||||
#include "app/script/engine.h"
|
||||
#include "app/script/luacpp.h"
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
#include "doc/tag.h"
|
||||
#include "doc/tileset.h"
|
||||
#include "doc/tilesets.h"
|
||||
#include "undo/undo_state.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
@ -1029,6 +1030,42 @@ int Sprite_set_useLayerUuids(lua_State* L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int Sprite_get_undoHistory(lua_State* L)
|
||||
{
|
||||
const auto* sprite = get_docobj<Sprite>(L, 1);
|
||||
const auto* doc = static_cast<Doc*>(sprite->document());
|
||||
const auto* history = doc->undoHistory();
|
||||
|
||||
if (!history) {
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const undo::UndoState* currentState = history->currentState();
|
||||
const undo::UndoState* s = history->firstState();
|
||||
const bool canRedo = history->canRedo();
|
||||
bool pastCurrent = !currentState && canRedo;
|
||||
|
||||
int undoSteps = 0;
|
||||
int redoSteps = 0;
|
||||
while (s) {
|
||||
if (pastCurrent && canRedo)
|
||||
redoSteps++;
|
||||
else if (currentState || !canRedo)
|
||||
undoSteps++;
|
||||
|
||||
if (s == currentState || !currentState)
|
||||
pastCurrent = true;
|
||||
|
||||
s = s->next();
|
||||
}
|
||||
|
||||
lua_newtable(L);
|
||||
setfield_integer(L, "undoSteps", undoSteps);
|
||||
setfield_integer(L, "redoSteps", redoSteps);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const luaL_Reg Sprite_methods[] = {
|
||||
{ "__eq", Sprite_eq },
|
||||
{ "resize", Sprite_resize },
|
||||
|
@ -1094,6 +1131,7 @@ const Property Sprite_properties[] = {
|
|||
{ "events", Sprite_get_events, nullptr },
|
||||
{ "tileManagementPlugin", Sprite_get_tileManagementPlugin, Sprite_set_tileManagementPlugin },
|
||||
{ "useLayerUuids", Sprite_get_useLayerUuids, Sprite_set_useLayerUuids },
|
||||
{ "undoHistory", Sprite_get_undoHistory, nullptr },
|
||||
{ nullptr, nullptr, nullptr }
|
||||
};
|
||||
|
||||
|
|
|
@ -168,6 +168,21 @@ SelectLayerBoundariesOp get_select_layer_in_canvas_op(ui::Message* msg)
|
|||
return SelectLayerBoundariesOp::REPLACE;
|
||||
}
|
||||
|
||||
bool get_layer_index(LayerGroup* parent, const Layer* layer, layer_t& index)
|
||||
{
|
||||
for (Layer* child : parent->layers()) {
|
||||
if (child->isGroup() && get_layer_index(static_cast<LayerGroup*>(child), layer, index)) {
|
||||
return index;
|
||||
}
|
||||
|
||||
if (child == layer) {
|
||||
return true;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
Timeline::Hit::Hit(int part, layer_t layer, col_t frame, ObjectId tag, int band)
|
||||
|
@ -4055,6 +4070,12 @@ layer_t Timeline::getLayerIndex(const Layer* layer) const
|
|||
return -1;
|
||||
}
|
||||
|
||||
layer_t Timeline::getLayerIndexFromSprite(const Layer* layer) const
|
||||
{
|
||||
layer_t index = 0;
|
||||
return get_layer_index(m_sprite->root(), layer, index) ? index : -1;
|
||||
}
|
||||
|
||||
bool Timeline::isLayerActive(const layer_t layerIndex) const
|
||||
{
|
||||
Layer* layer = getLayer(layerIndex);
|
||||
|
@ -4576,7 +4597,7 @@ void Timeline::onDrop(ui::DragEvent& e)
|
|||
|
||||
// Determine at which frame and layer the content was dropped on.
|
||||
frame_t frame = m_frame;
|
||||
layer_t layerIndex = getLayerIndex(m_layer);
|
||||
layer_t layerIndex = getLayerIndexFromSprite(m_layer);
|
||||
InsertionPoint insert = InsertionPoint::BeforeLayer;
|
||||
DroppedOn droppedOn = DroppedOn::Unspecified;
|
||||
TRACE("m_dropRange.type() %d\n", m_dropRange.type());
|
||||
|
@ -4602,7 +4623,7 @@ void Timeline::onDrop(ui::DragEvent& e)
|
|||
break;
|
||||
case Range::kLayers:
|
||||
droppedOn = DroppedOn::Layer;
|
||||
if (m_dropTarget.vhit != DropTarget::VeryBottom) {
|
||||
if (m_dropTarget.vhit != DropTarget::VeryBottom && !m_dropRange.selectedLayers().empty()) {
|
||||
auto* selectedLayer = *m_dropRange.selectedLayers().begin();
|
||||
layerIndex = getLayerIndex(selectedLayer);
|
||||
}
|
||||
|
|
|
@ -355,6 +355,8 @@ private:
|
|||
gfx::Point getMaxScrollablePos() const;
|
||||
doc::Layer* getLayer(int layerIndex) const;
|
||||
layer_t getLayerIndex(const Layer* layer) const;
|
||||
// Get layer index regardless of visibility in the UI.
|
||||
layer_t getLayerIndexFromSprite(const Layer* layer) const;
|
||||
bool isLayerActive(const layer_t layerIdx) const;
|
||||
bool isFrameActive(const col_t frame) const;
|
||||
bool isCelActive(const layer_t layerIdx, const col_t frame) const;
|
||||
|
|
|
@ -228,3 +228,69 @@ do
|
|||
c = app.open(fn)
|
||||
assert(c.tileManagementPlugin == nil)
|
||||
end
|
||||
|
||||
-- Undo History
|
||||
|
||||
function test_undo_history()
|
||||
local sprite = Sprite(1, 1)
|
||||
|
||||
assert(sprite.undoHistory.undoSteps == 0)
|
||||
assert(sprite.undoHistory.redoSteps == 0)
|
||||
|
||||
sprite:resize(10, 10)
|
||||
|
||||
assert(sprite.undoHistory.undoSteps == 1)
|
||||
assert(sprite.undoHistory.redoSteps == 0)
|
||||
|
||||
sprite:resize(10, 15)
|
||||
|
||||
assert(sprite.undoHistory.undoSteps == 2)
|
||||
assert(sprite.undoHistory.redoSteps == 0)
|
||||
|
||||
sprite:resize(10, 30)
|
||||
|
||||
assert(sprite.undoHistory.undoSteps == 3)
|
||||
assert(sprite.undoHistory.redoSteps == 0)
|
||||
|
||||
app.undo()
|
||||
assert(sprite.undoHistory.undoSteps == 2)
|
||||
assert(sprite.undoHistory.redoSteps == 1)
|
||||
|
||||
app.undo()
|
||||
assert(sprite.undoHistory.undoSteps == 1)
|
||||
assert(sprite.undoHistory.redoSteps == 2)
|
||||
|
||||
app.redo()
|
||||
assert(sprite.undoHistory.undoSteps == 2)
|
||||
assert(sprite.undoHistory.redoSteps == 1)
|
||||
|
||||
app.undo()
|
||||
app.undo()
|
||||
|
||||
assert(sprite.undoHistory.undoSteps == 0)
|
||||
assert(sprite.undoHistory.redoSteps == 3)
|
||||
|
||||
sprite:resize(10, 30)
|
||||
|
||||
if (app.preferences.undo.allow_nonlinear_history) then
|
||||
assert(sprite.undoHistory.undoSteps == 4)
|
||||
assert(sprite.undoHistory.redoSteps == 0)
|
||||
else
|
||||
assert(sprite.undoHistory.undoSteps == 1)
|
||||
assert(sprite.undoHistory.redoSteps == 0)
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local prevSetting = app.preferences.undo.allow_nonlinear_history
|
||||
app.preferences.undo.allow_nonlinear_history = true
|
||||
test_undo_history()
|
||||
app.preferences.undo.allow_nonlinear_history = prevSetting
|
||||
end
|
||||
|
||||
do
|
||||
local prevSetting = app.preferences.undo.allow_nonlinear_history
|
||||
app.preferences.undo.allow_nonlinear_history = false
|
||||
test_undo_history()
|
||||
app.preferences.undo.allow_nonlinear_history = prevSetting
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue