# HG changeset patch # User Matti Hamalainen # Date 1533455085 -10800 # Node ID 9d17f991f10261fec3328d1a3c934c7df5a03c64 # Parent 4d0bdd2b215d5b9f38aebceb11df21e7f9fc0e0f Move undo and spare page management into buffers.pde as in Multipaint 2018. diff -r 4d0bdd2b215d -r 9d17f991f102 Interface.pde --- a/Interface.pde Sun Aug 05 09:55:17 2018 +0300 +++ b/Interface.pde Sun Aug 05 10:44:45 2018 +0300 @@ -182,130 +182,15 @@ } -void ustats() { - //a debug thingie in case the step undo does not work - //println("UINDEX:"+g_uindex[g_spare]); - //println("UTOP:"+g_utop[g_spare]); - //println("UBOTTOM:"+g_ubottom[g_spare]); -} - - -void store_undo() //to_undo +void sussborder() { - if (g_spare) - arrayCopy(g_map, g_undobs[g_uindex[g_spare]]); - else - arrayCopy(g_map, g_undob[g_uindex[g_spare]]); - - g_uindex[g_spare]++; - if (g_uindex[g_spare] > 10) - g_uindex[g_spare] = 0; - - if (g_uindex[g_spare] == g_ubottom[g_spare]) { - g_ubottom[g_spare]++; - if (g_ubottom[g_spare] > 10) - g_ubottom[g_spare] = 0; - } - g_utop[g_spare] = g_uindex[g_spare]; - - refreshpalette(); - ustats(); -} - - -void restore_undo() { - if (g_uindex[g_spare] == g_ubottom[g_spare]) - return; - - if (g_spare) - arrayCopy(g_map, g_undobs[g_uindex[g_spare]]); - else - arrayCopy(g_map, g_undob[g_uindex[g_spare]]); - - g_uindex[g_spare]--; - if (g_uindex[g_spare] < 0) - g_uindex[g_spare] = 10; - - if (g_spare) - arrayCopy(g_undobs[g_uindex[g_spare]], g_map); - else - arrayCopy(g_undob[g_uindex[g_spare]], g_map); - - refreshpalette(); - ustats(); -} - - -void redo_undo() { - if (g_uindex[g_spare] == g_utop[g_spare]) - return; - - g_uindex[g_spare]++; - if (g_uindex[g_spare] > 10) - g_uindex[g_spare] = 0; - - if (g_spare) - arrayCopy(g_undobs[g_uindex[g_spare]], g_map); - else - arrayCopy(g_undob[g_uindex[g_spare]], g_map); - - refreshpalette(); - ustats(); -} - - -void spare() //dpaint style spare page -{ - arrayCopy(g_sparepage, g_swappage); - arrayCopy(g_map, g_sparepage); - arrayCopy(g_swappage, g_map); - - mpSetTitle(g_spare ? sfilename : filename); - - g_spare = 1 - g_spare; - g_realfront = byte(g_farge); - g_realback = byte(g_backg); - refreshpalette(); -} - - -void switcher(int di) { - // this achieves varieties of whole screen copying - // needed for brush copy and pre-drawing the shapes when a - // tool is active etc. - switch (di) { - case 0: - arrayCopy(g_map, g_rmap); - break; - case 1: - arrayCopy(g_rmap, g_map); - for (int i = 0; i < 1024; i++) { - if (g_remdo[i] == 1) { - g_remdo[i] = 0; - g_redo[i] = 0; - } - } - break; - case 2: - arrayCopy(g_map, g_brush); - break; - case 3: - arrayCopy(g_map, g_sparepage); - break; - case 4: - arrayCopy(g_sparepage, g_mapm); - break; - } -} - - -void sussborder() { makecolor(259, g_r[g_map[0]], g_g[g_map[0]], g_b[g_map[0]]); g_boxreconstruct = 2; } -void makecolor(int c, int rr, int gg, int bb) { +void makecolor(int c, int rr, int gg, int bb) +{ //0-255 go to g_map[] up until 1021-1023 //the rest is not stored if (c < 256) { @@ -321,7 +206,8 @@ } -int fylli() { +int fylli() +{ //for the animated rubberband thingy g_rband++; if (g_rband > g_rbang) { diff -r 4d0bdd2b215d -r 9d17f991f102 buffers.pde --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/buffers.pde Sun Aug 05 10:44:45 2018 +0300 @@ -0,0 +1,134 @@ +// undo / spare + +final int UNDOSTEPS = 20; // max # of undo steps + +byte[] g_sparepage = new byte[88000]; +byte[] g_swappage = new byte[88000]; +byte[][] g_undob = new byte[UNDOSTEPS + 1][88000]; +byte[][] g_undobs = new byte[UNDOSTEPS + 1][88000]; +int[] g_uindex = new int[8]; +int[] g_ubottom = new int[8]; +int[] g_utop = new int[8]; + + +void ustats() +{ + //a debug thingie in case the step undo does not work + //println("UINDEX:"+g_uindex[g_spare]); + //println("UTOP:"+g_utop[g_spare]); + //println("UBOTTOM:"+g_ubottom[g_spare]); +} + + +void store_undo() +{ + if (g_spare) + arrayCopy(g_map, g_undobs[g_uindex[g_spare]]); + else + arrayCopy(g_map, g_undob[g_uindex[g_spare]]); + + g_uindex[g_spare]++; + if (g_uindex[g_spare] > UNDOSTEPS) + g_uindex[g_spare] = 0; + + if (g_uindex[g_spare] == g_ubottom[g_spare]) { + g_ubottom[g_spare]++; + if (g_ubottom[g_spare] > UNDOSTEPS) + g_ubottom[g_spare] = 0; + } + g_utop[g_spare] = g_uindex[g_spare]; + + refreshpalette(); + ustats(); +} + + +void restore_undo() +{ + if (g_uindex[g_spare] == g_ubottom[g_spare]) + return; + + if (g_spare) + arrayCopy(g_map, g_undobs[g_uindex[g_spare]]); + else + arrayCopy(g_map, g_undob[g_uindex[g_spare]]); + + g_uindex[g_spare]--; + if (g_uindex[g_spare] < 0) + g_uindex[g_spare] = UNDOSTEPS; + + if (g_spare) + arrayCopy(g_undobs[g_uindex[g_spare]], g_map); + else + arrayCopy(g_undob[g_uindex[g_spare]], g_map); + + refreshpalette(); + ustats(); +} + + +void redo_undo() +{ + if (g_uindex[g_spare] == g_utop[g_spare]) + return; + + g_uindex[g_spare]++; + if (g_uindex[g_spare] > UNDOSTEPS) + g_uindex[g_spare] = 0; + + if (g_spare) + arrayCopy(g_undobs[g_uindex[g_spare]], g_map); + else + arrayCopy(g_undob[g_uindex[g_spare]], g_map); + + refreshpalette(); + ustats(); +} + + +void spare() //dpaint style spare page +{ + arrayCopy(g_sparepage, g_swappage); + arrayCopy(g_map, g_sparepage); + arrayCopy(g_swappage, g_map); + + mpSetTitle(g_spare ? sfilename : filename); + + g_spare = 1 - g_spare; + g_realfront = byte(g_farge); + g_realback = byte(g_backg); + refreshpalette(); +} + + +void switcher(int di) +{ + // this achieves varieties of whole screen copying + // needed for brush copy and pre-drawing the shapes when a + // tool is active etc. + switch (di) { + case 0: + arrayCopy(g_map, g_rmap); + break; + case 1: + arrayCopy(g_rmap, g_map); + for (int i = 0; i < 1024; i++) { + if (g_remdo[i] == 1) { + g_remdo[i] = 0; + g_redo[i] = 0; + } + } + break; + case 2: + arrayCopy(g_map, g_brush); + break; + case 3: + arrayCopy(g_map, g_sparepage); + break; + case 4: + arrayCopy(g_sparepage, g_mapm); + break; + } +} + + diff -r 4d0bdd2b215d -r 9d17f991f102 mpui.js --- a/mpui.js Sun Aug 05 09:55:17 2018 +0300 +++ b/mpui.js Sun Aug 05 10:44:45 2018 +0300 @@ -15,6 +15,7 @@ var mpSources = [ + "buffers.pde", "draw_inputs.pde", "draw_outputs.pde", "draw_smart.pde", diff -r 4d0bdd2b215d -r 9d17f991f102 multipaint.pde --- a/multipaint.pde Sun Aug 05 09:55:17 2018 +0300 +++ b/multipaint.pde Sun Aug 05 10:44:45 2018 +0300 @@ -37,21 +37,14 @@ byte[] g_map = new byte[88000]; byte[] g_fillmap = new byte[88000]; -byte[] g_sparepage = new byte[88000]; -byte[] g_swappage = new byte[88000]; byte[] g_rmap = new byte[88000]; byte[] g_icons = new byte[88000]; byte[] g_brush = new byte[88000]; -byte[][] g_undob = new byte[11][88000]; -byte[][] g_undobs = new byte[11][88000]; byte[] g_template = new byte[16384]; byte[] g_redo = new byte[1024]; byte[] g_remdo = new byte[1024]; int[] g_chaup = new int[64]; byte[] g_data = new byte[1024]; -int[] g_uindex = new int[8]; -int[] g_ubottom = new int[8]; -int[] g_utop = new int[8]; int[] g_magpix = new int[64]; int[] g_magpiy = new int[64];