improve layer history, fix doc open
This commit is contained in:
@@ -2500,15 +2500,15 @@ bool Canvas::project_open_thread(std::string file_path)
|
|||||||
resize(m_width, m_height);
|
resize(m_width, m_height);
|
||||||
App::I.async_end();
|
App::I.async_end();
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Layer>> tmp_layers;
|
std::vector<std::shared_ptr<Layer>> tmp_layers(n_layers);
|
||||||
|
|
||||||
for (int i = 0; i < n_layers; i++)
|
for (int i = 0; i < n_layers; i++)
|
||||||
{
|
{
|
||||||
int n_order;
|
int n_order;
|
||||||
fread(&n_order, sizeof(int), 1, fp);
|
fread(&n_order, sizeof(int), 1, fp);
|
||||||
|
|
||||||
tmp_layers.push_back(std::make_unique<Layer>());
|
tmp_layers[n_order] = std::make_unique<Layer>();
|
||||||
auto& layer = tmp_layers.back();
|
auto& layer = tmp_layers[n_order];
|
||||||
|
|
||||||
fread(&layer->m_opacity, sizeof(float), 1, fp);
|
fread(&layer->m_opacity, sizeof(float), 1, fp);
|
||||||
|
|
||||||
@@ -2567,9 +2567,9 @@ bool Canvas::project_open_thread(std::string file_path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
App::I.async_start();
|
App::I.async_start();
|
||||||
tmp_layers.back()->create(m_width, m_height, name.c_str());
|
layer->create(m_width, m_height, name.c_str());
|
||||||
tmp_layers.back()->clear({ 0, 0, 0, 0 });
|
layer->clear({ 0, 0, 0, 0 });
|
||||||
tmp_layers.back()->restore(snap);
|
layer->restore(snap);
|
||||||
App::I.async_end();
|
App::I.async_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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*/)
|
std::shared_ptr<Layer> layer /*= nullptr*/, std::shared_ptr<NodeLayer> layer_node /*= nullptr*/, int index /*= 0*/)
|
||||||
{
|
{
|
||||||
if (index == -1)
|
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>();
|
auto l = layer_node ? layer_node : std::make_shared<NodeLayer>();
|
||||||
m_layers_container->add_child(l, index);
|
m_layers_container->add_child(l, index);
|
||||||
l->init();
|
l->init();
|
||||||
@@ -302,18 +302,21 @@ void NodePanelLayer::handle_layer_highlight(NodeLayer* target, bool highlight)
|
|||||||
|
|
||||||
void NodePanelLayer::handle_layer_visibility(NodeLayer* target, bool visible)
|
void NodePanelLayer::handle_layer_visibility(NodeLayer* target, bool visible)
|
||||||
{
|
{
|
||||||
|
save_history();
|
||||||
if (on_layer_visibility_changed)
|
if (on_layer_visibility_changed)
|
||||||
on_layer_visibility_changed(this, m_layers_container->get_child_index(target), visible);
|
on_layer_visibility_changed(this, m_layers_container->get_child_index(target), visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodePanelLayer::handle_layer_alpha_lock(NodeLayer* target, bool locked)
|
void NodePanelLayer::handle_layer_alpha_lock(NodeLayer* target, bool locked)
|
||||||
{
|
{
|
||||||
|
save_history();
|
||||||
if (on_layer_alpha_lock_changed)
|
if (on_layer_alpha_lock_changed)
|
||||||
on_layer_alpha_lock_changed(this, m_layers_container->get_child_index(target), locked);
|
on_layer_alpha_lock_changed(this, m_layers_container->get_child_index(target), locked);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodePanelLayer::handle_layer_blend_mode(NodeLayer* target, int mode)
|
void NodePanelLayer::handle_layer_blend_mode(NodeLayer* target, int mode)
|
||||||
{
|
{
|
||||||
|
save_history();
|
||||||
if (on_layer_blend_mode_changed)
|
if (on_layer_blend_mode_changed)
|
||||||
on_layer_blend_mode_changed(this, m_layers_container->get_child_index(target), mode);
|
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();
|
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()
|
void NodePanelLayer::clear()
|
||||||
{
|
{
|
||||||
m_layers_container->remove_all_children();
|
m_layers_container->remove_all_children();
|
||||||
@@ -342,6 +360,10 @@ void NodePanelLayer::update_attributes()
|
|||||||
m_opacity->set_value(l->m_opacity);
|
m_opacity->set_value(l->m_opacity);
|
||||||
m_alpha_lock->set_value(l->m_alpha_locked);
|
m_alpha_lock->set_value(l->m_alpha_locked);
|
||||||
m_blend_mode->set_index(l->m_blend_mode);
|
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)
|
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;
|
a->m_direction = m_direction == Direction::Undo ? Direction::Redo : Direction::Undo;
|
||||||
return a;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -74,10 +74,27 @@ public:
|
|||||||
void handle_layer_highlight(NodeLayer* target, bool highlight);
|
void handle_layer_highlight(NodeLayer* target, bool highlight);
|
||||||
void handle_layer_blend_mode(NodeLayer* target, int mode);
|
void handle_layer_blend_mode(NodeLayer* target, int mode);
|
||||||
void handle_layer_selected(NodeLayer* target);
|
void handle_layer_selected(NodeLayer* target);
|
||||||
|
void save_history();
|
||||||
void clear();
|
void clear();
|
||||||
void update_attributes();
|
void update_attributes();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ActionLayerChange : public Action
|
||||||
|
{
|
||||||
|
struct LayerState
|
||||||
|
{
|
||||||
|
bool visible;
|
||||||
|
float alpha;
|
||||||
|
bool lock;
|
||||||
|
};
|
||||||
|
NodePanelLayer* m_panel;
|
||||||
|
std::vector<LayerState> m_layers;
|
||||||
|
virtual void run() override { }
|
||||||
|
virtual Action* get_redo() override;
|
||||||
|
virtual void undo() override;
|
||||||
|
virtual size_t memory() override { return 0; }
|
||||||
|
};
|
||||||
|
|
||||||
class ActionLayerAdd : public Action
|
class ActionLayerAdd : public Action
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user