-Some fixes to drag and drop and canvas offset for GUI that were introduced after rewrite

This commit is contained in:
Juan Linietsky 2016-01-19 20:27:27 -03:00
parent d67df42cc8
commit 891e31b139
4 changed files with 32 additions and 10 deletions

View file

@ -606,14 +606,14 @@ void Control::force_drag(const Variant& p_data,Control *p_control) {
ERR_FAIL_COND(!is_inside_tree());
ERR_FAIL_COND(p_data.get_type()==Variant::NIL);
get_viewport()->_gui_force_drag(p_data,p_control);
get_viewport()->_gui_force_drag(this,p_data,p_control);
}
void Control::set_drag_preview(Control *p_control) {
ERR_FAIL_COND(!is_inside_tree());
get_viewport()->_gui_set_drag_preview(p_control);
get_viewport()->_gui_set_drag_preview(this,p_control);
}
@ -2046,6 +2046,26 @@ Vector2 Control::get_scale() const{
return data.scale;
}
Control *Control::get_root_parent_control() const {
const CanvasItem *ci=this;
const Control *root=this;
while(ci) {
const Control *c = ci->cast_to<Control>();
if (c) {
root=c;
if (c->data.RI || c->data.MI || c->is_toplevel_control())
break;
}
ci=ci->get_parent_item();
}
return const_cast<Control*>(root);
}
void Control::_bind_methods() {

View file

@ -360,6 +360,8 @@ public:
virtual bool is_text_field() const;
Control *get_root_parent_control() const;
Control();
~Control();

View file

@ -1460,7 +1460,7 @@ Control* Viewport::_gui_find_control(const Point2& p_global) {
Matrix32 xform;
CanvasItem *pci = sw->get_parent_item();
if (pci)
xform=pci->get_global_transform();
xform=pci->get_global_transform_with_canvas();
Control *ret = _gui_find_control_at_pos(sw,p_global,xform,gui.focus_inv_xform);
@ -1477,7 +1477,7 @@ Control* Viewport::_gui_find_control(const Point2& p_global) {
Matrix32 xform;
CanvasItem *pci = sw->get_parent_item();
if (pci)
xform=pci->get_global_transform();
xform=pci->get_global_transform_with_canvas();
Control *ret = _gui_find_control_at_pos(sw,p_global,xform,gui.focus_inv_xform);
@ -1979,17 +1979,17 @@ void Viewport::_gui_remove_from_modal_stack(List<Control*>::Element *MI,ObjectID
}
}
void Viewport::_gui_force_drag(const Variant& p_data,Control *p_control) {
void Viewport::_gui_force_drag(Control *p_base, const Variant& p_data, Control *p_control) {
gui.drag_data=p_data;
gui.mouse_focus=NULL;
if (p_control) {
_gui_set_drag_preview(p_control);
_gui_set_drag_preview(p_base,p_control);
}
}
void Viewport::_gui_set_drag_preview(Control *p_control) {
void Viewport::_gui_set_drag_preview(Control *p_base, Control *p_control) {
ERR_FAIL_NULL(p_control);
ERR_FAIL_COND( !((Object*)p_control)->cast_to<Control>());
@ -2001,7 +2001,7 @@ void Viewport::_gui_set_drag_preview(Control *p_control) {
}
p_control->set_as_toplevel(true);
p_control->set_pos(gui.last_mouse_pos);
add_child(p_control); //add as child of viewport
p_base->get_root_parent_control()->add_child(p_control); //add as child of viewport
p_control->raise();
if (gui.drag_preview) {
memdelete( gui.drag_preview );

View file

@ -246,8 +246,8 @@ friend class Control;
void _gui_remove_control(Control *p_control);
void _gui_hid_control(Control *p_control);
void _gui_force_drag(const Variant& p_data,Control *p_control);
void _gui_set_drag_preview(Control *p_control);
void _gui_force_drag(Control *p_base,const Variant& p_data,Control *p_control);
void _gui_set_drag_preview(Control *p_base,Control *p_control);
bool _gui_is_modal_on_top(const Control* p_control);
List<Control*>::Element* _gui_show_modal(Control* p_control);