2015-09-28 05:06:06 +02:00
|
|
|
/*************************************************************************/
|
2016-06-03 22:04:44 +02:00
|
|
|
/* texture_region_editor_plugin.h */
|
2015-09-28 05:06:06 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2015-09-28 05:06:06 +02: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-03 22:04:44 +02:00
|
|
|
#ifndef TEXTURE_REGION_EDITOR_PLUGIN_H
|
|
|
|
#define TEXTURE_REGION_EDITOR_PLUGIN_H
|
2015-09-28 05:06:06 +02: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-03 22:04:44 +02:00
|
|
|
#include "scene/gui/patch_9_frame.h"
|
2016-06-04 18:40:53 +02:00
|
|
|
#include "scene/resources/style_box.h"
|
2016-06-10 12:31:38 +02:00
|
|
|
#include "scene/resources/texture.h"
|
2015-09-28 05:06:06 +02:00
|
|
|
|
2016-06-20 03:16:41 +02:00
|
|
|
class TextureRegionEditor : public Control {
|
2015-09-28 05:06:06 +02:00
|
|
|
|
2016-06-20 03:16:41 +02:00
|
|
|
OBJ_TYPE(TextureRegionEditor, Control );
|
2015-09-28 05:06:06 +02:00
|
|
|
|
2016-06-14 04:54:58 +02:00
|
|
|
enum SnapMode {
|
|
|
|
SNAP_NONE,
|
|
|
|
SNAP_PIXEL,
|
|
|
|
SNAP_GRID,
|
|
|
|
SNAP_AUTOSLICE
|
|
|
|
};
|
|
|
|
|
2016-06-03 22:04:44 +02:00
|
|
|
friend class TextureRegionEditorPlugin;
|
2016-06-14 04:54:58 +02:00
|
|
|
MenuButton *snap_mode_button;
|
2015-09-28 05:06:06 +02:00
|
|
|
TextureFrame *icon_zoom;
|
2016-06-20 03:16:41 +02:00
|
|
|
ToolButton *zoom_in;
|
|
|
|
ToolButton *zoom_reset;
|
|
|
|
ToolButton *zoom_out;
|
2016-06-14 04:54:58 +02:00
|
|
|
HBoxContainer * hb_grid; //For showing/hiding the grid controls when changing the SnapMode
|
2016-01-10 23:02:32 +01:00
|
|
|
SpinBox *sb_step_y;
|
|
|
|
SpinBox *sb_step_x;
|
|
|
|
SpinBox *sb_off_y;
|
|
|
|
SpinBox *sb_off_x;
|
2016-06-14 04:54:58 +02:00
|
|
|
SpinBox *sb_sep_y;
|
|
|
|
SpinBox *sb_sep_x;
|
2015-09-28 05:06:06 +02:00
|
|
|
Control *edit_draw;
|
|
|
|
|
|
|
|
VScrollBar *vscroll;
|
|
|
|
HScrollBar *hscroll;
|
|
|
|
|
|
|
|
EditorNode *editor;
|
|
|
|
UndoRedo* undo_redo;
|
|
|
|
|
|
|
|
Vector2 draw_ofs;
|
|
|
|
float draw_zoom;
|
|
|
|
bool updating_scroll;
|
|
|
|
|
2016-06-14 04:54:58 +02:00
|
|
|
int snap_mode;
|
2015-09-28 05:06:06 +02:00
|
|
|
Vector2 snap_offset;
|
|
|
|
Vector2 snap_step;
|
2016-06-14 04:54:58 +02:00
|
|
|
Vector2 snap_separation;
|
2015-09-28 05:06:06 +02:00
|
|
|
|
2016-06-03 22:04:44 +02:00
|
|
|
Patch9Frame *node_patch9;
|
|
|
|
Sprite *node_sprite;
|
2016-06-20 03:16:41 +02:00
|
|
|
Ref<StyleBoxTexture> obj_styleBox;
|
|
|
|
Ref<AtlasTexture> atlas_tex;
|
2016-06-04 18:40:53 +02:00
|
|
|
|
2015-09-28 05:06:06 +02:00
|
|
|
Rect2 rect;
|
|
|
|
Rect2 rect_prev;
|
2016-06-20 03:16:41 +02:00
|
|
|
float prev_margin;
|
|
|
|
int edited_margin;
|
2016-06-14 04:54:58 +02:00
|
|
|
List<Rect2> autoslice_cache;
|
2016-06-03 22:04:44 +02:00
|
|
|
|
2015-09-28 05:06:06 +02:00
|
|
|
bool drag;
|
|
|
|
bool creating;
|
|
|
|
Vector2 drag_from;
|
|
|
|
int drag_index;
|
|
|
|
|
2016-06-14 04:54:58 +02:00
|
|
|
void _set_snap_mode(int p_mode);
|
2015-09-28 05:06:06 +02:00
|
|
|
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-14 04:54:58 +02:00
|
|
|
void _set_snap_sep_x(float p_val);
|
|
|
|
void _set_snap_sep_y(float p_val);
|
|
|
|
void _zoom_in();
|
|
|
|
void _zoom_reset();
|
|
|
|
void _zoom_out();
|
2016-06-03 22:04:44 +02:00
|
|
|
void apply_rect(const Rect2& rect);
|
2015-09-28 05:06:06 +02:00
|
|
|
protected:
|
|
|
|
|
|
|
|
void _notification(int p_what);
|
2016-06-04 18:40:53 +02:00
|
|
|
void _node_removed(Object *p_obj);
|
2015-09-28 05:06:06 +02:00
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
Vector2 snap_point(Vector2 p_target) const;
|
|
|
|
|
2016-10-11 11:31:25 +02:00
|
|
|
virtual void _changed_callback(Object *p_changed, const char *p_prop);
|
|
|
|
|
2015-09-28 05:06:06 +02:00
|
|
|
public:
|
|
|
|
|
2016-06-03 22:04:44 +02:00
|
|
|
void _edit_region();
|
2015-09-28 05:06:06 +02:00
|
|
|
void _region_draw();
|
|
|
|
void _region_input(const InputEvent &p_input);
|
|
|
|
void _scroll_changed(float);
|
|
|
|
|
2016-06-04 18:40:53 +02:00
|
|
|
void edit(Object *p_obj);
|
2016-06-03 22:04:44 +02:00
|
|
|
TextureRegionEditor(EditorNode* p_editor);
|
2015-09-28 05:06:06 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-06-03 22:04:44 +02:00
|
|
|
class TextureRegionEditorPlugin : public EditorPlugin
|
2015-09-28 05:06:06 +02:00
|
|
|
{
|
2016-06-03 22:04:44 +02:00
|
|
|
OBJ_TYPE( TextureRegionEditorPlugin, EditorPlugin );
|
2015-09-28 05:06:06 +02:00
|
|
|
|
2016-06-20 03:16:41 +02:00
|
|
|
Button *region_button;
|
2016-06-03 22:04:44 +02:00
|
|
|
TextureRegionEditor *region_editor;
|
2015-09-28 05:06:06 +02:00
|
|
|
EditorNode *editor;
|
|
|
|
public:
|
|
|
|
|
2016-06-20 03:16:41 +02:00
|
|
|
virtual String get_name() const { return "TextureRegion"; }
|
2015-09-28 05:06:06 +02: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 23:02:32 +01:00
|
|
|
void set_state(const Dictionary &p_state);
|
|
|
|
Dictionary get_state() const;
|
2015-09-28 05:06:06 +02:00
|
|
|
|
2016-06-03 22:04:44 +02:00
|
|
|
TextureRegionEditorPlugin(EditorNode *p_node);
|
2015-09-28 05:06:06 +02:00
|
|
|
};
|
|
|
|
|
2016-06-03 22:04:44 +02:00
|
|
|
#endif // TEXTURE_REGION_EDITOR_PLUGIN_H
|