LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I put a callback on a line draw on a canvas?

Solved!
Go to solution

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));

 

 

0 Kudos
Message 1 of 6
(4,732 Views)

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.

 

 

0 Kudos
Message 2 of 6
(4,729 Views)
Can you give me some code examples to make this...I have some ideeas but I don`t know that well LabWindows/CVI
0 Kudos
Message 3 of 6
(4,714 Views)

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.

0 Kudos
Message 4 of 6
(4,703 Views)
one alternative to a canvsa might be to use a xy graph: here you could define a graph cursor and easily read back its coordinates.
0 Kudos
Message 5 of 6
(4,683 Views)
Solution
Accepted by Annees

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 6
(4,678 Views)