diff --git a/modules/paint/nodes/paint_canvas.cpp b/modules/paint/nodes/paint_canvas.cpp index ce7626572..ff55b132e 100644 --- a/modules/paint/nodes/paint_canvas.cpp +++ b/modules/paint/nodes/paint_canvas.cpp @@ -337,6 +337,10 @@ Ref PaintCanvas::get_preview_image_texture() { return _preview_image_texture; } +Ref PaintCanvas::_get_save_image() { + return _image; +} + void PaintCanvas::handle_draw(const Vector2 &local_position, const Ref &event) { PaintProject *proj = get_paint_project(); diff --git a/modules/paint/nodes/paint_canvas.h b/modules/paint/nodes/paint_canvas.h index f7d85f5a0..508414cc0 100644 --- a/modules/paint/nodes/paint_canvas.h +++ b/modules/paint/nodes/paint_canvas.h @@ -82,6 +82,8 @@ public: Ref get_image_texture(); Ref get_preview_image_texture(); + Ref _get_save_image(); + void handle_draw(const Vector2 &local_position, const Ref &event); Color get_current_color(); void update_mouse_position(const Vector2 &local_position, const Ref &event); diff --git a/modules/paint/nodes/paint_node.cpp b/modules/paint/nodes/paint_node.cpp index 9feaa33c4..294553b48 100644 --- a/modules/paint/nodes/paint_node.cpp +++ b/modules/paint/nodes/paint_node.cpp @@ -26,12 +26,19 @@ void PaintNode::set_draw_outline(const bool val) { } } -void PaintNode::save() { - notification(NOTIFICATION_PAINT_PROJECT_PRE_SAVE); - call("_save"); - notification(NOTIFICATION_PAINT_PROJECT_POST_SAVE); +void PaintNode::save_image() { + _propagate_notification_project_pre_save(); + call("_save_image"); + _propagate_notification_project_post_save(); } -void PaintNode::_save() { +void PaintNode::_save_image() { +} + +Ref PaintNode::get_save_image() { + return call("_get_save_image"); +} +Ref PaintNode::_get_save_image() { + return Ref(); } PoolVector2iArray PaintNode::util_get_pixels_in_line(const Vector2i &from, const Vector2i &to) { @@ -109,6 +116,29 @@ void PaintNode::_propagate_notification_resized() { } } +void PaintNode::_propagate_notification_project_pre_save() { + notification(NOTIFICATION_PAINT_PROJECT_PRE_SAVE); + + for (int i = 0; i < get_child_count(); ++i) { + PaintNode *pn = Object::cast_to(get_child(i)); + + if (pn) { + pn->_propagate_notification_project_pre_save(); + } + } +} +void PaintNode::_propagate_notification_project_post_save() { + notification(NOTIFICATION_PAINT_PROJECT_POST_SAVE); + + for (int i = 0; i < get_child_count(); ++i) { + PaintNode *pn = Object::cast_to(get_child(i)); + + if (pn) { + pn->_propagate_notification_project_post_save(); + } + } +} + PaintNode::PaintNode() { _draw_outline = true; } @@ -140,9 +170,13 @@ void PaintNode::_bind_methods() { ClassDB::bind_method(D_METHOD("set_draw_outline", "val"), &PaintNode::set_draw_outline); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_outline"), "set_draw_outline", "get_draw_outline"); - BIND_VMETHOD(MethodInfo("_save")); - ClassDB::bind_method(D_METHOD("save"), &PaintNode::save); - ClassDB::bind_method(D_METHOD("_save"), &PaintNode::_save); + BIND_VMETHOD(MethodInfo("_save_image")); + ClassDB::bind_method(D_METHOD("save_image"), &PaintNode::save_image); + ClassDB::bind_method(D_METHOD("_save_image"), &PaintNode::_save_image); + + BIND_VMETHOD(MethodInfo("_get_save_image")); + ClassDB::bind_method(D_METHOD("get_save_image"), &PaintNode::get_save_image); + ClassDB::bind_method(D_METHOD("_get_save_image"), &PaintNode::_get_save_image); ClassDB::bind_method(D_METHOD("util_get_pixels_in_line", "from", "to"), &PaintNode::util_get_pixels_in_line); diff --git a/modules/paint/nodes/paint_node.h b/modules/paint/nodes/paint_node.h index 9c6055f7a..19e1a317f 100644 --- a/modules/paint/nodes/paint_node.h +++ b/modules/paint/nodes/paint_node.h @@ -23,8 +23,11 @@ public: bool get_draw_outline(); void set_draw_outline(const bool val); - void save(); - virtual void _save(); + void save_image(); + virtual void _save_image(); + + Ref get_save_image(); + virtual Ref _get_save_image(); PoolVector2iArray util_get_pixels_in_line(const Vector2i &from, const Vector2i &to); @@ -44,6 +47,8 @@ public: String get_configuration_warning() const; virtual void _propagate_notification_resized(); + void _propagate_notification_project_pre_save(); + void _propagate_notification_project_post_save(); PaintNode(); ~PaintNode(); diff --git a/modules/paint/nodes/paint_project.cpp b/modules/paint/nodes/paint_project.cpp index ee9493a2a..1c30bcb4c 100644 --- a/modules/paint/nodes/paint_project.cpp +++ b/modules/paint/nodes/paint_project.cpp @@ -6,6 +6,13 @@ #include "core/config/engine.h" +String PaintProject::get_save_file_name() { + return _save_file_name; +} +void PaintProject::set_save_file_name(const String &fn) { + _save_file_name = fn; +} + Color PaintProject::get_current_color() { return _current_color; } @@ -58,6 +65,14 @@ void PaintProject::set_colors_as_default() { } } +void PaintProject::_save_image() { + ERR_FAIL_COND(_save_file_name.empty()); + + //create image + //collect and merge in all images returned by _get_save_image() in each PaintNode child + //save image +} + void PaintProject::add_paint_canvas_backgorund() { PaintCanvasBackground *bg = memnew(PaintCanvasBackground); add_child(bg); @@ -101,6 +116,12 @@ void PaintProject::_bind_methods() { ADD_SIGNAL(MethodInfo("current_color_changed", PropertyInfo(Variant::COLOR, "color"))); ADD_SIGNAL(MethodInfo("color_presets_changed")); + ClassDB::bind_method(D_METHOD("get_save_file_name"), &PaintProject::get_save_file_name); + ClassDB::bind_method(D_METHOD("set_save_file_name", "size"), &PaintProject::set_save_file_name); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "save_file_name"), "set_save_file_name", "get_save_file_name"); + + ADD_PROPERTY(PropertyInfo(Variant::NIL, "run_save_image", PROPERTY_HINT_BUTTON, "save_image"), "", ""); + ClassDB::bind_method(D_METHOD("get_current_color"), &PaintProject::get_current_color); ClassDB::bind_method(D_METHOD("set_current_color", "size"), &PaintProject::set_current_color); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "current_color"), "set_current_color", "get_current_color"); diff --git a/modules/paint/nodes/paint_project.h b/modules/paint/nodes/paint_project.h index 02d6b995a..190265619 100644 --- a/modules/paint/nodes/paint_project.h +++ b/modules/paint/nodes/paint_project.h @@ -9,6 +9,9 @@ class PaintProject : public PaintNode { GDCLASS(PaintProject, PaintNode); public: + String get_save_file_name(); + void set_save_file_name(const String &fn); + Color get_current_color(); void set_current_color(const Color &color); @@ -23,6 +26,8 @@ public: void set_colors_as_default(); + void _save_image(); + void add_paint_canvas_backgorund(); void add_paint_visual_grid(); @@ -36,6 +41,7 @@ protected: static void _bind_methods(); + String _save_file_name; Color _current_color; PoolColorArray _color_presets; };