collision_shape_2d_editor_plugin.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*************************************************************************/
  2. /* collision_shape_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 COLLISION_SHAPE_2D_EDITOR_PLUGIN_H
  31. #define COLLISION_SHAPE_2D_EDITOR_PLUGIN_H
  32. #include "editor/editor_node.h"
  33. #include "editor/editor_plugin.h"
  34. #include "scene/2d/collision_shape_2d.h"
  35. class CanvasItemEditor;
  36. class CollisionShape2DEditor : public Control {
  37. GDCLASS(CollisionShape2DEditor, Control);
  38. enum ShapeType {
  39. CAPSULE_SHAPE,
  40. CIRCLE_SHAPE,
  41. CONCAVE_POLYGON_SHAPE,
  42. CONVEX_POLYGON_SHAPE,
  43. LINE_SHAPE,
  44. RAY_SHAPE,
  45. RECTANGLE_SHAPE,
  46. SEGMENT_SHAPE
  47. };
  48. EditorNode *editor;
  49. UndoRedo *undo_redo;
  50. CanvasItemEditor *canvas_item_editor;
  51. CollisionShape2D *node;
  52. Vector<Point2> handles;
  53. int shape_type;
  54. int edit_handle;
  55. bool pressed;
  56. Variant original;
  57. Variant get_handle_value(int idx) const;
  58. void set_handle(int idx, Point2 &p_point);
  59. void commit_handle(int idx, Variant &p_org);
  60. void _get_current_shape_type();
  61. protected:
  62. static void _bind_methods();
  63. public:
  64. bool forward_canvas_gui_input(const Ref<InputEvent> &p_event);
  65. void forward_canvas_draw_over_viewport(Control *p_overlay);
  66. void edit(Node *p_node);
  67. CollisionShape2DEditor(EditorNode *p_editor);
  68. };
  69. class CollisionShape2DEditorPlugin : public EditorPlugin {
  70. GDCLASS(CollisionShape2DEditorPlugin, EditorPlugin);
  71. CollisionShape2DEditor *collision_shape_2d_editor;
  72. EditorNode *editor;
  73. public:
  74. virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) { return collision_shape_2d_editor->forward_canvas_gui_input(p_event); }
  75. virtual void forward_canvas_draw_over_viewport(Control *p_overlay) { return collision_shape_2d_editor->forward_canvas_draw_over_viewport(p_overlay); }
  76. virtual String get_name() const { return "CollisionShape2D"; }
  77. bool has_main_screen() const { return false; }
  78. virtual void edit(Object *p_obj);
  79. virtual bool handles(Object *p_obj) const;
  80. virtual void make_visible(bool visible);
  81. CollisionShape2DEditorPlugin(EditorNode *p_editor);
  82. ~CollisionShape2DEditorPlugin();
  83. };
  84. #endif //COLLISION_SHAPE_2D_EDITOR_PLUGIN_H