qq99 / echoplexus

Socket.io powered chat, JavaScript REPL, whiteboard, and WebRTC calls
Other
392 stars 54 forks source link

Undo button for draw #191

Open ghost opened 10 years ago

ghost commented 10 years ago

I was drawing with friends there are were so many times an undo button would have saved our picture.

jamiees2 commented 10 years ago

I couldn't implement this when i was writing that because of the huge redrawing queue. Essentially to undo we would have to redraw the entire image, which requires representing the entire path in memory. I figured this was too much of a performance cost for the gain. If you guys have an alternate implementation, im open to suggestions.

qq99 commented 10 years ago

Hmm, yeah, interesting problem. Right now we represent the thing as a state machine that can only go forwards, so it's not simple to just undo one command.

The one possibility is representing an inverse operation of draw. e.g., inverse of draw path from A->B is erase from B->A. Maybe this could get messy if you were trying to undo just your own changes (vs. the global state of your changes interwoven with others' changes)

jamiees2 commented 10 years ago

Even that wouldn't really work, because say you draw an X, and then delete the overlapping line. An erasing technique would leave you with 2 diagonal dashes with a small space in the middle.

qq99 commented 10 years ago

True, so perhaps the only thing to do would be to replay the animations with the set of undo'd items removed. Perhaps there's a smarter approach