public void updateViewportFromMouse(int mousex, int mousey,
HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
{
+ resetAlignmentDims();
+
// convert mousex and mousey to alignment units as well as
// translating to top left corner of viewport - this is an absolute position
int xAsRes = getLeftXFromCentreX(mousex, hiddenCols);
int visXAsRes = hiddenCols.findColumnPosition(xAsRes);
yAsSeq = hiddenSeqs.adjustForHiddenSeqs(
hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq));
+ yAsSeq = Math.max(yAsSeq, 0); // -1 if before first visible sequence
int visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq);
+ visYAsSeq = Math.max(visYAsSeq, 0); // -1 if before first visible sequence
// update viewport accordingly
updateViewportFromTopLeft(visXAsRes, visYAsSeq, hiddenSeqs, hiddenCols);
public void adjustViewportFromMouse(int mousex, int mousey,
HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
{
+ resetAlignmentDims();
+
// calculate translation in pixel terms:
// get mouse location in viewport coords, add translation in viewport
// coords,
// convert back to pixel coords
- int vpx = Math.round((float) mousex * alwidth / width);
+ int vpx = Math.round(mousex * widthRatio);
int visXAsRes = hiddenCols.findColumnPosition(vpx) + xdiff;
- int vpy = Math.round((float) mousey * alheight / sequencesHeight);
+ int vpy = Math.round(mousey * heightRatio);
int visYAsRes = hiddenSeqs.findIndexWithoutHiddenSeqs(vpy) + ydiff;
// update viewport accordingly
- updateViewportFromTopLeft(visXAsRes, visYAsRes,
- hiddenSeqs,
- hiddenCols);
+ updateViewportFromTopLeft(visXAsRes, visYAsRes, hiddenSeqs, hiddenCols);
}
+ /**
+ * {@inheritDoc} Callers should have already called resetAlignmentDims to
+ * refresh alwidth, alheight and width/height ratios
+ */
@Override
protected void updateViewportFromTopLeft(int leftx, int topy,
HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
{
int visXAsRes = leftx;
int visYAsSeq = topy;
- resetAlignmentDims();
if (visXAsRes < 0)
{
visYAsSeq = 0;
}
+ if (ranges.isWrappedMode())
+ {
+ visYAsSeq = 0; // sorry, no vertical scroll when wrapped
+ }
+
// Determine where scrollCol should be, given visXAsRes
// get viewport width in residues
// went past the end of the alignment, adjust backwards
if (ranges.getEndSeq() < visAlignHeight)
{
- visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(hiddenSeqs
- .subtractVisibleRows(vpheight - 1, alheight - 1));
+ visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(
+ hiddenSeqs.subtractVisibleRows(vpheight - 1, alheight - 1));
}
else
{
}
// update viewport
- ranges.setStartRes(visXAsRes);
- ranges.setStartSeq(visYAsSeq);
+ ranges.setStartResAndSeq(visXAsRes, visYAsSeq);
}
/**
int startSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getStartSeq());
int endSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getEndSeq());
- setBoxPosition(startRes, startSeq, endRes - startRes + 1, endSeq
- - startSeq + 1);
+ setBoxPosition(startRes, startSeq, endRes - startRes + 1,
+ endSeq - startSeq + 1);
}
@Override
public AlignmentColsCollectionI getColumns(AlignmentI al)
{
- return new AllColsCollection(0,
- ranges.getAbsoluteAlignmentWidth() - 1, al);
+ return new AllColsCollection(0, ranges.getAbsoluteAlignmentWidth() - 1,
+ al);
}
@Override
public AlignmentRowsCollectionI getRows(AlignmentI al)
{
- return new AllRowsCollection(0,
- ranges.getAbsoluteAlignmentHeight() - 1,
+ return new AllRowsCollection(0, ranges.getAbsoluteAlignmentHeight() - 1,
al);
}
{
alwidth = ranges.getAbsoluteAlignmentWidth();
alheight = ranges.getAbsoluteAlignmentHeight();
+
+ widthRatio = (float) alwidth / width;
+ heightRatio = (float) alheight / sequencesHeight;
}
+
+ /**
+ * {@inheritDoc} Callers should have already called resetAlignmentDims to
+ * refresh widthRatio
+ */
@Override
protected int getLeftXFromCentreX(int mousex, HiddenColumns hidden)
{
- int vpx = Math.round((float) mousex * alwidth / width);
+ int vpx = Math.round(mousex * widthRatio);
return hidden.subtractVisibleColumns(ranges.getViewportWidth() / 2,
vpx);
}
+ /**
+ * {@inheritDoc} Callers should have already called resetAlignmentDims to
+ * refresh heightRatio
+ */
@Override
protected int getTopYFromCentreY(int mousey, HiddenSequences hidden)
{
- int vpy = Math.round((float) mousey * alheight / sequencesHeight);
+ int vpy = Math.round(mousey * heightRatio);
return hidden.subtractVisibleRows(ranges.getViewportHeight() / 2, vpy);
}
public void setDragPoint(int x, int y, HiddenSequences hiddenSeqs,
HiddenColumns hiddenCols)
{
+ resetAlignmentDims();
+
// get alignment position of x and box (can get directly from vpranges) and
// calculate difference between the positions
- int vpx = Math.round((float) x * alwidth / width);
- int vpy = Math.round((float) y * alheight / sequencesHeight);
+ int vpx = Math.round(x * widthRatio);
+ int vpy = Math.round(y * heightRatio);
xdiff = ranges.getStartRes() - hiddenCols.findColumnPosition(vpx);
ydiff = ranges.getStartSeq()