Notifications
Clear all

[Closed] PickPoint and losing focus

I have a script that accepts user input via pickpoint:
-When the user LMB clicks, the fn saves where the user clicked, then calls itself.
-When the user RMB click, the fn calls another fn.
-When the user presses ESC, the fn cancels.

    This is all working just fine. [b] The exception is that if the user begins the script, and is in the middle of LMB clicking, but then decides that they want to select the move tool (or any other common task) without first pressing RMB or ESC, the fn breaks.[/b]  So, I'm referring to that process described as the 'function losing focus'.  (Only that fn in the script breaks, other fns work fine.)
    
    When the function loses focus, I think that the fn is still running, awaiting user input in the form of a LMB, RMB, or key press, but for some reason the fn isn't accepting them.  I tried to conceptually beat this problem by adding in a default to the case statement described below, but it didn't work.
p = pickpoint()
   case of
   (
   (p == undefined): ...
   (p == #escape): ...
   (p == #rightClick): ...
   (classOf p == Point3): ...
   default: ...
   )
          
Questions:
  1. What exactly is going on? My guess is probably wrong.
  2. Is there a way to ‘reset’ the fn to a working state? (Besides re-running the script)
    3. Can this be handled by a callback/handler/event listener/thingymajig?
  3. How would you solve this problem?
6 Replies

Ah, after having banged my head into the wall for a while on this, I don’t think there is a solution.
Or rather, the solution would be not to use pickpoint recursively.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

for me the solution is to use mouseTrack instead of pickPoint:


(
	fn mouseTracking msg ir obj faceNum shift ctrl alt =
	(
		format "%
" msg

		case msg of
		(
			#mouseAbort: ()
			#freeMove: ()
			#mousePoint: ()
			#mouseMove: ()
		)
		if msg == #mouseAbort then #abort else #continue 
	)
	act = mouseTrack trackCallback:mouseTracking
	format "act: %
" act
)

it gives me all that I need. Also it gives me ability to check the state of any external variable (or UI control state) to #abort or #continue the tracking.

You might be able to watch when the user switches to move or what have you, and if the function was still running/they didn’t escape or whatever, try calling that function again?

Dennis would definitely have a better idea on all of this though. I think he answered someones question regarding something similar with the user activating move and so forth, but I’m not sure it would be of help in this situation.

Hopefully he replies!

thanks DenisT! I’ll be digesting that code for a while!

Hey DenisT,

Is there an easy way to simulate the rubberband function of pickPoint() using your method?

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

global _points = #()
global _pmouse = undefined
unRegisterRedrawViewsCallback drawRubberband

fn drawRubberband = if _points.count > 0 and _pmouse != undefined do
(
	gw.setTransform (matrix3 1)

	local points = for p in _points collect (gw.transPoint p)
	append points (gw.transPoint _pmouse)

	gw.setcolor #line (color 200 200 200)
	for k=2 to points.count do gw.wPolyline #(points[k-1], points[k]) off
	
	gw.enlargeUpdateRect #whole
	gw.updateScreen()
)
fn mouseTracking msg ir obj faceNum shift ctrl alt =
(
	_pmouse = ir.pos
	case msg of
	(
		#mouseAbort: ()
		  #freeMove: if _points.count > 0 do completeRedraw()
		#mousePoint: append _points _pmouse
		 #mouseMove: if _points.count > 0 do completeRedraw()
	)
	if msg == #mouseAbort then #abort else #continue 
)
_points = #()
registerRedrawViewsCallback drawRubberband
act = mouseTrack trackCallback:mouseTracking snap:#3D
unRegisterRedrawViewsCallback drawRubberband
completeRedraw()
format "act:% numpoints:% points:%
" act _points.count _points

a fancy line style do yourself