Clickable Paths

Problems with Canvas, OpenGL, etc...

Clickable Paths

Postby bern » Fri Dec 10, 2010 4:39 pm

Hi all,

Currently I am making use of the Graphics.Path class to draw lines on a map. The path is constructed based on LatLong coordinates that are converted to X and Y points so they can be drawn on the screen.

Now I am trying to make it possible to let the user click on the path that is drawn on the screen.When the user clicks on the screen the application loops through the paths that are drawn on the screen to check for an intersection.

Is there any (easy) way to check for an intersection with a rectangle and a path?

Currently I am trying to do this by creating a Region from the current path:

path.computeBounds(currentPathBounds, false);
clickablePath.computeBounds(currentClickablePathBounds, false);
Region pathBounderies = new Region((int)currentClickablePathBounds.left,(int)currentClickablePathBounds.top, (int)currentClickablePathBounds.right,(int)currentClickablePathBounds.bottom);

pathRegion = new Region();
pathRegionCreated = pathRegion.setPath(clickablePath, pathBounderies);


I check if the path intersects as follows:

RegionIterator ri = new RegionIterator(pathRegion);
Rect pixel = new Rect();

while(ri.next(pixel))
{
int centerX = pixel.centerX();
int centerY = pixel.centerY();

if (regionClicked.contains(centerX,centerY))
{
return true;
}
}

However, this seems to only work sometimes...
I am trying to solve this thing for a week now but I still havent figured out how to fix this.

Could anyone confirm that this is indeed the right/only way to do this? Or is my approach to this problem very wrong?
bern
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Nov 30, 2010 3:15 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 1 guest