JAL-2613 Centre alignment at click point
[jalview.git] / src / jalview / viewmodel / OverviewDimensionsShowHidden.java
index 4b396a6..be69db9 100644 (file)
@@ -66,19 +66,19 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions
   public void updateViewportFromMouse(int mousex, int mousey,
           HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
   {
-    int x = mousex;
-    int y = mousey;
+    int xAsRes = getLeftXFromCentreX(mousex, hiddenCols);
+    int yAsSeq = getTopYFromCentreY(mousey, hiddenSeqs);
 
     resetAlignmentDims();
 
-    if (x < 0)
+    if (xAsRes < 0)
     {
-      x = 0;
+      xAsRes = 0;
     }
 
-    if (y < 0)
+    if (yAsSeq < 0)
     {
-      y = 0;
+      yAsSeq = 0;
     }
 
     //
@@ -90,7 +90,7 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions
     // correction
 
     // convert x to residues - this is an absolute position
-    int xAsRes = Math.round((float) x * alwidth / width);
+    // int xAsRes = Math.round((float) x * alwidth / width);
 
     // get viewport width in residues
     int vpwidth = ranges.getViewportWidth();
@@ -124,7 +124,7 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions
     //
 
     // convert y to residues
-    int yAsSeq = Math.round((float) y * alheight / sequencesHeight);
+    // int yAsSeq = Math.round((float) y * alheight / sequencesHeight);
 
     // get viewport height in sequences
     int vpheight = ranges.getViewportHeight();
@@ -207,4 +207,20 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions
     alwidth = ranges.getAbsoluteAlignmentWidth();
     alheight = ranges.getAbsoluteAlignmentHeight();
   }
+
+  @Override
+  protected int getLeftXFromCentreX(int mousex, HiddenColumns hidden)
+  {
+    int vpx = Math.round((float) mousex * alwidth / width);
+    return hidden.findColumnPosition(hidden.subtractVisibleColumns(
+            ranges.getViewportWidth() / 2, vpx));
+  }
+
+  @Override
+  protected int getTopYFromCentreY(int mousey, HiddenSequences hidden)
+  {
+    int vpy = Math.round((float) mousey * alheight / sequencesHeight);
+    return hidden.findIndexWithoutHiddenSeqs(hidden.subtractVisibleRows(
+            ranges.getViewportHeight() / 2, vpy));
+  }
 }