From 7d1abdb3dbefe2bbd980dc92ef649fd6bacfade4 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Thu, 8 Dec 2022 19:53:24 +0100 Subject: [PATCH] Fix BackBufferCopy `rect` property appearing when not relevant in inspector The `rect` property is only effective if `copy_mode` is Rect. --- doc/classes/BackBufferCopy.xml | 12 ++++++------ scene/2d/back_buffer_copy.cpp | 8 ++++++++ scene/2d/back_buffer_copy.h | 1 + 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/doc/classes/BackBufferCopy.xml b/doc/classes/BackBufferCopy.xml index 87a6a77a5..0d7422d2b 100644 --- a/doc/classes/BackBufferCopy.xml +++ b/doc/classes/BackBufferCopy.xml @@ -4,8 +4,8 @@ Copies a region of the screen (or the whole screen) to a buffer so it can be accessed in your shader scripts through the [code]texture(SCREEN_TEXTURE, ...)[/code] function. - Node for back-buffering the currently-displayed screen. The region defined in the BackBufferCopy node is buffered with the content of the screen it covers, or the entire screen according to the copy mode set. Use the [code]texture(SCREEN_TEXTURE, ...)[/code] function in your shader scripts to access the buffer. - [b]Note:[/b] Since this node inherits from [Node2D] (and not [Control]), anchors and margins won't apply to child [Control]-derived nodes. This can be problematic when resizing the window. To avoid this, add [Control]-derived nodes as [i]siblings[/i] to the BackBufferCopy node instead of adding them as children. + Node for back-buffering the currently-displayed screen. The region defined in the [BackBufferCopy] node is buffered with the content of the screen it covers, or the entire screen according to the copy mode set. Use the [code]texture(SCREEN_TEXTURE, ...)[/code] function in your shader scripts to access the buffer. + [b]Note:[/b] Since this node inherits from [Node2D] (and not [Control]), anchors and margins won't apply to child [Control]-derived nodes. This can be problematic when resizing the window. To avoid this, add [Control]-derived nodes as [i]siblings[/i] to the [BackBufferCopy] node instead of adding them as children. @@ -16,18 +16,18 @@ Buffer mode. See [enum CopyMode] constants. - The area covered by the BackBufferCopy. Only used if [member copy_mode] is [constant COPY_MODE_RECT]. + The area covered by the [BackBufferCopy]. Only used if [member copy_mode] is [constant COPY_MODE_RECT]. - Disables the buffering mode. This means the BackBufferCopy node will directly use the portion of screen it covers. + Disables the buffering mode. This means the [BackBufferCopy] node will directly use the portion of screen it covers. - BackBufferCopy buffers a rectangular region. + [BackBufferCopy] buffers a rectangular region. - BackBufferCopy buffers the entire screen. + [BackBufferCopy] buffers the entire screen. diff --git a/scene/2d/back_buffer_copy.cpp b/scene/2d/back_buffer_copy.cpp index 455208586..52b34e1ef 100644 --- a/scene/2d/back_buffer_copy.cpp +++ b/scene/2d/back_buffer_copy.cpp @@ -71,11 +71,19 @@ Rect2 BackBufferCopy::get_rect() const { void BackBufferCopy::set_copy_mode(CopyMode p_mode) { copy_mode = p_mode; _update_copy_mode(); + _change_notify(); } + BackBufferCopy::CopyMode BackBufferCopy::get_copy_mode() const { return copy_mode; } +void BackBufferCopy::_validate_property(PropertyInfo &p_property) const { + if (copy_mode != COPY_MODE_RECT && p_property.name == "rect") { + p_property.usage = PROPERTY_USAGE_NOEDITOR; + } +} + void BackBufferCopy::_bind_methods() { ClassDB::bind_method(D_METHOD("set_rect", "rect"), &BackBufferCopy::set_rect); ClassDB::bind_method(D_METHOD("get_rect"), &BackBufferCopy::get_rect); diff --git a/scene/2d/back_buffer_copy.h b/scene/2d/back_buffer_copy.h index 75c674bcd..27ed30143 100644 --- a/scene/2d/back_buffer_copy.h +++ b/scene/2d/back_buffer_copy.h @@ -50,6 +50,7 @@ private: protected: static void _bind_methods(); + void _validate_property(PropertyInfo &p_property) const; public: #ifdef TOOLS_ENABLED