Wow braynee tried to make undo/redo & it don't work! shocker

wow, it’s the epic sequel to “art pad 2.3 worksn’t”! yay

i am not currently trying to integrate undo/redo into my art pad yet. i am trying to code undo/redo on its own, then add it to my art pad when i get undo/redo to work! so far i have not started the renderer thingy [whatever it is that redraws the thing after you use undo or redo], just make it work internally [list of points & whatnot], before i try to use it to render stuff.

current version is here:

since all i have right now is trying to work internally, here is an explanation of how it works internally:

strokes are saved as a list of points, encoded in a string. they’re encoded in 7 characters each. the first one is a comma, 2-4 is x position - 25[1], & 5-7 is y position. [packing zeros are added, of course] the variable they’re saved to is called “goigly”, because of course it is. whenever the screen stops being pressed, i add a slash [“/”] [2] to the end. this is to signify the end of a stroke. in order to remember how many points are in each stroke, i save the length of strokes [i.e., the number of points they have] to another listlike variable called “stroke lanks record”. this is the setup to internally navigating the “goigly” variable, so nothing gets tripped up by the extra character that is the slash, & ends up treating half of two encoded points as one point. stroke lengths are encoded as a comma followed by a number of points, with packing zeros added so that each encoded stroke in “stroke lanks record” is always 5 characters [3] the last layer of abstraction is that the number of strokes that have been drawn is also saved, as an integer variable called “full strokes”. this makes it easier to navigate “stroke lanks record” internally. these three variables [4] are meant to remember everything that has been drawn, so that i can add it back in by pressing “redo”. in order to track the stuff that, when i code the renderer, will actually be onscreen & not just in the memory, the three variables have “active” variants [5]. the original variables aren’t deleted from if i press “undo”, but the active ones are. “active goigly” tracks drawn points, “active stroke lanks record” tracks drawn strokes, & “active strokes” counts drawn strokes. i have a popup that tells you the current values of the three variables & their active variants, whenever you finish a stroke or use undo or redo.

one issue is that sometimes [just sometimes! augh], “stroke lanks record” would report there is one more point in a stroke than there are saved in that stroke in “goigly”. the other thing is that the “undo” button removes too much stuff off the end of “active goigly”, hence the project title above. i expect more problems will arise as this project continues to unfold, but hey, who ever said coding undo & redo was easy??

help


  1. i subtract 25 because this is on a stage size of 1,024 x 768. “1024” is four characters, but by subtracting 25, it can range from “-24” to “999”, which is always 3 ↩︎

  2. also known as a solidus! ↩︎

  3. for instance, if a stroke has 14 points in it, then “,0014” is added to the end of “stroke lanks record”. ↩︎

  4. “goigly”, “stroke lanks record”, & “full strokes” ↩︎

  5. i.e., what is actively onscreen ↩︎

9 Likes

[robbing first post by tradition]

10 Likes

Super weird…

I have made this a while ago: TEST_PAD (v0.4) by Crosbyman64

The positions are rounded to compensate for different mobile screens (to ensure the data doesn’t break). This should give you an idea of how the system knows when to stop drawing…

5 Likes

so like

i should just track the character index where everything after it is “undone” & everything before it is onscreen instead of creating a whole other variable & hoping they’re the same when i want them to be??

how did i not think of that

4 Likes

I guess so.

I too couldn’t get it to work the first time… and if I was using some form of character encoding, I could get the xy position down to only 4 characters instead of 8 (6 in your case).

How? I just need 40 characters, then I can do (number of letter 1 × 40) + number of letter 2 which would give me a range of 0 to 1599 (and the largest screen I have has a width of 1590.

For getting the number of the letters? I can just do some binary stuff (not the kind you’re thinking of, but the kind I used in my RGBA pixel engine).

4 Likes

i think my idea still works & i kind of want to see it through now

3 Likes

Ok. Good luck…

3 Likes

pfft fair

3 Likes

ill check whats up later/tmr but just a reminder to round the xy touch variables because they may show with decimals with a different size screen :))

7 Likes

No way lol i started to make undo/redo too
Its in my drafts rn
Not working yet but theres some progress

3 Likes

ah good catch

e:

7 Likes

hi it’s me! i’m back, here’s proof: “goigly”

also i tried to code the rendererererer thing, here’s proof:

since “undo” always deleted all of the active goigly i genuinely can’t tell if it works or not

2 Likes

I AM IN NEED OF THE HELPS :(

i want to tag someone who is smarter than me who can help me with my problems but who should i

3 Likes

@Crosbyman64 please help me

i can’t tell if i’m close to done or in for a world of pain
probably the latter ;-;

3 Likes

Let’s see if I’m able to break my little system down…

Creating the Stroke History

  • I use yellow variables, which I named “drawing”, to control when stuff is being added to the history.

  • If both and x and y positions are different from the previous, then it’s added to the history (x pos + y pos + -)

  • when the device is not pressed, it checks if “drawing” = 1. If it is (which means we just stopped drawing), then it replaces the last character with the end character (in my case, ;) ((chars in (history) between 0 and -1)+;) (and obviously “drawing” is reset to 0)

    • Why -1? It’s the same as ((length(history))-1)

When pressing UNDO?

  • The number of lines to draw is decreased by 1, lines drawn and last_idx are both reset to 0 (because it has to clear everything and draw the lines again to undo), then the redraw mode takes over

When pressing REDO?

  • The number of lines to draw is set to 1. That’s it. The, again, the redraw mode takes over.

What the goigly is REDRAW MODE?! (Sorry, I just had to say it)

  • When redraw mode is initiated (obviously, the normal drawing is disabled), the drawing is repeated times the number of lines to draw.

  • for each loop, we scan through the history for either a property change or line draw. If it’s the first, then we set the properties and go further into the scan. But if it’s the latter, then we set our starting position to the first position data.

  • This is where we go into draw from (history) idx (idx)

    • inside the draw trail block, we set the position (exactly like the initial position), then we check if the ending character at idx is the lines connected character (- in my case). If so, then we continue doing draw from (history).. but we also increment idx (9 in my case). Otherwise, we set last_idx to idx + 9, and increase lines drawn by 1. This is where both the draw from and scan history custom blocks end
  • After the loops end, lines to draw is set to lines drawn, the normal drawing is reenabled, and our pen settings are restored to the way we had them.


Now, that’s a lot! Even I’m confused by this, lol…

The redraw and stroke history stuff are all done by the pen itself. And the undo and redo buttons just control how many lines the redraw mode needs to draw.

5 Likes

Hehe i finished mine before you braynee i am better- /j
It only has one working undo and one working redo

I was thinking last night and i think i know how to make infinite undos now, but redos are way harder
But i’ll still try, i think i might be able to do the redos too

3 Likes

redo is just the reverse of undo, with the additional convienence of being able to totally wipe out any redoable lines when a new undoable one is added

3 Likes

so like

when you draw 2 squigglys then hit undo, “goigly” is supposed to be like the draw history & store both squigglys but “active goigly” only stores the first one, & it directs the retroactive pen [renderer] to only redraw the first squiggly

5 Likes

I think you’re over-complicating things a little…

My code only stores the Trail History, and for getting the right number of lines? Each you draw a trail, the number of lines drawn increases by one. My code basically uses a combination of Lines Drawn and Draw Lines to tell the system how many lines to draw at any given time…

I could make a video of me (obviously it’ll be a screen recording) coding an UNDO / REDO system from scratch… might make it easier to understand…

5 Likes

yeah i also think i am overcomplicating but i don’t want to rip out all the variables

undo doesn’t remove the last stroke from active goigly rn it deletes EVERYTHING

maybe i should just store a character index

5 Likes