| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2016-06-04 04:04:44 +08:00
										 |  |  | /*  texture_region_editor_plugin.h                                        */ | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							|  |  |  | /*                    http://www.godotengine.org                         */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2016-01-01 11:50:53 -02:00
										 |  |  | /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Author: Mariano Suligoy                                               */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the       */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including   */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,   */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to    */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to */ | 
					
						
							|  |  |  | /* the following conditions:                                             */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be        */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.       */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-04 04:04:44 +08:00
										 |  |  | #ifndef TEXTURE_REGION_EDITOR_PLUGIN_H
 | 
					
						
							|  |  |  | #define TEXTURE_REGION_EDITOR_PLUGIN_H
 | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "canvas_item_editor_plugin.h"
 | 
					
						
							|  |  |  | #include "tools/editor/editor_plugin.h"
 | 
					
						
							|  |  |  | #include "tools/editor/editor_node.h"
 | 
					
						
							|  |  |  | #include "scene/2d/sprite.h"
 | 
					
						
							| 
									
										
										
										
											2016-06-04 04:04:44 +08:00
										 |  |  | #include "scene/gui/patch_9_frame.h"
 | 
					
						
							| 
									
										
										
										
											2016-06-05 00:40:53 +08:00
										 |  |  | #include "scene/resources/style_box.h"
 | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-04 04:04:44 +08:00
										 |  |  | class TextureRegionEditor : public HBoxContainer { | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-04 04:04:44 +08:00
										 |  |  | 	OBJ_TYPE(TextureRegionEditor, HBoxContainer ); | 
					
						
							|  |  |  | 	enum RegionType { | 
					
						
							|  |  |  | 		REGION_TEXTURE_REGION, | 
					
						
							|  |  |  | 		REGION_PATCH_MARGIN | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-04 04:04:44 +08:00
										 |  |  | 	friend class TextureRegionEditorPlugin; | 
					
						
							|  |  |  | 	ToolButton *region_button; | 
					
						
							|  |  |  | 	ToolButton *margin_button; | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | 	ToolButton *b_snap_enable; | 
					
						
							|  |  |  | 	ToolButton *b_snap_grid; | 
					
						
							|  |  |  | 	TextureFrame *icon_zoom; | 
					
						
							|  |  |  | 	HSlider *zoom; | 
					
						
							|  |  |  | 	SpinBox *zoom_value; | 
					
						
							| 
									
										
										
										
											2016-01-10 19:02:32 -03:00
										 |  |  | 	SpinBox *sb_step_y; | 
					
						
							|  |  |  | 	SpinBox *sb_step_x; | 
					
						
							|  |  |  | 	SpinBox *sb_off_y; | 
					
						
							|  |  |  | 	SpinBox *sb_off_x; | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | 	Control *edit_draw; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	VScrollBar *vscroll; | 
					
						
							|  |  |  | 	HScrollBar *hscroll; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	EditorNode *editor; | 
					
						
							|  |  |  | 	AcceptDialog *dlg_editor; | 
					
						
							|  |  |  | 	UndoRedo* undo_redo; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Vector2 draw_ofs; | 
					
						
							|  |  |  | 	float draw_zoom; | 
					
						
							|  |  |  | 	bool updating_scroll; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool use_snap; | 
					
						
							|  |  |  | 	bool snap_show_grid; | 
					
						
							|  |  |  | 	Vector2 snap_offset; | 
					
						
							|  |  |  | 	Vector2 snap_step; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-04 04:04:44 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	String node_type; | 
					
						
							|  |  |  | 	Patch9Frame *node_patch9; | 
					
						
							|  |  |  | 	Sprite *node_sprite; | 
					
						
							| 
									
										
										
										
											2016-06-05 00:40:53 +08:00
										 |  |  | 	StyleBoxTexture *obj_styleBox; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-04 04:04:44 +08:00
										 |  |  | 	int editing_region; | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | 	Rect2 rect; | 
					
						
							|  |  |  | 	Rect2 rect_prev; | 
					
						
							| 
									
										
										
										
											2016-06-04 04:04:44 +08:00
										 |  |  | 	Rect2 tex_region; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | 	bool drag; | 
					
						
							|  |  |  | 	bool creating; | 
					
						
							|  |  |  | 	Vector2 drag_from; | 
					
						
							|  |  |  | 	int drag_index; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	AcceptDialog *error; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void _set_use_snap(bool p_use); | 
					
						
							|  |  |  | 	void _set_show_grid(bool p_show); | 
					
						
							|  |  |  | 	void _set_snap_off_x(float p_val); | 
					
						
							|  |  |  | 	void _set_snap_off_y(float p_val); | 
					
						
							|  |  |  | 	void _set_snap_step_x(float p_val); | 
					
						
							|  |  |  | 	void _set_snap_step_y(float p_val); | 
					
						
							| 
									
										
										
										
											2016-06-04 04:04:44 +08:00
										 |  |  | 	void apply_rect(const Rect2& rect); | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | protected: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void _notification(int p_what); | 
					
						
							| 
									
										
										
										
											2016-06-05 00:40:53 +08:00
										 |  |  | 	void _node_removed(Object *p_obj); | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | 	static void _bind_methods(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Vector2 snap_point(Vector2 p_target) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-04 04:04:44 +08:00
										 |  |  | 	void _edit_node(int tex_region); | 
					
						
							|  |  |  | 	void _edit_region(); | 
					
						
							|  |  |  | 	void _edit_margin(); | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | 	void _region_draw(); | 
					
						
							|  |  |  | 	void _region_input(const InputEvent &p_input); | 
					
						
							|  |  |  | 	void _scroll_changed(float); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-05 00:40:53 +08:00
										 |  |  | 	void edit(Object *p_obj); | 
					
						
							| 
									
										
										
										
											2016-06-04 04:04:44 +08:00
										 |  |  | 	TextureRegionEditor(EditorNode* p_editor); | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-04 04:04:44 +08:00
										 |  |  | class TextureRegionEditorPlugin : public EditorPlugin | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-04 04:04:44 +08:00
										 |  |  | 	OBJ_TYPE( TextureRegionEditorPlugin, EditorPlugin ); | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-04 04:04:44 +08:00
										 |  |  | 	TextureRegionEditor *region_editor; | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | 	EditorNode *editor; | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-19 00:08:12 +02:00
										 |  |  | 	virtual String get_name() const { return "SpriteRegion"; } | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | 	bool has_main_screen() const { return false; } | 
					
						
							|  |  |  | 	virtual void edit(Object *p_node); | 
					
						
							|  |  |  | 	virtual bool handles(Object *p_node) const; | 
					
						
							|  |  |  | 	virtual void make_visible(bool p_visible); | 
					
						
							| 
									
										
										
										
											2016-01-10 19:02:32 -03:00
										 |  |  | 	void set_state(const Dictionary &p_state); | 
					
						
							|  |  |  | 	Dictionary get_state() const; | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-04 04:04:44 +08:00
										 |  |  | 	TextureRegionEditorPlugin(EditorNode *p_node); | 
					
						
							| 
									
										
										
										
											2015-09-28 00:06:06 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-04 04:04:44 +08:00
										 |  |  | #endif // TEXTURE_REGION_EDITOR_PLUGIN_H
 |