Frage

I'm creating some kind of drawings/flowchart/UML-diagram like tool with GWT Canvas (Java). For hit-detection of my drawings I could imagine 3 different strategies, but I do not know which would work best for my goal.

  • Just keep track of all Shape coordinates and iterate all objects on mouseclick
  • draw all objects on a ghost-canvas on mouseclick, and use isPointInPath() after every object drawing
  • using a ghost-canvas and draw each object with its own color (like #000001, #000002), and keep reference of them in a Map. Then just detecting the mouseclick on the ghost-canvas and get the object belonging to the pixelcolor under mouse

What would you prefer, and why?

War es hilfreich?

Lösung

i think first aproach is best, very likly you will keep reference to shape (ie in case when you want to move or resize displayed object), so all what you need to do is implementing extra method boolean isIn(Point mouseclick,Shape shape) (because implementation of if might be different for each type of object, will be better if you place it on your Shape)

i'm not sure how you want your ghostcanvas work, but imho drawing anything extra sounds like huge waste of resources.

your third strategy will require grab raw pixel from image/canvas which might be expensive operation

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top