diff --git a/engine/app.h b/engine/app.h index 85b629e..45f9a74 100644 --- a/engine/app.h +++ b/engine/app.h @@ -106,4 +106,5 @@ public: void dialog_open(); void dialog_export(); void dialog_layer_rename(); + void brush_update(); }; diff --git a/engine/app_layout.cpp b/engine/app_layout.cpp index 9887bcc..1534e65 100644 --- a/engine/app_layout.cpp +++ b/engine/app_layout.cpp @@ -373,6 +373,12 @@ void App::init_menu_edit() } } +void App::brush_update() +{ + brushes->set_texture_id(canvas->m_brush.m_tex_id); + stroke->set_params(canvas->m_brush); +} + void App::init_menu_layer() { if (auto* menu_file = layout[main_id]->find("menu-layers")) diff --git a/engine/canvas_modes.cpp b/engine/canvas_modes.cpp index c9854cb..6526989 100644 --- a/engine/canvas_modes.cpp +++ b/engine/canvas_modes.cpp @@ -139,8 +139,16 @@ void CanvasModePen::leave() void CanvasModePen::enter() { - if (node) + if (m_valid_brush) + { node->m_brush = m_brush; + App::I.brush_update(); + } + else + { + m_brush = node->m_brush; + m_valid_brush = true; + } } //////////////////////////////////////////////////////////////////// diff --git a/engine/canvas_modes.h b/engine/canvas_modes.h index 06f2cdb..8d0aaae 100644 --- a/engine/canvas_modes.h +++ b/engine/canvas_modes.h @@ -41,6 +41,7 @@ class CanvasModePen : public CanvasMode float m_camera_fov; float m_zoom_canvas = 1.f; float m_zoom_start; + bool m_valid_brush = false; ui::Brush m_brush; public: virtual void on_MouseEvent(MouseEvent* me, glm::vec2& loc) override; diff --git a/engine/node_panel_brush.cpp b/engine/node_panel_brush.cpp index 8e78738..e68ce5c 100644 --- a/engine/node_panel_brush.cpp +++ b/engine/node_panel_brush.cpp @@ -81,3 +81,18 @@ uint16_t NodePanelBrush::get_texture_id(int index) const { return m_brushes[index]->img->m_tex_id; } + +// select the current brush based on the texture id +void NodePanelBrush::set_texture_id(int texid) +{ + if (m_current) + m_current->m_selected = false; + for (auto b : m_brushes) + { + if (b->img->m_tex_id == texid) + { + b->m_selected = true; + m_current = b; + } + } +} diff --git a/engine/node_panel_brush.h b/engine/node_panel_brush.h index 3fc50c5..3d154ac 100644 --- a/engine/node_panel_brush.h +++ b/engine/node_panel_brush.h @@ -27,4 +27,5 @@ public: void handle_click(Node* target); std::vector FindAllBrushes(const std::string& folder); uint16_t get_texture_id(int index) const; + void set_texture_id(int texid); }; diff --git a/engine/node_panel_stroke.cpp b/engine/node_panel_stroke.cpp index 4c08e27..f06316f 100644 --- a/engine/node_panel_stroke.cpp +++ b/engine/node_panel_stroke.cpp @@ -21,18 +21,20 @@ void NodePanelStroke::init() void NodePanelStroke::set_params(const ui::Brush &b) { - m_tip_size->set_value(b.m_tip_size); - m_tip_spacing->set_value(b.m_tip_spacing); - m_tip_flow->set_value(b.m_tip_flow); - m_tip_opacity->set_value(b.m_tip_opacity); - m_tip_angle->set_value(b.m_tip_angle); - m_jitter_scale->set_value(b.m_jitter_scale); - m_jitter_angle->set_value(b.m_jitter_angle); - m_jitter_spread->set_value(b.m_jitter_spread); - m_jitter_flow->set_value(b.m_jitter_flow); + m_tip_size->m_value.x = b.m_tip_size; + m_tip_spacing->m_value.x = b.m_tip_spacing; + m_tip_flow->m_value.x = b.m_tip_flow; + m_tip_opacity->m_value.x = b.m_tip_opacity; + m_tip_angle->m_value.x = b.m_tip_angle; + m_jitter_scale->m_value.x = b.m_jitter_scale; + m_jitter_angle->m_value.x = b.m_jitter_angle; + m_jitter_spread->m_value.x = b.m_jitter_spread; + m_jitter_flow->m_value.x = b.m_jitter_flow; m_tip_angle_follow->checked = b.m_tip_angle_follow; m_tip_flow_pressure->checked = b.m_tip_flow_pressure; m_tip_size_pressure->checked = b.m_tip_size_pressure; + m_canvas->m_brush = b; + m_canvas->draw_stroke(); } void NodePanelStroke::init_controls()