From 50cf64b7f19a91451a525530da05bba98e934f6a Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 19 Nov 2022 13:17:30 +0100 Subject: [PATCH] Added a few notifications to PaintNodes. --- modules/paint/nodes/paint_node.cpp | 29 +++++++++++++++++++++++++++ modules/paint/nodes/paint_node.h | 12 +++++++++++ modules/paint/nodes/paint_project.cpp | 5 ++++- modules/paint/nodes/paint_project.h | 2 ++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/modules/paint/nodes/paint_node.cpp b/modules/paint/nodes/paint_node.cpp index ab149686c..9feaa33c4 100644 --- a/modules/paint/nodes/paint_node.cpp +++ b/modules/paint/nodes/paint_node.cpp @@ -10,6 +10,7 @@ void PaintNode::set_size(const Vector2i &size) { _size = size; if (is_inside_tree()) { + _propagate_notification_resized(); update(); } } @@ -25,6 +26,14 @@ 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() { +} + PoolVector2iArray PaintNode::util_get_pixels_in_line(const Vector2i &from, const Vector2i &to) { return PaintUtilities::get_pixels_in_line(from, to); } @@ -88,6 +97,18 @@ String PaintNode::get_configuration_warning() const { return "This Node should be a child of a PaintProject!"; } +void PaintNode::_propagate_notification_resized() { + notification(NOTIFICATION_PAINT_NODE_RESIZED); + + for (int i = 0; i < get_child_count(); ++i) { + PaintNode *pn = Object::cast_to(get_child(i)); + + if (pn) { + pn->_propagate_notification_resized(); + } + } +} + PaintNode::PaintNode() { _draw_outline = true; } @@ -119,6 +140,10 @@ 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); + ClassDB::bind_method(D_METHOD("util_get_pixels_in_line", "from", "to"), &PaintNode::util_get_pixels_in_line); ClassDB::bind_method(D_METHOD("util_to_1d_v", "p", "w"), &PaintNode::util_to_1d_v); @@ -134,4 +159,8 @@ void PaintNode::_bind_methods() { ClassDB::bind_method(D_METHOD("_forward_canvas_gui_input", "event"), &PaintNode::_forward_canvas_gui_input); ClassDB::bind_method(D_METHOD("get_paint_project"), &PaintNode::get_paint_project); + + BIND_CONSTANT(NOTIFICATION_PAINT_NODE_RESIZED); + BIND_CONSTANT(NOTIFICATION_PAINT_PROJECT_PRE_SAVE); + BIND_CONSTANT(NOTIFICATION_PAINT_PROJECT_POST_SAVE); } diff --git a/modules/paint/nodes/paint_node.h b/modules/paint/nodes/paint_node.h index 16d0e39a5..2716d8b9f 100644 --- a/modules/paint/nodes/paint_node.h +++ b/modules/paint/nodes/paint_node.h @@ -11,12 +11,22 @@ class PaintNode : public Node2D { GDCLASS(PaintNode, Node2D); public: + enum { + NOTIFICATION_PAINT_NODE_RESIZED = 2500, + NOTIFICATION_PAINT_PROJECT_PRE_SAVE = 2501, + NOTIFICATION_PAINT_PROJECT_POST_SAVE = 2502, + }; + + Vector2i get_size(); void set_size(const Vector2i &size); bool get_draw_outline(); void set_draw_outline(const bool val); + void save(); + virtual void _save(); + PoolVector2iArray util_get_pixels_in_line(const Vector2i &from, const Vector2i &to); int util_to_1d_v(const Vector2i &p, int w); @@ -34,6 +44,8 @@ public: String get_configuration_warning() const; + virtual void _propagate_notification_resized(); + PaintNode(); ~PaintNode(); diff --git a/modules/paint/nodes/paint_project.cpp b/modules/paint/nodes/paint_project.cpp index 841ef9733..ee9493a2a 100644 --- a/modules/paint/nodes/paint_project.cpp +++ b/modules/paint/nodes/paint_project.cpp @@ -1,8 +1,8 @@ #include "paint_project.h" -#include "core/config/project_settings.h" #include "../ui/paint_canvas_background.h" #include "../ui/paint_visual_grid.h" +#include "core/config/project_settings.h" #include "core/config/engine.h" @@ -77,6 +77,9 @@ void PaintProject::add_paint_visual_grid() { } } +void PaintProject::_propagate_notification_resized() { +} + PaintProject::PaintProject() { _current_color = Color(1, 1, 1, 1); } diff --git a/modules/paint/nodes/paint_project.h b/modules/paint/nodes/paint_project.h index bfb2f155f..02d6b995a 100644 --- a/modules/paint/nodes/paint_project.h +++ b/modules/paint/nodes/paint_project.h @@ -26,6 +26,8 @@ public: void add_paint_canvas_backgorund(); void add_paint_visual_grid(); + void _propagate_notification_resized(); + PaintProject(); ~PaintProject();