1 /*************************************************************************/
2 /*  sprite_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 SPRITE_EDITOR_PLUGIN_H
32 #define SPRITE_EDITOR_PLUGIN_H
33 
34 #include "editor/editor_node.h"
35 #include "editor/editor_plugin.h"
36 #include "scene/2d/sprite.h"
37 #include "scene/gui/spin_box.h"
38 
39 class SpriteEditor : public Control {
40 
41 	GDCLASS(SpriteEditor, Control);
42 
43 	enum Menu {
44 		MENU_OPTION_CONVERT_TO_MESH_2D,
45 		MENU_OPTION_CONVERT_TO_POLYGON_2D,
46 		MENU_OPTION_CREATE_COLLISION_POLY_2D,
47 		MENU_OPTION_CREATE_LIGHT_OCCLUDER_2D
48 	};
49 
50 	Menu selected_menu_item;
51 
52 	Sprite *node;
53 
54 	MenuButton *options;
55 
56 	ConfirmationDialog *outline_dialog;
57 
58 	AcceptDialog *err_dialog;
59 
60 	ConfirmationDialog *debug_uv_dialog;
61 	Control *debug_uv;
62 	Vector<Vector2> uv_lines;
63 	Vector<Vector<Vector2> > outline_lines;
64 	Vector<Vector<Vector2> > computed_outline_lines;
65 	Vector<Vector2> computed_vertices;
66 	Vector<Vector2> computed_uv;
67 	Vector<int> computed_indices;
68 
69 	SpinBox *simplification;
70 	SpinBox *grow_pixels;
71 	SpinBox *shrink_pixels;
72 	Button *update_preview;
73 
74 	void _menu_option(int p_option);
75 
76 	//void _create_uv_lines();
77 	friend class SpriteEditorPlugin;
78 
79 	void _debug_uv_draw();
80 	void _update_mesh_data();
81 
82 	void _create_node();
83 	void _convert_to_mesh_2d_node();
84 	void _convert_to_polygon_2d_node();
85 	void _create_collision_polygon_2d_node();
86 	void _create_light_occluder_2d_node();
87 
88 	void _add_as_sibling_or_child(Node *p_own_node, Node *p_new_node);
89 
90 protected:
91 	void _node_removed(Node *p_node);
92 	static void _bind_methods();
93 
94 public:
95 	void edit(Sprite *p_sprite);
96 	SpriteEditor();
97 };
98 
99 class SpriteEditorPlugin : public EditorPlugin {
100 
101 	GDCLASS(SpriteEditorPlugin, EditorPlugin);
102 
103 	SpriteEditor *sprite_editor;
104 	EditorNode *editor;
105 
106 public:
get_name()107 	virtual String get_name() const { return "Sprite"; }
has_main_screen()108 	bool has_main_screen() const { return false; }
109 	virtual void edit(Object *p_object);
110 	virtual bool handles(Object *p_object) const;
111 	virtual void make_visible(bool p_visible);
112 
113 	SpriteEditorPlugin(EditorNode *p_node);
114 	~SpriteEditorPlugin();
115 };
116 
117 #endif // SPRITE_EDITOR_PLUGIN_H
118