I need an advice how to achieve the following functionality under Android:
I can imagine how to do this with SurfaceView
:
Vertex
class, which among other things, has an x,y coordinate representing where to draw the vertex. If your vertex was a png image of a circle, then the top-left x,y coordinates of the image are stored in the Vertex
class.List
, and iterate through and draw each vertex.Edge
class that contains the starting x,y and ending x,y coordinates.List
of Edge
s and draw the lines accordinglyIn order to detect when a user clicks on them, you should override the onTouch
method and check the event.rawX()
and event.rawY()
values to see if they match up to a Vertex or Edge class.
for a Vertex
class, you can check if x <= event.rawX <= x + image_width
and y <= event.rawY <= y + image_height
for an Edge
, you can check if the event.rawX, event.rawY
coordinates are found in the line formed by the two sets of coordinates you stored in the Edge
class.
I've used a similar method to draw a set of nodes in a game. I'm not so sure how to do the edges though - the method I outline would only work if they were straight and do not criss-cross.
I am sure there is a better way to do this using openGL, but I have not used openGL before.
Hopefully you can get some ideas out of this.