Getting mouse coordinates within a widget

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting mouse coordinates within a widget

loremipsum
Hi folks,

I'm trying to get the relative coordinates of a mouse event inside a widget. I've tried to use viewPortLeft/top, screenLeft/top and documentLeft/Top getters of the Mouse event class, but with no result. The given values seem to be relative to the screen, since when I click in the top-left corner of the widget (the instance which listens to its mouse events), I do not get {0, 0} coordinates as expected.

See this example : http://tinyurl.com/76qvzk6

When I click in the blue widget, I'd like to know where in the widget I clicked...

Thanks a lot, this drives me mad ^^
Reply | Threaded
Open this post in threaded view
|

Re: Getting mouse coordinates within a widget

Marc Puts
I use the following code:

var box = widget.getContainerLocation("box");
var mouseX = e.getDocumentLeft() - box.left
var mouseY = e.getDocumentTop() - box.top


Regards,
Marc




On 03/08/2012 02:14 PM, loremipsum wrote:

> Hi folks,
>
> I'm trying to get the relative coordinates of a mouse event inside a widget.
> I've tried to use viewPortLeft/top, screenLeft/top and documentLeft/Top
> getters of the Mouse event class, but with no result. The given values seem
> to be relative to the screen, since when I click in the top-left corner of
> the widget (the instance which listens to its mouse events), I do not get
> {0, 0} coordinates as expected.
>
> See this example : http://tinyurl.com/76qvzk6
>
> When I click in the blue widget, I'd like to know where in the widget I
> clicked...
>
> Thanks a lot, this drives me mad ^^
>
> --
> View this message in context: http://qooxdoo.678.n2.nabble.com/Getting-mouse-coordinates-within-a-widget-tp7354861p7354861.html
> Sent from the qooxdoo mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Virtualization&  Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Getting mouse coordinates within a widget

loremipsum
You are a lifesaver, buddy ! Thank you very much !

Here's what I'll use :

getMouseCoordinates: function(event) {
  var box = event.getTarget().getContainerLocation("box");
  return {x: event.getDocumentLeft() - box.left, y: event.getDocumentTop() - box.top};
}