Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OPTION DEFINT
- DIM UNDODATA[0] 'stores pixel data
- DIM UNDOINFO[0] 'stores location and size of undo data
- '=== call when a user edits the image ===
- DEF SAVEUNDO X,Y,X2,Y2 'rectangle
- 'calculate size
- VAR W=X2-X+1
- VAR H=Y2-Y+1
- 'delete old undo data if undo array is too big
- WHILE LEN(UNDODATA) + W*H > (maximum undo array size)
- IF LEN(UNDOINFO)==0 THEN RETURN'bad
- VAR SIZE=UNDOINFO[2]*UNDOINFO[3]'get size (width*height)
- REMOVESTART UNDODATA,SIZE 'remove pixel data
- REMOVESTART UNDOINFO,4 'remove location and size
- WEND
- 'get the new undo data
- DIM IMAGE[W*H]
- GSAVE X,Y,W,H,IMAGE,1
- 'add the size and location
- PUSH UNDOINFO,X:PUSH UNDOINFO,Y
- PUSH UNDOINFO,W:PUSH UNDOINFO,H
- 'add the new undo data
- APPEND UNDODATA,IMAGE
- END
- '=== call when the undo button is pressed ===
- DEF UNDO
- IF LEN(UNDOINFO)==0 THEN RETURN
- 'get size and location
- VAR H=POP(UNDOINFO)
- VAR W=POP(UNDOINFO)
- VAR Y=POP(UNDOINFO)
- VAR X=POP(UNDOINFO)
- 'get pixel data
- DIM IMAGE[W*H]
- COPY IMAGE,UNDODATA,W*H,LEN(UNDODATA)-W*H
- REMOVEEND UNDODATA,W*H
- 'load pixel data
- GLOAD X,Y,W,H,IMAGE,1,1
- END
- DEF REMOVEEND ARRAY,SIZE
- VAR I
- FOR I=1 TO SIZE
- VAR TEMP=POP(ARRAY)
- NEXT
- END
- DEF REMOVESTART ARRAY,SIZE
- 'shift the data towards the start
- COPY ARRAY,ARRAY,SIZE,LEN(ARRAY)-SIZE
- 'remove the leftover data on the end
- REMOVEEND ARRAY,SIZE
- END
- DEF APPEND ARRAY,ARRAY2
- COPY ARRAY,LEN(ARRAY),ARRAY2
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement