add duplicate layer

This commit is contained in:
2019-01-18 22:39:15 +01:00
parent e0bb60980a
commit d019c2467e
4 changed files with 45 additions and 13 deletions

View File

@@ -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<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_remove = find<NodeButtonCustom>("btn-remove");
btn_up = find<NodeButtonCustom>("btn-up");
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*) {
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)