Debian Codegraph @

editor/scene/2d/path_2d_editor_plugin.h

raw symbols SCIP
1 /**************************************************************************/
2 /* path_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/path_2d.h"
35 #include "scene/gui/box_container.h"
36
37 class CanvasItemEditor;
38 class ConfirmationDialog;
39 class MenuButton;
40
41 class Path2DEditor : public HBoxContainer {
42 GDCLASS(Path2DEditor, HBoxContainer);
43
44 friend class Path2DEditorPlugin;
45
46 CanvasItemEditor *canvas_item_editor = nullptr;
47 Panel *panel = nullptr;
48 Path2D *node = nullptr;
49
50 enum Mode {
51 MODE_CREATE,
52 MODE_EDIT,
53 MODE_EDIT_CURVE,
54 MODE_DELETE,
55 MODE_CLOSE,
56 MODE_CLEAR_POINTS,
57 };
58
59 Mode mode = MODE_EDIT;
60 HBoxContainer *toolbar = nullptr;
61 Button *curve_clear_points = nullptr;
62 Button *curve_close = nullptr;
63 Button *curve_create = nullptr;
64 Button *curve_del = nullptr;
65 Button *curve_edit = nullptr;
66 Button *curve_edit_curve = nullptr;
67 MenuButton *handle_menu = nullptr;
68
69 Button *create_curve_button = nullptr;
70 ConfirmationDialog *clear_points_dialog = nullptr;
71
72 bool mirror_handle_angle = true;
73 bool mirror_handle_length = true;
74 bool on_edge = false;
75
76 enum HandleOption {
77 HANDLE_OPTION_ANGLE,
78 HANDLE_OPTION_LENGTH,
79 };
80
81 enum Action {
82 ACTION_NONE,
83 ACTION_MOVING_POINT,
84 ACTION_MOVING_NEW_POINT,
85 ACTION_MOVING_NEW_POINT_FROM_SPLIT,
86 ACTION_MOVING_IN,
87 ACTION_MOVING_OUT,
88 };
89
90 Action action = ACTION_NONE;
91 int action_point = 0;
92 Point2 moving_from;
93 Point2 moving_screen_from;
94 float orig_in_length = 0.0f;
95 float orig_out_length = 0.0f;
96 Vector2 edge_point;
97 Vector2 original_mouse_pos;
98
99 // Number of control points in range of the last click.
100 // 0, 1, or 2.
101 int control_points_in_range = 0;
102
103 void _mode_selected(int p_mode);
104 void _handle_option_pressed(int p_option);
105 void _cancel_current_action();
106
107 void _node_visibility_changed();
108 void _update_toolbar();
109
110 void _create_curve();
111 void _confirm_clear_points();
112 void _clear_curve_points(Path2D *p_path2d);
113 void _restore_curve_points(Path2D *p_path2d, const PackedVector2Array &p_points);
114
115 RID debug_mesh_rid;
116 RID debug_handle_mesh_rid;
117 RID debug_handle_multimesh_rid;
118
119 RID debug_handle_curve_multimesh_rid;
120 RID debug_handle_sharp_multimesh_rid;
121 RID debug_handle_smooth_multimesh_rid;
122
123 LocalVector<Vector2> debug_handle_lines;
124 LocalVector<Transform2D> debug_handle_curve_transforms;
125 LocalVector<Transform2D> debug_handle_sharp_transforms;
126 LocalVector<Transform2D> debug_handle_smooth_transforms;
127
128 protected:
129 void _notification(int p_what);
130 void _node_removed(Node *p_node);
131 static void _bind_methods();
132
133 public:
134 bool forward_gui_input(const Ref<InputEvent> &p_event);
135 void forward_canvas_draw_over_viewport(Control *p_overlay);
136 void edit(Node *p_path2d);
137 Path2DEditor();
138 ~Path2DEditor();
139 };
140
141 class Path2DEditorPlugin : public EditorPlugin {
142 GDCLASS(Path2DEditorPlugin, EditorPlugin);
143
144 Path2DEditor *path2d_editor = nullptr;
145
146 public:
147 virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) override { return path2d_editor->forward_gui_input(p_event); }
148 virtual void forward_canvas_draw_over_viewport(Control *p_overlay) override { path2d_editor->forward_canvas_draw_over_viewport(p_overlay); }
149
150 virtual String get_plugin_name() const override { return "Path2D"; }
151 bool has_main_screen() const override { return false; }
152 virtual void edit(Object *p_object) override;
153 virtual bool handles(Object *p_object) const override;
154 virtual void make_visible(bool p_visible) override;
155
156 Path2DEditorPlugin();
157 };