Publication date: 08/13/2020

Using the Mouse

Mouse activity is supported through two feedback functions. The Patch Editor.jsl sample script uses these functions to support the dragging and dropping of points. Part of that script, the call-back function for mouse activity, is explained below. To run the script, open PatchEditor.jsl in the Scene3D folder inside the JMP Sample Scripts folder.

topClick2d = Function( {x, y, m, k},
	dragfunc( x, boxhigh - y, m, 1, 2 );
	1;
);
frontClick2d = Function( {x, y, m, k},
	dragfunc( x, boxhigh - y, m, 1, 3 );
	1;
);
rightClick2d = Function( {x, y, m, k},
	dragfunc( x, boxhigh - y, m, 2, 3 );
	1;
);
 
Click3d = Function( {x, y, m, k, hitlist},
	If( m == 1,
		If( N Items( hitlist ) > 0,
			CurrentPoint = hitlist[1][3], /* first matrix in the list is the closest; 3rd element of matrix is ID*/
			CurrentPoint = 0
		);
		makePatch();
	);
	0; /* cares only about initial mouse down. return 1 if drag, release is needed, but then arcball does not happen. */
);
 
/* after one of the 3 Click2d functions figures out which axis of the model is represented by the screen X, Y, pass in to this common code */
dragfunc = Function( {x, y, m, ix, iy}, /* ix, iy are the index of the X, Y, or Z part of the coord in the points matrix */
	If( CurrentPoint > 0,
		points[CurrentPoint, ix] = (x / boxwide) * (orthoright - ortholeft) + ortholeft;
		points[CurrentPoint, iy] = (y / boxhigh) * (orthotop - orthobottom) + orthobottom;
		makepatch();
	)
);

When a 2-D function is called, the arguments are X, Y, M, K.

X and Y are the coordinates of the mouse.

M shows the state of the mouse and button. M=0 says that the mouse button is up. M=1 says that the button was just pressed. M=2 says that the button is down and the mouse is moving. M=3 says that the button was just released.

K is related to the keys Shift, Alt, and control. K=1 for the Shift key, K=2 for the Control (command) key, and K=3 for the Alt (Option) key.

The 3-D function is called similarly. The arguments are X, Y, M, K, hitlist, where hitlist is a list of matrices

[znear, zfar, id1, id2, id3, ...]

znear, zfar is the Z distance from the camera of the near and far edge of the object. The matrices are sorted from near to far by the midpoint of znear, zfar. The ids in the list are the pushname, loadname, and popname values you just put in the display list.

The drag functions use a return value to tell if mouse processing should continue. That is the trailing “1” you see in the functions. Anything else stops the mouse tracking. This is needed because the 2-D and 3-D functions do not run in parallel. You might want the 2-D to return 0 and the 3-D to return 1 so the tracking would happen in 3-D rather than 2-D.

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).
.