tooltip for vector drawn shape within canvas

Windows specific forum
ehowington
Enthusiast
Enthusiast
Posts: 117
Joined: Sat Sep 12, 2009 3:06 pm

tooltip for vector drawn shape within canvas

Post 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?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: tooltip for vector drawn shape within canvas

Post 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.
BERESHEIT
ehowington
Enthusiast
Enthusiast
Posts: 117
Joined: Sat Sep 12, 2009 3:06 pm

Re: tooltip for vector drawn shape within canvas

Post by ehowington »

seems interesting thou im going to have play with how to produce a tooltip on this lib
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Re: tooltip for vector drawn shape within canvas

Post 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.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: tooltip for vector drawn shape within canvas

Post 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?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Re: tooltip for vector drawn shape within canvas

Post 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!
Post Reply