Page 1 of 1

tooltip for vector drawn shape within canvas

Posted: Fri Dec 02, 2011 6:15 pm
by ehowington
I was curious if it's possible to have a tool tip for items drawn within a canvas for example a circle that been drawn and when the mouse is over that circle display a tool tip?

Re: tooltip for vector drawn shape within canvas

Posted: Fri Dec 02, 2011 6:50 pm
by netmaestro
The main thing you need for that is a way to mark off and test different-shaped regions in your canvas. Your very question occurring to me some time ago is in fact the principal reason I developed this: http://www.purebasic.fr/english/viewtop ... 12&t=46739 which provides the tool for the job.

Re: tooltip for vector drawn shape within canvas

Posted: Fri Dec 02, 2011 8:08 pm
by ehowington
seems interesting thou im going to have play with how to produce a tooltip on this lib

Re: tooltip for vector drawn shape within canvas

Posted: Thu Dec 15, 2011 11:23 am
by RichardL
The following nasty solution could be considered bad practice, but it got me out of a hole when a solution was needed … “NOW”. It also fails / gets complex if you have lots of colours and / or complex drawings. I used it when the vectors were black and I wanted to distinguish between one of five pixel wide graph lines.

Simply take advantage of the eyes inability to see very small colour differences and plot each feature in a slightly different colour, it only need have a difference of 1 on R or G or B. You can then read the colour at mouse Point(x,y) , consult a table and find out which artefact you are over.

As I said not nice, but it works.

Re: tooltip for vector drawn shape within canvas

Posted: Fri Dec 16, 2011 4:58 am
by IdeasVacuum
If you were coding a CAD app, then you might class each geometry element as an object, and keep a record of each object (and their relationships), in a database. So, you would store all the info about the circle, including it's diameter, it's min-max boundary (a square in the case of a circle) location, line attributes etc, and indeed tool tip text. Things that need instant access, such as tooltips, would have a unique id of some sort and generally be pre-loaded in ram, as you might do with prompts too. I think I've said enough to inspire?

Re: tooltip for vector drawn shape within canvas

Posted: Fri Dec 16, 2011 9:37 am
by RichardL
Random thoughts… Another path to consider…

I assume drawing a tool tip is not the problem; the challenge is to find out what entities exist at a point identified by the mouse.

Memory is generally plentiful so you could make a two dimensional map equal in size to the display area and write the identity of the entity into it as you draw the entity. That way you have a list that can be accessed without needing to compute anything at read out time… so it is very fast solution.

A down side is that you probably need to handle multiple entities that overlap. If you have a small number of entities you could pack entity identifiers into the 16/32/64 bit variables that make the entity map. Sixteen entities could be packed into a map of Quads. This is slower to write but fast to read out.

A variation of the last idea is to use bit set and clear to flag, for example, 32 entities using map of Long values. (Or 64 entities with a map of Quads)

If you have a very large numbers of overlapping entities the look up map could contain pointers to lists that could allow any number of overlapping features at the same point. This may not be too heavy on memory if the display area is mainly empty; like a typical graph with several lines.

Anyway… it will soon be Xmas and there will be lots of holiday time to ponder the ultimate solution!