04-02-2010 02:30 PM
Hi,
I have a command button that should have the following action:
while pushed down, zoom a graph into a predefined region,
if released, zoom back
I do not want to use a toggle button.
What I did: on EVENT_LEFT_CLICK: SetAxisScalingMode to desired region, in case of EVENT_LEFT_CLICK_UP set scaling mode to original region.
Hence, as long as the user pushes the button, the graph is zoomed in, as desired.
Now, there is a little drawback: the user may (unwittingly) 'cheat' and, while pushing the button, move the mouse cursor away: in this case there will be no left_click_up event anymore... I tried using 'lost_focus' but this happens only much later, when a new control is clicked. And I tried EVENT_MOUSE_POINTER_MOVE, but this is not practical either: any shiver will zoom out.
Does anybody have a suggestion/trick to achieve the desired result?
Thanks!
Solved! Go to Solution.
04-02-2010 02:57 PM
Hey Wolfgang -
You could set a global flag in the EVENT_LEFT_CLICK of the button callback. Then in the EVENT_LEFT_CLICK_UP event of the panel callback, you could check if the global flag is set. If so, zoom out and clear the flag.
If the user moves completely off the panel, you'll be in trouble - otherwise it should work.
NickB
National Instruments
04-02-2010 03:08 PM
Hi Nick,
thanks - I was considering this approach, but because it does not fully solve the request, I was (and still am...) hoping for some other idea. Another (rejected) possibility could be to use timer ticks, but I didn't like it for the complexity involved. Hm...
04-05-2010 07:47 AM
04-05-2010 11:52 AM
Hi TStanley,
Thanks! Your suggestion is very similar to what NickB suggested? This approach maximizes the chances to catch the 'up' event for the panel is larger than the button; still it is not foolproof, the user could move the mouse off the panel and release the button only then...
04-05-2010 12:03 PM
04-06-2010 06:18 AM
Hi TStanley,
this indeed solved my problem. Thanks!
Btw, using this approach there is no need to check for lost focus - I found no possibility not to receive an EVENT_MOUSE_POINTER_MOVE event when leaving the Zoom button with the mouse.
Wolfgang
04-06-2010 06:26 AM
So, here comes the Postscriptum...
While the problem is solved, function-wise, there is an optical drawback; I don't know if it is caused by Windows or CVI - in any case I would ask NI to look at it and may be change the behavior...
If you push the button and leave the button with mouse cursor depressed, the button returns to its off position (not depressed); hovering around and then returning to the same button, still with the mouse cursor depressed, the button is depressed again, automatically. (It does not respond to a left click, because there is no additional click)
This does not happen if you start somewhere on the panel, click and move with the depressed mouse cursor onto the button: the button remains in its unclicked, not depressed state.
This is very depressing 🙂 But seriously, it is somewhat inconsistent, at least for the user.
Wolfgang
04-06-2010 08:26 AM
Wolfgang wrote:If you push the button and leave the button with mouse cursor depressed, the button returns to its off position (not depressed); hovering around and then returning to the same button, still with the mouse cursor depressed, the button is depressed again, automatically. (It does not respond to a left click, because there is no additional click)
This does not happen if you start somewhere on the panel, click and move with the depressed mouse cursor onto the button: the button remains in its unclicked, not depressed state.
Hi Wolfgang, this behaviour is consistent with every Windows application, not only within CVI: functions are launched when you release the buttons; while you keep the mouse button button pressed and move the pointer, the buttons on the screen operate as you have noted but with no function is launched (I suppose this is intended as a chance for the user to abandon a function: if you press a button on a panel, then move the mouse and release the mouse button no function is executed).
04-06-2010 08:41 AM - edited 04-06-2010 08:42 AM
Hi Roberto,
Thanks! I never played with the mouse cursor like this before... You are right, I just verified, this observation is typical Windows behavior.
However, in my case the intended behavior is different, trying to simulate a pushbutton: I zoom in when a left-click is received, and regularly zoom out if a mouse-up event is received: so there is no possibility for the user to 'cancel' the operation... just like a door bell: if you push the button, it starts making noise until you release the button.
Unfortunately, there is no such function in CVI.