diff options
Diffstat (limited to 'tools/editor/plugins')
-rw-r--r-- | tools/editor/plugins/path_2d_editor_plugin.cpp | 90 | ||||
-rw-r--r-- | tools/editor/plugins/path_2d_editor_plugin.h | 11 | ||||
-rw-r--r-- | tools/editor/plugins/path_editor_plugin.cpp | 61 | ||||
-rw-r--r-- | tools/editor/plugins/spatial_editor_plugin.cpp | 61 | ||||
-rw-r--r-- | tools/editor/plugins/spatial_editor_plugin.h | 2 |
5 files changed, 146 insertions, 79 deletions
diff --git a/tools/editor/plugins/path_2d_editor_plugin.cpp b/tools/editor/plugins/path_2d_editor_plugin.cpp index e83fed5ced..5e4cd98127 100644 --- a/tools/editor/plugins/path_2d_editor_plugin.cpp +++ b/tools/editor/plugins/path_2d_editor_plugin.cpp @@ -78,6 +78,9 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { if (!node) return false; + if (!node->is_visible()) + return false; + if (!node->get_curve().is_valid()) return false; @@ -89,9 +92,9 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Vector2 gpoint = Point2(mb.x,mb.y); - Vector2 cpoint = xform.affine_inverse().xform(gpoint); + Vector2 cpoint = !mb.mod.alt? snap_point(xform.affine_inverse().xform(gpoint)) + : node->get_global_transform().affine_inverse().xform( snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)) ); //first check if a point is to be added (segment split) real_t grab_treshold=EDITOR_DEF("poly_editor/point_grab_radius",8); @@ -112,7 +115,7 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { Point2 p = xform.xform( curve->get_point_pos(i) ); if (gpoint.distance_to(p) < grab_treshold ) { - if (!mb.mod.control) { + if (!mb.mod.shift) { action=ACTION_MOVING_POINT; action_point=i; @@ -173,6 +176,8 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { moving_from=curve->get_point_pos(action_point); moving_screen_from=gpoint; + canvas_item_editor->get_viewport_control()->update(); + return true; } @@ -188,7 +193,7 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { undo_redo->create_action("Move Point in Curve"); - undo_redo->add_do_method(curve.ptr(),"set_point_pos",action_point,new_pos); + undo_redo->add_do_method(curve.ptr(),"set_point_pos",action_point,cpoint); undo_redo->add_undo_method(curve.ptr(),"set_point_pos",action_point,moving_from); undo_redo->add_do_method(canvas_item_editor,"update"); undo_redo->add_undo_method(canvas_item_editor,"update"); @@ -420,17 +425,18 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Vector2 gpoint = Point2(mm.x,mm.y); + Vector2 cpoint = !mm.mod.alt? snap_point(xform.affine_inverse().xform(gpoint)) + : node->get_global_transform().affine_inverse().xform( snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)) ); Ref<Curve2D> curve = node->get_curve(); - Vector2 new_pos = moving_from + xform.basis_xform( gpoint - moving_screen_from ); switch(action) { case ACTION_MOVING_POINT: { - curve->set_point_pos(action_point,new_pos); + curve->set_point_pos(action_point,cpoint); } break; case ACTION_MOVING_IN: { @@ -445,7 +451,7 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { } - canvas_item_editor->update(); + canvas_item_editor->get_viewport_control()->update(); return true; } @@ -471,59 +477,74 @@ void Path2DEditor::_canvas_draw() { if (!node) return ; + if (!node->is_visible()) + return; + if (!node->get_curve().is_valid()) return ; Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Ref<Texture> handle= get_icon("EditorHandle","EditorIcons"); + Size2 handle_size = handle->get_size(); Ref<Curve2D> curve = node->get_curve(); int len = curve->get_point_count(); - RID ci = canvas_item_editor->get_canvas_item(); + Control *vpc = canvas_item_editor->get_viewport_control(); + for(int i=0;i<len;i++) { Vector2 point = xform.xform(curve->get_point_pos(i)); - handle->draw(ci,point-handle->get_size()*0.5,Color(1,1,1,0.3)); + vpc->draw_texture_rect(handle,Rect2(point-handle_size*0.5,handle_size),false,Color(1,1,1,1)); if (i<len-1) { Vector2 pointout = xform.xform(curve->get_point_pos(i)+curve->get_point_out(i)); - canvas_item_editor->draw_line(point,pointout,Color(0.5,0.5,1.0,0.8),1.0); - handle->draw(ci,pointout-handle->get_size()*0.5,Color(1,0.5,1,0.3)); + vpc->draw_line(point,pointout,Color(0.5,0.5,1.0,0.8),1.0); + vpc->draw_texture_rect(handle, Rect2(pointout-handle_size*0.5,handle_size),false,Color(1,0.5,1,0.3)); } if (i>0) { Vector2 pointin = xform.xform(curve->get_point_pos(i)+curve->get_point_in(i)); - canvas_item_editor->draw_line(point,pointin,Color(0.5,0.5,1.0,0.8),1.0); - handle->draw(ci,pointin-handle->get_size()*0.5,Color(1,0.5,1,0.3)); + vpc->draw_line(point,pointin,Color(0.5,0.5,1.0,0.8),1.0); + vpc->draw_texture_rect(handle, Rect2(pointin-handle_size*0.5,handle_size),false,Color(1,0.5,1,0.3)); } } } +void Path2DEditor::_node_visibility_changed() { + if (!node) + return; + canvas_item_editor->get_viewport_control()->update(); +} -void Path2DEditor::edit(Node *p_collision_polygon) { +void Path2DEditor::edit(Node *p_path2d) { if (!canvas_item_editor) { canvas_item_editor=CanvasItemEditor::get_singleton(); } - if (p_collision_polygon) { - - node=p_collision_polygon->cast_to<Path2D>(); - if (!canvas_item_editor->is_connected("draw",this,"_canvas_draw")) - canvas_item_editor->connect("draw",this,"_canvas_draw"); + if (p_path2d) { + node=p_path2d->cast_to<Path2D>(); + if (!canvas_item_editor->get_viewport_control()->is_connected("draw",this,"_canvas_draw")) + canvas_item_editor->get_viewport_control()->connect("draw",this,"_canvas_draw"); + if (!node->is_connected("visibility_changed", this, "_node_visibility_changed")) + node->connect("visibility_changed", this, "_node_visibility_changed"); } else { - node=NULL; - if (canvas_item_editor->is_connected("draw",this,"_canvas_draw")) - canvas_item_editor->disconnect("draw",this,"_canvas_draw"); + if (canvas_item_editor->get_viewport_control()->is_connected("draw",this,"_canvas_draw")) + canvas_item_editor->get_viewport_control()->disconnect("draw",this,"_canvas_draw"); + + // node may have been deleted at this point + if (node && node->is_connected("visibility_changed", this, "_node_visibility_changed")) + node->disconnect("visibility_changed", this, "_node_visibility_changed"); + node=NULL; } } @@ -532,7 +553,7 @@ void Path2DEditor::_bind_methods() { //ObjectTypeDB::bind_method(_MD("_menu_option"),&Path2DEditor::_menu_option); ObjectTypeDB::bind_method(_MD("_canvas_draw"),&Path2DEditor::_canvas_draw); - + ObjectTypeDB::bind_method(_MD("_node_visibility_changed"),&Path2DEditor::_node_visibility_changed); } Path2DEditor::Path2DEditor(EditorNode *p_editor) { @@ -559,7 +580,7 @@ Path2DEditor::Path2DEditor(EditorNode *p_editor) { void Path2DEditorPlugin::edit(Object *p_object) { - collision_polygon_editor->edit(p_object->cast_to<Node>()); + path2d_editor->edit(p_object->cast_to<Node>()); } bool Path2DEditorPlugin::handles(Object *p_object) const { @@ -570,11 +591,11 @@ bool Path2DEditorPlugin::handles(Object *p_object) const { void Path2DEditorPlugin::make_visible(bool p_visible) { if (p_visible) { - collision_polygon_editor->show(); + path2d_editor->show(); } else { - collision_polygon_editor->hide(); - collision_polygon_editor->edit(NULL); + path2d_editor->hide(); + path2d_editor->edit(NULL); } } @@ -582,19 +603,10 @@ void Path2DEditorPlugin::make_visible(bool p_visible) { Path2DEditorPlugin::Path2DEditorPlugin(EditorNode *p_node) { editor=p_node; - collision_polygon_editor = memnew( Path2DEditor(p_node) ); - editor->get_viewport()->add_child(collision_polygon_editor); - - collision_polygon_editor->set_margin(MARGIN_LEFT,200); - collision_polygon_editor->set_margin(MARGIN_RIGHT,230); - collision_polygon_editor->set_margin(MARGIN_TOP,0); - collision_polygon_editor->set_margin(MARGIN_BOTTOM,10); - - - collision_polygon_editor->hide(); - - + path2d_editor = memnew( Path2DEditor(p_node) ); + CanvasItemEditor::get_singleton()->add_control_to_menu_panel(path2d_editor); + path2d_editor->hide(); } diff --git a/tools/editor/plugins/path_2d_editor_plugin.h b/tools/editor/plugins/path_2d_editor_plugin.h index 3f917f29d9..1ddda3f65f 100644 --- a/tools/editor/plugins/path_2d_editor_plugin.h +++ b/tools/editor/plugins/path_2d_editor_plugin.h @@ -40,9 +40,9 @@ */ class CanvasItemEditor; -class Path2DEditor : public ButtonGroup { +class Path2DEditor : public HBoxContainer { - OBJ_TYPE(Path2DEditor, ButtonGroup ); + OBJ_TYPE(Path2DEditor, HBoxContainer); UndoRedo *undo_redo; @@ -67,6 +67,7 @@ class Path2DEditor : public ButtonGroup { void _canvas_draw(); + void _node_visibility_changed(); protected: void _notification(int p_what); @@ -76,7 +77,7 @@ public: Vector2 snap_point(const Vector2& p_point) const; bool forward_input_event(const InputEvent& p_event); - void edit(Node *p_collision_polygon); + void edit(Node *p_path2d); Path2DEditor(EditorNode *p_editor); }; @@ -84,12 +85,12 @@ class Path2DEditorPlugin : public EditorPlugin { OBJ_TYPE( Path2DEditorPlugin, EditorPlugin ); - Path2DEditor *collision_polygon_editor; + Path2DEditor *path2d_editor; EditorNode *editor; public: - virtual bool forward_input_event(const InputEvent& p_event) { return collision_polygon_editor->forward_input_event(p_event); } + virtual bool forward_input_event(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/path_editor_plugin.cpp b/tools/editor/plugins/path_editor_plugin.cpp index 1c910e5436..61b1df9ca8 100644 --- a/tools/editor/plugins/path_editor_plugin.cpp +++ b/tools/editor/plugins/path_editor_plugin.cpp @@ -1,31 +1,31 @@ -/*************************************************************************/ -/* path_editor_plugin.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ +/*************************************************************************/
+/* path_editor_plugin.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* http://www.godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
#include "path_editor_plugin.h"
#include "spatial_editor_plugin.h"
#include "scene/resources/curve.h"
@@ -565,9 +565,8 @@ PathEditorPlugin::PathEditorPlugin(EditorNode *p_node) { curve_del->set_tooltip("Delete Point.");
SpatialEditor::get_singleton()->add_control_to_menu_panel(curve_del);
curve_close = memnew( ToolButton );
-//curve_close->set_icon(SpatialEditor::get_singleton()->get_icon("CurveDelete","EditorIcons"));
- curve_close->set_text("close");
- curve_close->hide();
+ curve_close->set_icon(SpatialEditor::get_singleton()->get_icon("CurveClose","EditorIcons"));
+ curve_close->hide();
curve_close->set_focus_mode(Control::FOCUS_NONE);
curve_close->set_tooltip("Close Curve");
SpatialEditor::get_singleton()->add_control_to_menu_panel(curve_close);
diff --git a/tools/editor/plugins/spatial_editor_plugin.cpp b/tools/editor/plugins/spatial_editor_plugin.cpp index 3b8a068cac..8161025731 100644 --- a/tools/editor/plugins/spatial_editor_plugin.cpp +++ b/tools/editor/plugins/spatial_editor_plugin.cpp @@ -1468,6 +1468,12 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { case KEY_F: { _menu_option(VIEW_CENTER_TO_SELECTION); } break; + + case KEY_SPACE: { + if (!k.pressed) + emit_signal("toggle_maximize_view", this); + } break; + } @@ -1874,6 +1880,7 @@ void SpatialEditorViewport::_bind_methods(){ ObjectTypeDB::bind_method(_MD("_toggle_camera_preview"),&SpatialEditorViewport::_toggle_camera_preview); ObjectTypeDB::bind_method(_MD("_preview_exited_scene"),&SpatialEditorViewport::_preview_exited_scene); + ADD_SIGNAL( MethodInfo("toggle_maximize_view", PropertyInfo(Variant::OBJECT, "viewport")) ); } @@ -2974,6 +2981,48 @@ void SpatialEditor::_request_gizmo(Object* p_obj) { } +void SpatialEditor::_toggle_maximize_view(Object* p_viewport) { + if (!p_viewport) return; + SpatialEditorViewport *current_viewport = p_viewport->cast_to<SpatialEditorViewport>(); + if (!current_viewport) return; + + int index=-1; + bool maximized = false; + for(int i=0;i<4;i++) { + if (viewports[i]==current_viewport) { + index=i; + if ( current_viewport->get_global_rect() == viewport_base->get_global_rect() ) + maximized=true; + break; + } + } + if (index==-1) return; + + if (!maximized) { + + for(int i=0;i<4;i++) { + if (i==index) + viewports[i]->set_area_as_parent_rect(); + else + viewports[i]->hide(); + } + } else { + + for(int i=0;i<4;i++) + viewports[i]->show(); + + if (view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT) )) + _menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT); + else if (view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS) )) + _menu_item_pressed(MENU_VIEW_USE_2_VIEWPORTS); + else if (view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS) )) + _menu_item_pressed(MENU_VIEW_USE_3_VIEWPORTS); + else if (view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS) )) + _menu_item_pressed(MENU_VIEW_USE_4_VIEWPORTS); + } + +} + void SpatialEditor::_bind_methods() { // ObjectTypeDB::bind_method("_input_event",&SpatialEditor::_input_event); @@ -2986,8 +3035,11 @@ void SpatialEditor::_bind_methods() { ObjectTypeDB::bind_method("_get_editor_data",&SpatialEditor::_get_editor_data); ObjectTypeDB::bind_method("_request_gizmo",&SpatialEditor::_request_gizmo); + ObjectTypeDB::bind_method("_toggle_maximize_view",&SpatialEditor::_toggle_maximize_view); + ADD_SIGNAL( MethodInfo("transform_key_request") ); + } SpatialEditor::SpatialEditor(EditorNode *p_editor) { @@ -3087,10 +3139,10 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { p->add_check_item("Use Default Light",MENU_VIEW_USE_DEFAULT_LIGHT); p->add_separator(); - p->add_check_item("1 Viewport",MENU_VIEW_USE_1_VIEWPORT); - p->add_check_item("2 Viewports",MENU_VIEW_USE_2_VIEWPORTS); - p->add_check_item("3 Viewports",MENU_VIEW_USE_3_VIEWPORTS); - p->add_check_item("4 Viewports",MENU_VIEW_USE_4_VIEWPORTS); + p->add_check_item("1 Viewport",MENU_VIEW_USE_1_VIEWPORT,KEY_MASK_ALT+KEY_1); + p->add_check_item("2 Viewports",MENU_VIEW_USE_2_VIEWPORTS,KEY_MASK_ALT+KEY_2); + p->add_check_item("3 Viewports",MENU_VIEW_USE_3_VIEWPORTS,KEY_MASK_ALT+KEY_3); + p->add_check_item("4 Viewports",MENU_VIEW_USE_4_VIEWPORTS,KEY_MASK_ALT+KEY_4); p->add_separator(); p->add_check_item("Display Normal",MENU_VIEW_DISPLAY_NORMAL); @@ -3127,6 +3179,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { for(int i=0;i<4;i++) { viewports[i] = memnew( SpatialEditorViewport(this,editor) ); + viewports[i]->connect("toggle_maximize_view",this,"_toggle_maximize_view"); viewport_base->add_child(viewports[i]); } //vbc->add_child(viewport_base); diff --git a/tools/editor/plugins/spatial_editor_plugin.h b/tools/editor/plugins/spatial_editor_plugin.h index 94711a5f02..aac2d62002 100644 --- a/tools/editor/plugins/spatial_editor_plugin.h +++ b/tools/editor/plugins/spatial_editor_plugin.h @@ -376,6 +376,8 @@ private: void _init_indicators(); void _finish_indicators(); + void _toggle_maximize_view(Object* p_viewport); + Node *custom_camera; Object *_get_editor_data(Object *p_what); |