path_editor_plugin.h 4.6 KB

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