android: draw outside of closed path instead of inside - android

I am drawing a filled polygon on a canvas in android.
canvas.drawPath(path,myPaint);
Now I want to do exactly the opposite: Fill the area outside of the polygon.
how can I tell the paint to fill the outer region - the region which is not covered by the polygon?

simply use
path.setFillType(FillType.INVERSE_EVEN_ODD);

This can be complicated or very simple.
The complicated way:
Create a path exactly like your polygon, except don't close it. The continue that path to the nearest wall. Draw around the walls. Close and fill. In code, this isn't too fun.
The simple way:
Color the canvas. Draw the polygon.
Good luck.

Related

osmdroid trying to display many polygons overlay

i need to overlay many (clickable) polygons on the map (over 5000), so the normal Polygon overlay is slow in performance.
My idea is to create a custom bitmap overlay, drawing on a bitmap canvas only polygons that are inside current bounding coordinates, ignoring all drawing for polygons outside.
Moreover i would to redraw the overlay only when the user has finished to zoom or panning, not during this operation, for performance reasons.
Can someone please point some help to me?
Thanks.
In your case, Bounding box test is a good solution when a lot of polygons are completely outside the viewbox.
You can subclass the Polygon, add a bounding box attribute, and override the draw method to first test if this bounding box is completely outside the viewbox.
No need to draw on a bitmap canvas.
Now, if the user zoom-out, he will have all polygons inside the viewbox: back to the initial issue... A solution could be to handle levels of details. Maybe using the DouglasPeucker reducer (available in OSMBonusPack utils).

Drawing and storing a user's touch path in libgdx

I'm struggling with something I would expect to be straight forward with libgdx.
In short this is a "finger paint" app where I want to draw a path of a certain width where the user touches the screen.
I've earlier done this by using a plain Android android.view.View. I had a android.graphics.Path in which I stored the coordinates of the user's current touch. In the onDraw() method of the view I drew the path to the android.graphics.Canvas. Whenever the user released a finger I drew the path to an offline canvas/android.graphics.Bitmap which also was drawn in the onDraw() method. Plain and simple.
How can that be done using libgdx?
I have tried using a com.badlogic.gdx.graphics.Pixmap that I can draw a line to whenever the user moves a finger. This works well except the fact that I'm unable to control the witdh of the line using Gdx.gl.glLineWidth(). I know I can draw a rectangle instead of a line to set the width, but Pixmap doesn't seem to have any means of rotating, so I don't see how this can be done.
I can use a com.badlogic.gdx.graphics.glutils.ShapeRenderer for drawing lines (or rectangles) in com.badlogic.gdx.Screen.render(). As far as I can see I then need to store every single touch point of the current touch, and then draw all lines on render. Whenever the user relases a finger I guess I can store the screen as-is with something like com.badlogic.gdx.utils.ScreenUtils.getFrameBufferPixmap(). Hopefully there is a easier way to achieve what I want.
I ended up drawing circles on a pixmap where the line should be:
One circle on touchDown
Several circles from last touch point to next touch point reported to touchDragged
I'm not very happy with this solution, but it kinda works.
Maybe you can calculate line dot coordinates manually and use triangles to draw them on pixmap? Like use 2 triangles to form (rotated) box?

draw canvas 3d rectangle

I Have extended View class and override draw method. In draw method I draw rectangle using canvas. but this rectangle is simple I need to show as blow. how can I draw rectangle like shown in below image?
create a Path for the top side using 4 points (moveTo and lineTo) and then draw it with Canvas.drawPath. Do the same for the right side
Here is the link for the HoloGraphLibrary. Just check it.
It has no 3d effect as you want but it has Same ui as you want. You will have to play little to have effect like 3d rectangle.
Try a look and let me know if it do not help you.
Enjoy Coding and All The Best. :)

What's the best way to do collision detection?

I have a need to define a polygon that would be the "legal" area, and allow a user to move a rectangle around within that polygon, preventing them from moving the rectangle anywhere where its points venture outside the polygon.
The polygon is a fixed shape, so, I was thinking it may be easiest to import a PNG of that shape and pull the points in that way, somehow? But I'm still at a loss as to the math involved in checking the coordinates of the rectangle as the user drags it, and testing at what point they have moved the shape to the edge of the bounding polygon.
Unfortunately the bounding polygon is a fairly complex shape. I'm hoping someone can point me at a tutorial that shows what the best way to run such a collision detection is.
Metanet's excellent collision detection tutorial has a good section on how to do swept collision with axis-aligned bounding boxes (AABB) and arbitrary "walls."
If your polygon is concave, you'll probably find it easiest to first decompose it into multiple convex polygons, which will simplify the available collision detection algorithms.
If you only looking to check the corners of the rectangle, you can do a "inside" test for each of them.
http://en.wikipedia.org/wiki/Point_in_polygon
And if you also want to make sure that no pointy part of the polygon "punctures" your rectangle you could do a test for each of the 4 lines in the rectangle against all the lines in the polygon to see if they are intersecting.
http://en.wikipedia.org/wiki/Line-line_intersection

Draw a Circle With Reverse Filling in Android

Not sure how to do this, or what the right terms are for describing this, but here goes:
I want to make a closing circle animation in my android app, much like the end of this video. I'm guessing what I need to do is somehow draw a black circle but instead of filling the inside of the circle fill the outside. How exactly would I do that, given the tools I have with Android's Canvas class?
Have you tried using clipPath to achieve this?
I was working on the same kind of thing and achieved it by using clipPath of canvas.

Categories

Resources