layers control
This commit is contained in:
@@ -320,7 +320,7 @@
|
||||
<!--Brushes-->
|
||||
<panel-brushes id="panel-brushes"></panel-brushes>
|
||||
<!--Layers-->
|
||||
<panel-layers></panel-layers>
|
||||
<panel-layers id="panel-layers"></panel-layers>
|
||||
</border>
|
||||
</node>
|
||||
<!-- content panel -->
|
||||
|
||||
@@ -154,6 +154,7 @@ void App::initLayout()
|
||||
LOG("initializing layout components");
|
||||
sidebar = layout[main_id]->find<NodeBorder>("sidebar");
|
||||
brushes = layout[main_id]->find<NodePanelBrushes>("panel-brushes");
|
||||
layers = layout[main_id]->find<NodePanelLayers>("panel-layers");
|
||||
if (auto* button = layout[main_id]->find<NodeButton>("btn-close"))
|
||||
{
|
||||
button->on_click = [](Node*) { exit(0); };
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
NodePopupMenu* menu_layers = nullptr;
|
||||
NodeBorder* sidebar = nullptr;
|
||||
NodePanelBrushes* brushes;
|
||||
NodePanelLayers* layers;
|
||||
const uint16_t main_id = const_hash("main");
|
||||
float width;
|
||||
float height;
|
||||
|
||||
@@ -1172,7 +1172,11 @@ class NodePanelLayers : public Node
|
||||
NodeButtonCustom* btn_remove;
|
||||
NodeButtonCustom* btn_up;
|
||||
NodeButtonCustom* btn_down;
|
||||
int id_counter = 0;
|
||||
public:
|
||||
std::function<void(Node* target, int old_idx, int new_idx)> on_layer_change;
|
||||
std::function<void(Node* target, int index)> on_layer_delete;
|
||||
std::function<void(Node* target)> on_layer_add;
|
||||
NodeLayer* m_current_layer = nullptr;
|
||||
std::vector<NodeLayer*> m_layers;
|
||||
NodeBorder* m_layers_container;
|
||||
@@ -1181,11 +1185,9 @@ public:
|
||||
{
|
||||
init_template("tpl-panel-layers");
|
||||
m_layers_container = find<NodeBorder>("layers-container");
|
||||
for (int i = 0; i < 5; i++)
|
||||
for (int i = 0; i < 1; i++)
|
||||
{
|
||||
static char s[64];
|
||||
sprintf(s, "Layer-%d", i);
|
||||
add_layer(s);
|
||||
add_layer();
|
||||
}
|
||||
m_current_layer = m_layers[0];
|
||||
m_layers[0]->m_selected = true;
|
||||
@@ -1193,20 +1195,26 @@ public:
|
||||
btn_remove = find<NodeButtonCustom>("btn-remove");
|
||||
btn_up = find<NodeButtonCustom>("btn-up");
|
||||
btn_down = find<NodeButtonCustom>("btn-down");
|
||||
btn_add->on_click = [this](Node*) { add_layer("New Layer"); };
|
||||
btn_add->on_click = [this](Node*) {
|
||||
add_layer();
|
||||
};
|
||||
btn_remove->on_click = [this](Node*) {
|
||||
if (m_layers.size() == 1)
|
||||
return; // dont' delete the last layer
|
||||
auto it = std::find(m_layers.begin(), m_layers.end(), m_current_layer);
|
||||
auto i = m_layers_container->get_child_index(m_current_layer);
|
||||
m_layers_container->remove_child(m_current_layer);
|
||||
m_layers.erase(it);
|
||||
i = std::min<int>(i, m_layers.size() - 1);
|
||||
m_current_layer = m_layers[i];
|
||||
m_current_layer->m_selected = true;
|
||||
remove_layer(m_current_layer);
|
||||
};
|
||||
btn_up->on_click = [this](Node*) { m_layers_container->move_child_offset(m_current_layer, -1); };
|
||||
btn_down->on_click = [this](Node*) { m_layers_container->move_child_offset(m_current_layer, +1); };
|
||||
btn_up->on_click = [this](Node*) {
|
||||
m_layers_container->move_child_offset(m_current_layer, -1);
|
||||
};
|
||||
btn_down->on_click = [this](Node*) {
|
||||
m_layers_container->move_child_offset(m_current_layer, +1);
|
||||
};
|
||||
}
|
||||
void add_layer()
|
||||
{
|
||||
static char s[64];
|
||||
sprintf(s, "Layer-%d", id_counter++);
|
||||
add_layer(s);
|
||||
}
|
||||
void add_layer(const char* name)
|
||||
{
|
||||
@@ -1218,6 +1226,22 @@ public:
|
||||
l->set_name(name);
|
||||
l->on_selected = std::bind(&NodePanelLayers::handle_layer_selected, this, std::placeholders::_1);
|
||||
m_layers.push_back(l);
|
||||
if (on_layer_add)
|
||||
on_layer_add(this);
|
||||
}
|
||||
void remove_layer(NodeLayer* layer)
|
||||
{
|
||||
auto it = std::find(m_layers.begin(), m_layers.end(), m_current_layer);
|
||||
auto i = m_layers_container->get_child_index(m_current_layer);
|
||||
m_layers_container->remove_child(m_current_layer);
|
||||
m_layers.erase(it);
|
||||
i = std::min<int>(i, m_layers.size() - 1);
|
||||
m_current_layer = m_layers[i];
|
||||
m_current_layer->m_selected = true;
|
||||
if (on_layer_delete)
|
||||
on_layer_delete(this, std::distance(m_layers.begin(), it));
|
||||
if (on_layer_change)
|
||||
on_layer_change(this, -1, i);
|
||||
}
|
||||
void handle_layer_selected(NodeLayer* target)
|
||||
{
|
||||
@@ -1225,6 +1249,8 @@ public:
|
||||
m_current_layer->m_selected = false;
|
||||
m_current_layer = target;
|
||||
m_current_layer->m_selected = true;
|
||||
if (on_layer_change)
|
||||
on_layer_change(this, -1, m_layers_container->get_child_index(m_current_layer));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user