From edc56fae1830047218d2d1d6538765ae02806d7e Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Fri, 23 Apr 2010 22:48:26 +0000 Subject: BGE Fix: [#19951] mouse over sensor is broken with letterboxing framing Tested with GameLogic.mouse.position and mouse over sensor. It should be working with other mouse sensor as well. If not, please help to test and report a bug. (couldn't test blenderplayer but it should be working there as well). (Benoit, this is the same patch that I sent you. I hope it's OOP enough. Looking forward to hear from you on that) I believe that this was the last "mouse" related bug we had reported. MouseLoook scripts should be working 100% in Blender/BGE 2.50 now \o/ --- .../BlenderRoutines/KX_BlenderCanvas.cpp | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp') diff --git a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp index ec6923e280e..b04e951028d 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp @@ -31,10 +31,13 @@ #include "stdio.h" -KX_BlenderCanvas::KX_BlenderCanvas(struct wmWindow *win, RAS_Rect &rect) : +KX_BlenderCanvas::KX_BlenderCanvas(struct wmWindow *win, RAS_Rect &rect, struct ARegion *ar) : m_win(win), m_frame_rect(rect) { + // area boundaries needed for mouse coordinates in Letterbox framing mode + m_area_left = ar->winrct.xmin; + m_area_top = ar->winrct.ymax; } KX_BlenderCanvas::~KX_BlenderCanvas() @@ -100,6 +103,30 @@ int KX_BlenderCanvas::GetHeight( return m_frame_rect.GetHeight(); } +int KX_BlenderCanvas::GetMouseX(int x) +{ + float left = GetWindowArea().GetLeft(); + return float(x - (left - m_area_left)); +} + +int KX_BlenderCanvas::GetMouseY(int y) +{ + float top = GetWindowArea().GetTop(); + return float(y - (m_area_top - top)); +} + +float KX_BlenderCanvas::GetMouseNormalizedX(int x) +{ + int can_x = GetMouseX(x); + return float(can_x)/this->GetWidth(); +} + +float KX_BlenderCanvas::GetMouseNormalizedY(int y) +{ + int can_y = GetMouseY(y); + return float(can_y)/this->GetHeight(); +} + RAS_Rect & KX_BlenderCanvas:: GetWindowArea( -- cgit v1.2.3