add duplicate layer
This commit is contained in:
@@ -68,6 +68,9 @@
|
|||||||
<button-custom id="btn-add" thickness="1" color="0 0" border-color=".0" shrink="1" margin="0 2 0 5">
|
<button-custom id="btn-add" thickness="1" color="0 0" border-color=".0" shrink="1" margin="0 2 0 5">
|
||||||
<icon width="30" icon="add"/>
|
<icon width="30" icon="add"/>
|
||||||
</button-custom>
|
</button-custom>
|
||||||
|
<button-custom id="btn-duplicate" thickness="1" color="0 0" border-color=".0" shrink="1" margin="0 2 0 5">
|
||||||
|
<icon width="30" icon="page_copy"/>
|
||||||
|
</button-custom>
|
||||||
<button-custom id="btn-up" thickness="1" color="0 0" border-color=".0" shrink="1" margin="0 2 0 0">
|
<button-custom id="btn-up" thickness="1" color="0 0" border-color=".0" shrink="1" margin="0 2 0 0">
|
||||||
<icon width="30" icon="bullet_arrow_up"/>
|
<icon width="30" icon="bullet_arrow_up"/>
|
||||||
</button-custom>
|
</button-custom>
|
||||||
|
|||||||
@@ -170,6 +170,25 @@ void App::init_sidebar()
|
|||||||
title_update();
|
title_update();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
layers->on_layer_duplicate = [this](Node*, int source_index) {
|
||||||
|
Canvas::I->layer_add(layers->m_layers.back()->m_label_text.c_str());
|
||||||
|
auto& dst = Canvas::I->m_layers.back();
|
||||||
|
auto& src = Canvas::I->m_layers[Canvas::I->m_order[source_index]];
|
||||||
|
for (int i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
if (!src.m_dirty_face[i])
|
||||||
|
continue;
|
||||||
|
dst.m_rtt[i].copy(src.m_rtt[i]);
|
||||||
|
dst.m_dirty_face[i] = src.m_dirty_face[i];
|
||||||
|
dst.m_dirty_box[i] = src.m_dirty_box[i];
|
||||||
|
dst.m_opacity = src.m_opacity;
|
||||||
|
dst.m_blend_mode = src.m_blend_mode;
|
||||||
|
dst.m_alpha_locked = src.m_alpha_locked;
|
||||||
|
}
|
||||||
|
Canvas::I->m_unsaved = true;
|
||||||
|
title_update();
|
||||||
|
};
|
||||||
|
|
||||||
layers->on_layer_change = [this](Node*, int old_idx, int new_idx) {
|
layers->on_layer_change = [this](Node*, int old_idx, int new_idx) {
|
||||||
canvas->m_canvas->m_current_layer_idx = canvas->m_canvas->m_order[new_idx];
|
canvas->m_canvas->m_current_layer_idx = canvas->m_canvas->m_order[new_idx];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -110,24 +110,33 @@ Node* NodePanelLayer::clone_instantiate() const
|
|||||||
|
|
||||||
void NodePanelLayer::init()
|
void NodePanelLayer::init()
|
||||||
{
|
{
|
||||||
LOG("NodePanelLayer::init");
|
|
||||||
init_template("tpl-panel-layers");
|
init_template("tpl-panel-layers");
|
||||||
LOG("template initted");
|
|
||||||
m_layers_container = find<NodeBorder>("layers-container");
|
m_layers_container = find<NodeBorder>("layers-container");
|
||||||
LOG("template container found");
|
|
||||||
// for (int i = 0; i < 1; i++)
|
|
||||||
// {
|
|
||||||
// LOG("add layer");
|
|
||||||
// add_layer();
|
|
||||||
// }
|
|
||||||
LOG("find components");
|
|
||||||
// m_current_layer = m_layers[0];
|
|
||||||
// m_layers[0]->m_selected = true;
|
|
||||||
btn_add = find<NodeButtonCustom>("btn-add");
|
btn_add = find<NodeButtonCustom>("btn-add");
|
||||||
btn_remove = find<NodeButtonCustom>("btn-remove");
|
btn_remove = find<NodeButtonCustom>("btn-remove");
|
||||||
btn_up = find<NodeButtonCustom>("btn-up");
|
btn_up = find<NodeButtonCustom>("btn-up");
|
||||||
btn_down = find<NodeButtonCustom>("btn-down");
|
btn_down = find<NodeButtonCustom>("btn-down");
|
||||||
LOG("attach events");
|
btn_duplicate = find<NodeButtonCustom>("btn-duplicate");
|
||||||
|
btn_duplicate->on_click = [this](Node*) {
|
||||||
|
std::string next = m_current_layer->m_label_text + "01";
|
||||||
|
std::regex r(R"(([^\d]*)(\d+)$)");
|
||||||
|
std::smatch m;
|
||||||
|
if (std::regex_search(m_current_layer->m_label_text, m, r))
|
||||||
|
{
|
||||||
|
auto num = m[2].str();
|
||||||
|
int count = atoi(num.c_str()) + 1;
|
||||||
|
char tmp[128];
|
||||||
|
sprintf(tmp, "%s%0*d", m[1].str().c_str(), num.length(), count);
|
||||||
|
next = tmp;
|
||||||
|
}
|
||||||
|
int source_index = m_layers_container->get_child_index(m_current_layer);
|
||||||
|
add_layer(next.c_str());
|
||||||
|
if (on_layer_duplicate)
|
||||||
|
on_layer_duplicate(this, source_index);
|
||||||
|
if (on_layer_change)
|
||||||
|
on_layer_change(this, -1, m_layers_container->get_child_index(m_current_layer));
|
||||||
|
update_attributes();
|
||||||
|
};
|
||||||
btn_add->on_click = [this](Node*) {
|
btn_add->on_click = [this](Node*) {
|
||||||
add_layer();
|
add_layer();
|
||||||
if (on_layer_add)
|
if (on_layer_add)
|
||||||
@@ -171,7 +180,6 @@ void NodePanelLayer::init()
|
|||||||
m_blend_mode->on_select = [this](Node*, int index) {
|
m_blend_mode->on_select = [this](Node*, int index) {
|
||||||
handle_layer_blend_mode(m_current_layer, index);
|
handle_layer_blend_mode(m_current_layer, index);
|
||||||
};
|
};
|
||||||
LOG("done init");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeLayer* NodePanelLayer::add_layer(const char* name)
|
NodeLayer* NodePanelLayer::add_layer(const char* name)
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class NodePanelLayer : public Node
|
|||||||
NodeButtonCustom* btn_remove;
|
NodeButtonCustom* btn_remove;
|
||||||
NodeButtonCustom* btn_up;
|
NodeButtonCustom* btn_up;
|
||||||
NodeButtonCustom* btn_down;
|
NodeButtonCustom* btn_down;
|
||||||
|
NodeButtonCustom* btn_duplicate;
|
||||||
int id_counter = 0;
|
int id_counter = 0;
|
||||||
public:
|
public:
|
||||||
std::function<void(Node* target, int old_idx, int new_idx)> on_layer_change;
|
std::function<void(Node* target, int old_idx, int new_idx)> on_layer_change;
|
||||||
@@ -45,6 +46,7 @@ public:
|
|||||||
std::function<void(Node* target, int idx, bool highlight)> on_layer_highlight_changed;
|
std::function<void(Node* target, int idx, bool highlight)> on_layer_highlight_changed;
|
||||||
std::function<void(Node* target, int idx, int mode)> on_layer_blend_mode_changed;
|
std::function<void(Node* target, int idx, int mode)> on_layer_blend_mode_changed;
|
||||||
std::function<void(Node* target, int index)> on_layer_delete;
|
std::function<void(Node* target, int index)> on_layer_delete;
|
||||||
|
std::function<void(Node* target, int index)> on_layer_duplicate;
|
||||||
std::function<void(Node* target)> on_layer_add;
|
std::function<void(Node* target)> on_layer_add;
|
||||||
std::function<void(Node* target, int old_idx, int new_idx)> on_layer_order;
|
std::function<void(Node* target, int old_idx, int new_idx)> on_layer_order;
|
||||||
NodeLayer* m_current_layer = nullptr;
|
NodeLayer* m_current_layer = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user