Mercurial > hg > forks > multipaint-js
view buffers.pde @ 144:f91dda5dc8da
Integer fixes.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 14 Aug 2018 13:11:33 +0300 |
parents | 72ae62f2036b |
children | 7a9dc175ece5 |
line wrap: on
line source
// 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 mode) { // this achieves varieties of whole screen copying // needed for brush copy and pre-drawing the shapes when a // tool is active etc. switch (mode) { 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; } }