JAL-2622 no vertical scroll of wrapped alignment from trackpad / mouse
[jalview.git] / src / jalview / viewmodel / OverviewDimensionsShowHidden.java
index b897189..62e8000 100644 (file)
@@ -81,6 +81,11 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions
       y = 0;
     }
 
+    if (ranges.isWrappedMode())
+    {
+      y = 0; // sorry, no vertical scroll when wrapped
+    }
+
     //
     // Convert x value to residue position
     //
@@ -93,7 +98,7 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions
     int xAsRes = Math.round((float) x * alwidth / width);
 
     // get viewport width in residues
-    int vpwidth = ranges.getEndRes() - ranges.getStartRes() + 1;
+    int vpwidth = ranges.getViewportWidth();
 
     // get where x should be when accounting for hidden cols
     // if x is in a hidden col region, shift to left - but we still need
@@ -108,14 +113,14 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions
       // went past the end of the alignment, adjust backwards
 
       // if last position was before the end of the alignment, need to update
-      if ((scrollCol + vpwidth - 1) < visAlignWidth)
+      if (ranges.getEndRes() < visAlignWidth)
       {
         visXAsRes = hiddenCols.findColumnPosition(hiddenCols
                 .subtractVisibleColumns(vpwidth - 1, alwidth - 1));
       }
       else
       {
-        visXAsRes = scrollCol;
+        visXAsRes = ranges.getStartRes();
       }
     }
 
@@ -127,8 +132,7 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions
     int yAsSeq = Math.round((float) y * alheight / sequencesHeight);
 
     // get viewport height in sequences
-    // add 1 because height includes both endSeq and startSeq
-    int vpheight = ranges.getEndSeq() - ranges.getStartSeq() + 1;
+    int vpheight = ranges.getViewportHeight();
 
     // get where y should be when accounting for hidden rows
     // if y is in a hidden row region, shift up - but we still need absolute
@@ -136,28 +140,29 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions
     // so convert back after getting visible region position
     yAsSeq = hiddenSeqs.adjustForHiddenSeqs(hiddenSeqs
             .findIndexWithoutHiddenSeqs(yAsSeq));
+    yAsSeq = Math.max(yAsSeq, 0); // -1 if before first visible sequence
 
     // check in case we went off the edge of the alignment
     int visAlignHeight = hiddenSeqs.findIndexWithoutHiddenSeqs(alheight);
     int visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq);
+    visYAsSeq = Math.max(visYAsSeq, 0); // -1 if before first visible sequence
     if (visYAsSeq + vpheight - 1 > visAlignHeight)
     {
       // went past the end of the alignment, adjust backwards
-      if ((scrollRow + vpheight - 1) < visAlignHeight)
+      if (ranges.getEndSeq() < visAlignHeight)
       {
         visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(hiddenSeqs
                 .subtractVisibleRows(vpheight - 1, alheight - 1));
       }
       else
       {
-        visYAsSeq = scrollRow;
+        visYAsSeq = ranges.getStartSeq();
       }
     }
 
-    // update scroll values
-    scrollCol = visXAsRes;
-    scrollRow = visYAsSeq;
-
+    // update viewport
+    ranges.setStartRes(visXAsRes);
+    ranges.setStartSeq(visYAsSeq);
   }
 
   /**
@@ -176,15 +181,15 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions
           HiddenColumns hiddenCols)
   {
     // work with absolute values of startRes and endRes
-    int startRes = hiddenCols
-            .adjustForHiddenColumns(ranges.getStartRes());
+    int startRes = hiddenCols.adjustForHiddenColumns(ranges.getStartRes());
     int endRes = hiddenCols.adjustForHiddenColumns(ranges.getEndRes());
 
     // work with absolute values of startSeq and endSeq
     int startSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getStartSeq());
     int endSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getEndSeq());
 
-    setBoxPosition(startRes, endRes, startSeq, endSeq);
+    setBoxPosition(startRes, startSeq, endRes - startRes + 1, endSeq
+            - startSeq + 1);
   }
 
   @Override