summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-01-23 23:12:08 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-01-23 23:12:41 -0300
commit3b019bf644f61aaa2eaf9276448d97fb6e6a868a (patch)
treed9ccb2ad27aedad99d9781be1d1030bd28baf661 /scene
parent2527566ca899e2ac9d8baa8b4e68a22bf7077f35 (diff)
Ability to delete, drag and drop audio buses!
Diffstat (limited to 'scene')
-rw-r--r--scene/main/viewport.cpp76
-rw-r--r--scene/main/viewport.h2
2 files changed, 69 insertions, 9 deletions
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 63c86c8e9d..989c048682 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -1796,6 +1796,42 @@ Control* Viewport::_gui_find_control_at_pos(CanvasItem* p_node,const Point2& p_g
return NULL;
}
+bool Viewport::_gui_drop(Control *p_at_control,Point2 p_at_pos,bool p_just_check) {
+
+
+ { //attempt grab, try parent controls too
+ CanvasItem *ci=p_at_control;
+ while(ci) {
+
+ Control *control = ci->cast_to<Control>();
+ if (control) {
+
+
+ if (control->can_drop_data(p_at_pos,gui.drag_data)) {
+ if (!p_just_check) {
+ control->drop_data(p_at_pos,gui.drag_data);
+ }
+
+ return true;
+ }
+
+ if (control->data.mouse_filter==Control::MOUSE_FILTER_STOP)
+ break;
+ }
+
+ p_at_pos = ci->get_transform().xform(p_at_pos);
+
+ if (ci->is_set_as_toplevel())
+ break;
+
+ ci=ci->get_parent_item();
+ }
+ }
+
+ return false;
+}
+
+
void Viewport::_gui_input_event(InputEvent p_event) {
@@ -1937,8 +1973,8 @@ void Viewport::_gui_input_event(InputEvent p_event) {
if (gui.drag_data.get_type()!=Variant::NIL && p_event.mouse_button.button_index==BUTTON_LEFT) {
//alternate drop use (when using force_drag(), as proposed by #5342
- if (gui.mouse_focus && gui.mouse_focus->can_drop_data(pos,gui.drag_data)) {
- gui.mouse_focus->drop_data(pos,gui.drag_data);
+ if (gui.mouse_focus) {
+ _gui_drop(gui.mouse_focus,pos,false);
}
gui.drag_data=Variant();
@@ -1965,9 +2001,9 @@ void Viewport::_gui_input_event(InputEvent p_event) {
if (gui.mouse_over) {
Size2 pos = mpos;
pos = gui.focus_inv_xform.xform(pos);
- if (gui.mouse_over->can_drop_data(pos,gui.drag_data)) {
- gui.mouse_over->drop_data(pos,gui.drag_data);
- }
+
+ _gui_drop(gui.mouse_over,pos,false);
+
}
if (gui.drag_preview && p_event.mouse_button.button_index==BUTTON_LEFT) {
@@ -2028,11 +2064,33 @@ void Viewport::_gui_input_event(InputEvent p_event) {
gui.drag_accum+=Point2(p_event.mouse_motion.relative_x,p_event.mouse_motion.relative_y);
float len = gui.drag_accum.length();
if (len>10) {
- gui.drag_data=gui.mouse_focus->get_drag_data(gui.focus_inv_xform.xform(mpos)-gui.drag_accum);
- if (gui.drag_data.get_type()!=Variant::NIL) {
- gui.mouse_focus=NULL;
+ { //attempt grab, try parent controls too
+ CanvasItem *ci=gui.mouse_focus;
+ while(ci) {
+
+ Control *control = ci->cast_to<Control>();
+ if (control) {
+
+ gui.drag_data=control->get_drag_data(control->get_global_transform_with_canvas().affine_inverse().xform(mpos)-gui.drag_accum);
+ if (gui.drag_data.get_type()!=Variant::NIL) {
+
+ gui.mouse_focus=NULL;
+ }
+
+ if (control->data.mouse_filter==Control::MOUSE_FILTER_STOP)
+ break;
+ }
+
+ if (ci->is_set_as_toplevel())
+ break;
+
+ ci=ci->get_parent_item();
+ }
}
+
+
+
gui.drag_attempted=true;
if (gui.drag_data.get_type()!=Variant::NIL) {
@@ -2159,7 +2217,7 @@ void Viewport::_gui_input_event(InputEvent p_event) {
if (gui.drag_data.get_type()!=Variant::NIL && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) {
- bool can_drop = over->can_drop_data(pos,gui.drag_data);
+ bool can_drop = _gui_drop(over,pos,true);
if (!can_drop) {
OS::get_singleton()->set_cursor_shape( OS::CURSOR_FORBIDDEN );
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 2831d177c9..59e34d5c62 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -306,6 +306,8 @@ friend class Control;
Vector2 _get_window_offset() const;
+ bool _gui_drop(Control *p_at_control,Point2 p_at_pos,bool p_just_check);
+
friend class Listener;
void _listener_transform_changed_notify();
void _listener_set(Listener* p_listener);