Mercurial > hg > forks > multipaint-js
view buffers.pde @ 233:1d9f9c3d8ab1
Fixes to multicolor/pixelw==2 flood fill.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 06 Sep 2018 13:25:15 +0300 |
parents | 7a9dc175ece5 |
children |
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) g_undobs[g_uindex[g_spare]] = g_map.slice(0); else g_undob[g_uindex[g_spare]] = g_map.slice(0); 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) g_undobs[g_uindex[g_spare]] = g_map.slice(0); else g_undob[g_uindex[g_spare]] = g_map.slice(0); g_uindex[g_spare]--; if (g_uindex[g_spare] < 0) g_uindex[g_spare] = UNDOSTEPS; if (g_spare) g_map = g_undobs[g_uindex[g_spare]].slice(0); else g_map = g_undob[g_uindex[g_spare]].slice(0); 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) g_map = g_undobs[g_uindex[g_spare]].slice(0); else g_map = g_undob[g_uindex[g_spare]].slice(0); refreshpalette(); ustats(); } void spare() //dpaint style spare page { g_swappage = g_sparepage.slice(0); g_sparepage = g_map.slice(0); g_map = g_swappage.slice(0); 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: g_rmap = g_map.slice(0); break; case 1: g_map = g_rmap.slice(0); for (int i = 0; i < 1024; i++) { if (g_remdo[i] == 1) { g_remdo[i] = 0; g_redo[i] = 0; } } break; case 2: g_brush = g_map.slice(0); break; case 3: g_sparepage = g_map.slice(0); break; case 4: g_mapm = g_sparepage.slice(0); break; } }