added a function CanvasItem.get_item_and_children_rect() , fixes #4738

This commit is contained in:
Juan Linietsky 2016-06-13 21:37:04 -03:00
parent 26d63b5594
commit 4866713bc3
3 changed files with 25 additions and 3 deletions

View File

@ -1042,7 +1042,9 @@ void CanvasItem::_bind_methods() {
ObjectTypeDB::bind_method(_MD("edit_rotate","degrees"),&CanvasItem::edit_rotate); ObjectTypeDB::bind_method(_MD("edit_rotate","degrees"),&CanvasItem::edit_rotate);
ObjectTypeDB::bind_method(_MD("get_item_rect"),&CanvasItem::get_item_rect); ObjectTypeDB::bind_method(_MD("get_item_rect"),&CanvasItem::get_item_rect);
ObjectTypeDB::bind_method(_MD("get_item_and_children_rect"),&CanvasItem::get_item_and_children_rect);
//ObjectTypeDB::bind_method(_MD("get_transform"),&CanvasItem::get_transform); //ObjectTypeDB::bind_method(_MD("get_transform"),&CanvasItem::get_transform);
ObjectTypeDB::bind_method(_MD("get_canvas_item"),&CanvasItem::get_canvas_item); ObjectTypeDB::bind_method(_MD("get_canvas_item"),&CanvasItem::get_canvas_item);
ObjectTypeDB::bind_method(_MD("is_visible"),&CanvasItem::is_visible); ObjectTypeDB::bind_method(_MD("is_visible"),&CanvasItem::is_visible);
@ -1195,6 +1197,23 @@ int CanvasItem::get_canvas_layer() const {
return 0; return 0;
} }
Rect2 CanvasItem::get_item_and_children_rect() const {
Rect2 rect = get_item_rect();
for(int i=0;i<get_child_count();i++) {
CanvasItem *c=get_child(i)->cast_to<CanvasItem>();
if (c) {
Rect2 sir = c->get_transform().xform(c->get_item_and_children_rect());
rect = rect.merge(sir);
}
}
return rect;
}
CanvasItem::CanvasItem() : xform_change(this) { CanvasItem::CanvasItem() : xform_change(this) {

View File

@ -240,6 +240,8 @@ public:
virtual Matrix32 get_global_transform() const; virtual Matrix32 get_global_transform() const;
virtual Matrix32 get_global_transform_with_canvas() const; virtual Matrix32 get_global_transform_with_canvas() const;
Rect2 get_item_and_children_rect() const;
CanvasItem *get_toplevel() const; CanvasItem *get_toplevel() const;
_FORCE_INLINE_ RID get_canvas_item() const { return canvas_item; } _FORCE_INLINE_ RID get_canvas_item() const { return canvas_item; }

View File

@ -447,7 +447,7 @@ void Control::_notification(int p_notification) {
Node *parent=this; //meh Node *parent=this; //meh
Node *parent_control=NULL; Control *parent_control=NULL;
bool subwindow=false; bool subwindow=false;
while(parent) { while(parent) {
@ -463,8 +463,9 @@ void Control::_notification(int p_notification) {
break; break;
} }
if (parent->cast_to<Control>()) { parent_control=parent->cast_to<Control>();
parent_control=parent->cast_to<Control>();
if (parent_control) {
break; break;
} else if (ci) { } else if (ci) {