summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
authorGilles Roudiere <gilles.roudiere@gmail.com>2017-11-07 08:58:35 +0100
committerGilles Roudiere <gilles.roudiere@laas.fr>2018-02-16 10:14:52 +0100
commit8dad41e395220404fb0fdafaa0cd4ed18179231f (patch)
tree37b9190b77fa989f9d9d369b80957c3890e4164f /scene/2d
parent68f277477b5a5f3003405e36c6b6853720cb91de (diff)
2D editor GUI input rework. Changes are:
- The input handling is done into several distinct functions, and the code is more consistent. - The actions' history is more precise ("Edited CanvasItem" is now "Rotated CanvasItem","Moved CanvasItem",etc...) - Fixed a little bug about input key events not forwarded correctly to plugins - IK is followed by default when you move a bone node, the alt-key allow you to move it normally
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/animated_sprite.cpp83
-rw-r--r--scene/2d/animated_sprite.h6
-rw-r--r--scene/2d/canvas_item.h2
-rw-r--r--scene/2d/light_2d.cpp36
-rw-r--r--scene/2d/light_2d.h3
-rw-r--r--scene/2d/node_2d.cpp9
-rw-r--r--scene/2d/polygon_2d.cpp42
-rw-r--r--scene/2d/polygon_2d.h19
-rw-r--r--scene/2d/sprite.cpp20
-rw-r--r--scene/2d/sprite.h3
10 files changed, 131 insertions, 92 deletions
diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite.cpp
index f290a181ec..824f50495b 100644
--- a/scene/2d/animated_sprite.cpp
+++ b/scene/2d/animated_sprite.cpp
@@ -34,7 +34,51 @@
#define NORMAL_SUFFIX "_normal"
-////////////////////////////
+Dictionary AnimatedSprite::_edit_get_state() const {
+ Dictionary state = Node2D::_edit_get_state();
+ state["offset"] = offset;
+ return state;
+}
+
+void AnimatedSprite::_edit_set_state(const Dictionary &p_state) {
+ Node2D::_edit_set_state(p_state);
+ set_offset(p_state["offset"]);
+}
+
+void AnimatedSprite::_edit_set_pivot(const Point2 &p_pivot) {
+ set_offset(get_offset() - p_pivot);
+ set_position(get_transform().xform(p_pivot));
+}
+
+Point2 AnimatedSprite::_edit_get_pivot() const {
+ return Vector2();
+}
+
+bool AnimatedSprite::_edit_use_pivot() const {
+ return true;
+}
+
+Rect2 AnimatedSprite::_edit_get_rect() const {
+ if (!frames.is_valid() || !frames->has_animation(animation) || frame < 0 || frame >= frames->get_frame_count(animation)) {
+ return Node2D::_edit_get_rect();
+ }
+
+ Ref<Texture> t;
+ if (animation)
+ t = frames->get_frame(animation, frame);
+ if (t.is_null())
+ return Node2D::_edit_get_rect();
+ Size2 s = t->get_size();
+
+ Point2 ofs = offset;
+ if (centered)
+ ofs -= s / 2;
+
+ if (s == Size2(0, 0))
+ s = Size2(1, 1);
+
+ return Rect2(ofs, s);
+}
void SpriteFrames::add_frame(const StringName &p_anim, const Ref<Texture> &p_frame, int p_at_pos) {
@@ -248,20 +292,6 @@ SpriteFrames::SpriteFrames() {
add_animation(SceneStringNames::get_singleton()->_default);
}
-void AnimatedSprite::_edit_set_pivot(const Point2 &p_pivot) {
-
- set_offset(p_pivot);
-}
-
-Point2 AnimatedSprite::_edit_get_pivot() const {
-
- return get_offset();
-}
-bool AnimatedSprite::_edit_use_pivot() const {
-
- return true;
-}
-
void AnimatedSprite::_validate_property(PropertyInfo &property) const {
if (!frames.is_valid())
@@ -491,29 +521,6 @@ bool AnimatedSprite::is_flipped_v() const {
return vflip;
}
-Rect2 AnimatedSprite::_edit_get_rect() const {
-
- if (!frames.is_valid() || !frames->has_animation(animation) || frame < 0 || frame >= frames->get_frame_count(animation)) {
- return Node2D::_edit_get_rect();
- }
-
- Ref<Texture> t;
- if (animation)
- t = frames->get_frame(animation, frame);
- if (t.is_null())
- return Node2D::_edit_get_rect();
- Size2i s = t->get_size();
-
- Point2 ofs = offset;
- if (centered)
- ofs -= s / 2;
-
- if (s == Size2(0, 0))
- s = Size2(1, 1);
-
- return Rect2(ofs, s);
-}
-
void AnimatedSprite::_res_changed() {
set_frame(frame);
diff --git a/scene/2d/animated_sprite.h b/scene/2d/animated_sprite.h
index 2c356d619f..a38adf792c 100644
--- a/scene/2d/animated_sprite.h
+++ b/scene/2d/animated_sprite.h
@@ -150,9 +150,13 @@ protected:
virtual void _validate_property(PropertyInfo &property) const;
public:
+ virtual Dictionary _edit_get_state() const;
+ virtual void _edit_set_state(const Dictionary &p_state);
+
virtual void _edit_set_pivot(const Point2 &p_pivot);
virtual Point2 _edit_get_pivot() const;
virtual bool _edit_use_pivot() const;
+ virtual Rect2 _edit_get_rect() const;
void set_sprite_frames(const Ref<SpriteFrames> &p_frames);
Ref<SpriteFrames> get_sprite_frames() const;
@@ -182,8 +186,6 @@ public:
void set_modulate(const Color &p_color);
Color get_modulate() const;
- virtual Rect2 _edit_get_rect() const;
-
virtual String get_configuration_warning() const;
AnimatedSprite();
};
diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h
index 7e5bea0511..68384b9f1e 100644
--- a/scene/2d/canvas_item.h
+++ b/scene/2d/canvas_item.h
@@ -230,7 +230,7 @@ public:
// Used to resize/move/select the node
virtual void _edit_set_rect(const Rect2 &p_rect){};
virtual Rect2 _edit_get_rect() const { return Rect2(-32, -32, 64, 64); };
- virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { return true; }
+ virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { return _edit_get_rect().has_point(p_point); }
Rect2 _edit_get_item_and_children_rect() const;
virtual bool _edit_use_rect() const { return false; };
diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp
index 999d8a2630..1220ff299c 100644
--- a/scene/2d/light_2d.cpp
+++ b/scene/2d/light_2d.cpp
@@ -33,35 +33,36 @@
#include "engine.h"
#include "servers/visual_server.h"
-void Light2D::_edit_set_pivot(const Point2 &p_pivot) {
+Dictionary Light2D::_edit_get_state() const {
+ Dictionary state = Node2D::_edit_get_state();
+ state["offset"] = get_texture_offset();
+ return state;
+}
- set_texture_offset(p_pivot);
+void Light2D::_edit_set_state(const Dictionary &p_state) {
+ Node2D::_edit_set_state(p_state);
+ set_texture_offset(p_state["offset"]);
}
-Point2 Light2D::_edit_get_pivot() const {
+void Light2D::_edit_set_pivot(const Point2 &p_pivot) {
+ set_position(get_transform().xform(p_pivot));
+ set_texture_offset(get_texture_offset() - p_pivot);
+}
- return get_texture_offset();
+Point2 Light2D::_edit_get_pivot() const {
+ return Vector2();
}
-bool Light2D::_edit_use_pivot() const {
+bool Light2D::_edit_use_pivot() const {
return true;
}
Rect2 Light2D::_edit_get_rect() const {
-
if (texture.is_null())
- return Rect2(0, 0, 1, 1);
-
- Size2i s;
-
- s = texture->get_size() * _scale;
- Point2i ofs = texture_offset;
- ofs -= s / 2;
-
- if (s == Size2(0, 0))
- s = Size2(1, 1);
+ return Node2D::_edit_get_rect();
- return Rect2(ofs, s);
+ Size2 s = texture->get_size() * _scale;
+ return Rect2(texture_offset - s / 2.0, s);
}
void Light2D::_update_light_visibility() {
@@ -131,6 +132,7 @@ void Light2D::set_texture_offset(const Vector2 &p_offset) {
texture_offset = p_offset;
VS::get_singleton()->canvas_light_set_texture_offset(canvas_light, texture_offset);
item_rect_changed();
+ _change_notify("offset");
}
Vector2 Light2D::get_texture_offset() const {
diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h
index b216ad5e95..16d8c485d4 100644
--- a/scene/2d/light_2d.h
+++ b/scene/2d/light_2d.h
@@ -85,6 +85,9 @@ protected:
static void _bind_methods();
public:
+ virtual Dictionary _edit_get_state() const;
+ virtual void _edit_set_state(const Dictionary &p_state);
+
virtual void _edit_set_pivot(const Point2 &p_pivot);
virtual Point2 _edit_get_pivot() const;
virtual bool _edit_use_pivot() const;
diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp
index 95a1cbfce3..95e24505be 100644
--- a/scene/2d/node_2d.cpp
+++ b/scene/2d/node_2d.cpp
@@ -46,10 +46,9 @@ Dictionary Node2D::_edit_get_state() const {
}
void Node2D::_edit_set_state(const Dictionary &p_state) {
- Dictionary state = p_state;
- pos = state["position"];
- angle = state["rotation"];
- _scale = state["scale"];
+ pos = p_state["position"];
+ angle = p_state["rotation"];
+ _scale = p_state["scale"];
_update_transform();
_change_notify("rotation");
@@ -60,6 +59,8 @@ void Node2D::_edit_set_state(const Dictionary &p_state) {
void Node2D::_edit_set_position(const Point2 &p_position) {
pos = p_position;
+ _update_transform();
+ _change_notify("position");
}
Point2 Node2D::_edit_get_position() const {
diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp
index f6cb796b10..e63dc4e515 100644
--- a/scene/2d/polygon_2d.cpp
+++ b/scene/2d/polygon_2d.cpp
@@ -31,8 +31,31 @@
#include "polygon_2d.h"
#include "core/math/geometry.h"
-Rect2 Polygon2D::_edit_get_rect() const {
+Dictionary Polygon2D::_edit_get_state() const {
+ Dictionary state = Node2D::_edit_get_state();
+ state["offset"] = offset;
+ return state;
+}
+
+void Polygon2D::_edit_set_state(const Dictionary &p_state) {
+ Node2D::_edit_set_state(p_state);
+ set_offset(p_state["offset"]);
+}
+
+void Polygon2D::_edit_set_pivot(const Point2 &p_pivot) {
+ set_position(get_transform().xform(p_pivot));
+ set_offset(get_offset() - p_pivot);
+}
+
+Point2 Polygon2D::_edit_get_pivot() const {
+ return Vector2();
+}
+
+bool Polygon2D::_edit_use_pivot() const {
+ return true;
+}
+Rect2 Polygon2D::_edit_get_rect() const {
if (rect_cache_dirty) {
int l = polygon.size();
PoolVector<Vector2>::Read r = polygon.read();
@@ -52,21 +75,7 @@ Rect2 Polygon2D::_edit_get_rect() const {
bool Polygon2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
- return Geometry::is_point_in_polygon(p_point, Variant(polygon));
-}
-
-void Polygon2D::_edit_set_pivot(const Point2 &p_pivot) {
-
- set_offset(p_pivot);
-}
-
-Point2 Polygon2D::_edit_get_pivot() const {
-
- return get_offset();
-}
-bool Polygon2D::_edit_use_pivot() const {
-
- return true;
+ return Geometry::is_point_in_polygon(p_point - get_offset(), Variant(polygon));
}
void Polygon2D::_notification(int p_what) {
@@ -324,6 +333,7 @@ void Polygon2D::set_offset(const Vector2 &p_offset) {
offset = p_offset;
rect_cache_dirty = true;
update();
+ _change_notify("offset");
}
Vector2 Polygon2D::get_offset() const {
diff --git a/scene/2d/polygon_2d.h b/scene/2d/polygon_2d.h
index f62c78c55b..66f44cb3f1 100644
--- a/scene/2d/polygon_2d.h
+++ b/scene/2d/polygon_2d.h
@@ -59,6 +59,16 @@ protected:
static void _bind_methods();
public:
+ virtual Dictionary _edit_get_state() const;
+ virtual void _edit_set_state(const Dictionary &p_state);
+
+ virtual void _edit_set_pivot(const Point2 &p_pivot);
+ virtual Point2 _edit_get_pivot() const;
+ virtual bool _edit_use_pivot() const;
+ virtual Rect2 _edit_get_rect() const;
+
+ virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const;
+
void set_polygon(const PoolVector<Vector2> &p_polygon);
PoolVector<Vector2> get_polygon() const;
@@ -98,15 +108,6 @@ public:
void set_offset(const Vector2 &p_offset);
Vector2 get_offset() const;
- //editor stuff
-
- virtual void _edit_set_pivot(const Point2 &p_pivot);
- virtual Point2 _edit_get_pivot() const;
- virtual bool _edit_use_pivot() const;
-
- virtual Rect2 _edit_get_rect() const;
- virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const;
-
Polygon2D();
};
diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp
index 9c344b9581..17ca066fc0 100644
--- a/scene/2d/sprite.cpp
+++ b/scene/2d/sprite.cpp
@@ -34,17 +34,27 @@
#include "scene/main/viewport.h"
#include "scene/scene_string_names.h"
-void Sprite::_edit_set_pivot(const Point2 &p_pivot) {
+Dictionary Sprite::_edit_get_state() const {
+ Dictionary state = Node2D::_edit_get_state();
+ state["offset"] = offset;
+ return state;
+}
- set_offset(p_pivot);
+void Sprite::_edit_set_state(const Dictionary &p_state) {
+ Node2D::_edit_set_state(p_state);
+ set_offset(p_state["offset"]);
}
-Point2 Sprite::_edit_get_pivot() const {
+void Sprite::_edit_set_pivot(const Point2 &p_pivot) {
+ set_offset(get_offset() - p_pivot);
+ set_position(get_transform().xform(p_pivot));
+}
- return get_offset();
+Point2 Sprite::_edit_get_pivot() const {
+ return Vector2();
}
-bool Sprite::_edit_use_pivot() const {
+bool Sprite::_edit_use_pivot() const {
return true;
}
diff --git a/scene/2d/sprite.h b/scene/2d/sprite.h
index 261165bbf9..0422e0635f 100644
--- a/scene/2d/sprite.h
+++ b/scene/2d/sprite.h
@@ -65,6 +65,9 @@ protected:
virtual void _validate_property(PropertyInfo &property) const;
public:
+ virtual Dictionary _edit_get_state() const;
+ virtual void _edit_set_state(const Dictionary &p_state);
+
virtual void _edit_set_pivot(const Point2 &p_pivot);
virtual Point2 _edit_get_pivot() const;
virtual bool _edit_use_pivot() const;