LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

change line color in picture control by mouse click

HI!
Is it possible to change the color of a simple line in a picture by a mousclick on a specific line if there are more lines?
0 Kudos
Message 1 of 4
(3,223 Views)
May be I am completely out of the line here, but I believe that a pict control is just a bitmap. So apart using image analysis tools, there is no way to know if the point where you clicked on was on a line, or on the background or on anything else.
A work around could be to store the lines coordinates (start xy, end xy) somewhere, then to calculate the distance between the mouse click position and the "stored" lines, decide wether the click is sufficiently close to the line or not, then redraw eventualy the line in another color.
That's an interesting programming challenge...
Any comment ?
Chilly Charly    (aka CC)
0 Kudos
Message 2 of 4
(3,223 Views)
Hi,

Well, first of all, the picture control is probably drawn as a bitmap, but
it's really more like an enhanced meta file. It consists of a number of
opcodes, with parameters. Under the hood it's just a string to which these
opcodes are concatenated.

Since the lines are probably drawn by the program, the program can "check"
on which line the user clicked, and then redraw the picture with a different
line color. In practice, this is a bit difficult with lines... It's easier
with squares, circles and ovals... this principle is called hit detection.
There are some vi's in the picture.llb in the vi.lib (e.g. PointInRect.vi).

For a line it is a bit more difficult. Perhaps another solution is more
convenient. You could draw the lines just like always. But
then you also
draw the line a bit thicker in a second picture control, and with a ID for a
color. When the displayed picture is clicked, lookup the color (the ID) of
the point that is clicked in the second (offscreen) picture. Then redraw the
displayed picture with the line in a different color.

The biggest challenge is to keep the program nice and tidy.

Regards,

Wiebe.







"chilly charly" wrote in message
news:506500000005000000F6D60100-1079395200000@exchange.ni.com...
> May be I am completely out of the line here, but I believe that a pict
> control is just a bitmap. So apart using image analysis tools, there
> is no way to know if the point where you clicked on was on a line, or
> on the background or on anything else.
> A work around could be to store the lines coordinates (start xy, end
> xy) somewhere, then to calculate the distance between the mouse click
> position and the "stored" lines, decide wether the click is
> sufficiently close to the line or not, th
en redraw eventualy the line
> in another color.
> That's an interesting programming challenge...
> Any comment ?
0 Kudos
Message 3 of 4
(3,223 Views)
"Wiebe@CARYA" wrote in message
news:4174cdc2@newsgroups....
> Hi,
>
> Well, first of all, the picture control is probably drawn as a bitmap, but
> it's really more like an enhanced meta file. It consists of a number of
> opcodes, with parameters. Under the hood it's just a string to which these
> opcodes are concatenated.
>
> Since the lines are probably drawn by the program, the program can "check"
> on which line the user clicked, and then redraw the picture with a
different
> line color. In practice, this is a bit difficult with lines... It's easier
> with squares, circles and ovals... this principle is called hit detection.
> There are some vi's in the picture.llb in the vi.lib (e.g.
PointInRect.vi).

This is of course exactly like Charly already explained...



> For a line it is a bit more difficult. Perhaps another solution is more
> convenient. You could draw the lines just like always. But then you also
> draw the line a bit thicker in a second picture control, and with a ID for
a
> color. When the displayed picture is clicked, lookup the color (the ID) of
> the point that is clicked in the second (offscreen) picture. Then redraw
the
> displayed picture with the line in a different color.
>
> The biggest challenge is to keep the program nice and tidy.
>
> Regards,
>
> Wiebe.
>
>
>
>
>
>
>
> "chilly charly" wrote in message
> news:506500000005000000F6D60100-1079395200000@exchange.ni.com...
> > May be I am completely out of the line here, but I believe that a pict
> > control is just a bitmap. So apart using image analysis tools, there
> > is no way to know if the point where you clicked on was on a line, or
> > on the background or on anything else.
> > A work around could be to store the lines coordinates (start xy, end
> > xy) somewhere, then to calculate the distance between the mouse click
> > position and the "stored" lines, decide wether the click is
> > sufficiently close to the line or not, then redraw eventualy the line
> > in another color.
> > That's an interesting programming challenge...
> > Any comment ?
>
>
0 Kudos
Message 4 of 4
(3,223 Views)