Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/scene/2d/polygon_2d_editor_plugin.h
9903 views
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 EditorZoomWidget;
39
class HScrollBar;
40
class HSlider;
41
class Label;
42
class MenuButton;
43
class Panel;
44
class ScrollContainer;
45
class SpinBox;
46
class TextureRect;
47
class ViewPanner;
48
class VScrollBar;
49
50
class Polygon2DEditor : public AbstractPolygon2DEditor {
51
GDCLASS(Polygon2DEditor, AbstractPolygon2DEditor);
52
53
enum {
54
MENU_POLYGON_TO_UV,
55
MENU_UV_TO_POLYGON,
56
MENU_UV_CLEAR,
57
MENU_GRID_SETTINGS,
58
};
59
60
enum Mode {
61
MODE_POINTS,
62
MODE_POLYGONS,
63
MODE_UV,
64
MODE_BONES,
65
MODE_MAX
66
};
67
68
enum Action {
69
ACTION_CREATE,
70
ACTION_CREATE_INTERNAL,
71
ACTION_REMOVE_INTERNAL,
72
ACTION_EDIT_POINT,
73
ACTION_MOVE,
74
ACTION_ROTATE,
75
ACTION_SCALE,
76
ACTION_ADD_POLYGON,
77
ACTION_REMOVE_POLYGON,
78
ACTION_PAINT_WEIGHT,
79
ACTION_CLEAR_WEIGHT,
80
ACTION_MAX
81
};
82
83
Polygon2D *node = nullptr;
84
Polygon2D *previous_node = nullptr;
85
86
Button *dock_button = nullptr;
87
VBoxContainer *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();
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
Vector<int> polygon_create;
139
Action current_action = ACTION_CREATE;
140
Vector2 drag_from;
141
142
AcceptDialog *error = nullptr;
143
144
bool use_snap = false;
145
bool snap_show_grid = false;
146
Vector2 snap_offset;
147
Vector2 snap_step;
148
149
void _edit_menu_option(int p_option);
150
151
void _cancel_editing();
152
void _update_polygon_editing_state();
153
void _update_available_modes();
154
155
void _center_view();
156
void _update_zoom_and_pan(bool p_zoom_at_center);
157
void _canvas_input(const Ref<InputEvent> &p_input);
158
void _center_view_on_draw(bool p_enabled = true);
159
void _canvas_draw();
160
void _set_action(int p_mode);
161
162
void _set_use_snap(bool p_use);
163
void _set_show_grid(bool p_show);
164
void _set_snap_off_x(real_t p_val);
165
void _set_snap_off_y(real_t p_val);
166
void _set_snap_step_x(real_t p_val);
167
void _set_snap_step_y(real_t p_val);
168
169
void _select_mode(int p_mode);
170
void _bone_paint_selected(int p_index);
171
172
int _get_polygon_count() const override;
173
174
protected:
175
virtual Node2D *_get_node() const override;
176
virtual void _set_node(Node *p_polygon) override;
177
178
virtual Vector2 _get_offset(int p_idx) const override;
179
180
virtual bool _has_uv() const override { return true; }
181
virtual void _commit_action() override;
182
183
void _notification(int p_what);
184
static void _bind_methods();
185
186
Vector2 snap_point(Vector2 p_target) const;
187
188
public:
189
Polygon2DEditor();
190
};
191
192
class Polygon2DEditorPlugin : public AbstractPolygon2DEditorPlugin {
193
GDCLASS(Polygon2DEditorPlugin, AbstractPolygon2DEditorPlugin);
194
195
public:
196
Polygon2DEditorPlugin();
197
};
198
199