changeset 182:55a3fee48fe1

Implement UI resolution changer.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 23 Aug 2018 14:10:22 +0300
parents b8be804f1052
children 1cb7ecd73554
files mpui.js multipaint.pde
diffstat 2 files changed, 56 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mpui.js	Thu Aug 23 13:36:15 2018 +0300
+++ b/mpui.js	Thu Aug 23 14:10:22 2018 +0300
@@ -2,7 +2,7 @@
  * Multipaint.JS - Initializer/loader
  * (C) Copyright 2018 Matti 'ccr' Hämäläinen <ccr@tnsp.org>
  */
-var mpMachine = 0, mpUIZoom = 0;
+var mpMachine = 0, mpUIZoom, mpForcedWidth, mpForcedHeight;
 var mpURL;
 
 var mpMachines =
@@ -23,6 +23,14 @@
 ];
 
 
+var mpResolutions =
+[
+  [ -1, -1 ],
+  [ 1200, 980 ],
+  [ 1600, 1200 ],
+];
+
+
 var mpSources =
 [
   "buffers.pde",
@@ -94,7 +102,7 @@
   mobj.textContent = "Multipaint.JS"
   mpUI.appendChild(mobj);
 
-  var mdiv = stCE("div");
+  var mdiv = stCE("div", "mmachine");
   mpUI.appendChild(mdiv);
 
   mobj = stCE("p");
@@ -117,8 +125,31 @@
   stAddEventOb(mobj.name, mobj, "click", mpMachineSelected);
   mdiv.appendChild(mobj);
 
+
+  mdiv = stCE("div", "mresolution");
+  mpUI.appendChild(mdiv);
+
+  mobj = stCE("p");
+  mobj.textContent = "Choose optional resolution:";
+  mdiv.appendChild(mobj);
+
+  mobj = stCE("select", "resolutionID");
+  for (var n = 0; n < mpResolutions.length; n++)
+  {
+    var mp = mpResolutions[n];
+    var opt = stCE("option");
+    opt.value = n;
+    if (n == 0)
+      opt.textContent = "DEFAULT";
+    else
+      opt.textContent = mp[0] +" x " +mp[1];
+    mobj.appendChild(opt);
+  }
+  mdiv.appendChild(mobj);
+
+
   mobj = stCE("div");
-  mobj.innerHTML = 
+  mobj.innerHTML =
     "<p><b>Things of note:</b></p>"+
     "<ul>"+
     "<li>All of Multipaint v1.8.2018 changes have been integrated, "+
@@ -153,12 +184,21 @@
   var mpUI = stGE("mpUI");
   var id = stGE("machineID");
   mpMachine = id.selectedIndex >= 0 ? id.options[id.selectedIndex].value : 0;
+
+  id = stGE("resolutionID");
+  var index = id.selectedIndex >= 0 ? id.options[id.selectedIndex].value : 0;
+  if (index > 0)
+  {
+    mpForcedWidth = mpResolutions[index][0];
+    mpForcedHeight = mpResolutions[index][1];
+  }
+
   stClearChildren(mpUI);
 
   var mpCanvas = stGE("mpCanvas");
   mpCanvas.style.display = "block";
 
-  window.location.href = mpURL +"?"+ mpMachine.toString();
+  window.location.href = mpURL +"?"+ mpMachine.toString() +":"+ mpForcedWidth +":"+ mpForcedHeight;
 
   mpRunSketch(mpCanvas);
 }
@@ -174,9 +214,10 @@
   var spos, found = false;
   if ((spos = slink.indexOf("?")) >= 0)
   {
-    var tmp = parseInt(unescape(slink.substr(spos + 1)));
+    var sargs = unescape(slink.substr(spos + 1)).split(":");
     mpURL = slink.substr(0, spos);
 
+    var tmp = parseInt(sargs[0]);
     for (var n = 0; n < mpMachines.length; n++)
     {
       var mp = mpMachines[n];
@@ -187,6 +228,12 @@
         break;
       }
     }
+
+    if (sargs.length > 2)
+    {
+      mpForcedWidth = parseInt(sargs[1]);
+      mpForcedHeight = parseInt(sargs[2]);
+    }
   }
   else
     mpURL = slink;
--- a/multipaint.pde	Thu Aug 23 13:36:15 2018 +0300
+++ b/multipaint.pde	Thu Aug 23 14:10:22 2018 +0300
@@ -63,7 +63,8 @@
 
 int g_tooltrigger, g_prevtool, g_rband, g_rbang, g_boxreconstruct,
     g_charlimit, g_animx, g_animy, g_animframes, g_animno, g_animtime,
-    g_animspeed, g_keymacpos, g_forced_width, g_forced_height;
+    g_animspeed, g_keymacpos, g_forced_width, g_forced_height,
+    g_hadjust, g_vadjust;
 
 int g_wheelup = int(':'), g_wheeldown = int(';'), g_middlebutton = int(',');
 int g_gridmode = GRIDMODE_OLD;
@@ -108,6 +109,8 @@
     // Get settings from Javascript runner, or use defaults
     g_machine = (mpMachine >= 0) ? mpMachine : C64;
     g_uizoom = (mpUIZoom >= 1 && mpUIZoom <= 3) ? mpUIZoom : 2;
+    g_forced_width = mpForcedWidth > 0 ? mpForcedWidth : 0;
+    g_forced_height = mpForcedHeight > 0 ? mpForcedHeight : 0;
     g_animspeed = 1;
 
     //normi