summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-05-03 11:10:28 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-05-03 11:10:28 -0300
commitc7e8def44696da9ddf0b459e166280668c84c4cb (patch)
treebf5ef33775916aa1c817e38715375bf231800275 /scene/gui
parent5bb7cef8367e77c70b9a1ad045741fb97b32ef9d (diff)
Add ability to send drag events to another object
will be documented/tested later
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/control.cpp36
-rw-r--r--scene/gui/control.h2
-rw-r--r--scene/gui/item_list.h1
3 files changed, 38 insertions, 1 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 2912dcb3ae..86ec31a9c2 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -652,8 +652,24 @@ bool Control::has_point(const Point2& p_point) const {
return Rect2( Point2(), get_size() ).has_point(p_point);
}
+void Control::set_drag_forwarding(Control* p_target) {
+
+ if (p_target)
+ data.drag_owner=p_target->get_instance_ID();
+ else
+ data.drag_owner=0;
+}
+
Variant Control::get_drag_data(const Point2& p_point) {
+ if (data.drag_owner) {
+ Object *obj = ObjectDB::get_instance(data.drag_owner);
+ if (obj) {
+ Control *c = obj->cast_to<Control>();
+ return c->call("get_drag_data_fw",p_point,this);
+ }
+ }
+
if (get_script_instance()) {
Variant v=p_point;
const Variant *p=&v;
@@ -669,6 +685,14 @@ Variant Control::get_drag_data(const Point2& p_point) {
bool Control::can_drop_data(const Point2& p_point,const Variant& p_data) const {
+ if (data.drag_owner) {
+ Object *obj = ObjectDB::get_instance(data.drag_owner);
+ if (obj) {
+ Control *c = obj->cast_to<Control>();
+ return c->call("can_drop_data_fw",p_point,p_data,this);
+ }
+ }
+
if (get_script_instance()) {
Variant v=p_point;
const Variant *p[2]={&v,&p_data};
@@ -683,6 +707,15 @@ bool Control::can_drop_data(const Point2& p_point,const Variant& p_data) const {
}
void Control::drop_data(const Point2& p_point,const Variant& p_data){
+ if (data.drag_owner) {
+ Object *obj = ObjectDB::get_instance(data.drag_owner);
+ if (obj) {
+ Control *c = obj->cast_to<Control>();
+ c->call("drop_data_fw",p_point,p_data,this);
+ return;
+ }
+ }
+
if (get_script_instance()) {
Variant v=p_point;
const Variant *p[2]={&v,&p_data};
@@ -711,7 +744,6 @@ void Control::set_drag_preview(Control *p_control) {
-
bool Control::is_window_modal_on_top() const {
if (!is_inside_tree())
@@ -2273,6 +2305,7 @@ void Control::_bind_methods() {
ObjectTypeDB::bind_method(_MD("grab_click_focus"),&Control::grab_click_focus);
+ ObjectTypeDB::bind_method(_MD("set_drag_forwarding;","target:Control"),&Control::set_drag_forwarding);
ObjectTypeDB::bind_method(_MD("set_drag_preview","control:Control"),&Control::set_drag_preview);
ObjectTypeDB::bind_method(_MD("warp_mouse","to_pos"),&Control::warp_mouse);
@@ -2380,6 +2413,7 @@ Control::Control() {
data.rotation=0;
data.parent_canvas_item=NULL;
data.scale=Vector2(1,1);
+ data.drag_owner=0;
for (int i=0;i<4;i++) {
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 1e2db7a575..aa9a7612a5 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -129,6 +129,7 @@ private:
bool stop_mouse;
Control *parent;
+ ObjectID drag_owner;
bool modal;
bool modal_exclusive;
Ref<Theme> theme;
@@ -229,6 +230,7 @@ public:
virtual Size2 get_combined_minimum_size() const;
virtual bool has_point(const Point2& p_point) const;
virtual bool clips_input() const;
+ virtual void set_drag_forwarding(Control* p_target);
virtual Variant get_drag_data(const Point2& p_point);
virtual bool can_drop_data(const Point2& p_point,const Variant& p_data) const;
virtual void drop_data(const Point2& p_point,const Variant& p_data);
diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h
index c9c575fd54..2c3f8a5a01 100644
--- a/scene/gui/item_list.h
+++ b/scene/gui/item_list.h
@@ -69,6 +69,7 @@ protected:
static void _bind_methods();
public:
+
void add_item(const String& p_item,const Ref<Texture>& p_texture=Ref<Texture>(),bool p_selectable=true);
void add_icon_item(const Ref<Texture>& p_item,bool p_selectable=true);