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-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_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. PathSpatialGizmoPlugin();
  55. };
  56. class PathEditorPlugin : public EditorPlugin {
  57. GDCLASS(PathEditorPlugin, EditorPlugin);
  58. Separator *sep;
  59. ToolButton *curve_create;
  60. ToolButton *curve_edit;
  61. ToolButton *curve_del;
  62. ToolButton *curve_close;
  63. MenuButton *handle_menu;
  64. EditorNode *editor;
  65. Path *path;
  66. void _mode_changed(int p_idx);
  67. void _close_curve();
  68. void _handle_option_pressed(int p_option);
  69. bool handle_clicked;
  70. bool mirror_handle_angle;
  71. bool mirror_handle_length;
  72. enum HandleOption {
  73. HANDLE_OPTION_ANGLE,
  74. HANDLE_OPTION_LENGTH
  75. };
  76. protected:
  77. void _notification(int p_what);
  78. static void _bind_methods();
  79. public:
  80. Path *get_edited_path() { return path; }
  81. static PathEditorPlugin *singleton;
  82. virtual bool forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event);
  83. //virtual bool forward_gui_input(const InputEvent& p_event) { return collision_polygon_editor->forward_gui_input(p_event); }
  84. //virtual Ref<SpatialEditorGizmo> create_spatial_gizmo(Spatial *p_spatial);
  85. virtual String get_name() const { return "Path"; }
  86. bool has_main_screen() const { return false; }
  87. virtual void edit(Object *p_object);
  88. virtual bool handles(Object *p_object) const;
  89. virtual void make_visible(bool p_visible);
  90. bool mirror_angle_enabled() { return mirror_handle_angle; }
  91. bool mirror_length_enabled() { return mirror_handle_length; }
  92. bool is_handle_clicked() { return handle_clicked; }
  93. void set_handle_clicked(bool clicked) { handle_clicked = clicked; }
  94. PathEditorPlugin(EditorNode *p_node);
  95. ~PathEditorPlugin();
  96. };
  97. #endif // PATH_EDITOR_PLUGIN_H