1 /*************************************************************************/ 2 /* path_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_EDITOR_PLUGIN_H 32 #define PATH_EDITOR_PLUGIN_H 33 34 #include "editor/spatial_editor_gizmos.h" 35 #include "scene/3d/path.h" 36 37 class PathSpatialGizmo : public EditorSpatialGizmo { 38 39 GDCLASS(PathSpatialGizmo, EditorSpatialGizmo); 40 41 Path *path; 42 mutable Vector3 original; 43 mutable float orig_in_length; 44 mutable float orig_out_length; 45 46 public: 47 virtual String get_handle_name(int p_idx) const; 48 virtual Variant get_handle_value(int p_idx); 49 virtual void set_handle(int p_idx, Camera *p_camera, const Point2 &p_point); 50 virtual void commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false); 51 52 virtual void redraw(); 53 PathSpatialGizmo(Path *p_path = NULL); 54 }; 55 56 class PathSpatialGizmoPlugin : public EditorSpatialGizmoPlugin { 57 58 GDCLASS(PathSpatialGizmoPlugin, EditorSpatialGizmoPlugin); 59 60 protected: 61 Ref<EditorSpatialGizmo> create_gizmo(Spatial *p_spatial); 62 63 public: 64 String get_name() const; 65 int get_priority() const; 66 PathSpatialGizmoPlugin(); 67 }; 68 69 class PathEditorPlugin : public EditorPlugin { 70 71 GDCLASS(PathEditorPlugin, EditorPlugin); 72 73 Separator *sep; 74 ToolButton *curve_create; 75 ToolButton *curve_edit; 76 ToolButton *curve_del; 77 ToolButton *curve_close; 78 MenuButton *handle_menu; 79 80 EditorNode *editor; 81 82 Path *path; 83 84 void _mode_changed(int p_idx); 85 void _close_curve(); 86 void _handle_option_pressed(int p_option); 87 bool handle_clicked; 88 bool mirror_handle_angle; 89 bool mirror_handle_length; 90 91 enum HandleOption { 92 HANDLE_OPTION_ANGLE, 93 HANDLE_OPTION_LENGTH 94 }; 95 96 protected: 97 void _notification(int p_what); 98 static void _bind_methods(); 99 100 public: get_edited_path()101 Path *get_edited_path() { return path; } 102 103 static PathEditorPlugin *singleton; 104 virtual bool forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event); 105 106 //virtual bool forward_gui_input(const InputEvent& p_event) { return collision_polygon_editor->forward_gui_input(p_event); } 107 //virtual Ref<SpatialEditorGizmo> create_spatial_gizmo(Spatial *p_spatial); get_name()108 virtual String get_name() const { return "Path"; } has_main_screen()109 bool has_main_screen() const { return false; } 110 virtual void edit(Object *p_object); 111 virtual bool handles(Object *p_object) const; 112 virtual void make_visible(bool p_visible); 113 mirror_angle_enabled()114 bool mirror_angle_enabled() { return mirror_handle_angle; } mirror_length_enabled()115 bool mirror_length_enabled() { return mirror_handle_length; } is_handle_clicked()116 bool is_handle_clicked() { return handle_clicked; } set_handle_clicked(bool clicked)117 void set_handle_clicked(bool clicked) { handle_clicked = clicked; } 118 119 PathEditorPlugin(EditorNode *p_node); 120 ~PathEditorPlugin(); 121 }; 122 123 #endif // PATH_EDITOR_PLUGIN_H 124