godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.11k stars 69 forks source link

Expose _edit_get_rect, _edit_use_rect to gdscript #5289

Open Giwayume opened 2 years ago

Giwayume commented 2 years ago

Describe the project you are working on

Plugin that uses custom rendering, needs to set the 2D rect bounds for the editor.

Describe the problem or limitation you are having in your project

The engine provides GDScript no way to set the editor rect bounds manually via gdscript.

image

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Expose _edit_get_rect, _edit_use_rect as virtual functions for Canvas Item.

https://github.com/godotengine/godot/blob/2d210fecf03bf751bcf660d6439a51db8d6032f5/scene/main/canvas_item.h#L183

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Similar to this: https://github.com/godotengine/godot/blob/2.1/scene/2d/node_2d.cpp#L217-L226

If this enhancement will not be used often, can it be worked around with a few lines of script?

There is no workaround.

Is there a reason why this should be core and not an add-on in the asset library?

This is for the purpose of writing an add-on. Need engine help.

RabbitB commented 1 year ago

I've run into this issue a small number of times now when creating nodes with custom draw calls and it makes me wonder if in addition to exposing those hooks, if we should discuss implementing a picking flag as part of this proposal. Picking is common in many engines, and while not suitable for all use cases, it makes it very easy for anyone to allow complex shapes to be easily selected.

To make it work, we would need to capture the output of any CanvasItem visible in the editor, and check it against a mouse-click within the viewport. Easiest way I can think of implementing this would be to perform a depth-pass check on the point where the mouse was clicked. Whichever CanvasItem the clicked pixel corresponds to, is selected. Then just expose a flag inside CanvasItem which determines if we're even interested in picking.

nathanfranke commented 1 year ago

I was curious so for complex shapes you can also have a custom function like does the polygon contain this point. https://github.com/godotengine/godot/blob/master/scene/2d/polygon_2d.cpp#L61-L90

Cratesmith commented 1 year ago

I'm less interested in the complex shapes/picking element to this, and just being able to use the draggable rect ui for custom nodes in the editor.

Unless I'm mistaken the only way to get similar functionality without there methods being acessable through script would be to completely re-implement the draggable rect gui?

mopifish commented 4 months ago

This would be really useful in a project I'm building now. In my game, every object is an individual window, and I need to get the scenes rect so I can properly set the window size during instantiation.

My current work around is to use a reference rect and size the scene manually, but this method would be significantly easier and safer.