You paint into a canvas using its Context2D object (canvas.getContext2d()). 
It has a bunch of methods for still styles and shapes.

Since canvas is just something you paint on you can not attach a handler 
for each painted rectangle, a painted rectangle is just pixels. You need to 
attach a handler to the canvas itself and then use some math to figure out 
which painted shape has been clicked. To be able to do that you would need 
to store every painted shape in a data structure, e.g. for a rectangle 
store x,y and maybe z axis as well as width and height. To make a rectangle 
visible/invisible on click you also have to store the visibility 
information somewhere.

In graphics language the above data structure is called a scene graph which 
is a model that describes the scene you want to render. Once you have build 
up your scene graph you can render its information to a canvas. Based on 
user input you would modify the scene graph and then repaint it to the 
canvas again (either the whole graph or you would calculate which parts of 
the canvas need to be repainted based on the changes in the scene graph).

In short: I would use a library that allows you to build such a scene 
graph. From the top of my head I only know lienzo but I never used it.

https://github.com/ahome-it/lienzo-core


-- J.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Reply via email to