diff --git a/doc/base/classes.xml b/doc/base/classes.xml index 842f38dd3ee..8ed783129dd 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -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. - + - + + + - 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. + + + + + + + + + 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](). @@ -11514,7 +11524,7 @@ - Get tool for generating resource previews. + Get tool for generating resource previews. @@ -11567,7 +11577,7 @@ - Inspect an object in the inspector. + Inspect an object in the inspector. @@ -11637,6 +11647,11 @@ Restore the plugin GUI layout saved by [method EditorPlugin.get_window_layout]. + + + Updates the control used to draw the edited scene over the 2D canvas. This is used together with [method forward_canvas_input_event](). + + diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 56170e14898..9a81d287b23 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -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(); } diff --git a/tools/editor/editor_node.h b/tools/editor/editor_node.h index e6119cf577d..147a0fd6ed5 100644 --- a/tools/editor/editor_node.h +++ b/tools/editor/editor_node.h @@ -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(); diff --git a/tools/editor/editor_plugin.cpp b/tools/editor/editor_plugin.cpp index 752e961c872..0cfb9c083c4 100644 --- a/tools/editor/editor_plugin.cpp +++ b/tools/editor/editor_plugin.cpp @@ -131,13 +131,25 @@ Ref EditorPlugin::create_spatial_gizmo(Spatial* p_spatial) { return Ref(); } -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; diff --git a/tools/editor/editor_plugin.h b/tools/editor/editor_plugin.h index ed949c74f63..f73fb47cc83 100644 --- a/tools/editor/editor_plugin.h +++ b/tools/editor/editor_plugin.h @@ -101,7 +101,8 @@ public: void remove_control_from_bottom_panel(Control *p_control); virtual Ref 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 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()); diff --git a/tools/editor/plugins/canvas_item_editor_plugin.cpp b/tools/editor/plugins/canvas_item_editor_plugin.cpp index 3468f42a6cd..b0e002ba448 100644 --- a/tools/editor/plugins/canvas_item_editor_plugin.cpp +++ b/tools/editor/plugins/canvas_item_editor_plugin.cpp @@ -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"); diff --git a/tools/editor/plugins/collision_polygon_2d_editor_plugin.h b/tools/editor/plugins/collision_polygon_2d_editor_plugin.h index 982ba35fe8e..431d3651c14 100644 --- a/tools/editor/plugins/collision_polygon_2d_editor_plugin.h +++ b/tools/editor/plugins/collision_polygon_2d_editor_plugin.h @@ -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; } diff --git a/tools/editor/plugins/collision_shape_2d_editor_plugin.h b/tools/editor/plugins/collision_shape_2d_editor_plugin.h index 1ee81eda43c..a8930dc0f20 100644 --- a/tools/editor/plugins/collision_shape_2d_editor_plugin.h +++ b/tools/editor/plugins/collision_shape_2d_editor_plugin.h @@ -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; } diff --git a/tools/editor/plugins/light_occluder_2d_editor_plugin.h b/tools/editor/plugins/light_occluder_2d_editor_plugin.h index b570fff506b..0176eb87dd3 100644 --- a/tools/editor/plugins/light_occluder_2d_editor_plugin.h +++ b/tools/editor/plugins/light_occluder_2d_editor_plugin.h @@ -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; } diff --git a/tools/editor/plugins/navigation_polygon_editor_plugin.h b/tools/editor/plugins/navigation_polygon_editor_plugin.h index 503b4c26620..defdebbec24 100644 --- a/tools/editor/plugins/navigation_polygon_editor_plugin.h +++ b/tools/editor/plugins/navigation_polygon_editor_plugin.h @@ -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; } diff --git a/tools/editor/plugins/path_2d_editor_plugin.h b/tools/editor/plugins/path_2d_editor_plugin.h index 973c17464e4..acbc481e097 100644 --- a/tools/editor/plugins/path_2d_editor_plugin.h +++ b/tools/editor/plugins/path_2d_editor_plugin.h @@ -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; } diff --git a/tools/editor/plugins/polygon_2d_editor_plugin.h b/tools/editor/plugins/polygon_2d_editor_plugin.h index d8b951ec44e..33bae94340e 100644 --- a/tools/editor/plugins/polygon_2d_editor_plugin.h +++ b/tools/editor/plugins/polygon_2d_editor_plugin.h @@ -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; } diff --git a/tools/editor/plugins/spatial_editor_plugin.cpp b/tools/editor/plugins/spatial_editor_plugin.cpp index 41956747e1b..8076a91a32e 100644 --- a/tools/editor/plugins/spatial_editor_plugin.cpp +++ b/tools/editor/plugins/spatial_editor_plugin.cpp @@ -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) { diff --git a/tools/editor/plugins/tile_map_editor_plugin.h b/tools/editor/plugins/tile_map_editor_plugin.h index 4b47dccd152..2f24002770f 100644 --- a/tools/editor/plugins/tile_map_editor_plugin.h +++ b/tools/editor/plugins/tile_map_editor_plugin.h @@ -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; }