How to add undo/redo feature into android drawing app? - android

I want to add undo & redo feature to the finger paint, does anyone got ideas?
it is suitable to use in finger paint of android API demos.

You want to record your drawing steps, such as using an array of Paths every time a new path is drawn. When the undo button is pressed, you decrease your "draw counter" by one and redraw all the paths up to your "draw counter". When you redo, increase your "draw counter" by one and redraw all the paths up to the counter (or end of the array, naturally!). And after undoing and then drawing anew, remove the later entries from the draw array.

Related

Draw a line on top of entire layout in Android?

I am drag and dropping an ImageView on to another ImageView.
I am following this http://developer.android.com/guide/topics/ui/drag-drop.html
While I can display a drag shadow and change drop targets with different colors and drawables. I am happy with the article.
But I am looking for a little bit more. I am looking to draw a straight line between my drag shadow and the source. I want this line to be straight and update it's length and direction as I drag the item around. When I finally drop the item in my drop zone I want the line to stay permanently (unless I remove it later).
Like this:
Drag without line, this is my current situation
Drag with a line following, this is what I want
I should also mention that I want to do this with multiple sources and single target (maybe multiple target in future).
Here is the code that I am working on https://github.com/ishanatmuz/HelloDrag
I think you will need to override onDraw( Canvas ) and then when you are dragging call a routine to draw your line.
When you are not dragging draw the lines between the boxes.
both routines as sub-routines of onDraw
If you do this don't forget to call super.onDraw( Canvas ).

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?

Redraw On Touch

Hello All,
I have erased an image using mPaint.setXfermode(new PorterDuffXfermode(Mode.DST_OUT)); on touch events, now I want to undo this drawing (basically removing the path which were drawn earlier) on touch events. I don't want to draw the whole path at once instead clear the path point wise as finger move above these paths. I have stored all tha paths in an array list. Any Idea how can I do this. I'm able to remove the whole path but not point wise redrawing.

Android Paint. 2 canvas?

I let my user draw geometries on it. So I store all the data(ie. coordinates) required for each geometries(ie. line, triangle, quads, etc). Now, I'm implementing a paint/brush on it which I don't care about all the points that was inputted. My problem is I need to call canvas.drawColor(Color.WHITE); every time the user modify the geometry resulting to clearing also the paint which is gone now and I don't have access to.
Is there any way to actually separate the two in two canvas and combining it later? I mean, the paint is directly draw on one canvas and the geometry on other canvas and combine it.
Yout can set the backgroundcolor of your View to White.
mView.setBackgroundColor(Color.WHITE);
This way you dont need to use
canvas.drawColor(Color.WHITE);
Check out TouchPaint.java in the API demos included in the Android SDK, for an example of how you can do what you want to do.

Antialiasing and updating a path lead to thicker lines than expected

The problem is pretty complicated to explain but here goes:
I'm making a paint program that draws paths onto a canvas with textured background. Each stroke is stored as a path that updates as the user moves the stylus across the screen. When the path is updated I call drawpath on the canvas. The problem is that on each move event, the path is drawn over the existing line on the canvas, so the antialiasing on it darkens the existing line and make it appear thicker and jaggier than expected.
I had a solution where I store the older canvas (the one without the active path) and keep another transparent canvas on top of that. I would clear the top canvas and redraw the path on each move event, and then draw both canvases together. BUT that makes the program so slow that the paths look terrible - you can tell the drawing is lagging way behind the stylus movements.
Is there any way to make either A) drawing / clearing multiple canvases faster or B) make antialiasing not mess up on multiple redraws?
Figured out.
It was so simple I can't believe I got stuck on it.
The "canvas" used in onDraw() is automatically erased every time, so I just called canvas.drawPath() with the currently updating path in the onDraw() function, at no extra cost.

Categories

Resources