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) 2007-2020 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2020 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 
31 #ifndef POLYGON_2D_EDITOR_PLUGIN_H
32 #define POLYGON_2D_EDITOR_PLUGIN_H
33 
34 #include "editor/plugins/abstract_polygon_2d_editor.h"
35 #include "scene/gui/scroll_container.h"
36 
37 class Polygon2DEditor : public AbstractPolygon2DEditor {
38 
39 	GDCLASS(Polygon2DEditor, AbstractPolygon2DEditor);
40 
41 	enum Mode {
42 		MODE_EDIT_UV = MODE_CONT,
43 		UVEDIT_POLYGON_TO_UV,
44 		UVEDIT_UV_TO_POLYGON,
45 		UVEDIT_UV_CLEAR,
46 		UVEDIT_GRID_SETTINGS
47 	};
48 
49 	enum UVMode {
50 		UV_MODE_CREATE,
51 		UV_MODE_CREATE_INTERNAL,
52 		UV_MODE_REMOVE_INTERNAL,
53 		UV_MODE_EDIT_POINT,
54 		UV_MODE_MOVE,
55 		UV_MODE_ROTATE,
56 		UV_MODE_SCALE,
57 		UV_MODE_ADD_POLYGON,
58 		UV_MODE_REMOVE_POLYGON,
59 		UV_MODE_PAINT_WEIGHT,
60 		UV_MODE_CLEAR_WEIGHT,
61 		UV_MODE_MAX
62 	};
63 
64 	ToolButton *uv_edit_mode[4];
65 	Ref<ButtonGroup> uv_edit_group;
66 
67 	Polygon2D *node;
68 
69 	UVMode uv_mode;
70 	AcceptDialog *uv_edit;
71 	ToolButton *uv_button[UV_MODE_MAX];
72 	ToolButton *b_snap_enable;
73 	ToolButton *b_snap_grid;
74 	Panel *uv_edit_draw;
75 	HSlider *uv_zoom;
76 	SpinBox *uv_zoom_value;
77 	HScrollBar *uv_hscroll;
78 	VScrollBar *uv_vscroll;
79 	MenuButton *uv_menu;
80 	TextureRect *uv_icon_zoom;
81 
82 	VBoxContainer *bone_scroll_main_vb;
83 	ScrollContainer *bone_scroll;
84 	VBoxContainer *bone_scroll_vb;
85 	Button *sync_bones;
86 	HSlider *bone_paint_strength;
87 	SpinBox *bone_paint_radius;
88 	Label *bone_paint_radius_label;
89 	bool bone_painting;
90 	int bone_painting_bone;
91 	PoolVector<float> prev_weights;
92 	Vector2 bone_paint_pos;
93 	AcceptDialog *grid_settings;
94 
95 	void _sync_bones();
96 	void _update_bone_list();
97 
98 	Vector2 uv_draw_ofs;
99 	float uv_draw_zoom;
100 	PoolVector<Vector2> points_prev;
101 	PoolVector<Vector2> uv_create_uv_prev;
102 	PoolVector<Vector2> uv_create_poly_prev;
103 	PoolVector<Color> uv_create_colors_prev;
104 	int uv_create_prev_internal_vertices;
105 	Array uv_create_bones_prev;
106 	Array polygons_prev;
107 
108 	Vector2 uv_create_to;
109 	int point_drag_index;
110 	bool uv_drag;
111 	bool uv_create;
112 	Vector<int> polygon_create;
113 	UVMode uv_move_current;
114 	Vector2 uv_drag_from;
115 	bool updating_uv_scroll;
116 
117 	AcceptDialog *error;
118 
119 	ToolButton *button_uv;
120 
121 	bool use_snap;
122 	bool snap_show_grid;
123 	Vector2 snap_offset;
124 	Vector2 snap_step;
125 
126 	virtual void _menu_option(int p_option);
127 
128 	void _cancel_editing();
129 	void _update_polygon_editing_state();
130 
131 	void _uv_scroll_changed(float);
132 	void _uv_input(const Ref<InputEvent> &p_input);
133 	void _uv_draw();
134 	void _uv_mode(int p_mode);
135 
136 	void _set_use_snap(bool p_use);
137 	void _set_show_grid(bool p_show);
138 	void _set_snap_off_x(float p_val);
139 	void _set_snap_off_y(float p_val);
140 	void _set_snap_step_x(float p_val);
141 	void _set_snap_step_y(float p_val);
142 
143 	void _uv_edit_mode_select(int p_mode);
144 	void _uv_edit_popup_hide();
145 	void _bone_paint_selected(int p_index);
146 
147 	int _get_polygon_count() const;
148 
149 protected:
150 	virtual Node2D *_get_node() const;
151 	virtual void _set_node(Node *p_polygon);
152 
153 	virtual Vector2 _get_offset(int p_idx) const;
154 
_has_uv()155 	virtual bool _has_uv() const { return true; };
156 	virtual void _commit_action();
157 
158 	void _notification(int p_what);
159 	static void _bind_methods();
160 
161 	Vector2 snap_point(Vector2 p_target) const;
162 
163 public:
164 	Polygon2DEditor(EditorNode *p_editor);
165 };
166 
167 class Polygon2DEditorPlugin : public AbstractPolygon2DEditorPlugin {
168 
169 	GDCLASS(Polygon2DEditorPlugin, AbstractPolygon2DEditorPlugin);
170 
171 public:
172 	Polygon2DEditorPlugin(EditorNode *p_node);
173 };
174 
175 #endif // POLYGON_2D_EDITOR_PLUGIN_H
176