changeset 156:5d73681b97eb

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 16 Aug 2018 15:04:39 +0300
parents b9ad669fb025
children cdfda0354332
files Interface.pde draw_outputs.pde events.pde
diffstat 3 files changed, 59 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/Interface.pde	Thu Aug 16 14:33:36 2018 +0300
+++ b/Interface.pde	Thu Aug 16 15:04:39 2018 +0300
@@ -1315,8 +1315,8 @@
     maxx--;
     mayy--;
 
-    g_ofx = clipv(g_ofx, 0, MX - magx());
-    g_ofy = clipv(g_ofy, 0, MY - magy());
+    g_ofx = clampv(g_ofx, 0, MX - magx());
+    g_ofy = clampv(g_ofy, 0, MY - magy());
 
     if (mmode == 10) {
         g_ofx = 0;
--- a/draw_outputs.pde	Thu Aug 16 14:33:36 2018 +0300
+++ b/draw_outputs.pde	Thu Aug 16 15:04:39 2018 +0300
@@ -1,7 +1,7 @@
 // Collect all that "writes" the virtual image in some way or other
 // plus other active manipulations
 
-int clipv(int v, int vmin, int vmax)
+int clampv(int v, int vmin, int vmax)
 {
     return (v < vmin) ? vmin : (v > vmax ? vmax : v);
 }
--- a/events.pde	Thu Aug 16 14:33:36 2018 +0300
+++ b/events.pde	Thu Aug 16 15:04:39 2018 +0300
@@ -136,12 +136,12 @@
 
 void mousePressed()
 {
-    int msx, msy;
-
     g_dirty = true;
     if (g_pgrab)
         return;
 
+    int msx, msy, tt = tool();
+
     g_iconx = mouseX;
     g_icony = mouseY;
     g_button = mouseButton;
@@ -178,62 +178,70 @@
         g_msx = g_iconx;
         g_msy = g_icony;
 
-        if (g_data[int('m')] == 0 && g_data[int('M')] == 0)
+        if (g_button == CENTER)
         {
-            msx = g_iconx - g_windowx;
-            msy = g_icony - g_windowy;
-        } else {
-            msx = g_iconx;
-            msy = g_icony;
-        }
+            command(g_middlebutton);
+            g_phase = 1;
+            return;
 
-        if (g_button != CENTER)
-        {
-            if (tool() != 5 && tool() != 4) store_undo();
-            if (tool() == 4) { //cut brush results in undo
-                if (g_button == RIGHT) store_undo();
-            }
+            //g_button = 255;
+            //g_repanel = -2;
+            //if (g_shift) g_button = 254;
         }
         else
         {
-            g_button = 255;
-            g_repanel = -2;
-            if (g_shift) g_button = 254;
+            if (g_data[int('m')] == 0 && g_data[int('M')] == 0)
+            {
+                msx = g_iconx - g_windowx;
+                msy = g_icony - g_windowy;
+            } else {
+                msx = g_iconx;
+                msy = g_icony;
+            }
+
+            // XXX weird logic again .. might not make sense
+            if ((tt != 5 && tt != 4) ||
+                (tt == 4 && g_button == RIGHT))
+                store_undo();
+
+            g_phase = 0;
+            do_tool(msx, msy, g_button);
+            g_phase = 1;
         }
 
-        g_phase = 0;
-        do_tool(msx, msy, g_button);
-        g_phase = 1;
     }
 }
 
 
 void mouseReleased()
 {
+    int tt = tool();
+
     g_dirty = true;
     g_tooltrigger = 0;
     g_klikkeri = false;
 
-    if (tool() == 8) {
-        if (g_phase == 1) {
-            g_phase = 0;
+    if (g_phase == 1)
+    switch (tt)
+    {
+        case 8:
             do_rectangle(g_rx, g_ry, g_rx2, g_ry2);
-        }
-    }
-    if (tool() == 7) { //circle
-        if (g_phase == 1) {
             g_phase = 0;
+            break;
+
+        case 7:
             do_circle(g_rx, g_ry, g_rx2, g_ry2);
-        }
-    }
-    if (tool() == 6) {
-        if (g_phase == 1) {
             g_phase = 0;
+            break;
+
+        case 6:
             do_line(g_rx, g_ry, g_rx2, g_ry2, 0);
-        }
+            g_phase = 0;
+            break;
     }
 
-    if (g_data[int('4')] == 1) {
+    if (g_data[int('4')] == 1)
+    {
         if (g_phase == 1) {
             g_phase = 0;
             g_rubbermode = 0;
@@ -249,27 +257,24 @@
             g_data[int('t')] = 0;
             g_data[int('n')] = 0;
             switcher(2);
-            if (g_pixelw == 2) {
+
+            if (g_pixelw == 2)
+            {
                 g_rx = chop2(g_rx);
                 g_rx2 = chop2(g_rx2);
             }
-            g_bsourcex = g_rx;
-            g_bsourcey = g_ry;
-            g_bsourcex2 = g_rx2;
-            g_bsourcey2 = g_ry2;
-            if (g_bsourcex <= 0) g_bsourcex = 0;
-            if (g_bsourcey <= 0) g_bsourcey = 0;
-            if (g_bsourcex >= X) g_bsourcex = X - 1;
-            if (g_bsourcey >= Y) g_bsourcex = Y - 1;
-            if (g_bsourcex2 <= 0) g_bsourcex2 = 0;
-            if (g_bsourcey2 <= 0) g_bsourcey2 = 0;
-            if (g_bsourcex2 >= X) g_bsourcex2 = X - 1;
-            if (g_bsourcey2 >= Y) g_bsourcey2 = Y - 1;
+
+            g_bsourcex = clampv(g_rx, 0, X - 1);
+            g_bsourcey = clampv(g_ry, 0, Y - 1);
+            g_bsourcex2 = clampv(g_rx2, 0, X - 1);
+            g_bsourcey2 = clampv(g_ry2, 0, Y - 1);
 
             set_tool(1);
             g_btype = 9;
             g_repanel = -2;
-            if (g_button == RIGHT) {
+
+            if (g_button == RIGHT)
+            {
                 storeparameters();
                 g_data[int('f')] = 1;
                 g_data[int('X')] = 0;
@@ -280,7 +285,9 @@
         }
         consistency();
     }
-    if (g_phase == 1) {
+
+    if (g_phase == 1)
+    {
         g_phase = 0;
         g_rubbermode = 0;
         refresh(); //needed otherwise the pen color is kept e.g. after right mousebutton