From 5a78997c83408e02cfa208191caff43c471af7c7 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 19 Nov 2022 01:23:33 +0100 Subject: [PATCH] Now PaintNodes can draw their outlines. --- modules/paint/nodes/paint_node.cpp | 35 ++++++++++++++++++++++++++++++ modules/paint/nodes/paint_node.h | 6 +++++ 2 files changed, 41 insertions(+) diff --git a/modules/paint/nodes/paint_node.cpp b/modules/paint/nodes/paint_node.cpp index 9bce07bec..ab149686c 100644 --- a/modules/paint/nodes/paint_node.cpp +++ b/modules/paint/nodes/paint_node.cpp @@ -8,6 +8,21 @@ Vector2i PaintNode::get_size() { } void PaintNode::set_size(const Vector2i &size) { _size = size; + + if (is_inside_tree()) { + update(); + } +} + +bool PaintNode::get_draw_outline() { + return _draw_outline; +} +void PaintNode::set_draw_outline(const bool val) { + _draw_outline = val; + + if (is_inside_tree()) { + update(); + } } PoolVector2iArray PaintNode::util_get_pixels_in_line(const Vector2i &from, const Vector2i &to) { @@ -74,16 +89,36 @@ String PaintNode::get_configuration_warning() const { } PaintNode::PaintNode() { + _draw_outline = true; } PaintNode::~PaintNode() { } +void PaintNode::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_DRAW: { + if (_draw_outline) { + draw_line(Point2(0, 0), Point2(_size.x, 0), Color(0, 0, 0, 1)); + draw_line(Point2(0, _size.y), Point2(_size.x, _size.y), Color(0, 0, 0, 1)); + draw_line(Point2(0, 0), Point2(0, _size.y), Color(0, 0, 0, 1)); + draw_line(Point2(_size.x, 0), Point2(_size.x, _size.y), Color(0, 0, 0, 1)); + } + } break; + default: + break; + } +} + void PaintNode::_bind_methods() { ClassDB::bind_method(D_METHOD("get_size"), &PaintNode::get_size); ClassDB::bind_method(D_METHOD("set_size", "size"), &PaintNode::set_size); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "size"), "set_size", "get_size"); + ClassDB::bind_method(D_METHOD("get_draw_outline"), &PaintNode::get_draw_outline); + 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"); + 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); diff --git a/modules/paint/nodes/paint_node.h b/modules/paint/nodes/paint_node.h index 531234667..16d0e39a5 100644 --- a/modules/paint/nodes/paint_node.h +++ b/modules/paint/nodes/paint_node.h @@ -14,6 +14,9 @@ public: Vector2i get_size(); void set_size(const Vector2i &size); + bool get_draw_outline(); + void set_draw_outline(const bool val); + PoolVector2iArray util_get_pixels_in_line(const Vector2i &from, const Vector2i &to); int util_to_1d_v(const Vector2i &p, int w); @@ -35,9 +38,12 @@ public: ~PaintNode(); protected: + void _notification(int p_what); + static void _bind_methods(); Vector2i _size; + bool _draw_outline; }; #endif