1 /*************************************************************************/ 2 /* path_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 PATH_2D_EDITOR_PLUGIN_H 32 #define PATH_2D_EDITOR_PLUGIN_H 33 34 #include "editor/editor_node.h" 35 #include "editor/editor_plugin.h" 36 #include "scene/2d/path_2d.h" 37 #include "scene/gui/tool_button.h" 38 39 class CanvasItemEditor; 40 41 class Path2DEditor : public HBoxContainer { 42 43 GDCLASS(Path2DEditor, HBoxContainer); 44 45 UndoRedo *undo_redo; 46 47 CanvasItemEditor *canvas_item_editor; 48 EditorNode *editor; 49 Panel *panel; 50 Path2D *node; 51 52 HBoxContainer *base_hb; 53 Separator *sep; 54 55 enum Mode { 56 MODE_CREATE, 57 MODE_EDIT, 58 MODE_EDIT_CURVE, 59 MODE_DELETE, 60 ACTION_CLOSE 61 }; 62 63 Mode mode; 64 ToolButton *curve_create; 65 ToolButton *curve_edit; 66 ToolButton *curve_edit_curve; 67 ToolButton *curve_del; 68 ToolButton *curve_close; 69 MenuButton *handle_menu; 70 71 bool mirror_handle_angle; 72 bool mirror_handle_length; 73 bool on_edge; 74 75 enum HandleOption { 76 HANDLE_OPTION_ANGLE, 77 HANDLE_OPTION_LENGTH 78 }; 79 80 enum Action { 81 82 ACTION_NONE, 83 ACTION_MOVING_POINT, 84 ACTION_MOVING_IN, 85 ACTION_MOVING_OUT, 86 }; 87 88 Action action; 89 int action_point; 90 Point2 moving_from; 91 Point2 moving_screen_from; 92 float orig_in_length; 93 float orig_out_length; 94 Vector2 edge_point; 95 96 void _mode_selected(int p_mode); 97 void _handle_option_pressed(int p_option); 98 99 void _node_visibility_changed(); 100 friend class Path2DEditorPlugin; 101 102 protected: 103 void _notification(int p_what); 104 void _node_removed(Node *p_node); 105 static void _bind_methods(); 106 107 public: 108 bool forward_gui_input(const Ref<InputEvent> &p_event); 109 void forward_canvas_draw_over_viewport(Control *p_overlay); 110 void edit(Node *p_path2d); 111 Path2DEditor(EditorNode *p_editor); 112 }; 113 114 class Path2DEditorPlugin : public EditorPlugin { 115 116 GDCLASS(Path2DEditorPlugin, EditorPlugin); 117 118 Path2DEditor *path2d_editor; 119 EditorNode *editor; 120 121 public: forward_canvas_gui_input(const Ref<InputEvent> & p_event)122 virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) { return path2d_editor->forward_gui_input(p_event); } forward_canvas_draw_over_viewport(Control * p_overlay)123 virtual void forward_canvas_draw_over_viewport(Control *p_overlay) { path2d_editor->forward_canvas_draw_over_viewport(p_overlay); } 124 get_name()125 virtual String get_name() const { return "Path2D"; } has_main_screen()126 bool has_main_screen() const { return false; } 127 virtual void edit(Object *p_object); 128 virtual bool handles(Object *p_object) const; 129 virtual void make_visible(bool p_visible); 130 131 Path2DEditorPlugin(EditorNode *p_node); 132 ~Path2DEditorPlugin(); 133 }; 134 135 #endif // PATH_2D_EDITOR_PLUGIN_H 136