diff --git a/data/layout.xml b/data/layout.xml index 0be3147..46a5c59 100644 --- a/data/layout.xml +++ b/data/layout.xml @@ -68,6 +68,9 @@ + + + diff --git a/src/app_layout.cpp b/src/app_layout.cpp index e22da19..2502551 100644 --- a/src/app_layout.cpp +++ b/src/app_layout.cpp @@ -170,6 +170,25 @@ void App::init_sidebar() 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) { canvas->m_canvas->m_current_layer_idx = canvas->m_canvas->m_order[new_idx]; }; diff --git a/src/node_panel_layer.cpp b/src/node_panel_layer.cpp index c333f85..16a696e 100644 --- a/src/node_panel_layer.cpp +++ b/src/node_panel_layer.cpp @@ -110,24 +110,33 @@ Node* NodePanelLayer::clone_instantiate() const void NodePanelLayer::init() { - LOG("NodePanelLayer::init"); init_template("tpl-panel-layers"); - LOG("template initted"); m_layers_container = find("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("btn-add"); btn_remove = find("btn-remove"); btn_up = find("btn-up"); btn_down = find("btn-down"); - LOG("attach events"); + btn_duplicate = find("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*) { add_layer(); if (on_layer_add) @@ -171,7 +180,6 @@ void NodePanelLayer::init() m_blend_mode->on_select = [this](Node*, int index) { handle_layer_blend_mode(m_current_layer, index); }; - LOG("done init"); } NodeLayer* NodePanelLayer::add_layer(const char* name) diff --git a/src/node_panel_layer.h b/src/node_panel_layer.h index f069cf2..81de575 100644 --- a/src/node_panel_layer.h +++ b/src/node_panel_layer.h @@ -36,6 +36,7 @@ class NodePanelLayer : public Node NodeButtonCustom* btn_remove; NodeButtonCustom* btn_up; NodeButtonCustom* btn_down; + NodeButtonCustom* btn_duplicate; int id_counter = 0; public: std::function on_layer_change; @@ -45,6 +46,7 @@ public: std::function on_layer_highlight_changed; std::function on_layer_blend_mode_changed; std::function on_layer_delete; + std::function on_layer_duplicate; std::function on_layer_add; std::function on_layer_order; NodeLayer* m_current_layer = nullptr;