Skip to content

Commit

Permalink
Account for X translation when recording screen coordinates for featu…
Browse files Browse the repository at this point in the history
…res. Important in expanded insertion multi-frame rendering.
  • Loading branch information
jrobinso committed Aug 27, 2023
1 parent 7ae949f commit 3917f97
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
12 changes: 7 additions & 5 deletions src/main/java/org/broad/igv/sam/AlignmentRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,8 @@ private void drawAlignment(
y,
h,
gapPxEnd - gapPxStart - 2,
null);
null,
context);
}
}
}
Expand Down Expand Up @@ -903,7 +904,8 @@ private void drawAlignment(
y,
h,
(int) pxWidthExact,
aBlock);
aBlock,
context );
} else {
int pxWing = (h > 10 ? 2 : (h > 5) ? 1 : 0);
Graphics2D ig = context.getGraphics();
Expand All @@ -912,7 +914,7 @@ private void drawAlignment(
ig.fillRect(x - pxWing, y, 2 + 2 * pxWing, 2);
ig.fillRect(x - pxWing, y + h - 2, 2 + 2 * pxWing, 2);

aBlock.setPixelRange(x - pxWing, x + 2 + pxWing);
aBlock.setPixelRange(context.translateX + x - pxWing, context.translateX + x + 2 + pxWing);
}
}
}
Expand Down Expand Up @@ -1016,7 +1018,7 @@ private static void drawClippedEnds(final Graphics2D g, final int[] xPoly, final
}

private void drawLargeIndelLabel(Graphics2D g, boolean isInsertion, String labelText, int pxCenter,
int pxTop, int pxH, int pxWmax, AlignmentBlock insertionBlock) {
int pxTop, int pxH, int pxWmax, AlignmentBlock insertionBlock, RenderContext context) {

final int pxPad = 2; // text padding in the label
final int pxWing = (pxH > 10 ? 2 : 1); // width of the cursor "wing"
Expand Down Expand Up @@ -1051,7 +1053,7 @@ private void drawLargeIndelLabel(Graphics2D g, boolean isInsertion, String label
} // draw the text if it fits

if (insertionBlock != null) {
insertionBlock.setPixelRange(pxLeft, pxRight);
insertionBlock.setPixelRange(context.translateX + pxLeft, context.translateX + pxRight);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/broad/igv/sam/BaseRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static void drawExpandedInsertions(InsertionMarker insertionMarker,

// Compute the start and end of the expanded insertion in pixels
int pixelStart = (int) ((insertion.getStart() - origin) / locScale);
int pixelEnd = (int) ((insertion.getEnd() - origin) / locScale) + 1;
int pixelEnd = (int) (pixelStart + insertion.getLength() / locScale);

// Skip if insertion is out of clipping rectangle -- this probably shouldn't happen
if (pixelEnd < rect.x || pixelStart > rect.getMaxX()) {
Expand Down Expand Up @@ -127,7 +127,7 @@ public static void drawExpandedInsertions(InsertionMarker insertionMarker,
drawBase(g, color, c,(int) pX, rect.y, (int) dX, rect.height - (leaveMargin ? 2 : 0), false, null);
}
}
insertion.setPixelRange(pixelStart, pixelEnd);
insertion.setPixelRange(context.translateX + pixelStart, context.translateX + pixelEnd);
}
}
} finally {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/broad/igv/track/RenderContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public class RenderContext {
public boolean multiframe = false;
public int expandedInsertionPosition = -1;

/**
* X trasnlation for this context relative to its parent. This is used in expanded insertion "multi-frame* view
* to convert screen coordinates to parent reference system when recording the pixel location of drawn objects
*/
public int translateX = 0;

public RenderContext(JComponent panel, Graphics2D graphics, ReferenceFrame referenceFrame, Rectangle visibleRect) {
this.graphics = graphics;
this.panel = panel;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/ui/panel/DataPanelPainter.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ private RenderContext shiftRenderContext(RenderContext ctx, double position, int
newContext.getReferenceFrame().widthInPixels = pixelWidth;
newContext.getReferenceFrame().origin = position;
newContext.visibleRect = new Rectangle(0, ctx.visibleRect.y, pixelWidth, ctx.visibleRect.height);
newContext.translateX = translateX;

Graphics2D dG = newContext.getGraphics();
Rectangle dRect = newContext.visibleRect;
dG.translate(translateX, 0);
dG.setClip(newContext.visibleRect);

Expand Down

0 comments on commit 3917f97

Please sign in to comment.