Name: Anonymous 2009-02-04 7:08
Quick question /prog/,
I'm trying to make a program where you can drag around a number of graphical shapes (basically bezier curves etc) in Java.
Java's 2D api has a method which returns true/false for hit-tests, but that would mean going through every shape and checking which are at the location you click, and then which is "in front" (i.e. the one you would be dragging).
My current solution is to essentially render 2 different images, the 1st which is displayed, and the 2nd which is used for the hit test. For this version, the colour in the second image at the clicked location is checked against a list of colours (shapes are painted with a single colour predefined during the initial render) which matches the colour to which shape. Essentially rendering twice cuts out the multiple hit-tests and "order" check.
This solution seems to be a little excessive, since I doubt there'll ever be enough objects to need all 32bits of "colour"-references supported this way.
Is there a way of "painting" an object reference to each co-ordinate in the same way you just colour in the pixels (through the 2D images api), or would I essentially have to reinvent the whole 2D api to support this secondary layer?
I'm trying to make a program where you can drag around a number of graphical shapes (basically bezier curves etc) in Java.
Java's 2D api has a method which returns true/false for hit-tests, but that would mean going through every shape and checking which are at the location you click, and then which is "in front" (i.e. the one you would be dragging).
My current solution is to essentially render 2 different images, the 1st which is displayed, and the 2nd which is used for the hit test. For this version, the colour in the second image at the clicked location is checked against a list of colours (shapes are painted with a single colour predefined during the initial render) which matches the colour to which shape. Essentially rendering twice cuts out the multiple hit-tests and "order" check.
This solution seems to be a little excessive, since I doubt there'll ever be enough objects to need all 32bits of "colour"-references supported this way.
Is there a way of "painting" an object reference to each co-ordinate in the same way you just colour in the pixels (through the 2D images api), or would I essentially have to reinvent the whole 2D api to support this secondary layer?