Merge pull request #2528 from MarianoGnu/sprite-edit
SpriteRegionEditor
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
*.cpp eol=lf
|
||||
*.h eol=lf
|
||||
*.py eol=lf
|
||||
*.hpp eol=lf
|
||||
@@ -189,6 +189,7 @@ void Sprite::set_region_rect(const Rect2& p_region_rect) {
|
||||
if (region && changed) {
|
||||
update();
|
||||
item_rect_changed();
|
||||
_change_notify("region_rect");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
|
||||
// plugins
|
||||
#include "plugins/sprite_frames_editor_plugin.h"
|
||||
#include "plugins/sprite_region_editor_plugin.h"
|
||||
#include "plugins/canvas_item_editor_plugin.h"
|
||||
#include "plugins/spatial_editor_plugin.h"
|
||||
#include "plugins/sample_editor_plugin.h"
|
||||
@@ -5475,6 +5476,7 @@ EditorNode::EditorNode() {
|
||||
add_editor_plugin( memnew( TileSetEditorPlugin(this) ) );
|
||||
add_editor_plugin( memnew( TileMapEditorPlugin(this) ) );
|
||||
add_editor_plugin( memnew( SpriteFramesEditorPlugin(this) ) );
|
||||
add_editor_plugin( memnew( SpriteRegionEditorPlugin(this) ) );
|
||||
add_editor_plugin( memnew( Particles2DEditorPlugin(this) ) );
|
||||
add_editor_plugin( memnew( Path2DEditorPlugin(this) ) );
|
||||
add_editor_plugin( memnew( PathEditorPlugin(this) ) );
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 354 B |
Binary file not shown.
|
After Width: | Height: | Size: 171 B |
@@ -50,6 +50,9 @@ void Polygon2DEditor::_notification(int p_what) {
|
||||
uv_button[UV_MODE_ROTATE]->set_icon(get_icon("ToolRotate","EditorIcons"));
|
||||
uv_button[UV_MODE_SCALE]->set_icon(get_icon("ToolScale","EditorIcons"));
|
||||
|
||||
b_snap_grid->set_icon( get_icon("Grid", "EditorIcons"));
|
||||
b_snap_enable->set_icon( get_icon("Snap", "EditorIcons"));
|
||||
uv_icon_zoom->set_texture( get_icon("Zoom", "EditorIcons"));
|
||||
|
||||
} break;
|
||||
case NOTIFICATION_FIXED_PROCESS: {
|
||||
@@ -158,6 +161,41 @@ void Polygon2DEditor::_menu_option(int p_option) {
|
||||
}
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_set_use_snap(bool p_use)
|
||||
{
|
||||
use_snap=p_use;
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_set_show_grid(bool p_show)
|
||||
{
|
||||
snap_show_grid=p_show;
|
||||
uv_edit_draw->update();
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_set_snap_off_x(float p_val)
|
||||
{
|
||||
snap_offset.x=p_val;
|
||||
uv_edit_draw->update();
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_set_snap_off_y(float p_val)
|
||||
{
|
||||
snap_offset.y=p_val;
|
||||
uv_edit_draw->update();
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_set_snap_step_x(float p_val)
|
||||
{
|
||||
snap_step.x=p_val;
|
||||
uv_edit_draw->update();
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_set_snap_step_y(float p_val)
|
||||
{
|
||||
snap_step.y=p_val;
|
||||
uv_edit_draw->update();
|
||||
}
|
||||
|
||||
void Polygon2DEditor::_wip_close() {
|
||||
|
||||
undo_redo->create_action("Create Poly");
|
||||
@@ -494,7 +532,7 @@ void Polygon2DEditor::_uv_input(const InputEvent& p_input) {
|
||||
|
||||
Vector2 tuv=mtx.xform(uv_prev[i]);
|
||||
if (tuv.distance_to(Vector2(mb.x,mb.y))<8) {
|
||||
|
||||
uv_drag_from=tuv;
|
||||
uv_drag_index=i;
|
||||
}
|
||||
}
|
||||
@@ -545,7 +583,7 @@ void Polygon2DEditor::_uv_input(const InputEvent& p_input) {
|
||||
|
||||
} else if (uv_drag) {
|
||||
|
||||
Vector2 uv_drag_to(mm.x,mm.y);
|
||||
Vector2 uv_drag_to=snap_point(Vector2(mm.x,mm.y));
|
||||
Vector2 drag = mtx.affine_inverse().xform(uv_drag_to) - mtx.affine_inverse().xform(uv_drag_from);
|
||||
|
||||
|
||||
@@ -649,6 +687,33 @@ void Polygon2DEditor::_uv_draw() {
|
||||
uv_edit_draw->draw_texture(base_tex,Point2());
|
||||
VS::get_singleton()->canvas_item_add_set_transform(uv_edit_draw->get_canvas_item(),Matrix32());
|
||||
|
||||
if (snap_show_grid) {
|
||||
Size2 s = uv_edit_draw->get_size();
|
||||
int last_cell;
|
||||
|
||||
if (snap_step.x!=0) {
|
||||
for(int i=0;i<s.width;i++) {
|
||||
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(i,0)).x-snap_offset.x)/snap_step.x));
|
||||
if (i==0)
|
||||
last_cell=cell;
|
||||
if (last_cell!=cell)
|
||||
uv_edit_draw->draw_line(Point2(i,0),Point2(i,s.height),Color(0.3,0.7,1,0.3));
|
||||
last_cell=cell;
|
||||
}
|
||||
}
|
||||
|
||||
if (snap_step.y!=0) {
|
||||
for(int i=0;i<s.height;i++) {
|
||||
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(0,i)).y-snap_offset.y)/snap_step.y));
|
||||
if (i==0)
|
||||
last_cell=cell;
|
||||
if (last_cell!=cell)
|
||||
uv_edit_draw->draw_line(Point2(0,i),Point2(s.width,i),Color(0.3,0.7,1,0.3));
|
||||
last_cell=cell;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DVector<Vector2> uvs = node->get_uv();
|
||||
Ref<Texture> handle = get_icon("EditorHandle","EditorIcons");
|
||||
|
||||
@@ -720,10 +785,29 @@ void Polygon2DEditor::_bind_methods() {
|
||||
ObjectTypeDB::bind_method(_MD("_uv_input"),&Polygon2DEditor::_uv_input);
|
||||
ObjectTypeDB::bind_method(_MD("_uv_scroll_changed"),&Polygon2DEditor::_uv_scroll_changed);
|
||||
ObjectTypeDB::bind_method(_MD("_node_removed"),&Polygon2DEditor::_node_removed);
|
||||
ObjectTypeDB::bind_method(_MD("_set_use_snap"),&Polygon2DEditor::_set_use_snap);
|
||||
ObjectTypeDB::bind_method(_MD("_set_show_grid"),&Polygon2DEditor::_set_show_grid);
|
||||
ObjectTypeDB::bind_method(_MD("_set_snap_off_x"),&Polygon2DEditor::_set_snap_off_x);
|
||||
ObjectTypeDB::bind_method(_MD("_set_snap_off_y"),&Polygon2DEditor::_set_snap_off_y);
|
||||
ObjectTypeDB::bind_method(_MD("_set_snap_step_x"),&Polygon2DEditor::_set_snap_step_x);
|
||||
ObjectTypeDB::bind_method(_MD("_set_snap_step_y"),&Polygon2DEditor::_set_snap_step_y);
|
||||
|
||||
|
||||
}
|
||||
|
||||
inline float _snap_scalar(float p_offset, float p_step, float p_target) {
|
||||
return p_step != 0 ? Math::stepify(p_target - p_offset, p_step) + p_offset : p_target;
|
||||
}
|
||||
|
||||
Vector2 Polygon2DEditor::snap_point(Vector2 p_target) const {
|
||||
if (use_snap) {
|
||||
p_target.x = _snap_scalar(snap_offset.x*uv_draw_zoom-uv_draw_ofs.x, snap_step.x*uv_draw_zoom, p_target.x);
|
||||
p_target.y = _snap_scalar(snap_offset.y*uv_draw_zoom-uv_draw_ofs.y, snap_step.y*uv_draw_zoom, p_target.y);
|
||||
}
|
||||
|
||||
return p_target;
|
||||
}
|
||||
|
||||
Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) {
|
||||
|
||||
node=NULL;
|
||||
@@ -731,6 +815,10 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) {
|
||||
editor=p_editor;
|
||||
undo_redo = editor->get_undo_redo();
|
||||
|
||||
snap_step=Vector2(10,10);
|
||||
use_snap=false;
|
||||
snap_show_grid=false;
|
||||
|
||||
add_child( memnew( VSeparator ));
|
||||
button_create = memnew( ToolButton );
|
||||
add_child(button_create);
|
||||
@@ -800,9 +888,72 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) {
|
||||
uv_menu->get_popup()->add_separator();
|
||||
uv_menu->get_popup()->add_item("Clear UV",UVEDIT_UV_CLEAR);
|
||||
uv_menu->get_popup()->connect("item_pressed",this,"_menu_option");
|
||||
|
||||
uv_mode_hb->add_child( memnew( VSeparator ));
|
||||
|
||||
b_snap_enable = memnew( ToolButton );
|
||||
uv_mode_hb->add_child(b_snap_enable);
|
||||
b_snap_enable->set_text("Snap");
|
||||
b_snap_enable->set_focus_mode(FOCUS_NONE);
|
||||
b_snap_enable->set_toggle_mode(true);
|
||||
b_snap_enable->set_pressed(use_snap);
|
||||
b_snap_enable->set_tooltip("Enable Snap");
|
||||
b_snap_enable->connect("toggled",this,"_set_use_snap");
|
||||
|
||||
b_snap_grid = memnew( ToolButton );
|
||||
uv_mode_hb->add_child(b_snap_grid);
|
||||
b_snap_grid->set_text("Grid");
|
||||
b_snap_grid->set_focus_mode(FOCUS_NONE);
|
||||
b_snap_grid->set_toggle_mode(true);
|
||||
b_snap_grid->set_pressed(snap_show_grid);
|
||||
b_snap_grid->set_tooltip("Show Grid");
|
||||
b_snap_grid->connect("toggled",this,"_set_show_grid");
|
||||
|
||||
uv_mode_hb->add_child( memnew( VSeparator ));
|
||||
uv_mode_hb->add_child( memnew( Label("Grid Offset:") ) );
|
||||
|
||||
SpinBox *sb_off_x = memnew( SpinBox );
|
||||
sb_off_x->set_min(-256);
|
||||
sb_off_x->set_max(256);
|
||||
sb_off_x->set_step(1);
|
||||
sb_off_x->set_val(snap_offset.x);
|
||||
sb_off_x->set_suffix("px");
|
||||
sb_off_x->connect("value_changed", this, "_set_snap_off_x");
|
||||
uv_mode_hb->add_child(sb_off_x);
|
||||
|
||||
SpinBox *sb_off_y = memnew( SpinBox );
|
||||
sb_off_y->set_min(-256);
|
||||
sb_off_y->set_max(256);
|
||||
sb_off_y->set_step(1);
|
||||
sb_off_y->set_val(snap_offset.y);
|
||||
sb_off_y->set_suffix("px");
|
||||
sb_off_y->connect("value_changed", this, "_set_snap_off_y");
|
||||
uv_mode_hb->add_child(sb_off_y);
|
||||
|
||||
uv_mode_hb->add_child( memnew( VSeparator ));
|
||||
uv_mode_hb->add_child( memnew( Label("Grid Step:") ) );
|
||||
|
||||
SpinBox *sb_step_x = memnew( SpinBox );
|
||||
sb_step_x->set_min(-256);
|
||||
sb_step_x->set_max(256);
|
||||
sb_step_x->set_step(1);
|
||||
sb_step_x->set_val(snap_step.x);
|
||||
sb_step_x->set_suffix("px");
|
||||
sb_step_x->connect("value_changed", this, "_set_snap_step_x");
|
||||
uv_mode_hb->add_child(sb_step_x);
|
||||
|
||||
SpinBox *sb_step_y = memnew( SpinBox );
|
||||
sb_step_y->set_min(-256);
|
||||
sb_step_y->set_max(256);
|
||||
sb_step_y->set_step(1);
|
||||
sb_step_y->set_val(snap_step.y);
|
||||
sb_step_y->set_suffix("px");
|
||||
sb_step_y->connect("value_changed", this, "_set_snap_step_y");
|
||||
uv_mode_hb->add_child(sb_step_y);
|
||||
|
||||
uv_mode_hb->add_child( memnew( VSeparator ));
|
||||
uv_icon_zoom = memnew( TextureFrame );
|
||||
uv_main_hb->add_child( uv_icon_zoom );
|
||||
uv_mode_hb->add_child( uv_icon_zoom );
|
||||
uv_zoom = memnew( HSlider );
|
||||
uv_zoom->set_min(0.01);
|
||||
uv_zoom->set_max(4);
|
||||
|
||||
@@ -41,6 +41,8 @@ class Polygon2DEditor : public HBoxContainer {
|
||||
UVMode uv_mode;
|
||||
AcceptDialog *uv_edit;
|
||||
ToolButton *uv_button[4];
|
||||
ToolButton *b_snap_enable;
|
||||
ToolButton *b_snap_grid;
|
||||
Control *uv_edit_draw;
|
||||
HSlider *uv_zoom;
|
||||
SpinBox *uv_zoom_value;
|
||||
@@ -78,6 +80,11 @@ class Polygon2DEditor : public HBoxContainer {
|
||||
Vector<Vector2> wip;
|
||||
bool wip_active;
|
||||
|
||||
bool use_snap;
|
||||
bool snap_show_grid;
|
||||
Vector2 snap_offset;
|
||||
Vector2 snap_step;
|
||||
|
||||
void _uv_scroll_changed(float);
|
||||
void _uv_input(const InputEvent& p_input);
|
||||
void _uv_draw();
|
||||
@@ -86,10 +93,20 @@ class Polygon2DEditor : public HBoxContainer {
|
||||
void _canvas_draw();
|
||||
void _menu_option(int p_option);
|
||||
|
||||
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);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
void _node_removed(Node *p_node);
|
||||
static void _bind_methods();
|
||||
|
||||
Vector2 snap_point(Vector2 p_target) const;
|
||||
|
||||
public:
|
||||
|
||||
bool forward_input_event(const InputEvent& p_event);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,125 @@
|
||||
/*************************************************************************/
|
||||
/* sprite_region_editor_plugin.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef SPRITE_REGION_EDITOR_PLUGIN_H
|
||||
#define SPRITE_REGION_EDITOR_PLUGIN_H
|
||||
|
||||
#include "canvas_item_editor_plugin.h"
|
||||
#include "tools/editor/editor_plugin.h"
|
||||
#include "tools/editor/editor_node.h"
|
||||
#include "scene/2d/sprite.h"
|
||||
|
||||
class SpriteRegionEditor : public HBoxContainer {
|
||||
|
||||
OBJ_TYPE(SpriteRegionEditor, HBoxContainer );
|
||||
|
||||
ToolButton *edit_node;
|
||||
// Button *use_region;
|
||||
ToolButton *b_snap_enable;
|
||||
ToolButton *b_snap_grid;
|
||||
TextureFrame *icon_zoom;
|
||||
HSlider *zoom;
|
||||
SpinBox *zoom_value;
|
||||
Control *edit_draw;
|
||||
|
||||
VScrollBar *vscroll;
|
||||
HScrollBar *hscroll;
|
||||
|
||||
Sprite *node;
|
||||
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;
|
||||
|
||||
Rect2 rect;
|
||||
Rect2 rect_prev;
|
||||
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);
|
||||
|
||||
protected:
|
||||
|
||||
void _notification(int p_what);
|
||||
void _node_removed(Node *p_node);
|
||||
static void _bind_methods();
|
||||
|
||||
Vector2 snap_point(Vector2 p_target) const;
|
||||
|
||||
public:
|
||||
|
||||
void edit();
|
||||
void _edit_node();
|
||||
void _region_draw();
|
||||
void _region_input(const InputEvent &p_input);
|
||||
void _scroll_changed(float);
|
||||
|
||||
void edit(Node *p_sprite);
|
||||
SpriteRegionEditor(EditorNode* p_editor);
|
||||
|
||||
};
|
||||
|
||||
class SpriteRegionEditorPlugin : public EditorPlugin
|
||||
{
|
||||
|
||||
OBJ_TYPE( SpriteRegionEditorPlugin, EditorPlugin );
|
||||
|
||||
SpriteRegionEditor *region_editor;
|
||||
EditorNode *editor;
|
||||
public:
|
||||
|
||||
virtual String get_name() const { return "Sprite"; }
|
||||
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);
|
||||
|
||||
SpriteRegionEditorPlugin(EditorNode *p_node);
|
||||
};
|
||||
|
||||
#endif // SPRITE_REGION_EDITOR_PLUGIN_H
|
||||
Reference in New Issue
Block a user