Made it possible to properly draw over the 2D canvas for 2D objects. Arranged some functions to achieve this.
This commit is contained in:
parent
67d3935eb1
commit
491dde2eb4
14 changed files with 95 additions and 39 deletions
|
@ -11459,14 +11459,24 @@
|
|||
This function is used for plugins that edit specific object types (nodes or resources). It requests the editor to edit the given object.
|
||||
</description>
|
||||
</method>
|
||||
<method name="forward_input_event" qualifiers="virtual">
|
||||
<method name="forward_canvas_input_event" qualifiers="virtual">
|
||||
<return type="bool">
|
||||
</return>
|
||||
<argument index="0" name="event" type="InputEvent">
|
||||
<argument index="0" name="canvas_xform" type="Matrix32">
|
||||
</argument>
|
||||
<argument index="1" name="event" type="InputEvent">
|
||||
</argument>
|
||||
<description>
|
||||
This is a low level function for plugins that edit a given object type derived from CanvasItem to capture the input in the 2D editor viewport. The function is only being called if your object is being edited.
|
||||
Return true if you want to capture the input, otherwise false.
|
||||
If your plugin is active (because handles() returned true to the object), any input interaction with the 2D canvas editor will be first forwarded here. The canvas transform (containing zoom and offset to transform to edited world coordinates) is provided, but the input supplied is in untransformed coordinates to the canvas editor.
|
||||
</description>
|
||||
</method>
|
||||
<method name="forward_draw_over_canvas" qualifiers="virtual">
|
||||
<argument index="0" name="canvas_xform" type="Matrix32">
|
||||
</argument>
|
||||
<argument index="1" name="canvas" type="Control">
|
||||
</argument>
|
||||
<description>
|
||||
This function is called every time the 2D canvas editor draws (which overlays over the edited scene). Drawing over the supplied control will draw over the edited scene. To convert from control coordinates to edited scene coordinates (including zoom and offset), a transform is also provided. If you require this control to be redraw, call [method update_canvas]().
|
||||
</description>
|
||||
</method>
|
||||
<method name="forward_spatial_input_event" qualifiers="virtual">
|
||||
|
@ -11514,7 +11524,7 @@
|
|||
<return type="EditorResourcePreview">
|
||||
</return>
|
||||
<description>
|
||||
Get tool for generating resource previews.
|
||||
Get tool for generating resource previews.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_selection">
|
||||
|
@ -11567,7 +11577,7 @@
|
|||
<argument index="1" name="for_property" type="String" default="""">
|
||||
</argument>
|
||||
<description>
|
||||
Inspect an object in the inspector.
|
||||
Inspect an object in the inspector.
|
||||
</description>
|
||||
</method>
|
||||
<method name="make_visible" qualifiers="virtual">
|
||||
|
@ -11637,6 +11647,11 @@
|
|||
Restore the plugin GUI layout saved by [method EditorPlugin.get_window_layout].
|
||||
</description>
|
||||
</method>
|
||||
<method name="update_canvas">
|
||||
<description>
|
||||
Updates the control used to draw the edited scene over the 2D canvas. This is used together with [method forward_canvas_input_event]().
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<constants>
|
||||
<constant name="CONTAINER_TOOLBAR" value="0">
|
||||
|
|
|
@ -6681,45 +6681,54 @@ EditorNode::~EditorNode() {
|
|||
|
||||
|
||||
void EditorPluginList::make_visible(bool p_visible) {
|
||||
if (!plugins_list.empty()) {
|
||||
for (int i = 0; i < plugins_list.size(); i++) {
|
||||
plugins_list[i]->make_visible(p_visible);
|
||||
}
|
||||
|
||||
for (int i = 0; i < plugins_list.size(); i++) {
|
||||
plugins_list[i]->make_visible(p_visible);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void EditorPluginList::edit(Object* p_object) {
|
||||
if (!plugins_list.empty()) {
|
||||
for (int i = 0; i < plugins_list.size(); i++) {
|
||||
plugins_list[i]->edit(p_object);
|
||||
}
|
||||
|
||||
for (int i = 0; i < plugins_list.size(); i++) {
|
||||
plugins_list[i]->edit(p_object);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool EditorPluginList::forward_input_event(const InputEvent& p_event) {
|
||||
bool EditorPluginList::forward_input_event(const Matrix32& p_canvas_xform,const InputEvent& p_event) {
|
||||
|
||||
bool discard = false;
|
||||
if (!plugins_list.empty()) {
|
||||
for (int i = 0; i < plugins_list.size(); i++) {
|
||||
if (plugins_list[i]->forward_input_event(p_event)) {
|
||||
discard = true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < plugins_list.size(); i++) {
|
||||
if (plugins_list[i]->forward_canvas_input_event(p_canvas_xform,p_event)) {
|
||||
discard = true;
|
||||
}
|
||||
}
|
||||
|
||||
return discard;
|
||||
}
|
||||
|
||||
bool EditorPluginList::forward_spatial_input_event(Camera* p_camera, const InputEvent& p_event) {
|
||||
bool discard = false;
|
||||
if (!plugins_list.empty()) {
|
||||
for (int i = 0; i < plugins_list.size(); i++) {
|
||||
if (plugins_list[i]->forward_spatial_input_event(p_camera, p_event)) {
|
||||
discard = true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < plugins_list.size(); i++) {
|
||||
if (plugins_list[i]->forward_spatial_input_event(p_camera, p_event)) {
|
||||
discard = true;
|
||||
}
|
||||
}
|
||||
|
||||
return discard;
|
||||
}
|
||||
|
||||
void EditorPluginList::forward_draw_over_canvas(const Matrix32& p_canvas_xform,Control* p_canvas) {
|
||||
|
||||
for (int i = 0; i < plugins_list.size(); i++) {
|
||||
plugins_list[i]->forward_draw_over_canvas(p_canvas_xform,p_canvas);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool EditorPluginList::empty() {
|
||||
return plugins_list.empty();
|
||||
}
|
||||
|
|
|
@ -780,8 +780,9 @@ public:
|
|||
|
||||
void make_visible(bool p_visible);
|
||||
void edit(Object *p_object);
|
||||
bool forward_input_event(const InputEvent& p_event);
|
||||
bool forward_input_event(const Matrix32& p_canvas_xform,const InputEvent& p_event);
|
||||
bool forward_spatial_input_event(Camera* p_camera, const InputEvent& p_event);
|
||||
void forward_draw_over_canvas(const Matrix32& p_canvas_xform,Control* p_canvas);
|
||||
void clear();
|
||||
bool empty();
|
||||
|
||||
|
|
|
@ -131,13 +131,25 @@ Ref<SpatialEditorGizmo> EditorPlugin::create_spatial_gizmo(Spatial* p_spatial) {
|
|||
return Ref<SpatialEditorGizmo>();
|
||||
}
|
||||
|
||||
bool EditorPlugin::forward_input_event(const InputEvent& p_event) {
|
||||
bool EditorPlugin::forward_canvas_input_event(const Matrix32& p_canvas_xform,const InputEvent& p_event) {
|
||||
|
||||
if (get_script_instance() && get_script_instance()->has_method("forward_input_event")) {
|
||||
return get_script_instance()->call("forward_input_event",p_event);
|
||||
if (get_script_instance() && get_script_instance()->has_method("forward_canvas_input_event")) {
|
||||
return get_script_instance()->call("forward_canvas_input_event",p_canvas_xform,p_event);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void EditorPlugin::forward_draw_over_canvas(const Matrix32& p_canvas_xform,Control *p_canvas) {
|
||||
|
||||
if (get_script_instance() && get_script_instance()->has_method("forward_draw_over_canvas")) {
|
||||
get_script_instance()->call("forward_draw_over_canvas",p_canvas_xform,p_canvas);
|
||||
}
|
||||
}
|
||||
|
||||
void EditorPlugin::update_canvas() {
|
||||
CanvasItemEditor::get_singleton()->get_viewport_control()->update();
|
||||
}
|
||||
|
||||
bool EditorPlugin::forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event) {
|
||||
|
||||
if (get_script_instance() && get_script_instance()->has_method("forward_spatial_input_event")) {
|
||||
|
@ -327,6 +339,7 @@ void EditorPlugin::_bind_methods() {
|
|||
ObjectTypeDB::bind_method(_MD("get_resource_previewer:EditorResourcePreview"),&EditorPlugin::get_resource_previewer);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("inspect_object","object","for_property"),&EditorPlugin::inspect_object,DEFVAL(String()));
|
||||
ObjectTypeDB::bind_method(_MD("update_canvas"),&EditorPlugin::update_canvas);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_base_control:Control"),&EditorPlugin::get_base_control);
|
||||
ObjectTypeDB::bind_method(_MD("get_undo_redo:UndoRedo"),&EditorPlugin::_get_undo_redo);
|
||||
|
@ -334,7 +347,8 @@ void EditorPlugin::_bind_methods() {
|
|||
ObjectTypeDB::bind_method(_MD("get_editor_settings:EditorSettings"),&EditorPlugin::get_editor_settings);
|
||||
ObjectTypeDB::bind_method(_MD("queue_save_layout"),&EditorPlugin::queue_save_layout);
|
||||
|
||||
ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::BOOL,"forward_input_event",PropertyInfo(Variant::INPUT_EVENT,"event")));
|
||||
ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::BOOL,"forward_canvas_input_event",PropertyInfo(Variant::MATRIX32,"canvas_xform"),PropertyInfo(Variant::INPUT_EVENT,"event")));
|
||||
ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo("forward_draw_over_canvas",PropertyInfo(Variant::MATRIX32,"canvas_xform"),PropertyInfo(Variant::OBJECT,"canvas:Control")));
|
||||
ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::BOOL,"forward_spatial_input_event",PropertyInfo(Variant::OBJECT,"camera",PROPERTY_HINT_RESOURCE_TYPE,"Camera"),PropertyInfo(Variant::INPUT_EVENT,"event")));
|
||||
MethodInfo gizmo = MethodInfo(Variant::OBJECT,"create_spatial_gizmo",PropertyInfo(Variant::OBJECT,"for_spatial:Spatial"));
|
||||
gizmo.return_val.hint=PROPERTY_HINT_RESOURCE_TYPE;
|
||||
|
|
|
@ -101,7 +101,8 @@ public:
|
|||
void remove_control_from_bottom_panel(Control *p_control);
|
||||
|
||||
virtual Ref<SpatialEditorGizmo> create_spatial_gizmo(Spatial* p_spatial);
|
||||
virtual bool forward_input_event(const InputEvent& p_event);
|
||||
virtual bool forward_canvas_input_event(const Matrix32& p_canvas_xform, const InputEvent& p_event);
|
||||
virtual void forward_draw_over_canvas(const Matrix32& p_canvas_xform,Control *p_canvas);
|
||||
virtual bool forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event);
|
||||
virtual String get_name() const;
|
||||
virtual bool has_main_screen() const;
|
||||
|
@ -120,6 +121,7 @@ public:
|
|||
virtual void get_window_layout(Ref<ConfigFile> p_layout);
|
||||
virtual void edited_scene_changed(){} // if changes are pending in editor, apply them
|
||||
|
||||
void update_canvas();
|
||||
|
||||
virtual void inspect_object(Object *p_obj,const String& p_for_property=String());
|
||||
|
||||
|
|
|
@ -1058,7 +1058,7 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) {
|
|||
EditorPluginList *over_plugin_list = en->get_editor_plugins_over();
|
||||
|
||||
if (!over_plugin_list->empty()) {
|
||||
bool discard = over_plugin_list->forward_input_event(p_event);
|
||||
bool discard = over_plugin_list->forward_input_event(transform,p_event);
|
||||
if (discard) {
|
||||
accept_event();
|
||||
return;
|
||||
|
@ -2090,6 +2090,18 @@ void CanvasItemEditor::_viewport_draw() {
|
|||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
EditorNode *en = editor;
|
||||
EditorPluginList *over_plugin_list = en->get_editor_plugins_over();
|
||||
|
||||
if (!over_plugin_list->empty()) {
|
||||
|
||||
over_plugin_list->forward_draw_over_canvas(transform,viewport);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (skeleton_show_bones) {
|
||||
int bone_width = EditorSettings::get_singleton()->get("2d_editor/bone_width");
|
||||
Color bone_color1 = EditorSettings::get_singleton()->get("2d_editor/bone_color1");
|
||||
|
|
|
@ -95,7 +95,7 @@ class CollisionPolygon2DEditorPlugin : public EditorPlugin {
|
|||
|
||||
public:
|
||||
|
||||
virtual bool forward_input_event(const InputEvent& p_event) { return collision_polygon_editor->forward_input_event(p_event); }
|
||||
virtual bool forward_canvas_input_event(const Matrix32& p_canvas_xform,const InputEvent& p_event) { return collision_polygon_editor->forward_input_event(p_event); }
|
||||
|
||||
virtual String get_name() const { return "CollisionPolygon2D"; }
|
||||
bool has_main_screen() const { return false; }
|
||||
|
|
|
@ -86,7 +86,7 @@ class CollisionShape2DEditorPlugin : public EditorPlugin {
|
|||
EditorNode* editor;
|
||||
|
||||
public:
|
||||
virtual bool forward_input_event(const InputEvent& p_event) { return collision_shape_2d_editor->forward_input_event(p_event); }
|
||||
virtual bool forward_canvas_input_event(const Matrix32& p_canvas_xform,const InputEvent& p_event) { return collision_shape_2d_editor->forward_input_event(p_event); }
|
||||
|
||||
virtual String get_name() const { return "CollisionShape2D"; }
|
||||
bool has_main_screen() const { return false; }
|
||||
|
|
|
@ -99,7 +99,7 @@ class LightOccluder2DEditorPlugin : public EditorPlugin {
|
|||
|
||||
public:
|
||||
|
||||
virtual bool forward_input_event(const InputEvent& p_event) { return collision_polygon_editor->forward_input_event(p_event); }
|
||||
virtual bool forward_canvas_input_event(const Matrix32& p_canvas_xform,const InputEvent& p_event) { return collision_polygon_editor->forward_input_event(p_event); }
|
||||
|
||||
virtual String get_name() const { return "LightOccluder2D"; }
|
||||
bool has_main_screen() const { return false; }
|
||||
|
|
|
@ -101,7 +101,7 @@ class NavigationPolygonEditorPlugin : public EditorPlugin {
|
|||
|
||||
public:
|
||||
|
||||
virtual bool forward_input_event(const InputEvent& p_event) { return collision_polygon_editor->forward_input_event(p_event); }
|
||||
virtual bool forward_canvas_input_event(const Matrix32& p_canvas_xform,const InputEvent& p_event) { return collision_polygon_editor->forward_input_event(p_event); }
|
||||
|
||||
virtual String get_name() const { return "NavigationPolygonInstance"; }
|
||||
bool has_main_screen() const { return false; }
|
||||
|
|
|
@ -108,7 +108,7 @@ class Path2DEditorPlugin : public EditorPlugin {
|
|||
|
||||
public:
|
||||
|
||||
virtual bool forward_input_event(const InputEvent& p_event) { return path2d_editor->forward_input_event(p_event); }
|
||||
virtual bool forward_canvas_input_event(const Matrix32& p_canvas_xform,const InputEvent& p_event) { return path2d_editor->forward_input_event(p_event); }
|
||||
|
||||
virtual String get_name() const { return "Path2D"; }
|
||||
bool has_main_screen() const { return false; }
|
||||
|
|
|
@ -151,7 +151,7 @@ class Polygon2DEditorPlugin : public EditorPlugin {
|
|||
|
||||
public:
|
||||
|
||||
virtual bool forward_input_event(const InputEvent& p_event) { return collision_polygon_editor->forward_input_event(p_event); }
|
||||
virtual bool forward_canvas_input_event(const Matrix32& p_canvas_xform,const InputEvent& p_event) { return collision_polygon_editor->forward_input_event(p_event); }
|
||||
|
||||
virtual String get_name() const { return "Polygon2D"; }
|
||||
bool has_main_screen() const { return false; }
|
||||
|
|
|
@ -3469,6 +3469,8 @@ void SpatialEditor::_unhandled_key_input(InputEvent p_event) {
|
|||
if (!is_visible() || get_viewport()->gui_has_modal_stack())
|
||||
return;
|
||||
|
||||
#if 0
|
||||
//i don't remember this being used
|
||||
{
|
||||
|
||||
EditorNode *en = editor;
|
||||
|
@ -3480,6 +3482,7 @@ void SpatialEditor::_unhandled_key_input(InputEvent p_event) {
|
|||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
switch(p_event.type) {
|
||||
|
||||
|
|
|
@ -181,7 +181,7 @@ class TileMapEditorPlugin : public EditorPlugin {
|
|||
|
||||
public:
|
||||
|
||||
virtual bool forward_input_event(const InputEvent& p_event) { return tile_map_editor->forward_input_event(p_event); }
|
||||
virtual bool forward_canvas_input_event(const Matrix32& p_canvas_xform,const InputEvent& p_event) { return tile_map_editor->forward_input_event(p_event); }
|
||||
|
||||
virtual String get_name() const { return "TileMap"; }
|
||||
bool has_main_screen() const { return false; }
|
||||
|
|
Loading…
Reference in a new issue