changeset 2379:aa727f279c3a

More cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 04 Nov 2021 05:16:40 +0200
parents 341947615417
children 4876ffa21bc0
files src/util.js
diffstat 1 files changed, 20 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/util.js	Thu Nov 04 05:15:33 2021 +0200
+++ b/src/util.js	Thu Nov 04 05:16:40 2021 +0200
@@ -4,13 +4,13 @@
 // (C) Copyright 2007-2021 Tecnic Software productions (TNSP)
 //
 
+var mapElem = null;
 var mapCurrLoc = null;
 var mapScrollTimerID = -1;
 var mapScrollPosStart, mapScrollPosEnd;
-var mapScrollIndex = 0.0;
+var mapScrollIndex = 0.0, mapScrollSteps;
 var mapDragEnable = false;
 var mapDragPos = { x0: 0, y0: 0, mx: 0, my: 0 }, mapLocPos = mapDragPos;
-var mapElem = null;
 
 
 function mapAddEventOb(obname, evobj, evtype, evcallback)
@@ -83,6 +83,17 @@
 }
 
 
+function mapSetWindowPos(px, py)
+{
+  const dim = mapGetWindowSize();
+  mapDragPos.x0 = px - (dim.w / 2);
+  mapDragPos.y0 = py - (dim.h / 2);
+
+  mapElem.scrollLeft = mapDragPos.x0;
+  mapElem.scrollTop = mapDragPos.y0;
+}
+
+
 function mapClamp10(a)
 {
   return (a < 0.0 ? 0.0 : (a > 1.0 ? 1.0 : a));
@@ -101,15 +112,6 @@
 }
 
 
-function mapSetWindowPos(px, py)
-{
-  const dim = mapGetWindowSize();
-  mapDragPos.x0 = px - (dim.w / 2);
-  mapDragPos.y0 = py - (dim.h / 2);
-  mapElem.scrollTo(mapDragPos.x0, mapDragPos.y0);
-}
-
-
 function mapScrollToPos()
 {
   if (mapScrollIndex <= 1.0)
@@ -119,7 +121,7 @@
     const py = mapLerp(n, mapScrollPosStart.y, mapScrollPosEnd.y);
 
     mapSetWindowPos(px, py);
-    mapScrollIndex += 0.01;
+    mapScrollIndex += 1.0 / mapScrollSteps;
   }
   else
   {
@@ -181,6 +183,11 @@
 function mapGotoLocation()
 {
   var newLoc = document.getElementById("slocation").value;
+  if (newLoc == "")
+  {
+    mapCurrLoc = null;
+  }
+  else
   if (mapCurrLoc != newLoc)
   {
     var nelem = document.getElementById(newLoc);
@@ -196,6 +203,7 @@
         mapScrollPosStart = mapFindElemCoords(celem);
         mapScrollPosEnd = mapFindElemCoords(nelem);
         mapScrollIndex = 0.0;
+        mapScrollSteps = 100;
 
         mapScrollTimerID = setInterval(mapScrollToPos, 10);
       }