mirror of https://github.com/aseprite/aseprite.git
Refactor getLayerIndexFromSprite into LayerGroup
This commit is contained in:
parent
d61ae919ad
commit
1227f9c49c
|
@ -168,21 +168,6 @@ 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)
|
||||
|
@ -4070,12 +4055,6 @@ 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);
|
||||
|
@ -4597,7 +4576,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 = getLayerIndexFromSprite(m_layer);
|
||||
layer_t layerIndex = m_sprite->root()->getLayerIndex(m_layer);
|
||||
InsertionPoint insert = InsertionPoint::BeforeLayer;
|
||||
DroppedOn droppedOn = DroppedOn::Unspecified;
|
||||
TRACE("m_dropRange.type() %d\n", m_dropRange.type());
|
||||
|
|
|
@ -355,8 +355,6 @@ 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;
|
||||
|
|
|
@ -597,4 +597,22 @@ void LayerGroup::displaceFrames(frame_t fromThis, frame_t delta)
|
|||
layer->displaceFrames(fromThis, delta);
|
||||
}
|
||||
|
||||
layer_t LayerGroup::getLayerIndex(const Layer* layer, layer_t& index) const
|
||||
{
|
||||
for (Layer* child : this->layers()) {
|
||||
if ((child->isGroup() && static_cast<LayerGroup*>(child)->getLayerIndex(layer, index) != -1) ||
|
||||
(child == layer)) {
|
||||
return index;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
layer_t LayerGroup::getLayerIndex(const Layer* layer) const
|
||||
{
|
||||
layer_t index = 0;
|
||||
return this->getLayerIndex(layer, index);
|
||||
}
|
||||
|
||||
} // namespace doc
|
||||
|
|
|
@ -236,9 +236,13 @@ public:
|
|||
|
||||
bool isBrowsable() const override { return isGroup() && isExpanded() && !m_layers.empty(); }
|
||||
|
||||
layer_t getLayerIndex(const Layer* layer) const;
|
||||
|
||||
private:
|
||||
void destroyAllLayers();
|
||||
|
||||
layer_t getLayerIndex(const Layer* layer, layer_t& index) const;
|
||||
|
||||
LayerList m_layers;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue