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-2019 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2019 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 #ifndef PATH_2D_EDITOR_PLUGIN_H 31 #define PATH_2D_EDITOR_PLUGIN_H 32 33 #include "editor/editor_node.h" 34 #include "editor/editor_plugin.h" 35 #include "scene/2d/path_2d.h" 36 #include "scene/gui/button_group.h" 37 #include "scene/gui/tool_button.h" 38 39 /** 40 @author Juan Linietsky <reduzio@gmail.com> 41 */ 42 class CanvasItemEditor; 43 44 class Path2DEditor : public HBoxContainer { 45 46 OBJ_TYPE(Path2DEditor, HBoxContainer); 47 48 UndoRedo *undo_redo; 49 50 CanvasItemEditor *canvas_item_editor; 51 EditorNode *editor; 52 Panel *panel; 53 Path2D *node; 54 55 HBoxContainer *base_hb; 56 Separator *sep; 57 58 enum Mode { 59 MODE_CREATE, 60 MODE_EDIT, 61 MODE_EDIT_CURVE, 62 MODE_DELETE, 63 ACTION_CLOSE 64 }; 65 66 Mode mode; 67 ToolButton *curve_create; 68 ToolButton *curve_edit; 69 ToolButton *curve_edit_curve; 70 ToolButton *curve_del; 71 ToolButton *curve_close; 72 73 enum Action { 74 75 ACTION_NONE, 76 ACTION_MOVING_POINT, 77 ACTION_MOVING_IN, 78 ACTION_MOVING_OUT, 79 }; 80 81 Action action; 82 int action_point; 83 Point2 moving_from; 84 Point2 moving_screen_from; 85 86 void _mode_selected(int p_mode); 87 88 void _canvas_draw(); 89 void _node_visibility_changed(); 90 friend class Path2DEditorPlugin; 91 92 protected: 93 void _notification(int p_what); 94 void _node_removed(Node *p_node); 95 static void _bind_methods(); 96 97 public: 98 bool forward_input_event(const InputEvent &p_event); 99 void edit(Node *p_path2d); 100 Path2DEditor(EditorNode *p_editor); 101 }; 102 103 class Path2DEditorPlugin : public EditorPlugin { 104 105 OBJ_TYPE(Path2DEditorPlugin, EditorPlugin); 106 107 Path2DEditor *path2d_editor; 108 EditorNode *editor; 109 110 public: forward_input_event(const InputEvent & p_event)111 virtual bool forward_input_event(const InputEvent &p_event) { return path2d_editor->forward_input_event(p_event); } 112 get_name()113 virtual String get_name() const { return "Path2D"; } has_main_screen()114 bool has_main_screen() const { return false; } 115 virtual void edit(Object *p_node); 116 virtual bool handles(Object *p_node) const; 117 virtual void make_visible(bool p_visible); 118 119 Path2DEditorPlugin(EditorNode *p_node); 120 ~Path2DEditorPlugin(); 121 }; 122 123 #endif // PATH_2D_EDITOR_PLUGIN_H 124