Added the ability for PaintNode rendering to skip evaluating certain PaintNode's childrens.

This commit is contained in:
Relintai 2022-11-19 23:19:41 +01:00
parent 9141997c87
commit e5fd8cd2b5
4 changed files with 26 additions and 4 deletions

View File

@ -67,17 +67,26 @@ Ref<Image> PaintNode::_get_rendered_image() {
return Ref<Image>();
}
bool PaintNode::render_should_evaluate_children() {
return call("_render_should_evaluate_children");
}
bool PaintNode::_render_should_evaluate_children() {
return true;
}
void PaintNode::render_evaluate_paint_node(PaintNode *node, Transform2D transform, Ref<Image> image) {
ERR_FAIL_COND(!node);
ERR_FAIL_COND(!image.is_valid());
Transform2D currtf = transform * node->get_transform();
for (int i = 0; i < node->get_child_count(); ++i) {
PaintNode *pn = Object::cast_to<PaintNode>(node->get_child(i));
if (node->render_should_evaluate_children()) {
for (int i = 0; i < node->get_child_count(); ++i) {
PaintNode *pn = Object::cast_to<PaintNode>(node->get_child(i));
if (pn && pn->is_visible()) {
render_evaluate_paint_node(pn, currtf, image);
if (pn && pn->is_visible()) {
render_evaluate_paint_node(pn, currtf, image);
}
}
}
@ -290,6 +299,10 @@ void PaintNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_rendered_image"), &PaintNode::get_rendered_image);
ClassDB::bind_method(D_METHOD("_get_rendered_image"), &PaintNode::_get_rendered_image);
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::BOOL, "r"), "_render_should_evaluate_children"));
ClassDB::bind_method(D_METHOD("render_should_evaluate_children"), &PaintNode::render_should_evaluate_children);
ClassDB::bind_method(D_METHOD("_render_should_evaluate_children"), &PaintNode::_render_should_evaluate_children);
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);

View File

@ -29,6 +29,9 @@ public:
Ref<Image> get_rendered_image();
virtual Ref<Image> _get_rendered_image();
bool render_should_evaluate_children();
virtual bool _render_should_evaluate_children();
void render_evaluate_paint_node(PaintNode *node, Transform2D transform, Ref<Image> image);
void render_paint_node(PaintNode *node, Transform2D transform, Ref<Image> image);

View File

@ -94,6 +94,10 @@ void PaintProject::add_paint_visual_grid() {
}
}
bool PaintProject::_render_should_evaluate_children() {
return false;
}
PaintProject::PaintProject() {
_current_color = Color(1, 1, 1, 1);
}

View File

@ -31,6 +31,8 @@ public:
void add_paint_canvas_backgorund();
void add_paint_visual_grid();
bool _render_should_evaluate_children();
PaintProject();
~PaintProject();