fix layer delete
This commit is contained in:
@@ -96,6 +96,10 @@ void App::initLayout()
|
||||
canvas->m_canvas->layer_order(old_idx, new_idx);
|
||||
};
|
||||
|
||||
layers->on_layer_delete = [this](Node*, int idx) {
|
||||
canvas->m_canvas->layer_remove(canvas->m_canvas->m_order[idx]);
|
||||
};
|
||||
|
||||
layers->on_layer_opacity_changed = [this](Node*, int idx, float value) {
|
||||
canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]].m_opacity = value;
|
||||
};
|
||||
|
||||
@@ -441,6 +441,16 @@ void ui::Canvas::layer_add(std::string name)
|
||||
m_layers.emplace_back();
|
||||
m_layers.back().create(m_width, m_height, name);
|
||||
m_order.push_back(idx);
|
||||
m_current_layer_idx = idx;
|
||||
}
|
||||
void ui::Canvas::layer_remove(int idx)
|
||||
{
|
||||
for (auto& i : m_order)
|
||||
if (i > m_order[idx])
|
||||
i--;
|
||||
m_layers.erase(m_layers.begin() + idx);
|
||||
m_order.erase(m_order.begin() + idx);
|
||||
m_current_layer_idx = std::max<int>(m_layers.size() - 1, idx);
|
||||
}
|
||||
void ui::Canvas::layer_order(int idx, int pos)
|
||||
{
|
||||
|
||||
@@ -94,6 +94,7 @@ public:
|
||||
Canvas() { I = this; }
|
||||
bool create(int width, int height);
|
||||
void resize(int width, int height);
|
||||
void layer_remove(int idx);
|
||||
void layer_add(std::string name);
|
||||
void layer_order(int idx, int pos);
|
||||
void stroke_start(glm::vec2 point, float pressure, const ui::Brush& brush);
|
||||
|
||||
@@ -11,7 +11,7 @@ void NodeCanvas::init()
|
||||
{
|
||||
m_mouse_ignore = false;
|
||||
m_canvas = std::make_unique<ui::Canvas>();
|
||||
m_canvas->create(1024, 1024);
|
||||
m_canvas->create(2048, 2048);
|
||||
m_sampler.create(GL_NEAREST);
|
||||
m_face_plane.create<1>(2, 2);
|
||||
m_line.create();
|
||||
@@ -25,7 +25,7 @@ void NodeCanvas::init()
|
||||
void NodeCanvas::restore_context()
|
||||
{
|
||||
Node::restore_context();
|
||||
m_canvas->create(1024, 1024);
|
||||
m_canvas->create(2048, 2048);
|
||||
m_sampler.create(GL_NEAREST);
|
||||
m_face_plane.create<1>(2, 2);
|
||||
m_canvas->snapshot_restore();
|
||||
|
||||
Reference in New Issue
Block a user