Undo/Redo Stacks & Flood Fill

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.

Ty. That does seem a bit too advanced for me. I did change the .jpg to .png, hoping that would make my redraws cleaner. It helped slightly. I also put in several “emptying” blocks for the global UndoIndex and ImageStack. I put these in places like my Reset Buttons, or changing Screens. It seems that things are working ok except for that last Redo. But, I can accept that, given my novice level with this software.

In this current arrangement:

  • I had to add the “BeforeUndoState” so that the app would undo/redo if I only clicked once on the Canvas.
  • I had to remove the “Add Items to List” on the initialize event, because it seemed to increase my UndoIndex incorrectly.
    • This was whether I initialized the UndoIndex at 0 or at 1. So, I removed it and set my UndoIndex to initialize at 0.
  • But, If I click say, 4 clicks… then hit undo, it will remove 2 areas at once.
    • But, if I click undo again, it will remove only 1 area at a time.
    • And if i click 4 clicks again, then click Undo, it will remove 1 area at a time.
    • And if I click redo once, it fills 3 areas at once.
    • So, it is very erratic.
  • I am thinking that my issue lies in my indexes, but I can’t figure it out. ABG has gotten me this far, and I am so appreciative. Does anyone have any suggestions about my indexes?

Here is a Video of how it is behaving: https://youtu.be/PD2N-htjEbA

When you Undo and Redo, you are reloading the background image of the Canvas from a list of file names traversed by the Undo and Redo buttons.

There is no actual flood fill action happening during Undo and Redo.

So the question is: Is the stack of image files truly reflecting the actions that filled it?

That can be confirmed independently, using a List Picker whose Elements are loaded from the Undo stack, and whose selection action is to display the selected image file.

From your description, it sounds like either the Canvas SaveAs operation is missing results of flood fills, or is not adding images to the Undo stack..

Diagnosing this requires going through the Undo stack and examining the images, one after another.