From 8ea26cfd5ef46f5f5e15a4e0e2b0a20dfa8204f6 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Mon, 21 Aug 2023 11:55:42 +0100 Subject: [PATCH] JAL-4250 Conservative setting of ANTIALIAS and readjustment of glyphs to avoid scrolling artifacts by pixel-out positioned glyphs --- src/jalview/renderer/AnnotationRenderer.java | 75 +++++++++++++++++--------- 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/src/jalview/renderer/AnnotationRenderer.java b/src/jalview/renderer/AnnotationRenderer.java index 5aea2cf..9a0081f 100644 --- a/src/jalview/renderer/AnnotationRenderer.java +++ b/src/jalview/renderer/AnnotationRenderer.java @@ -234,7 +234,6 @@ public class AnnotationRenderer { // Console.info(nonCanColor); - g.setColor(nonCanColor); int sCol = (lastSSX / charWidth) + hiddenColumns.visibleToAbsoluteColumn(startRes); int x1 = lastSSX; @@ -252,6 +251,13 @@ public class AnnotationRenderer // "+diffupstream+" // down:"+diffdownstream); // If a closing base pair half of the stem, display a backward arrow + if (diffupstream || diffdownstream) + { + // draw glyphline under arrow + this.drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset, + startRes, column, validRes, validEnd); + } + g.setColor(nonCanColor); if (column > 0 && Rna.isClosingParenthesis(dc)) { @@ -261,7 +267,8 @@ public class AnnotationRenderer { fillPolygon(g, new int[] { lastSSX + 5, lastSSX + 5, lastSSX }, new int[] - { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, + { y + iconOffset + 1, y + 13 + iconOffset, + y + 7 + iconOffset }, 3); x1 += 5; } @@ -276,9 +283,10 @@ public class AnnotationRenderer // display a forward arrow if (diffdownstream) { - fillPolygon(g, new int[] { x2 - 5, x2 - 5, x2 }, + fillPolygon(g, new int[] { x2 - 6, x2 - 6, x2 - 1 }, new int[] - { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, + { y + iconOffset + 1, y + 13 + iconOffset, + y + 7 + iconOffset }, 3); x2 -= 5; } @@ -288,7 +296,8 @@ public class AnnotationRenderer } } // draw arrow body - fillRect(g, x1, y + 4 + iconOffset, x2 - x1, 7); + unsetAntialias(g); + fillRect(g, x1 - 1, y + 4 + iconOffset, x2 - x1 + 1, 6); } // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI @@ -452,6 +461,7 @@ public class AnnotationRenderer int endRes) { Graphics2D g2d = (Graphics2D) g; + /* if (Cache.getDefault("ANTI_ALIAS", true)) { g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, @@ -459,6 +469,7 @@ public class AnnotationRenderer g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); } + */ long stime = System.currentTimeMillis(); boolean usedFaded = false; @@ -639,6 +650,7 @@ public class AnnotationRenderer : null; if (x > -1) { + unsetAntialias(g); if (activeRow == i) { g.setColor(Color.red); @@ -714,6 +726,7 @@ public class AnnotationRenderer g2d.transform( AffineTransform.getScaleInstance(fmScaling, 1.0)); } + setAntialias(g); if (column == 0 || row.graph > 0) { g2d.drawString(displayChar, 0, 0); @@ -892,9 +905,12 @@ public class AnnotationRenderer // temp = x; break; default: + unsetAntialias(g); g.setColor(GLYPHLINE_COLOR); g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2); + g.drawRect(lastSSX, y + 6 + iconOffset, + (x * charWidth) - lastSSX - 1, 2); // temp = x; break; } @@ -1166,9 +1182,11 @@ public class AnnotationRenderer int y, int iconOffset, int startRes, int column, boolean validRes, boolean validEnd) { + unsetAntialias(g); g.setColor(GLYPHLINE_COLOR); - unsetAntiAlias(g); g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2); + g.drawRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX - 1, + 2); } void drawSheetAnnot(Graphics g, Annotation[] row, @@ -1176,26 +1194,29 @@ public class AnnotationRenderer int lastSSX, int x, int y, int iconOffset, int startRes, int column, boolean validRes, boolean validEnd) { - g.setColor(SHEET_COLOUR); - if (!validEnd || !validRes || row == null || row[column] == null || row[column].secondaryStructure != 'E') { + // draw the glyphline underneath + drawGlyphLine(g, row, lastSSX, x, y, iconOffset, startRes, column, + validRes, validEnd); + g.setColor(SHEET_COLOUR); fillRect(g, lastSSX, y + 4 + iconOffset, (x * charWidth) - lastSSX - 4, 6); fillPolygon(g, new int[] - { (x * charWidth) - 4, (x * charWidth) - 4, (x * charWidth) }, + { (x * charWidth) - 6, (x * charWidth) - 6, + (x * charWidth - 1) }, new int[] - { y + iconOffset, y + 14 + iconOffset, y + 7 + iconOffset }, + { y + iconOffset + 1, y + 13 + iconOffset, + y + 7 + iconOffset }, 3); } else { - fillRect(g, lastSSX, y + 4 + iconOffset, - (x + 1) * charWidth - lastSSX, 6); + g.setColor(SHEET_COLOUR); + fillRect(g, lastSSX, y + 4 + iconOffset, x * charWidth - lastSSX, 6); } - } void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX, int x, @@ -1216,7 +1237,7 @@ public class AnnotationRenderer int ofs = charWidth / 2; // Off by 1 offset when drawing rects and ovals // to offscreen image on the MAC - fillRoundRect(g, lastSSX, y + 4 + iconOffset, x2 - x1, 8, 8, 8); + fillRoundRect(g, lastSSX, y + 4 + iconOffset, x2 - x1 - 1, 8, 8, 8); if (sCol == 0 || row[sCol - 1] == null || row[sCol - 1].secondaryStructure != 'H') { @@ -1224,8 +1245,8 @@ public class AnnotationRenderer else { // g.setColor(Color.orange); - fillRoundRect(g, lastSSX, y + 4 + iconOffset, x2 - x1 - ofs + 1, 8, - 0, 0); + fillRoundRect(g, lastSSX, y + 4 + iconOffset, x2 - x1 - ofs, 8, 0, + 0); } if (!validRes || row[column] == null || row[column].secondaryStructure != 'H') @@ -1235,8 +1256,8 @@ public class AnnotationRenderer else { // g.setColor(Color.magenta); - fillRoundRect(g, lastSSX + ofs, y + 4 + iconOffset, - x2 - x1 - ofs + 1, 8, 0, 0); + fillRoundRect(g, lastSSX + ofs, y + 4 + iconOffset, x2 - x1 - ofs, + 8, 0, 0); } @@ -1253,8 +1274,8 @@ public class AnnotationRenderer if (!validRes || row[column] == null || row[column].secondaryStructure != 'H') { - fillArc(g, (x * charWidth) - charWidth, y + 4 + iconOffset, charWidth, - 8, 270, 180); + fillArc(g, (x * charWidth) - charWidth - 1, y + 4 + iconOffset, + charWidth, 8, 270, 180); x2 -= charWidth / 2; } @@ -1294,6 +1315,7 @@ public class AnnotationRenderer y2 = y - (int) ((0 - min / range) * graphHeight); } + setAntialias(g); g.setColor(Color.gray); g.drawLine(x - charWidth, y2, (eRes - sRes + 1) * charWidth, y2); @@ -1774,14 +1796,15 @@ public class AnnotationRenderer private static void fillPolygon(Graphics g, int[] xpoints, int[] ypoints, int n) { - setAntiAlias(g); + unsetAntialias(g); + g.fillPolygon(xpoints, ypoints, n); + setAntialias(g); g.fillPolygon(xpoints, ypoints, n); g.drawPolygon(xpoints, ypoints, n); } private static void fillRect(Graphics g, int a, int b, int c, int d) { - setAntiAlias(g); g.fillRect(a, b, c, d); g.drawRect(a, b, c, d); } @@ -1789,7 +1812,7 @@ public class AnnotationRenderer private static void fillRoundRect(Graphics g, int a, int b, int c, int d, int e, int f) { - setAntiAlias(g); + setAntialias(g); g.fillRoundRect(a, b, c, d, e, f); g.drawRoundRect(a, b, c, d, e, f); } @@ -1797,12 +1820,12 @@ public class AnnotationRenderer private static void fillArc(Graphics g, int a, int b, int c, int d, int e, int f) { - setAntiAlias(g); + setAntialias(g); g.fillArc(a, b, c, d, e, f); g.drawArc(a, b, c, d, e, f); } - private static void setAntiAlias(Graphics g) + private static void setAntialias(Graphics g) { if (Cache.getDefault("ANTI_ALIAS", true)) { @@ -1812,7 +1835,7 @@ public class AnnotationRenderer } } - private static void unsetAntiAlias(Graphics g) + private static void unsetAntialias(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, -- 1.7.10.2