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