change node children from unique to shared ptr, rename Canvas2D to StrokePreview, add panel toolbar with icon buttons to toggle
This commit is contained in:
@@ -184,7 +184,7 @@ void App::initLayout()
|
||||
NodeBorder::static_init();
|
||||
NodeImage::static_init();
|
||||
NodeIcon::static_init();
|
||||
NodeCanvas2D::static_init();
|
||||
NodeStrokePreview::static_init();
|
||||
|
||||
layout.on_loaded = [&] {
|
||||
LOG("initializing layout updating after load");
|
||||
@@ -192,10 +192,36 @@ void App::initLayout()
|
||||
|
||||
LOG("initializing layout components");
|
||||
sidebar = layout[main_id]->find<NodeBorder>("sidebar");
|
||||
brushes = layout[main_id]->find<NodePanelBrush>("panel-brush");
|
||||
layers = layout[main_id]->find<NodePanelLayer>("panel-layer");
|
||||
color = layout[main_id]->find<NodePanelColor>("panel-color");
|
||||
stroke = layout[main_id]->find<NodePanelStroke>("panel-stroke");
|
||||
panels = layout[main_id]->find<Node>("panels");
|
||||
|
||||
//brushes = layout[main_id]->find<NodePanelBrush>("panel-brush");
|
||||
//layers = layout[main_id]->find<NodePanelLayer>("panel-layer");
|
||||
//color = layout[main_id]->find<NodePanelColor>("panel-color");
|
||||
//stroke = layout[main_id]->find<NodePanelStroke>("panel-stroke");
|
||||
|
||||
brushes = std::make_shared<NodePanelBrush>();
|
||||
brushes->m_manager = &layout;
|
||||
brushes->init();
|
||||
brushes->create();
|
||||
brushes->loaded();
|
||||
|
||||
layers = std::make_shared<NodePanelLayer>();
|
||||
layers->m_manager = &layout;
|
||||
layers->init();
|
||||
layers->create();
|
||||
layers->loaded();
|
||||
|
||||
color = std::make_shared<NodePanelColor>();
|
||||
color->m_manager = &layout;
|
||||
color->init();
|
||||
color->create();
|
||||
color->loaded();
|
||||
|
||||
stroke = std::make_shared<NodePanelStroke>();
|
||||
stroke->m_manager = &layout;
|
||||
stroke->init();
|
||||
stroke->create();
|
||||
stroke->loaded();
|
||||
|
||||
brushes->on_brush_changed = [this](Node* target, int index) {
|
||||
auto tid = brushes->get_texture_id(index);
|
||||
@@ -217,6 +243,67 @@ void App::initLayout()
|
||||
on_stroke_change();
|
||||
};
|
||||
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-stroke"))
|
||||
{
|
||||
button->on_click = [this](Node*) {
|
||||
panels->remove_all_children();
|
||||
if (current_panel != stroke.get())
|
||||
{
|
||||
panels->add_child(std::static_pointer_cast<Node>(stroke));
|
||||
current_panel = stroke.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
current_panel = nullptr;
|
||||
}
|
||||
};
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-brush"))
|
||||
{
|
||||
button->on_click = [this](Node*) {
|
||||
panels->remove_all_children();
|
||||
if (current_panel != brushes.get())
|
||||
{
|
||||
panels->add_child(std::static_pointer_cast<Node>(brushes));
|
||||
current_panel = brushes.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
current_panel = nullptr;
|
||||
}
|
||||
};
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-color"))
|
||||
{
|
||||
button->on_click = [this](Node*) {
|
||||
panels->remove_all_children();
|
||||
if (current_panel != color.get())
|
||||
{
|
||||
panels->add_child(std::static_pointer_cast<Node>(color));
|
||||
current_panel = color.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
current_panel = nullptr;
|
||||
}
|
||||
};
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-layer"))
|
||||
{
|
||||
button->on_click = [this](Node*) {
|
||||
panels->remove_all_children();
|
||||
if (current_panel != layers.get())
|
||||
{
|
||||
panels->add_child(std::static_pointer_cast<Node>(layers));
|
||||
current_panel = layers.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
current_panel = nullptr;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (auto* button = layout[main_id]->find<NodeButton>("btn-close"))
|
||||
{
|
||||
button->on_click = [](Node*) { exit(0); };
|
||||
|
||||
10
engine/app.h
10
engine/app.h
@@ -20,10 +20,12 @@ public:
|
||||
NodePopupMenu* menu_edit = nullptr;
|
||||
NodePopupMenu* menu_layers = nullptr;
|
||||
NodeBorder* sidebar = nullptr;
|
||||
NodePanelBrush* brushes;
|
||||
NodePanelLayer* layers;
|
||||
NodePanelColor* color;
|
||||
NodePanelStroke* stroke;
|
||||
std::shared_ptr<NodePanelBrush> brushes;
|
||||
std::shared_ptr<NodePanelLayer> layers;
|
||||
std::shared_ptr<NodePanelColor> color;
|
||||
std::shared_ptr<NodePanelStroke> stroke;
|
||||
Node* current_panel = nullptr;
|
||||
Node* panels;
|
||||
std::function<void(int)> on_brush_select;
|
||||
std::function<void(glm::vec4 color)> on_color_change;
|
||||
std::function<void()> on_stroke_change;
|
||||
|
||||
@@ -9,7 +9,7 @@ Plane NodeBorder::m_plane;
|
||||
Plane NodeImage::m_plane;
|
||||
Sampler NodeImage::m_sampler;
|
||||
std::map<std::string, glm::vec4> NodeIcon::m_icons;
|
||||
ui::Shader NodeCanvas2D::m_shader;
|
||||
ui::Shader NodeStrokePreview::m_shader;
|
||||
|
||||
kEventResult Node::on_event(Event* e)
|
||||
{
|
||||
@@ -112,9 +112,23 @@ void Node::add_child(Node* n, int index)
|
||||
YGNodeInsertChild(y_node, n->y_node, index);
|
||||
}
|
||||
|
||||
void Node::add_child(std::shared_ptr<Node> n)
|
||||
{
|
||||
m_children.push_back(n);
|
||||
n->parent = this;
|
||||
n->m_manager = m_manager;
|
||||
YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node));
|
||||
}
|
||||
void Node::add_child(std::shared_ptr<Node> n, int index)
|
||||
{
|
||||
m_children.push_back(n);
|
||||
n->parent = this;
|
||||
n->m_manager = m_manager;
|
||||
YGNodeInsertChild(y_node, n->y_node, index);
|
||||
}
|
||||
void Node::remove_child(Node* n)
|
||||
{
|
||||
auto i = std::find_if(m_children.begin(), m_children.end(), [=](std::unique_ptr<Node>& ptr) { return ptr.get() == n; });
|
||||
auto i = std::find_if(m_children.begin(), m_children.end(), [=](auto& ptr) { return ptr.get() == n; });
|
||||
if (i != m_children.end())
|
||||
{
|
||||
YGNodeRemoveChild(y_node, n->y_node);
|
||||
@@ -122,6 +136,12 @@ void Node::remove_child(Node* n)
|
||||
}
|
||||
}
|
||||
|
||||
void Node::remove_all_children()
|
||||
{
|
||||
for (auto& n : m_children)
|
||||
YGNodeRemoveChild(y_node, n->y_node);
|
||||
m_children.clear();
|
||||
}
|
||||
void Node::move_child(Node* n, int index)
|
||||
{
|
||||
YGNodeRemoveChild(y_node, n->y_node);
|
||||
@@ -443,7 +463,7 @@ void Node::load_internal(const tinyxml2::XMLElement* x_node)
|
||||
CASE(kWidget::PanelColor, NodePanelColor);
|
||||
CASE(kWidget::PanelStroke, NodePanelStroke);
|
||||
CASE(kWidget::ColorQuad, NodeColorQuad);
|
||||
CASE(kWidget::Canvas2D, NodeCanvas2D);
|
||||
CASE(kWidget::Canvas2D, NodeStrokePreview);
|
||||
#undef CASE
|
||||
case kWidget::Ref:
|
||||
{
|
||||
|
||||
@@ -155,7 +155,7 @@ public:
|
||||
class LayoutManager* m_manager;
|
||||
uint16_t m_nodeID;
|
||||
std::string m_nodeID_s;
|
||||
std::vector<std::unique_ptr<Node>> m_children;
|
||||
std::vector<std::shared_ptr<Node>> m_children;
|
||||
Node* current_mouse_capture = nullptr;
|
||||
Node* current_key_capture = nullptr;
|
||||
bool m_mouse_captured = false;
|
||||
@@ -301,7 +301,10 @@ public:
|
||||
const Node* init_template(const char* id);
|
||||
void add_child(Node* n);
|
||||
void add_child(Node* n, int index);
|
||||
void add_child(std::shared_ptr<Node> n);
|
||||
void add_child(std::shared_ptr<Node> n, int index);
|
||||
void remove_child(Node* n);
|
||||
void remove_all_children();
|
||||
void move_child(Node* n, int index);
|
||||
void move_child_offset(Node* n, int offset);
|
||||
int get_child_index(Node* n);
|
||||
@@ -732,10 +735,10 @@ public:
|
||||
case kEventType::KeyDown:
|
||||
switch (ke->m_key)
|
||||
{
|
||||
case VK_BACK:
|
||||
m_string.erase(m_string.end() - 1);
|
||||
m_text->set_text(m_string.c_str());
|
||||
break;
|
||||
// case VK_BACK:
|
||||
// m_string.erase(m_string.end() - 1);
|
||||
// m_text->set_text(m_string.c_str());
|
||||
// break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -1655,7 +1658,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class NodeCanvas2D : public NodeBorder
|
||||
class NodeStrokePreview : public NodeBorder
|
||||
{
|
||||
RTT m_rtt;
|
||||
Sampler m_sampler;
|
||||
@@ -1696,7 +1699,7 @@ public:
|
||||
"}";
|
||||
m_shader.create(shader_v, shader_f);
|
||||
}
|
||||
virtual Node* clone_instantiate() const override { return new NodeCanvas2D(); }
|
||||
virtual Node* clone_instantiate() const override { return new NodeStrokePreview(); }
|
||||
virtual void clone_copy(Node* dest) const override
|
||||
{
|
||||
NodeBorder::clone_copy(dest);
|
||||
@@ -1707,7 +1710,7 @@ public:
|
||||
}
|
||||
virtual void clone_finalize(Node* dest) const override
|
||||
{
|
||||
NodeCanvas2D* n = (NodeCanvas2D*)dest;
|
||||
NodeStrokePreview* n = (NodeStrokePreview*)dest;
|
||||
n->init_controls();
|
||||
}
|
||||
void init_controls()
|
||||
@@ -1798,7 +1801,7 @@ public:
|
||||
class NodePanelStroke : public Node
|
||||
{
|
||||
public:
|
||||
NodeCanvas2D* m_canvas;
|
||||
NodeStrokePreview* m_canvas;
|
||||
NodeSliderH* m_tip_size;
|
||||
NodeSliderH* m_tip_spacing;
|
||||
NodeSliderH* m_tip_flow;
|
||||
@@ -1821,26 +1824,26 @@ public:
|
||||
}
|
||||
void init_controls()
|
||||
{
|
||||
m_canvas = find<NodeCanvas2D>("canvas");
|
||||
m_canvas = find<NodeStrokePreview>("canvas");
|
||||
|
||||
init_slider(m_tip_size, "tip-size", &NodeCanvas2D::m_tip_size);
|
||||
init_slider(m_tip_spacing, "tip-spacing", &NodeCanvas2D::m_tip_spacing);
|
||||
init_slider(m_tip_flow, "tip-flow", &NodeCanvas2D::m_tip_flow);
|
||||
init_slider(m_tip_angle, "tip-angle", &NodeCanvas2D::m_tip_angle);
|
||||
init_slider(m_jitter_scale, "jitter-scale", &NodeCanvas2D::m_jitter_scale);
|
||||
init_slider(m_jitter_angle, "jitter-angle", &NodeCanvas2D::m_jitter_angle);
|
||||
init_slider(m_jitter_spread, "jitter-spread", &NodeCanvas2D::m_jitter_spread);
|
||||
init_slider(m_jitter_flow, "jitter-flow", &NodeCanvas2D::m_jitter_flow);
|
||||
init_slider(m_tip_size, "tip-size", &NodeStrokePreview::m_tip_size);
|
||||
init_slider(m_tip_spacing, "tip-spacing", &NodeStrokePreview::m_tip_spacing);
|
||||
init_slider(m_tip_flow, "tip-flow", &NodeStrokePreview::m_tip_flow);
|
||||
init_slider(m_tip_angle, "tip-angle", &NodeStrokePreview::m_tip_angle);
|
||||
init_slider(m_jitter_scale, "jitter-scale", &NodeStrokePreview::m_jitter_scale);
|
||||
init_slider(m_jitter_angle, "jitter-angle", &NodeStrokePreview::m_jitter_angle);
|
||||
init_slider(m_jitter_spread, "jitter-spread", &NodeStrokePreview::m_jitter_spread);
|
||||
init_slider(m_jitter_flow, "jitter-flow", &NodeStrokePreview::m_jitter_flow);
|
||||
//m_canvas->draw_stroke();
|
||||
}
|
||||
void init_slider(NodeSliderH*& slider, const char* id, float NodeCanvas2D::* prop)
|
||||
void init_slider(NodeSliderH*& slider, const char* id, float NodeStrokePreview::* prop)
|
||||
{
|
||||
slider = find<NodeSliderH>(id);
|
||||
slider->on_value_changed = std::bind(&NodePanelStroke::handle_slide,
|
||||
this, prop, std::placeholders::_1, std::placeholders::_2);
|
||||
m_canvas->*prop = slider->m_value.x;
|
||||
}
|
||||
void handle_slide(float NodeCanvas2D::* prop, Node* target, float value)
|
||||
void handle_slide(float NodeStrokePreview::* prop, Node* target, float value)
|
||||
{
|
||||
m_canvas->*prop = value;
|
||||
m_canvas->draw_stroke();
|
||||
|
||||
Reference in New Issue
Block a user