changeset 9:dfdc18b62fab

Change the help() function and its usage to have more than one parameter to deliver the cursor coordinates in a sane way.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 04 Jul 2018 08:55:48 +0300
parents f97ee354db2a
children 80380099f1ad
files Interface.pde draw_outputs.pde multipaint.pde
diffstat 3 files changed, 51 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/Interface.pde	Wed Jul 04 08:51:19 2018 +0300
+++ b/Interface.pde	Wed Jul 04 08:55:48 2018 +0300
@@ -549,56 +549,64 @@
 }
 
 
-void help(int a) {
+void help(int mode, int xc, int yc) {
     String teks;
-    int b, byt, ad, valu;
+
     if (g_msgctr > 0) return;
-    teks = "No Help";
+
     clearmsg();
-    if (a >= 1000) {
-        a = a - 1000;
-        b = a / X;
-        a = a - (b * X);
-        if (tool() == 4 && g_phase == 1) {
-            a = abs(g_rx2 - g_rx) + 1;
-            b = abs(g_ry2 - g_ry) + 1;
+
+
+    if (mode >= 1000) {
+        xc = int(xc);
+        yc = int(yc);
+
+        if (g_phase == 1) {
+            switch (tool()) {
+                case 4:
+                case 6:
+                    xc = abs(g_rx2 - g_rx) + 1;
+                    yc = abs(g_ry2 - g_ry) + 1;
+                    break;
+
+                case 7:
+                    xc = abs(g_rx2 - g_rx) * 2 + 1;
+                    yc = abs(g_ry2 - g_ry) * 2 + 1;
+                    break;
+
+                case 8:
+                    if (g_data[int('c')] == 1 || g_shift) {
+                        xc = abs(g_rx2 - g_rx);
+                        yc = abs(g_ry2 - g_ry);
+                    } //purkkaa
+                    else {
+                        xc = abs(g_rx2 - g_rx) + 1;
+                        yc = abs(g_ry2 - g_ry) + 1;
         }
-        if (tool() == 6 && g_phase == 1) {
-            a = abs(g_rx2 - g_rx) + 1;
-            b = abs(g_ry2 - g_ry) + 1;
-        }
-        if (tool() == 7 && g_phase == 1) {
-            a = abs(g_rx2 - g_rx) * 2 + 1;
-            b = abs(g_ry2 - g_ry) * 2 + 1;
+                    break;
+            }
         }
-        if (tool() == 8 && g_phase == 1) {
-            a = abs(g_rx2 - g_rx) + 1;
-            b = abs(g_ry2 - g_ry) + 1;
-            if (g_data[int('c')] == 1 || g_shift) {
-                a--;
-                b--;
-            } //purkkaa
-        }
+
         //coordinates
-
-        if (a < X && b < Y) {
+        if (xc < X && yc < Y) {
             printat(0, 0, str(a));
             printat(4, 0, str(b));
             printat(0, 1, str(int(a / 8)));
             printat(4, 1, str(int(b / 8)));
 
             if (tool() == 6 && g_phase == 1) {
-                printat(0, 2, nf(dist(0, 0, a - 1, b - 1), 0, 2));
                 float av = getangel(g_rx2 - g_rx, g_ry2 - g_ry);
+
+                printat(0, 2, nf(dist(0, 0, xc - 1, yc - 1), 0, 2));
                 printat(0, 3, nf((av), 0, 2));
             }
         }
         return;
     }
 
-    printat(7, 3, "Key:" + char(a));
+    printat(7, 3, "Key:" + str(char(mode)));
 
-    switch (a) {
+    switch (char(mode)) {
         case '.':
             teks = "Preset pens|.=reset";
             break;
@@ -756,6 +764,10 @@
             teks = "Export:|no support";
             if (g_formatname != "") teks = "Export as|" + g_formatname;
             break;
+
+        default:
+            teks = "No Help";
+            break;
     }
     printat(0, 0, teks);
 }
--- a/draw_outputs.pde	Wed Jul 04 08:51:19 2018 +0300
+++ b/draw_outputs.pde	Wed Jul 04 08:55:48 2018 +0300
@@ -1045,8 +1045,11 @@
         return;
     }
 
-    if (x >= 0 && y >= 0 && x < X && y < Y && g_mx < width - g_hedge && g_my < height - g_vedge) help(1000 + x + y * X);
-    if (g_phase > 0) help(1000 + x + y * X);
+    if (x >= 0 && y >= 0 && x < X && y < Y && g_mx < width - g_hedge && g_my < height - g_vedge)
+        help(1000, x, y);
+
+    if (g_phase > 0)
+        help(1000, x, y);
 
     if (tt == 1) craft(x, y, 0); //pixeller
 
--- a/multipaint.pde	Wed Jul 04 08:51:19 2018 +0300
+++ b/multipaint.pde	Wed Jul 04 08:55:48 2018 +0300
@@ -332,10 +332,11 @@
     }
     if(depis)g_repanel=-2;
     */
-    if (moicon(16 * 16 * g_uizoom, height - 32 * g_uizoom, 16 * g_uizoom, 24 * g_uizoom)) help('<');
-    if (moicon(16 * 16 * g_uizoom, height - 8 * g_uizoom, 16 * g_uizoom, 8 * g_uizoom)) help('>');
+
+    if (moicon(16 * 16 * g_uizoom, height - 32 * g_uizoom, 16 * g_uizoom, 24 * g_uizoom)) help(int('<'));
+    if (moicon(16 * 16 * g_uizoom, height - 8 * g_uizoom, 16 * g_uizoom, 8 * g_uizoom)) help(int('>'));
     if (moicon(0, height - 32 * g_uizoom, 15 * 16 * g_uizoom, 32 * g_uizoom)) help(TAB);
-    if (moicon(width - 32 * g_uizoom, 0, 32 * g_uizoom, 16 * g_uizoom)) help('.');
+    if (moicon(width - 32 * g_uizoom, 0, 32 * g_uizoom, 16 * g_uizoom)) help(int('.'));
 
     if (g_data[int('m')] == 0 && g_data[int('M')] == 0) {
         msx = mouseX - g_windowx;