Java Code Examples for org.eclipse.swt.graphics.GC#setAlpha()

The following examples show how to use org.eclipse.swt.graphics.GC#setAlpha() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndentGuidePainter.java    From IndentGuide with MIT License 6 votes vote down vote up
private void handleDrawRequest(GC gc, int x, int y, int w, int h) {
	int startLine = fTextWidget.getLineIndex(y);
	int endLine = fTextWidget.getLineIndex(y + h - 1);
	if (startLine <= endLine && startLine < fTextWidget.getLineCount()) {
		Color fgColor = gc.getForeground();
		LineAttributes lineAttributes = gc.getLineAttributes();
		gc.setForeground(Activator.getDefault().getColor());
		gc.setLineStyle(lineStyle);
		gc.setLineWidth(lineWidth);
		spaceWidth = gc.getAdvanceWidth(' ');
		if (fIsAdvancedGraphicsPresent) {
			int alpha = gc.getAlpha();
			gc.setAlpha(this.lineAlpha);
			drawLineRange(gc, startLine, endLine, x, w);
			gc.setAlpha(alpha);
		} else {
			drawLineRange(gc, startLine, endLine, x, w);
		}
		gc.setForeground(fgColor);
		gc.setLineAttributes(lineAttributes);
	}
}
 
Example 2
Source File: TimeGraphRender.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void innerDraw(GC gc) {
    Rectangle drawRect = getBounds();
    if (drawRect.width >= 2) {
        gc.fillRectangle(drawRect);
        if (drawRect.width > 2) {
            // Draw the top and bottom borders
            RGBAColor foregroundRGB = BLACK;
            gc.setAlpha(foregroundRGB.getAlpha());
            gc.setForeground(getColor(foregroundRGB.toInt()));
            gc.drawLine(drawRect.x, drawRect.y, drawRect.x + drawRect.width - 1, drawRect.y);
            gc.drawLine(drawRect.x, drawRect.y + drawRect.height - 1, drawRect.x + drawRect.width - 1, drawRect.y + drawRect.height - 1);
        }
    } else {
        gc.setForeground(gc.getBackground());
        gc.drawLine(drawRect.x, drawRect.y, drawRect.x, drawRect.y + drawRect.height - 1);
    }

}
 
Example 3
Source File: VerticalIndentGuidesPainter.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
private AutoCloseable configGC(final GC gc) {
    final int lineStyle = gc.getLineStyle();
    final int alpha = gc.getAlpha();
    final int[] lineDash = gc.getLineDash();

    final Color foreground = gc.getForeground();
    final Color background = gc.getBackground();

    gc.setForeground(this.indentGuide.getColor(styledText));
    gc.setBackground(styledText.getBackground());
    gc.setAlpha(this.indentGuide.getTransparency());
    gc.setLineStyle(SWT.LINE_CUSTOM);
    gc.setLineDash(new int[] { 1, 2 });
    return new AutoCloseable() {

        @Override
        public void close() throws Exception {
            gc.setForeground(foreground);
            gc.setBackground(background);
            gc.setAlpha(alpha);
            gc.setLineStyle(lineStyle);
            gc.setLineDash(lineDash);
        }
    };
}
 
Example 4
Source File: GraphUtils.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
public static void drawString(GC gc, String str, float x, float y, float width, float height, int bgAlpha) {
	if (str == null)
		return;

	org.eclipse.swt.graphics.Point size = gc.stringExtent(str);
	int posX = Math.round(x + width / 2 - size.x / 2);
	int posY = Math.round(y + height / 2 - size.y / 2);

	if (bgAlpha >= 255) {
		gc.drawString(str, posX, posY);
	} else {
		gc.drawString(str, posX, posY, true);
		if (bgAlpha > 0) {
			gc.setAlpha(bgAlpha);
			gc.fillRectangle(posX, posY, size.x, size.y);
			gc.setAlpha(255);
		}
	}
}
 
Example 5
Source File: IndentGuidesPainter.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private void handleDrawRequest(GC gc, int x, int y, int w, int h) {
	int startLine = fTextWidget.getLineIndex(y);
	int endLine = fTextWidget.getLineIndex(y + h - 1);
	if (startLine <= endLine && startLine < fTextWidget.getLineCount()) {
		Color fgColor = gc.getForeground();
		LineAttributes lineAttributes = gc.getLineAttributes();
		gc.setForeground(color);
		gc.setLineStyle(lineStyle);
		gc.setLineWidth(lineWidth);
		if (fIsAdvancedGraphicsPresent) {
			int alpha = gc.getAlpha();
			gc.setAlpha(this.lineAlpha);
			drawLineRange(gc, startLine, endLine, x, w);
			gc.setAlpha(alpha);
		} else {
			drawLineRange(gc, startLine, endLine, x, w);
		}
		gc.setForeground(fgColor);
		gc.setLineAttributes(lineAttributes);
	}
}
 
Example 6
Source File: CTree.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
protected void paintFocus(GC gc, Rectangle ebounds) {
	if (hasFocus) {
		if (win32 || (gtk && !paintedItems.isEmpty()))
			return;

		gc.setAlpha(255);
		gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
		gc.setLineDash(new int[] { 1, 1 });
		Rectangle r = getContentArea();
		r.x += (1 - ebounds.x);
		r.y += (1 - ebounds.y);
		r.width -= 3;
		r.height -= 3;
		gc.drawRectangle(r);
	}
}
 
Example 7
Source File: CTree.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
protected void paintViewport(GC gc, Rectangle ebounds) {
	if (drawViewportNorth || drawViewportEast || drawViewportSouth
			|| drawViewportWest) {
		gc.setAlpha(255);
		gc.setForeground(colors.getBorder());
		Rectangle r = getClientArea();
		if (drawViewportNorth)
			gc.drawLine(r.x, r.y, r.x + r.width, r.y);
		if (drawViewportEast)
			gc.drawLine(r.x + r.width - 1, r.y, r.x + r.width - 1, r.y
					+ r.height);
		if (drawViewportSouth)
			gc.drawLine(r.x, r.y + r.height - 1, r.x + r.width, r.y
					+ r.height - 1);
		if (drawViewportWest)
			gc.drawLine(r.x, r.y, r.x, r.y + r.height);
	}
}
 
Example 8
Source File: TimeGraphRender.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void draw(@Nullable ITimeGraphPresentationProvider provider, GC gc) {
    RGBAColor rgba = fColorRGBA;
    int colorInt = rgba.toInt();
    Color color = getColor(colorInt);
    for (int i = 0; i < this.fSeriesPoints.size(); i++) {
        Color prev = gc.getForeground();
        int prevAlpha = gc.getAlpha();
        gc.setAlpha(rgba.getAlpha());
        gc.setForeground(color);
        List<LongPoint> series = fSeriesPoints.get(i);
        int[] points = new int[series.size() * 2];
        for (int point = 0; point < series.size(); point++) {
            LongPoint longPoint = series.get(point);
            points[point * 2] = longPoint.x;
            points[point * 2 + 1] = fBounds.height - (int) ((longPoint.y - fMin) * fScale) + fBounds.y;
        }
        gc.drawPolyline(points);
        gc.setForeground(prev);
        gc.setAlpha(prevAlpha);
    }
}
 
Example 9
Source File: TimeGraphControl.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Draw the grid lines
 *
 * @param bounds
 *            The bounds of the control
 * @param gc
 *            Graphics context
 * @since 2.0
 */
public void drawGridLines(Rectangle bounds, GC gc) {
    if (!fGridLinesVisible) {
        return;
    }
    gc.setForeground(fGridLineColor);
    gc.setAlpha(fGridLineColor.getAlpha());
    for (int x : fTimeGraphScale.getTickList()) {
        gc.drawLine(x, bounds.y, x, bounds.y + bounds.height);
    }
    gc.setAlpha(OPAQUE);
}
 
Example 10
Source File: CellRendererBase.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draws a cell selection by overlaying alpha blended area using SELECTIONCOLOR.
 * 
 * @param gc GC
 * @param area area of the cell
 * @param style cellstyle
 * @param selected true if selecetd
 * @param printing true if printing - no selection will be drawn when printing
 */
protected void drawSelection(GC gc, Rectangle area, ICellStyle style, boolean selected, boolean printing) {
    Color c = gc.getBackground();
    Color bg;

    if (selected && !printing) {
        bg = SELECTIONCOLOR;
        gc.setBackground(bg);
        int alpha = gc.getAlpha();
        gc.setAlpha(SELECTIONALPHA);
        gc.fillRectangle(area);
        gc.setAlpha(alpha);
        gc.setBackground(c);
    }
}
 
Example 11
Source File: SwtMapPane.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private void drawFinalImage(final Image swtImage) {
	final Image tmpImage = new Image(getDisplay(), curPaintArea.width, curPaintArea.height);
	final GC tmpGc = new GC(tmpImage);
	tmpGc.setBackground(white);
	tmpGc.fillRectangle(0, 0, curPaintArea.width, curPaintArea.height);
	if (swtImage != null) {
		tmpGc.setAlpha(alpha);
		tmpGc.drawImage(swtImage, imageOrigin.x, imageOrigin.y);
	}
	if (gc != null && !gc.isDisposed()) {
		gc.drawImage(tmpImage, imageOrigin.x, imageOrigin.y);
	}
	tmpGc.dispose();
	tmpImage.dispose();
}
 
Example 12
Source File: TimeGraphControl.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void oldDrawMarker(IMarkerEvent marker, GC gc, Rectangle rect) {
    Color color = getColorScheme().getColor(marker.getColor());
    gc.setBackground(color);
    gc.setAlpha(color.getAlpha());
    gc.fillRectangle(rect);
    gc.setAlpha(OPAQUE);
    String label = marker.getLabel();
    if (fLabelsVisible && label != null && marker.getEntry() != null) {
        label = label.substring(0, Math.min(label.indexOf('\n') != -1 ? label.indexOf('\n') : label.length(), MAX_LABEL_LENGTH));
        gc.setForeground(color);
        Utils.drawText(gc, label, rect.x - gc.textExtent(label).x, rect.y, true);
    }
}
 
Example 13
Source File: VControl.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void setAlpha(GC gc, int alpha) {
	gc.setAlpha((int) ((double) alpha * (double) visibility * 0.01));
}
 
Example 14
Source File: LauncherLabel.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Draw the content of the LLabel
 *
 * @param event paintevent
 */
private void onPaint(final PaintEvent event) {
	final Rectangle rect = getClientArea();
	if (rect.width == 0 || rect.height == 0) {
		return;
	}

	final Image bufferImage = new Image(getDisplay(), Math.max(1, rect.width), Math.max(1, rect.height));

	final GC gc = new GC(bufferImage);
	gc.setForeground(getForeground());
	gc.setBackground(getBackground());

	gc.fillRectangle(rect);

	final Point extent = getTotalSize(image.getBounds().width, image.getBounds().height);
	final int xImage = (rect.width - image.getBounds().width) / 2;
	final int yImage = (rect.height - extent.y) / 2;
	gc.drawImage(image, xImage, yImage);

	gc.setFont(font);
	final int xText = (rect.width - textSize.x) / 2;
	final int yText = yImage + image.getBounds().height + GAP - textSize.y / 2;
	gc.drawString(text, xText, yText);

	if (animationStep != 0) {
		final float zoom = 1f + animationStep * (Math.max(extent.x, extent.y) - Math.max(image.getBounds().width, image.getBounds().height)) / MAX_NUMBER_OF_STEPS / 100f;

		final int newSizeX = (int) (image.getBounds().width * zoom);
		final int newSizeY = (int) (image.getBounds().height * zoom);

		gc.setAntialias(SWT.ON);
		gc.setInterpolation(SWT.HIGH);

		gc.setAlpha(255 - 255 / MAX_NUMBER_OF_STEPS * animationStep);

		final Point extentZoomedImage = getTotalSize(newSizeX, newSizeY);
		final int xZoomedImage = (rect.width - newSizeX) / 2;
		final int yZoomedImage = (rect.height - extentZoomedImage.y) / 2;
		gc.drawImage(image, 0, 0, image.getBounds().width, image.getBounds().height, xZoomedImage, yZoomedImage, (int) (image.getBounds().width * zoom), (int) (image.getBounds().height * zoom));

	}

	gc.dispose();

	event.gc.drawImage(bufferImage, 0, 0);

	bufferImage.dispose();

}
 
Example 15
Source File: AbstractPaintManager.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void drawCheckpoint(final GanttComposite ganttComposite, final ISettings settings, final IColorManager colorManager, final GanttEvent event, final GC gc, final boolean threeDee, final int dayWidth, final int x, final int y, final Rectangle bounds) {
    Color cEvent = event.getStatusColor();

    if (cEvent == null) {
        cEvent = settings.getDefaultEventColor();
    }

    gc.setBackground(cEvent);

    final int height = settings.getEventHeight();

    // draw a special fun thing! (tm)
    final long days = DateHelper.daysBetween(event.getActualStartDate(), event.getActualEndDate());

    drawCheckpointMarker(gc, settings, colorManager, event, threeDee, x, y, dayWidth, height, bounds);

    // multi day checkpoint
    if (days != 0) {
        final int width = (int) days * dayWidth;
        drawCheckpointMarker(gc, settings, colorManager, event, threeDee, x + width, y, dayWidth, height, bounds);

        // draw center
        final int neg = height / 2 - 1;
        final Rectangle rect = new Rectangle(x + dayWidth, y + neg, width - dayWidth, neg);
        gc.setForeground(colorManager.getBlack());
        gc.fillRectangle(rect);
        gc.drawRectangle(rect);

        if (settings.showBarsIn3D()) {
            final boolean alpha = (colorManager.useAlphaDrawing() || colorManager.useAlphaDrawingOn3DEventDropShadows());
            if (alpha) {
                gc.setAlpha(200);
            }

            gc.setForeground(colorManager.getFadeOffColor1());
            gc.drawLine(rect.x + 1, rect.y + rect.height + 1, rect.x + rect.width - 1, rect.y + rect.height + 1);

            if (alpha) {
                gc.setAlpha(100);
            }

            gc.setForeground(colorManager.getFadeOffColor2());
            gc.drawLine(rect.x + 1, rect.y + rect.height + 2, rect.x + rect.width - 1, rect.y + rect.height + 2);

            if (alpha) {
                gc.setAlpha(50);
            }

            gc.setForeground(colorManager.getFadeOffColor3());
            gc.drawLine(rect.x + 1, rect.y + rect.height + 3, rect.x + rect.width - 1, rect.y + rect.height + 3);

            if (alpha) {
                gc.setAlpha(255);
                gc.setAdvanced(false);
            }
        }
    }
}
 
Example 16
Source File: AbstractPaintManager.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void drawCheckpointMarker(final GC gc, final ISettings settings, final IColorManager colorManager, final GanttEvent event, final boolean threeDee, final int x, final int y, final int width, final int height, final Rectangle bounds) {
    final float fHoriSpacer = width * 0.17f;
    final int hSpacer = (int) fHoriSpacer;

    final float fVertiSpacer = height * 0.23f;
    final int vSpacer = (int) fVertiSpacer;

    final Rectangle topToBottom = new Rectangle(x + hSpacer, y, width - (hSpacer * 2), height + vSpacer);
    final Rectangle leftToRight = new Rectangle(x, y + vSpacer, width, height - vSpacer);
    final Rectangle inner = new Rectangle(x + hSpacer, y + vSpacer, width - (hSpacer * 2), height - (vSpacer * 2));

    Color cEvent = event.getStatusColor();
    Color gradient = event.getGradientStatusColor();

    if (cEvent == null) {
        cEvent = settings.getDefaultEventColor();
    }
    if (gradient == null) {
        gradient = settings.getDefaultGradientEventColor();
    }

    gc.setForeground(gradient);
    gc.setBackground(cEvent);
    gc.fillRectangle(topToBottom);
    gc.fillRectangle(leftToRight);
    gc.fillGradientRectangle(inner.x, inner.y, inner.width, inner.height, true);

    gc.setForeground(colorManager.getBlack());

    gc.drawRectangle(topToBottom);
    gc.drawRectangle(leftToRight);

    if (threeDee) {
        final boolean alpha = (colorManager.useAlphaDrawing() || colorManager.useAlphaDrawingOn3DEventDropShadows());
        if (alpha) {
            gc.setAlpha(200);
        }

        gc.setForeground(colorManager.getFadeOffColor1());
        // horizontal line.. ends a few pixles right of bottom right corner
        gc.drawLine(leftToRight.x, leftToRight.y + leftToRight.height + 1, leftToRight.x + hSpacer - 1, leftToRight.y + leftToRight.height + 1);
        gc.drawLine(leftToRight.x + hSpacer, leftToRight.y + leftToRight.height + vSpacer + 1, leftToRight.x - hSpacer + leftToRight.width, leftToRight.y + leftToRight.height + vSpacer + 1);
        gc.drawLine(leftToRight.x + leftToRight.width - hSpacer + 1, leftToRight.y + leftToRight.height + 1, leftToRight.x + leftToRight.width + 1, leftToRight.y + leftToRight.height + 1);

        // vertical line at end, starts slightly below top right corner
        gc.drawLine(leftToRight.x + leftToRight.width + 1, leftToRight.y + 2, leftToRight.x + leftToRight.width + 1, leftToRight.y + leftToRight.height + 1);

        if (alpha) {
            gc.setAlpha(100);
        }

        gc.setForeground(colorManager.getFadeOffColor2());
        gc.drawLine(leftToRight.x, leftToRight.y + leftToRight.height + 2, leftToRight.x + hSpacer - 1, leftToRight.y + leftToRight.height + 2);
        gc.drawLine(leftToRight.x + hSpacer, leftToRight.y + leftToRight.height + vSpacer + 2, leftToRight.x - hSpacer + leftToRight.width, leftToRight.y + leftToRight.height + vSpacer + 2);
        gc.drawLine(leftToRight.x + leftToRight.width - hSpacer + 1, leftToRight.y + leftToRight.height + 2, leftToRight.x + leftToRight.width + 1, leftToRight.y + leftToRight.height + 2);

        gc.drawLine(leftToRight.x + leftToRight.width + 2, leftToRight.y + 3, leftToRight.x + leftToRight.width + 2, leftToRight.y + leftToRight.height + 1);

        if (alpha) {
            gc.setAlpha(50);
        }

        gc.setForeground(colorManager.getFadeOffColor3());
        gc.drawLine(leftToRight.x, leftToRight.y + leftToRight.height + 3, leftToRight.x + hSpacer - 1, leftToRight.y + leftToRight.height + 3);
        gc.drawLine(leftToRight.x + hSpacer, leftToRight.y + leftToRight.height + vSpacer + 3, leftToRight.x - hSpacer + leftToRight.width, leftToRight.y + leftToRight.height + vSpacer + 3);
        gc.drawLine(leftToRight.x + leftToRight.width - hSpacer + 1, leftToRight.y + leftToRight.height + 3, leftToRight.x + leftToRight.width + 1, leftToRight.y + leftToRight.height + 3);

        gc.drawLine(leftToRight.x + leftToRight.width + 3, leftToRight.y + 4, leftToRight.x + leftToRight.width + 3, leftToRight.y + leftToRight.height + 1);

        if (alpha) {
            gc.setAlpha(255);
            gc.setAdvanced(false);
        }

    }
}
 
Example 17
Source File: NebulaToolbar.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Paint widget using Windows Vista mode on graphical canvas.
 * 
 * @param gc GC
 */
private void paintVista(GC gc)
{
	Color defaultForeground = gc.getForeground();
	Color defaultBackground = gc.getBackground();

	Rectangle rect = getClientArea();
	Device device = gc.getDevice();

	Color c1 = new Color(device, 5, 72, 117);
	Color c2 = new Color(device, 25, 108, 119);
	Color c3 = new Color(device, 28, 122, 134);
	Color wh = getDisplay().getSystemColor(SWT.COLOR_WHITE);

	int middle = (int) Math.ceil(rect.height / 2);

	Pattern patternBg1 = new Pattern(device, 0, 0, rect.width, middle, c1, 255, c3, 255);
	gc.setBackgroundPattern(patternBg1);
	gc.fillRectangle(new Rectangle(0, 0, rect.width, middle));
	gc.setBackgroundPattern(null);

	Pattern patternBg2 = new Pattern(device, 0, middle, rect.width, rect.height - middle, c1, 255, c2, 255);
	gc.setBackgroundPattern(patternBg2);
	gc.fillRectangle(new Rectangle(0, middle, rect.width, rect.height - middle));
	gc.setBackgroundPattern(null);

	Pattern patternTopGrad = new Pattern(device, 0, 0, 0, middle, wh, 120, wh, 50);
	gc.setBackgroundPattern(patternTopGrad);
	gc.fillRectangle(new Rectangle(0, 0, rect.width, middle));
	gc.setBackgroundPattern(null);

	Pattern patternBtmGrad = new Pattern(device, 0, middle + 5, 0, rect.height, c1, 0, wh, 125);
	gc.setBackgroundPattern(patternBtmGrad);
	gc.fillRectangle(new Rectangle(0, middle + 5, rect.width, rect.height));
	gc.setBackgroundPattern(null);

	gc.setAlpha(125);
	gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
	gc.drawPolygon(new int[]{0, 0, rect.width - 1, 0, rect.width - 1, rect.height - 2, 0, rect.height - 2});

	gc.setAlpha(200);
	gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_BLACK));
	gc.drawLine(0, rect.height - 1, rect.width - 1, rect.height - 1);

	gc.setForeground(defaultForeground);
	gc.setBackground(defaultBackground);
	gc.setAlpha(255);

	c1.dispose();
	c2.dispose();
	c3.dispose();

	patternBg1.dispose();
	patternBg2.dispose();
	patternTopGrad.dispose();
	patternBtmGrad.dispose();
}
 
Example 18
Source File: Plotter.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
protected void paintControl(Event e) {

		for (int c = 0; c < this.chan.length; c++) {

			// Go calculate the line
			Object[] result = calculate(c);
			int[] l1 = (int[]) result[0];
			int[] l2 = (int[]) result[1];

			PositionPolyLine(l1);
			PositionPolyLine(l2);

			// Draw it
			GC gc = e.gc;
			gc.setForeground(getForeground(c));
			gc.setAdvanced(true);
			gc.setAntialias(this.chan[c].antiAlias ? SWT.ON : SWT.OFF);
			gc.setLineWidth(getLineWidth(c));

			// Fade tail
			if (isFade(c)) {
				gc.setAlpha(0);
				double fade = 0;
				double fadeOutStep = (double) 125 / (double) ((getTailSize(c) * (getTailFade(c)) / 100));
				for (int i = 0; i < l1.length - 4;) {
					fade += (fadeOutStep / 2);
					setAlpha(gc, fade);
					gc.drawLine(l1[i], l1[i + 1], l1[i + 2], l1[i + 3]);
					i += 2;
				}

				for (int i = 0; i < l2.length - 4;) {
					fade += (fadeOutStep / 2);
					setAlpha(gc, fade);
					gc.drawLine(l2[i], l2[i + 1], l2[i + 2], l2[i + 3]);
					i += 2;
				}

			} else {
				gc.drawPolyline(l1);
				gc.drawPolyline(l2);
			}

			// Connects the head with the tail
			if (isConnect(c) && !isFade(c) && this.chan[c].originalTailSize == TAILSIZE_MAX && l1.length > 0
					&& l2.length > 0) {
				gc.drawLine(l2[l2.length - 2], l2[l2.length - 1], l1[0], l1[1]);
			}
		}
	}
 
Example 19
Source File: Oscilloscope.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
protected void paintControl(Event e) {

		for (int c = 0; c < chan.length; c++) {

			if (chan[c].tailSize <= 0) {
				chan[c].stack.popNegate(0);
				continue;
			}

			// Go calculate the line
			Object[] result = calculate(c);
			int[] l1 = (int[]) result[0];
			int[] l2 = (int[]) result[1];

			// Draw it
			GC gc = e.gc;
			gc.setForeground(getForeground(c));
			gc.setAdvanced(true);
			gc.setAntialias(chan[c].antiAlias ? SWT.ON : SWT.OFF);
			gc.setLineWidth(getLineWidth(c));

			// Fade tail
			if (isFade(c)) {
				gc.setAlpha(0);
				double fade = 0;
				double fadeOutStep = (double) 125 / (double) ((getTailSize(c) * (getTailFade(c)) / 100));
				for (int i = 0; i < l1.length - 4;) {
					fade += (fadeOutStep / 2);
					setAlpha(gc, fade);
					gc.drawLine(l1[i], l1[i + 1], l1[i + 2], l1[i + 3]);
					i += 2;
				}

				for (int i = 0; i < l2.length - 4;) {
					fade += (fadeOutStep / 2);
					setAlpha(gc, fade);
					gc.drawLine(l2[i], l2[i + 1], l2[i + 2], l2[i + 3]);
					i += 2;
				}

			} else {
				gc.drawPolyline(l1);
				gc.drawPolyline(l2);
			}

			// Connects the head with the tail
			if (isConnect(c) && !isFade(c) && chan[c].originalTailSize == TAILSIZE_MAX && l1.length > 0 && l2.length > 0) {
				gc.drawLine(l2[l2.length - 2], l2[l2.length - 1], l1[0], l1[1]);
			}
		}
	}
 
Example 20
Source File: PieUtils.java    From BiglyBT with GNU General Public License v2.0 2 votes vote down vote up
public static void
drawPie(
	GC gc,Image image, int x, int y,int width,int height,int percent, boolean draw_border )
{
	Rectangle image_size = image.getBounds();

	int	width_pad 	= ( width - image_size.width  )/2;
	int	height_pad 	= ( height - image_size.height  )/2;

    int angle = (percent * 360) / 100;
    if(angle<4){
    	angle = 0; // workaround fillArc rendering bug
    }

	Region old_clipping = new Region();

	gc.getClipping(old_clipping);

	Path path_done = new Path(gc.getDevice());

	path_done.addArc(x,y,width,height,90,-angle);
	path_done.lineTo( x+width/2, y+height/2);
	path_done.close();

	gc.setClipping( path_done );

	gc.drawImage(image, x+width_pad, y+height_pad+1);

	Path path_undone = new Path(gc.getDevice());

	path_undone.addArc(x,y,width,height,90-angle,angle-360);
	path_undone.lineTo( x+width/2, y+height/2);
	path_undone.close();

	gc.setClipping( path_undone );

	gc.setAlpha( 75 );
	gc.drawImage(image, x+width_pad, y+height_pad+1);
	gc.setAlpha( 255 );

	gc.setClipping( old_clipping );

	if ( draw_border ){

		gc.setForeground(Colors.blue);

		if ( percent == 100 ){

			gc.drawOval(x , y , width-1, height-1);

		}else{

			if ( angle > 0 ){

				gc.drawPath( path_done );
			}
		}
	}

	path_done.dispose();
	path_undone.dispose();
	old_clipping.dispose();

}