Debian Codegraph @

editor/scene/2d/physics/collision_shape_2d_editor_plugin.h

raw symbols SCIP
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) 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 #pragma once
32
33 #include "editor/plugins/editor_plugin.h"
34 #include "scene/2d/physics/collision_shape_2d.h"
35
36 class CanvasItemEditor;
37
38 class CollisionShape2DEditor : public Control {
39 GDCLASS(CollisionShape2DEditor, Control);
40
41 enum ShapeType {
42 CAPSULE_SHAPE,
43 CIRCLE_SHAPE,
44 CONCAVE_POLYGON_SHAPE,
45 CONVEX_POLYGON_SHAPE,
46 WORLD_BOUNDARY_SHAPE,
47 SEPARATION_RAY_SHAPE,
48 RECTANGLE_SHAPE,
49 SEGMENT_SHAPE
50 };
51
52 const Point2 RECT_HANDLES[8] = {
53 Point2(1, 0),
54 Point2(1, 1),
55 Point2(0, 1),
56 Point2(-1, 1),
57 Point2(-1, 0),
58 Point2(-1, -1),
59 Point2(0, -1),
60 Point2(1, -1),
61 };
62
63 CanvasItemEditor *canvas_item_editor = nullptr;
64 CollisionShape2D *node = nullptr;
65
66 Vector<Point2> handles;
67
68 int shape_type = -1;
69 int edit_handle = -1;
70 bool pressed = false;
71 real_t grab_threshold = 8;
72 Variant original;
73 Transform2D original_transform;
74 Vector2 original_point;
75 Point2 last_point;
76 Vector2 original_mouse_pos;
77
78 Ref<Shape2D> current_shape;
79
80 Variant get_handle_value(int idx) const;
81 void set_handle(int idx, Point2 &p_point);
82 void commit_handle(int idx, Variant &p_org);
83
84 void _shape_changed();
85
86 protected:
87 void _notification(int p_what);
88 void _node_removed(Node *p_node);
89
90 public:
91 bool forward_canvas_gui_input(const Ref<InputEvent> &p_event);
92 void forward_canvas_draw_over_viewport(Control *p_overlay);
93 void edit(Node *p_node);
94
95 CollisionShape2DEditor();
96 };
97
98 class CollisionShape2DEditorPlugin : public EditorPlugin {
99 GDCLASS(CollisionShape2DEditorPlugin, EditorPlugin);
100
101 CollisionShape2DEditor *collision_shape_2d_editor = nullptr;
102
103 public:
104 virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) override { return collision_shape_2d_editor->forward_canvas_gui_input(p_event); }
105 virtual void forward_canvas_draw_over_viewport(Control *p_overlay) override { collision_shape_2d_editor->forward_canvas_draw_over_viewport(p_overlay); }
106
107 virtual String get_plugin_name() const override { return "CollisionShape2D"; }
108 bool has_main_screen() const override { return false; }
109 virtual void edit(Object *p_obj) override;
110 virtual bool handles(Object *p_obj) const override;
111 virtual void make_visible(bool visible) override;
112
113 CollisionShape2DEditorPlugin();
114 };