APS Excellence in Physics Education Award
November 2019

Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

How to get cursor coordinates in drag/click events in drawing panel? post and replies

Return to the How to get cursor coordinates in drag/click events in drawing panel? thread
Login to post to this thread

How do I get cursor coordinates due to drag event in a drawing panel? - August 19 at 10:24:PM
mrg_psu
9 Posts

Post title says it all, I'm trying to get coordinates for the cursor at the end of a drag (or directions to documentation or listings that will let me figure it out).

I'm trying to port an old EJS app of Paco's that I did some small mods to years ago called particles and walls.  In that Java app, there was access to Pos X and Pos Y, but that doesn't exist for the drawing panel.  I'm assuming it will be just a method call, but I can't figure out what that might be.


Replies to How do I get cursor coordinates due to drag event in a drawing panel?

Re: How do I get cursor coordinates due to drag event in a drawing panel? - August 19 10:55:PM
lookang Avatar
lookang
215 Posts

Dear Prof Michael, i have been using _info.point[0] for x coordinate and _info.point[1] for y coordinate. in addition,

// since EJSS added ability to zoom and pan

// x = Math.round(x) // does not work well

// the coordinates of the mouse is captured in EJSS as (xmouse,ymouse) = (_info.point[0] , _info.point[1] ) 

x = Math.round(_info.point[0])

my documentation

https://github.com/lookang/codesforejss/blob/master/OnDrag%20_info.point%5B0%5D%20_info.point%5B1%5D


OSP@SG blog
OSP@SG Digital Library


Re: How do I get cursor coordinates due to drag event in a drawing panel? - August 20 9:22:AM
mrg_psu
9 Posts

Thanks Loo Kang!

Your documentation page made it easy: in the OnDrag for the drawingPanel:

position = _view.drawingPanel.getInteraction().getInteractionPoint();

addWalls();

position[0] for x and position[1] for y works perfectly in the service function addWalls()

 



Re: How do I get cursor coordinates due to drag event in a drawing panel? - August 19 11:05:PM
lookang Avatar
lookang
215 Posts

another method is

//define position in variable page

//copy this into the any of the OnPress or OnDrag depending on what you need

// make sure the name of the plottingPanel is reference correctly, if you change the name, please edit accordingly

position = _view.plottingPanel.getInteraction().getInteractionPoint();

// position[0] = x coordinate of mouse clicked

//position[1] = y  coordinate of mouse clicked


OSP@SG blog
OSP@SG Digital Library


The OSP Network:
Open Source Physics - Tracker - EJS Modeling
Physlet Physics
Physlet Quantum Physics