changeset 43:df6eecdf1cd4

Clean up g_spare related things.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 04 Jul 2018 14:50:11 +0300
parents 14b7d678dbc2
children 041cb75875af
files Interface.pde events.pde multipaint.pde
diffstat 3 files changed, 64 insertions(+), 73 deletions(-) [+]
line wrap: on
line diff
--- a/Interface.pde	Wed Jul 04 14:42:03 2018 +0300
+++ b/Interface.pde	Wed Jul 04 14:50:11 2018 +0300
@@ -192,13 +192,19 @@
 
 void store_undo() //to_undo
 {
-    if (g_spare == 0) arrayCopy(g_map, g_undob[g_uindex[g_spare]]);
-    if (g_spare == 1) arrayCopy(g_map, g_undobs[g_uindex[g_spare]]);
+    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] > 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;
+        if (g_ubottom[g_spare] > 10)
+            g_ubottom[g_spare] = 0;
     }
     g_utop[g_spare] = g_uindex[g_spare];
 
@@ -208,14 +214,22 @@
 
 
 void restore_undo() {
-    if (g_uindex[g_spare] == g_ubottom[g_spare]) return;
+    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]]);
 
-    if (g_spare == 0) arrayCopy(g_map, g_undob[g_uindex[g_spare]]);
-    if (g_spare == 1) arrayCopy(g_map, g_undobs[g_uindex[g_spare]]);
     g_uindex[g_spare]--;
-    if (g_uindex[g_spare] < 0) g_uindex[g_spare] = 10;
-    if (g_spare == 0) arrayCopy(g_undob[g_uindex[g_spare]], g_map);
-    if (g_spare == 1) arrayCopy(g_undobs[g_uindex[g_spare]], g_map);
+    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();
@@ -223,12 +237,18 @@
 
 
 void redo_undo() {
-    if (g_uindex[g_spare] == g_utop[g_spare]) return;
+    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 == 0) arrayCopy(g_undob[g_uindex[g_spare]], g_map);
-    if (g_spare == 1) arrayCopy(g_undobs[g_uindex[g_spare]], g_map);
-    if (g_uindex[g_spare] > 10) g_uindex[g_spare] = 0;
+    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();
 }
@@ -236,17 +256,12 @@
 
 void spare() //dpaint style spare page
 {
-    if (g_spare == 0) { // in REAL page, change to SPARE page
-        arrayCopy(g_sparepage, g_swappage);
-        arrayCopy(g_map, g_sparepage);
-        arrayCopy(g_swappage, g_map);
-        mpSetTitle(sfilename);
-    } else { // in SPARE page, change to REAL page
-        arrayCopy(g_sparepage, g_swappage);
-        arrayCopy(g_map, g_sparepage);
-        arrayCopy(g_swappage, g_map);
-        mpSetTitle(filename);
-    }
+    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);
@@ -357,6 +372,7 @@
             for (int xx = 0; xx < w; xx++) {
                 s = pixels[ad + xx];
                 fout = 0;
+
                 if (g_rgb[0] == s) fout = g_grids[0];
                 if (g_rgb[1] == s) fout = g_grids[1];
                 if (g_rgb[2] == s) fout = g_grids[2];
@@ -373,6 +389,7 @@
                 if (g_rgb[13] == s) fout = g_grids[13];
                 if (g_rgb[14] == s) fout = g_grids[14];
                 if (g_rgb[15] == s) fout = g_grids[15];
+
                 pixels[ad + xx] = fout;
             }
             ad = ad + width;
@@ -499,7 +516,7 @@
                 }
             } else {
                 far = 0xff000000;
-                if (g_spare == 1 && t <= 95) far = 0xff008000; //different background color for spare mode
+                if (g_spare && t <= 95) far = 0xff008000; //different background color for spare mode
                 if (g_msgctr > 0 && t + 32 < 128) far = 0xff0000ff; //different background color
             }
 
@@ -749,11 +766,7 @@
             teks = "Pen size " + (g_bsize + 1) + "|LMB/h=less|RMB/H=bigger";
             break;
         case 'j':
-            if (g_spare == 0) {
-                teks = "Switch to|spare page|RMB=CopyTo";
-            } else {
-                teks = "Switch to|front page|RMB=CopyTo";
-            }
+            teks = "Switch to|"+ (!g_spare ? "spare" : "front") +" page|RMB=CopyTo";
             break;
         case 'f':
             teks = "Geometry|fill|on/off";
@@ -838,8 +851,12 @@
         if (g_repanel <= 0) {
             if (ad != ';' && ad != ':' && ad != '.') {
                 if (realdraw == 1) {
-                    int icolor = int(g_data[ad]);
-                    if (ad == 'j' && g_spare == 1) icolor = 1;
+                    int icolor;
+                    if (ad == 'j' && g_spare)
+                        icolor = 1;
+                    else
+                        icolor = int(g_data[ad]);
+
                     drawicon(xx + x, yy + y, ad - 48, icolor);
                 }
             }
--- a/events.pde	Wed Jul 04 14:42:03 2018 +0300
+++ b/events.pde	Wed Jul 04 14:50:11 2018 +0300
@@ -685,23 +685,14 @@
         g_data[int('j')] = 0;
         spare();
         store_undo();
-        switch (g_spare) {
-            case 0:
-                message("Copied to|Front");
-                switcher(4);
-                break;
-            case 1:
-                message("Copied to|Spare");
-                switcher(4);
-                break;
-        }
+        message("Copied to|" + (g_spare ? "Spare" : "Front"));
+        switcher(4);
         spare();
     }
 
     if (g_data[int('j')] == 1) {
         g_data[int('j')] = 0;
-        if (g_spare == 0) message("Spare Page");
-        if (g_spare == 1) message("Front Page");
+        message((g_spare ? "Spare" : "Front") + " Page");
         spare();
         makecolor(259, g_r[g_map[0]], g_g[g_map[0]], g_b[g_map[0]]);
         g_boxreconstruct = 2;
@@ -795,19 +786,12 @@
     }
     if (g_data[int('S')] == 1) {
         g_data[int('S')] = 0;
-        if (g_spare == 0) elename = filename;
-        if (g_spare == 1) elename = sfilename;
+        elename = g_spare ? sfilename : filename;
 
         if (elename.length() > 3) {
             if (g_iconmode == 0) {
-                if (g_spare == 0) {
-                    message("Page saved");
-                    store(elename);
-                }
-                if (g_spare == 1) {
-                    message("Spare page|saved");
-                    store(elename);
-                }
+                message(g_spare ? "Spare page|saved" : "Page saved");
+                store(elename);
             }
 
         } else {
--- a/multipaint.pde	Wed Jul 04 14:42:03 2018 +0300
+++ b/multipaint.pde	Wed Jul 04 14:50:11 2018 +0300
@@ -455,10 +455,10 @@
             {
                 store_undo();
                 mpSetTitle(fh.name);
-                if (g_spare == 0)
+                if (g_spare)
+                    sfilename = fh.name;
+                else
                     filename = fh.name;
-                else
-                    sfilename = fh.name;
 
                 refresh();
             }
@@ -472,10 +472,8 @@
     if (saveas) // Fileselect "event" for Save as
     {
         String s = fileselector(path, SAVEIMG);
-        String orig = "";
+        String orig = g_spare ? sfilename : filename;
         int kuva = 0;
-        if (g_spare == 0) orig = filename;
-        if (g_spare == 1) orig = sfilename;
 
         if (s != null) {
             // Add extension if needed
@@ -489,7 +487,7 @@
             if (m1 != null || m2 != null) kuva = 1;
             if (m1 == null && m2 == null && m3 == null && m4 == null) l[1] = "bin";
 
-            if (g_spare == 0) {
+            if (!g_spare) {
                 filename = l[0] + "." + l[1];
                 mpSavePNGImage(filename);
                 if (kuva == 1) filename = orig;
@@ -510,11 +508,7 @@
     }
 
     if (exporttxt) {
-        if (g_spare == 0) {
-            exportemuname = filename + "." + l[1];
-        } else {
-            exportemuname = sfilename + "." + l[1];
-        }
+        exportemuname = (g_spare ? sfilename : filename) +"." +l[1];
 
         machine_export(exportemuname, 1);
 
@@ -524,11 +518,7 @@
     }
 
     if (exportemu) {
-        if (g_spare == 0) {
-            exportemuname = filename + "." + l[1];
-        } else {
-            exportemuname = sfilename + "." + l[1];
-        }
+        exportemuname = (g_spare ? sfilename : filename) +"." +l[1];
 
         machine_export(exportemuname, 0);