summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-09-10 16:44:03 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-09-10 16:44:03 -0300
commit491dde2eb46a3d5af60256a21a23d6c32e4bfa46 (patch)
tree7bf71d49ec7290294c330508fb59d0f8ca41b6da
parent67d3935eb17110d71235f52d1b2040f06c8f2b23 (diff)
Made it possible to properly draw over the 2D canvas for 2D objects. Arranged some functions to achieve this.
-rw-r--r--doc/base/classes.xml27
-rw-r--r--tools/editor/editor_node.cpp47
-rw-r--r--tools/editor/editor_node.h3
-rw-r--r--tools/editor/editor_plugin.cpp22
-rw-r--r--tools/editor/editor_plugin.h4
-rw-r--r--tools/editor/plugins/canvas_item_editor_plugin.cpp14
-rw-r--r--tools/editor/plugins/collision_polygon_2d_editor_plugin.h2
-rw-r--r--tools/editor/plugins/collision_shape_2d_editor_plugin.h2
-rw-r--r--tools/editor/plugins/light_occluder_2d_editor_plugin.h2
-rw-r--r--tools/editor/plugins/navigation_polygon_editor_plugin.h2
-rw-r--r--tools/editor/plugins/path_2d_editor_plugin.h2
-rw-r--r--tools/editor/plugins/polygon_2d_editor_plugin.h2
-rw-r--r--tools/editor/plugins/spatial_editor_plugin.cpp3
-rw-r--r--tools/editor/plugins/tile_map_editor_plugin.h2
14 files changed, 95 insertions, 39 deletions
diff --git a/doc/base/classes.xml b/doc/base/classes.xml
index 842f38dd3e..8ed783129d 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.
</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="&quot;&quot;">
</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">
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp
index 56170e1489..9a81d287b2 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 e6119cf577..147a0fd6ed 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 752e961c87..0cfb9c083c 100644
--- a/tools/editor/editor_plugin.cpp
+++ b/tools/editor/editor_plugin.cpp
@@ -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;
diff --git a/tools/editor/editor_plugin.h b/tools/editor/editor_plugin.h
index ed949c74f6..f73fb47cc8 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<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());
diff --git a/tools/editor/plugins/canvas_item_editor_plugin.cpp b/tools/editor/plugins/canvas_item_editor_plugin.cpp
index 3468f42a6c..b0e002ba44 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 982ba35fe8..431d3651c1 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 1ee81eda43..a8930dc0f2 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 b570fff506..0176eb87dd 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 503b4c2662..defdebbec2 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 973c17464e..acbc481e09 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 d8b951ec44..33bae94340 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 41956747e1..8076a91a32 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 4b47dccd15..2f24002770 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; }