Advertisement
12Me21

UNDO maybe

Jan 19th, 2017
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. OPTION DEFINT
  2.  
  3. DIM UNDODATA[0] 'stores pixel data
  4. DIM UNDOINFO[0] 'stores location and size of undo data
  5.  
  6. '=== call when a user edits the image ===
  7. DEF SAVEUNDO X,Y,X2,Y2 'rectangle
  8. 'calculate size
  9. VAR W=X2-X+1
  10. VAR H=Y2-Y+1
  11.  
  12. 'delete old undo data if undo array is too big
  13. WHILE LEN(UNDODATA) + W*H > (maximum undo array size)

  14. IF LEN(UNDOINFO)==0 THEN RETURN'bad
  15. VAR SIZE=UNDOINFO[2]*UNDOINFO[3]'get size (width*height)
  16. REMOVESTART UNDODATA,SIZE 'remove pixel data
  17. REMOVESTART UNDOINFO,4 'remove location and size
  18. WEND
  19.  
  20. 'get the new undo data
  21. DIM IMAGE[W*H]
  22. GSAVE X,Y,W,H,IMAGE,1
  23.  
  24. 'add the size and location
  25. PUSH UNDOINFO,X:PUSH UNDOINFO,Y
  26. PUSH UNDOINFO,W:PUSH UNDOINFO,H
  27.  
  28. 'add the new undo data
  29. APPEND UNDODATA,IMAGE
  30. END
  31.  
  32. '=== call when the undo button is pressed ===
  33. DEF UNDO
  34. IF LEN(UNDOINFO)==0 THEN RETURN
  35. 'get size and location
  36. VAR H=POP(UNDOINFO)
  37. VAR W=POP(UNDOINFO)
  38. VAR Y=POP(UNDOINFO)
  39. VAR X=POP(UNDOINFO)
  40.  
  41. 'get pixel data
  42. DIM IMAGE[W*H]
  43. COPY IMAGE,UNDODATA,W*H,LEN(UNDODATA)-W*H
  44. REMOVEEND UNDODATA,W*H
  45.  
  46. 'load pixel data
  47. GLOAD X,Y,W,H,IMAGE,1,1
  48. END
  49.  
  50. DEF REMOVEEND ARRAY,SIZE
  51. VAR I
  52. FOR I=1 TO SIZE
  53. VAR TEMP=POP(ARRAY)
  54. NEXT
  55. END
  56.  
  57. DEF REMOVESTART ARRAY,SIZE
  58. 'shift the data towards the start
  59. COPY ARRAY,ARRAY,SIZE,LEN(ARRAY)-SIZE
  60. 'remove the leftover data on the end
  61. REMOVEEND ARRAY,SIZE
  62. END
  63.  
  64. DEF APPEND ARRAY,ARRAY2
  65. COPY ARRAY,LEN(ARRAY),ARRAY2
  66. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement