Debian Codegraph @

editor/scene/2d/polygon_2d_editor_plugin.h

raw symbols SCIP
1 /**************************************************************************/
2 /* polygon_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/scene/2d/abstract_polygon_2d_editor.h"
34 #include "scene/2d/polygon_2d.h"
35
36 class AcceptDialog;
37 class ButtonGroup;
38 class EditorDock;
39 class EditorZoomWidget;
40 class HScrollBar;
41 class HSlider;
42 class Label;
43 class MenuButton;
44 class Panel;
45 class ScrollContainer;
46 class SpinBox;
47 class TextureRect;
48 class ViewPanner;
49 class VScrollBar;
50
51 class Polygon2DEditor : public AbstractPolygon2DEditor {
52 GDCLASS(Polygon2DEditor, AbstractPolygon2DEditor);
53
54 enum {
55 MENU_POLYGON_TO_UV,
56 MENU_UV_TO_POLYGON,
57 MENU_UV_CLEAR,
58 MENU_GRID_SETTINGS,
59 };
60
61 enum Mode {
62 MODE_POINTS,
63 MODE_POLYGONS,
64 MODE_UV,
65 MODE_BONES,
66 MODE_MAX
67 };
68
69 enum Action {
70 ACTION_CREATE,
71 ACTION_CREATE_INTERNAL,
72 ACTION_REMOVE_INTERNAL,
73 ACTION_EDIT_POINT,
74 ACTION_MOVE,
75 ACTION_ROTATE,
76 ACTION_SCALE,
77 ACTION_ADD_POLYGON,
78 ACTION_REMOVE_POLYGON,
79 ACTION_PAINT_WEIGHT,
80 ACTION_CLEAR_WEIGHT,
81 ACTION_MAX
82 };
83
84 Polygon2D *node = nullptr;
85 Polygon2D *previous_node = nullptr;
86
87 EditorDock *polygon_edit = nullptr;
88 Mode current_mode = MODE_MAX; // Uninitialized.
89 Button *mode_buttons[MODE_MAX];
90 Action selected_action = ACTION_CREATE;
91 Button *action_buttons[ACTION_MAX];
92 Button *b_snap_enable = nullptr;
93 Button *b_snap_grid = nullptr;
94 MenuButton *edit_menu = nullptr;
95
96 Control *canvas = nullptr;
97 Panel *canvas_background = nullptr;
98 Polygon2D *preview_polygon = nullptr;
99 EditorZoomWidget *zoom_widget = nullptr;
100 HScrollBar *hscroll = nullptr;
101 VScrollBar *vscroll = nullptr;
102 bool center_view_on_draw = false;
103
104 Ref<ViewPanner> panner;
105 void _pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event);
106 void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event);
107 Vector2 draw_offset;
108 real_t draw_zoom = 1.0;
109
110 VBoxContainer *bone_scroll_main_vb = nullptr;
111 ScrollContainer *bone_scroll = nullptr;
112 VBoxContainer *bone_scroll_vb = nullptr;
113 Button *sync_bones = nullptr;
114 HSlider *bone_paint_strength = nullptr;
115 SpinBox *bone_paint_radius = nullptr;
116 Label *bone_paint_radius_label = nullptr;
117 bool bone_painting = false;
118 int bone_painting_bone = 0;
119 Vector<float> prev_weights;
120 Vector2 bone_paint_pos;
121 AcceptDialog *grid_settings = nullptr;
122
123 void _sync_bones();
124 void _update_bone_list(const Polygon2D *p_for_node);
125
126 Vector<Vector2> editing_points;
127 Vector<Vector2> previous_uv;
128 Vector<Vector2> previous_polygon;
129 Vector<Color> previous_colors;
130 int previous_internal_vertices = 0;
131 Array previous_bones;
132 Array previous_polygons;
133
134 Vector2 create_to;
135 int point_drag_index = -1;
136 bool is_dragging = false;
137 bool is_creating = false;
138 int hovered_point = -1;
139 Vector<int> polygon_create;
140 Action current_action = ACTION_CREATE;
141 Vector2 drag_from;
142
143 AcceptDialog *error = nullptr;
144
145 bool use_snap = false;
146 bool snap_show_grid = false;
147 Vector2 snap_offset;
148 Vector2 snap_step;
149
150 void _edit_menu_option(int p_option);
151
152 void _cancel_editing();
153 void _update_polygon_editing_state();
154 void _update_available_modes();
155
156 void _center_view();
157 void _update_zoom_and_pan(bool p_zoom_at_center);
158 void _canvas_input(const Ref<InputEvent> &p_input);
159 void _center_view_on_draw(bool p_enabled = true);
160 void _canvas_draw();
161 void _set_action(int p_mode);
162
163 void _set_use_snap(bool p_use);
164 void _set_show_grid(bool p_show);
165 void _set_snap_off_x(real_t p_val);
166 void _set_snap_off_y(real_t p_val);
167 void _set_snap_step_x(real_t p_val);
168 void _set_snap_step_y(real_t p_val);
169
170 void _select_mode(int p_mode);
171 void _bone_paint_selected(int p_index);
172
173 int _get_polygon_count() const override;
174
175 protected:
176 virtual Node2D *_get_node() const override;
177 virtual void _set_node(Node *p_polygon) override;
178
179 virtual Vector2 _get_offset(int p_idx) const override;
180
181 virtual bool _has_uv() const override { return true; }
182 virtual void _commit_action() override;
183
184 void _notification(int p_what);
185 static void _bind_methods();
186
187 Vector2 snap_point(Vector2 p_target) const;
188
189 public:
190 Polygon2DEditor();
191 };
192
193 class Polygon2DEditorPlugin : public AbstractPolygon2DEditorPlugin {
194 GDCLASS(Polygon2DEditorPlugin, AbstractPolygon2DEditorPlugin);
195
196 public:
197 Polygon2DEditorPlugin();
198 };