2015-09-28 05:06:06 +02:00
|
|
|
/*************************************************************************/
|
2017-01-16 08:04:19 +01:00
|
|
|
/* texture_region_editor_plugin.h */
|
2015-09-28 05:06:06 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2015-09-28 05:06:06 +02:00
|
|
|
/*************************************************************************/
|
2018-01-01 14:40:08 +01:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
2015-09-28 05:06:06 +02:00
|
|
|
/* */
|
|
|
|
/* 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"
|
2017-03-05 14:21:25 +01:00
|
|
|
#include "editor/editor_node.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "editor/editor_plugin.h"
|
2015-09-28 05:06:06 +02:00
|
|
|
#include "scene/2d/sprite.h"
|
2017-10-24 07:59:04 +02:00
|
|
|
#include "scene/gui/nine_patch_rect.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
|
|
|
|
2018-01-05 00:50:27 +01:00
|
|
|
/**
|
|
|
|
@author Mariano Suligoy
|
|
|
|
*/
|
|
|
|
|
2016-06-20 03:16:41 +02:00
|
|
|
class TextureRegionEditor : public Control {
|
2015-09-28 05:06:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(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;
|
2017-01-12 22:27:27 +01:00
|
|
|
TextureRect *icon_zoom;
|
2016-06-20 03:16:41 +02:00
|
|
|
ToolButton *zoom_in;
|
|
|
|
ToolButton *zoom_reset;
|
|
|
|
ToolButton *zoom_out;
|
2017-03-05 16:44:50 +01: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;
|
2017-03-05 16:44:50 +01:00
|
|
|
UndoRedo *undo_redo;
|
2015-09-28 05:06:06 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2017-10-24 07:59:04 +02:00
|
|
|
NinePatchRect *node_ninepatch;
|
2016-06-03 22:04:44 +02:00
|
|
|
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();
|
2017-03-05 16:44:50 +01:00
|
|
|
void apply_rect(const Rect2 &rect);
|
2015-09-28 05:06:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
protected:
|
2015-09-28 05:06:06 +02:00
|
|
|
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();
|
2017-05-20 17:38:03 +02:00
|
|
|
void _region_input(const Ref<InputEvent> &p_input);
|
2015-09-28 05:06:06 +02:00
|
|
|
void _scroll_changed(float);
|
|
|
|
|
2016-06-04 18:40:53 +02:00
|
|
|
void edit(Object *p_obj);
|
2017-03-05 16:44:50 +01:00
|
|
|
TextureRegionEditor(EditorNode *p_editor);
|
2015-09-28 05:06:06 +02:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
class TextureRegionEditorPlugin : public EditorPlugin {
|
|
|
|
GDCLASS(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;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
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; }
|
2017-08-12 18:52:50 +02:00
|
|
|
virtual void edit(Object *p_object);
|
|
|
|
virtual bool handles(Object *p_object) const;
|
2015-09-28 05:06:06 +02:00
|
|
|
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
|