05-17-2010 07:45 AM
Can I put a callback on a line draw on a canvas? How can i do it? Some examples?
I want to click on the line and a panel to appear but I don`t know how to code this thing using a callback for the line.
My canvas:
Test_2 = NewCtrl (panelHandle, CTRL_CANVAS, "", o, 0);
Status = SetCtrlAttribute (panelHandle, Test_2, ATTR_HEIGHT, 693);
Status = SetCtrlAttribute (panelHandle, Test_2, ATTR_WIDTH, 693);
Status = SetCtrlAttribute (panelHandle, Test_2, ATTR_PICT_BGCOLOR, VAL_TRANSPARENT);
The line draw on the canvas:
Status = SetCtrlAttribute (panelHandle, Test_2, ATTR_PEN_WIDTH, 2);
Status = SetCtrlAttribute (panelHandle, Test_2, ATTR_PEN_COLOR, VAL_RED);
Status = CanvasDrawLine (panelHandle, Test_2, MakePoint(489,75), MakePoint (235, 620));
Solved! Go to Solution.
05-17-2010 07:55 AM
Hi,
my approach would be to read back the coordinates of the mouse cursor and compare it with the coordinates of your line...
the callback would be for the canvas control.
05-17-2010 02:07 PM
05-17-2010 02:34 PM
Well, first you should install a callback for your canvas control, second, write an event function as explained in your last thread: this callback function will give you the coordinates of the mouse click.
Then you will need to know the coordinates of your canvas control (upper left, lower left, upper right, lower right) and the range of values that make up the x and y range in order to translate your pixel coordinates of the canvas control into physical coordinates.
In the last step you will have to use your equation for the plotted line, insert the physical x value corresponding to the mouse coordinate, calculate the y value using your plot line equation to see if this values matches your physical value obtained from the transformed mouse cursor coordinates.
Also you should have a look at the canvas sample.
05-17-2010 11:43 PM
05-18-2010 01:56 AM
If you are using a canvas you can use GetRelativeMouseState to detect mouse position on the canvas. Take a look at canvas example (<cviSampleDir>\userint\canvas.prj), specifically ScratchPad () and DrawToCanvas () functions in which GetRelativeMouseState is used to permit free-hand drawing on the canvas.
The next step is to understand if the mouse is on the line: is the line drawn by hand from the user or is it programmatically drawn? In the second case I suppose you know the function that generates it so it is easy to check if the mouse is on the line or not.