Undo/Redo Stacks & Flood Fill

Yes, since you never look for anything in TinyDB.

That clear TinyDB block will just make trouble for you later if you store something else in TinyDB and wonder why it disappeared.

Third time's the charm.

It's always the corner cases that get you.

I started the stack index at 0, and should have started at 1, to match the first image on the stack taken at app startup.
blocks

Here's the sample, with a test run.


CanvasUndoRedo.aia (3.8 KB)
Sample run

I don't bother with TinyDB in my sample, because I am ony doing a single session.

If I were doing multiple sessions that I wanted to keep, I would need separate TinyDB tags for them, and I would need to keep their Undo stacks under those tags.

By the way, I made no provision for erasing those image files, because storage is cheap and life is short.

I do use the TinyDB on my later pages, for when I show the Quilt Block again, and when I TempSave and TempLoad. I took it off and tried the Undo, and the last 2 Fills got deleted again, like before. So, I refreshed the computer screen, and all was fine. So, now the only thing left is to figure out the Redo issue.

Ok, so I changed the UndoIndex to 1, and the Undo's are still working, but the Redo is now deleting everything on the 4rth Click. I wonder if it's because I am using that Extension??

For the Image Deletions.... I do have a Button that says "Delete All Temp Memory". It deletes the TinyDB memory. Do you think I can add a Canvas.Clear to that Button to clear the Images in Storage? ....NO, not Canvas.Clear... that just clears the Canvas.

That means nothing to me without seeing its Click event blocks.

Download the blocks for the Redo Event.

A Project Export aia file would help.

Look for the online book in

You are confusing various concepts

  • global variables
  • TinyDB
  • Canvas contents

Yes, I was confusing them. Ty for pointing that out so clearly.

I inserted your Redo Blocks into my project, clicked to fill 4 times, Clicked Undo 4 times, clicked Redo 4 times but, the 4rth Redo still clears the canvas. So, I changed the Redo If Statement to say > = 1, instead of > 0. And the 4rth
Redo kept the previous 3 fills in tact, but it still would not fill the 4rth area.

Use the Companion and Do It to show the contents of the image stack.

Look at the illegal file names you are generating for your saved image files.

Where is the .jpg file name suffix?

image

Also, where is the Screen.Initialize event where you capture the first image in the stack?

Lack of that would throw off the index (1 for an empty stack.)

Yes, I put that back. Not sure how it got deleted.

I don’t capture anything with the Screen.Initialize. I only capture when I start touching the Canvas. Here is my Screen.Initalize event.

You need to capture one image before your first touch event, otherwise the bottom of your image stack won't have a total Undo image.

When you say “capture one image”, I am not sure what you mean. The Pinwheel Block Image is set as a Background Image on the Canvas (this was set on the Designer Tab).

But, that same Pinwheel image is also set as the background image in the Screen.Initialize event. Could this double setting of an image cause issues with the Stack?

Canvas SaveAs in combination with adding the resulting file name to the stack.

I added the SaveAs and file name to the Initialize event. But now, the Undo deletes the 4rth and 3rd fills at once.

The Undo Click event does not change the contents of the stack.
My only guess is that the extension's flood fill is not reflected in the image files saved in the stack.

For debugging, try adding a List Picker whose Elements are loaded from the stack, and when selected, they are loaded into the Canvas Background for display.

I don't support extensions.

The sample app I supplied works okay without extensions,

Ty, I don’t know how to use a List Picker yet. I am going to sleep now, so I will check back here tomorrow. Ty again for all your help.

I just realized that if I click Undo, and then try to refill the area, the color does not fill completely, and the Outlines get distorted, just as they did when I used the Undo that came with the Extended Canvas extension. So, you may be right about that extension not supporting the image files saved in the stack. If this is true, is there any other way to do Flood Fill on these Quilt Blocks using the built-in tools? (I will check back tomorrow.)

Switch to a list of polygons and use the canvas polygons blocks.

Select the polygon using a slider ranging over the list indexes of the polygons.

Highlight the current polygon the same way the AI2 blocks editor highlights a block, with a yellow border.

Knowing which polygon to fill makes it a trivial redraw.