Avoid using LayerIndex in SpritePosition

We're planning to remove the LayerIndex as it doesn't make too much
sense with the new Timeline with groups.
This commit is contained in:
David Capello 2016-06-10 12:23:04 -03:00
parent 5deabfe365
commit 6bffc9f740
3 changed files with 35 additions and 20 deletions

View File

@ -65,7 +65,7 @@ std::string CmdTransaction::onLabel() const
doc::SpritePosition CmdTransaction::calcSpritePosition() doc::SpritePosition CmdTransaction::calcSpritePosition()
{ {
doc::Site site = context()->activeSite(); doc::Site site = context()->activeSite();
return doc::SpritePosition(site.layerIndex(), site.frame()); return doc::SpritePosition(site.layer(), site.frame());
} }
} // namespace app } // namespace app

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2015 David Capello // Copyright (C) 2001-2016 David Capello
// //
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as // it under the terms of the GNU General Public License version 2 as
@ -71,7 +71,7 @@ void UndoCommand::onExecute(Context* context)
Preferences::instance().undo.gotoModified(); Preferences::instance().undo.gotoModified();
if (gotoModified) { if (gotoModified) {
SpritePosition currentPosition(writer.site()->layerIndex(), SpritePosition currentPosition(writer.site()->layer(),
writer.site()->frame()); writer.site()->frame());
if (m_type == Undo) if (m_type == Undo)
@ -80,7 +80,9 @@ void UndoCommand::onExecute(Context* context)
spritePosition = undo->nextRedoSpritePosition(); spritePosition = undo->nextRedoSpritePosition();
if (spritePosition != currentPosition) { if (spritePosition != currentPosition) {
current_editor->setLayer(sprite->indexToLayer(spritePosition.layerIndex())); Layer* selectLayer = spritePosition.layer();
if (selectLayer)
current_editor->setLayer(selectLayer);
current_editor->setFrame(spritePosition.frame()); current_editor->setFrame(spritePosition.frame());
// Draw the current layer/frame (which is not undone yet) so the // Draw the current layer/frame (which is not undone yet) so the
@ -112,11 +114,13 @@ void UndoCommand::onExecute(Context* context)
// weren't able to reach before the undo). // weren't able to reach before the undo).
if (gotoModified) { if (gotoModified) {
SpritePosition currentPosition( SpritePosition currentPosition(
writer.site()->layerIndex(), writer.site()->layer(),
writer.site()->frame()); writer.site()->frame());
if (spritePosition != currentPosition) { if (spritePosition != currentPosition) {
current_editor->setLayer(sprite->indexToLayer(spritePosition.layerIndex())); Layer* selectLayer = spritePosition.layer();
if (selectLayer)
current_editor->setLayer(selectLayer);
current_editor->setFrame(spritePosition.frame()); current_editor->setFrame(spritePosition.frame());
} }
} }

View File

@ -1,5 +1,5 @@
// Aseprite Document Library // Aseprite Document Library
// Copyright (c) 2001-2015 David Capello // Copyright (c) 2001-2016 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information. // Read LICENSE.txt for more information.
@ -9,34 +9,45 @@
#pragma once #pragma once
#include "doc/frame.h" #include "doc/frame.h"
#include "doc/layer_index.h" #include "doc/layer.h"
#include "doc/object.h"
#include "doc/object_id.h"
namespace doc { namespace doc {
class Sprite;
class SpritePosition { class SpritePosition {
public: public:
SpritePosition() SpritePosition()
: m_layerIndex(0) : m_layerId(NullId)
, m_frame(0) { , m_frame(0) {
} }
SpritePosition(LayerIndex layerIndex, frame_t frame)
: m_layerIndex(layerIndex) SpritePosition(const Layer* layer, frame_t frame)
: m_layerId(layer ? layer->id(): NullId)
, m_frame(frame) { , m_frame(frame) {
} }
const LayerIndex& layerIndex() const { return m_layerIndex; } Layer* layer() const { return get<Layer>(m_layerId); }
const frame_t& frame() const { return m_frame; } ObjectId layerId() const { return m_layerId; }
frame_t frame() const { return m_frame; }
void layerIndex(LayerIndex layerIndex) { m_layerIndex = layerIndex; } void layer(Layer* layer) {
void frame(frame_t frame) { m_frame = frame; } m_layerId = (layer ? layer->id(): NullId);
}
bool operator==(const SpritePosition& o) const { return m_layerIndex == o.m_layerIndex && m_frame == o.m_frame; } void layerId(ObjectId layerId) {
bool operator!=(const SpritePosition& o) const { return m_layerIndex != o.m_layerIndex || m_frame != o.m_frame; } m_layerId = layerId;
}
void frame(frame_t frame) {
m_frame = frame;
}
bool operator==(const SpritePosition& o) const { return m_layerId == o.m_layerId && m_frame == o.m_frame; }
bool operator!=(const SpritePosition& o) const { return m_layerId != o.m_layerId || m_frame != o.m_frame; }
private: private:
LayerIndex m_layerIndex; ObjectId m_layerId;
frame_t m_frame; frame_t m_frame;
}; };