1 /*************************************************************************/ 2 /* collision_shape_2d_editor_plugin.h */ 3 /*************************************************************************/ 4 /* This file is part of: */ 5 /* GODOT ENGINE */ 6 /* https://godotengine.org */ 7 /*************************************************************************/ 8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 /* */ 11 /* Permission is hereby granted, free of charge, to any person obtaining */ 12 /* a copy of this software and associated documentation files (the */ 13 /* "Software"), to deal in the Software without restriction, including */ 14 /* without limitation the rights to use, copy, modify, merge, publish, */ 15 /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 /* permit persons to whom the Software is furnished to do so, subject to */ 17 /* the following conditions: */ 18 /* */ 19 /* The above copyright notice and this permission notice shall be */ 20 /* included in all copies or substantial portions of the Software. */ 21 /* */ 22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 /*************************************************************************/ 30 31 #ifndef COLLISION_SHAPE_2D_EDITOR_PLUGIN_H 32 #define COLLISION_SHAPE_2D_EDITOR_PLUGIN_H 33 34 #include "editor/editor_node.h" 35 #include "editor/editor_plugin.h" 36 37 #include "scene/2d/collision_shape_2d.h" 38 39 class CanvasItemEditor; 40 41 class CollisionShape2DEditor : public Control { 42 GDCLASS(CollisionShape2DEditor, Control); 43 44 enum ShapeType { 45 CAPSULE_SHAPE, 46 CIRCLE_SHAPE, 47 CONCAVE_POLYGON_SHAPE, 48 CONVEX_POLYGON_SHAPE, 49 LINE_SHAPE, 50 RAY_SHAPE, 51 RECTANGLE_SHAPE, 52 SEGMENT_SHAPE 53 }; 54 55 EditorNode *editor; 56 UndoRedo *undo_redo; 57 CanvasItemEditor *canvas_item_editor; 58 CollisionShape2D *node; 59 60 Vector<Point2> handles; 61 62 int shape_type; 63 int edit_handle; 64 bool pressed; 65 Variant original; 66 67 Variant get_handle_value(int idx) const; 68 void set_handle(int idx, Point2 &p_point); 69 void commit_handle(int idx, Variant &p_org); 70 71 void _get_current_shape_type(); 72 73 protected: 74 void _notification(int p_what); 75 void _node_removed(Node *p_node); 76 static void _bind_methods(); 77 78 public: 79 bool forward_canvas_gui_input(const Ref<InputEvent> &p_event); 80 void forward_canvas_draw_over_viewport(Control *p_overlay); 81 void edit(Node *p_node); 82 83 CollisionShape2DEditor(EditorNode *p_editor); 84 }; 85 86 class CollisionShape2DEditorPlugin : public EditorPlugin { 87 GDCLASS(CollisionShape2DEditorPlugin, EditorPlugin); 88 89 CollisionShape2DEditor *collision_shape_2d_editor; 90 EditorNode *editor; 91 92 public: forward_canvas_gui_input(const Ref<InputEvent> & p_event)93 virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) { return collision_shape_2d_editor->forward_canvas_gui_input(p_event); } forward_canvas_draw_over_viewport(Control * p_overlay)94 virtual void forward_canvas_draw_over_viewport(Control *p_overlay) { collision_shape_2d_editor->forward_canvas_draw_over_viewport(p_overlay); } 95 get_name()96 virtual String get_name() const { return "CollisionShape2D"; } has_main_screen()97 bool has_main_screen() const { return false; } 98 virtual void edit(Object *p_obj); 99 virtual bool handles(Object *p_obj) const; 100 virtual void make_visible(bool visible); 101 102 CollisionShape2DEditorPlugin(EditorNode *p_editor); 103 ~CollisionShape2DEditorPlugin(); 104 }; 105 106 #endif //COLLISION_SHAPE_2D_EDITOR_PLUGIN_H 107