From 33188605390566590beef2060469a3d24b72a8e0 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 20 Jun 2016 21:19:12 -0300 Subject: [PATCH] fix CanvasItem.get_global_transform() and CanvasItem.get_local_transform(), closes #4075 (cherry picked from commit fa0d1cd27cac45534097219b52a5b7ab08e1b917) --- core/image.cpp | 2 +- scene/2d/canvas_item.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/image.cpp b/core/image.cpp index bee1108de19..653d99b743f 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -1718,7 +1718,7 @@ Error Image::_decompress_bc() { int rofs=0; int wofs=0; - print_line("width: "+itos(wd)+" height: "+itos(ht)); + //print_line("width: "+itos(wd)+" height: "+itos(ht)); for(int i=0;i<=mm;i++) { diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 17e5503a2d7..f62cc7e665d 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -1020,11 +1020,14 @@ InputEvent CanvasItem::make_input_local(const InputEvent& p_event) const { Vector2 CanvasItem::get_global_mouse_pos() const { - return get_viewport_transform().affine_inverse().xform(Input::get_singleton()->get_mouse_pos()); + ERR_FAIL_COND_V(!get_viewport(),Vector2()); + return get_canvas_transform().affine_inverse().xform( get_viewport()->get_mouse_pos() ); } Vector2 CanvasItem::get_local_mouse_pos() const{ - return (get_viewport_transform() * get_global_transform()).affine_inverse().xform(Input::get_singleton()->get_mouse_pos()); + ERR_FAIL_COND_V(!get_viewport(),Vector2()); + + return get_global_transform().affine_inverse().xform( get_global_mouse_pos() ); }