tmf: Fix Linux drawing weirdness in Histogram
authorPatrick Tasse <patrick.tasse@gmail.com>
Tue, 3 Dec 2013 19:22:48 +0000 (14:22 -0500)
committerPatrick Tasse <patrick.tasse@gmail.com>
Tue, 3 Dec 2013 22:17:22 +0000 (17:17 -0500)
- Set anti-aliasing to off when drawing histogram bars because it's on
by default in Linux

- Change order of drawing histogram bars and draw one pixel too far
because Linux doesn't draw last pixel of a line

- Clamp rounded rectangle arc size to rectangle width because Linux
doesn't

Change-Id: I574c80ecf15cda8655b3fbb8b34b80fd0f5a6d0c
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/19263
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
IP-Clean: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Hudson CI
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/Histogram.java

index 9d3a29cb60c766b994427566020d03d2692f669c..823789c4fa57a59fe0683ed6e196fa90d63287f6 100644 (file)
@@ -685,6 +685,10 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi
             final int width = image.getBounds().width;
             final int height = image.getBounds().height;
 
+            // Turn off anti-aliasing
+            int aliasing = imageGC.getAntialias();
+            imageGC.setAntialias(SWT.OFF);
+
             // Clear the drawing area
             imageGC.setBackground(fBackgroundColor);
             imageGC.fillRectangle(0, 0, image.getBounds().width + 1, image.getBounds().height + 1);
@@ -693,24 +697,24 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi
             final int limit = width < scaledData.fWidth ? width : scaledData.fWidth;
             double factor = HistogramScaledData.hideLostEvents ? scaledData.fScalingFactor : scaledData.fScalingFactorCombined;
             for (int i = 0; i < limit; i++) {
-                imageGC.setForeground(fHistoBarColor);
                 final int value = (int) Math.ceil(scaledData.fData[i] * factor);
                 int x = i + fOffset;
-                imageGC.drawLine(x, height - value, x, height);
 
+                // in Linux, the last pixel in a line is not drawn,
+                // so draw lost events first, one pixel too far
                 if (!HistogramScaledData.hideLostEvents) {
                     imageGC.setForeground(fLostEventColor);
                     final int lostEventValue = (int) Math.ceil(scaledData.fLostEventsData[i] * factor);
                     if (lostEventValue != 0) {
-                        if (lostEventValue == 1) {
-                            // in linux, a line from x to x is not drawn, in windows it is.
-                            imageGC.drawPoint(x, height - value - 1);
-                        } else {
-                            // drawing a line is inclusive, so we need to remove 1 from the destination to have the correct length
-                            imageGC.drawLine(x, height - value - lostEventValue, x, height - value - 1);
-                        }
+                        // drawing a line is inclusive, so we should remove 1 from y2
+                        // but we don't because Linux
+                        imageGC.drawLine(x, height - value - lostEventValue, x, height - value);
                     }
                 }
+
+                // then draw normal events second, to overwrite that extra pixel
+                imageGC.setForeground(fHistoBarColor);
+                imageGC.drawLine(x, height - value, x, height);
             }
 
             // Draw the selection bars
@@ -743,6 +747,9 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi
             imageGC.setBackground(fFillColor);
             imageGC.fillRectangle(delimiterIndex + 1, 0, width - (delimiterIndex + 1), height);
 
+            // Restore anti-aliasing
+            imageGC.setAntialias(aliasing);
+
         } catch (final Exception e) {
             // Do nothing
         }
@@ -780,17 +787,18 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi
         int right = left + rangeWidth;
         int center = (left + right) / 2;
         int height = fCanvas.getSize().y;
+        int arc = Math.min(15, rangeWidth);
 
         // Draw the selection window
         imageGC.setForeground(fTimeRangeColor);
         imageGC.setLineWidth(1);
         imageGC.setLineStyle(SWT.LINE_SOLID);
-        imageGC.drawRoundRectangle(left, 0, rangeWidth, height - 1, 15, 15);
+        imageGC.drawRoundRectangle(left, 0, rangeWidth, height - 1, arc, arc);
 
         // Fill the selection window
         imageGC.setBackground(fTimeRangeColor);
         imageGC.setAlpha(35);
-        imageGC.fillRoundRectangle(left + 1, 1, rangeWidth - 1, height - 2, 15, 15);
+        imageGC.fillRoundRectangle(left + 1, 1, rangeWidth - 1, height - 2, arc, arc);
         imageGC.setAlpha(255);
 
         // Draw the cross hair
This page took 0.02636 seconds and 5 git commands to generate.