improve layer history, fix doc open
This commit is contained in:
@@ -199,7 +199,7 @@ NodeLayer* NodePanelLayer::add_layer(const char* name, bool add_history /*= true
|
||||
std::shared_ptr<Layer> layer /*= nullptr*/, std::shared_ptr<NodeLayer> layer_node /*= nullptr*/, int index /*= 0*/)
|
||||
{
|
||||
if (index == -1)
|
||||
index = m_layers_container->m_children.size();
|
||||
index = (int)m_layers_container->m_children.size();
|
||||
auto l = layer_node ? layer_node : std::make_shared<NodeLayer>();
|
||||
m_layers_container->add_child(l, index);
|
||||
l->init();
|
||||
@@ -302,18 +302,21 @@ void NodePanelLayer::handle_layer_highlight(NodeLayer* target, bool highlight)
|
||||
|
||||
void NodePanelLayer::handle_layer_visibility(NodeLayer* target, bool visible)
|
||||
{
|
||||
save_history();
|
||||
if (on_layer_visibility_changed)
|
||||
on_layer_visibility_changed(this, m_layers_container->get_child_index(target), visible);
|
||||
}
|
||||
|
||||
void NodePanelLayer::handle_layer_alpha_lock(NodeLayer* target, bool locked)
|
||||
{
|
||||
save_history();
|
||||
if (on_layer_alpha_lock_changed)
|
||||
on_layer_alpha_lock_changed(this, m_layers_container->get_child_index(target), locked);
|
||||
}
|
||||
|
||||
void NodePanelLayer::handle_layer_blend_mode(NodeLayer* target, int mode)
|
||||
{
|
||||
save_history();
|
||||
if (on_layer_blend_mode_changed)
|
||||
on_layer_blend_mode_changed(this, m_layers_container->get_child_index(target), mode);
|
||||
}
|
||||
@@ -329,6 +332,21 @@ void NodePanelLayer::handle_layer_selected(NodeLayer* target)
|
||||
update_attributes();
|
||||
}
|
||||
|
||||
void NodePanelLayer::save_history()
|
||||
{
|
||||
auto a = new ActionLayerChange;
|
||||
a->m_panel = this;
|
||||
for (auto const& l : Canvas::I->m_layers)
|
||||
{
|
||||
ActionLayerChange::LayerState s;
|
||||
s.alpha = l->m_opacity;
|
||||
s.lock = l->m_alpha_locked;
|
||||
s.visible = l->m_visible;
|
||||
a->m_layers.push_back(s);
|
||||
}
|
||||
ActionManager::add(a);
|
||||
}
|
||||
|
||||
void NodePanelLayer::clear()
|
||||
{
|
||||
m_layers_container->remove_all_children();
|
||||
@@ -342,6 +360,10 @@ void NodePanelLayer::update_attributes()
|
||||
m_opacity->set_value(l->m_opacity);
|
||||
m_alpha_lock->set_value(l->m_alpha_locked);
|
||||
m_blend_mode->set_index(l->m_blend_mode);
|
||||
for (int i = 0; i < Canvas::I->m_layers.size(); i++)
|
||||
{
|
||||
m_layers[i]->m_visibility->set_value(Canvas::I->m_layers[i]->m_visible);
|
||||
}
|
||||
}
|
||||
|
||||
kEventResult NodePanelLayer::handle_event(Event* e)
|
||||
@@ -487,3 +509,32 @@ Action* ActionLayerMerge::get_redo()
|
||||
a->m_direction = m_direction == Direction::Undo ? Direction::Redo : Direction::Undo;
|
||||
return a;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ActionLayerChange::undo()
|
||||
{
|
||||
for (int i = 0; i < m_layers.size(); i++)
|
||||
{
|
||||
auto& l = Canvas::I->m_layers[i];
|
||||
l->m_opacity = m_layers[i].alpha;
|
||||
l->m_alpha_locked = m_layers[i].lock;
|
||||
l->m_visible = m_layers[i].visible;
|
||||
}
|
||||
m_panel->update_attributes();
|
||||
}
|
||||
|
||||
Action* ActionLayerChange::get_redo()
|
||||
{
|
||||
auto a = new ActionLayerChange;
|
||||
a->m_panel = m_panel;
|
||||
for (auto const& l : Canvas::I->m_layers)
|
||||
{
|
||||
LayerState s;
|
||||
s.alpha = l->m_opacity;
|
||||
s.lock = l->m_alpha_locked;
|
||||
s.visible = l->m_visible;
|
||||
a->m_layers.push_back(s);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user