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

The following examples show how to use org.eclipse.swt.graphics.GC#getAlpha() . 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: TableColumnOTOF_Size.java    From BiglyBT with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void cellPaint(GC gc, TableCellSWT cell) {
 	Object ds = cell.getDataSource();
 	if (!(ds instanceof TorrentOpenFileOptions)) {
 		return;
 	}
 	TorrentOpenFileOptions tfi = (TorrentOpenFileOptions) ds;

 	float pct = tfi.lSize / (float) tfi.parent.getTorrent().getSize();

 	Rectangle bounds = cell.getBounds();

	bounds.width = (int) (bounds.width * pct);
	if (bounds.width > 2) {
		bounds.x++;
		bounds.y++;
		bounds.height -= 2;
		bounds.width -= 2;
 		gc.setBackground(gc.getForeground());
 		int alpha = gc.getAlpha();
 		gc.setAlpha(10);
 		gc.fillRectangle(bounds);
 		gc.setAlpha(alpha);
	}
}
 
Example 2
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 3
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 4
Source File: WhitespaceCharacterPainter.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draw characters in view range.
 * 
 * @param gc
 * @param x
 * @param y
 * @param w
 * @param h
 */
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())
	{
		if (fIsAdvancedGraphicsPresent)
		{
			int alpha = gc.getAlpha();
			gc.setAlpha(100);
			drawLineRange(gc, startLine, endLine, x, w);
			gc.setAlpha(alpha);
		}
		else
			drawLineRange(gc, startLine, endLine, x, w);
	}
}
 
Example 5
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 6
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 7
Source File: Oscilloscope.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void setAlpha(GC gc, double fade) {

		if (gc.getAlpha() == fade) {
			return;
		}
		if (fade >= 255) {
			gc.setAlpha(255);
		} else {
			gc.setAlpha((int) fade);
		}
	}
 
Example 8
Source File: Plotter.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private static void setAlpha(GC gc, double fade) {

		if (gc.getAlpha() == fade) {
			return;
		}
		if (fade >= 255) {
			gc.setAlpha(255);
		} else {
			gc.setAlpha((int) fade);
		}
	}
 
Example 9
Source File: TimeGraphRender.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public final void draw(@Nullable ITimeGraphPresentationProvider provider, GC gc) {
    Rectangle bounds = getBounds();
    // basic sanity
    if (bounds.width <= 0 || bounds.height <= 0) {
        return;
    }
    int prevAlpha = gc.getAlpha();
    Color prevBgColor = gc.getBackground();
    Color prevFgColor = gc.getForeground();
    int prevLineWidth = gc.getLineWidth();
    setContext(gc);
    innerDraw(gc);
    if (fLineWidth != NO_BORDER) {
        setContext(gc);
        gc.setAlpha(fBorderColor.getAlpha());
        drawBorder(gc);
    }
    setContext(gc);
    drawLabel(gc);
    if (provider != null) {
        gc.setLineWidth(prevLineWidth);
        gc.setBackground(prevBgColor);
        gc.setForeground(prevFgColor);
        gc.setAlpha(prevAlpha);
        postDraw(provider, gc);
    }
    // reset context
    gc.setLineWidth(prevLineWidth);
    gc.setBackground(prevBgColor);
    gc.setForeground(prevFgColor);
    gc.setAlpha(prevAlpha);
}
 
Example 10
Source File: CellRendererBase.java    From translationstudio8 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: 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 12
Source File: TimeGraphControl.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Draw an arrow
 *
 * @param colors
 *            Color scheme
 * @param event
 *            Time event for which we're drawing the arrow
 * @param rect
 *            The arrow rectangle
 * @param gc
 *            Graphics context
 * @return true if the arrow was drawn
 */
protected boolean drawArrow(TimeGraphColorScheme colors, @NonNull ITimeEvent event,
        Rectangle rect, GC gc) {

    if (rect == null || ((rect.height == 0) && (rect.width == 0))) {
        return false;
    }
    StyleManager styleManager = getStyleManager();
    OutputElementStyle elementStyle = getElementStyle(event);
    if (elementStyle == null) {
        return false;
    }

    RGBAColor rgba = styleManager.getColorStyle(elementStyle, StyleProperties.COLOR);
    rgba = (rgba != null) ? rgba : BLACK;
    int colorInt = rgba.toInt();
    Color color = TimeGraphRender.getColor(colorInt);
    int alpha = rgba.getAlpha();
    int prevAlpha = gc.getAlpha();
    gc.setAlpha(alpha);

    gc.setForeground(color);
    gc.setBackground(color);
    int old = gc.getLineWidth();
    Float widthFactor = styleManager.getFactorStyle(elementStyle, StyleProperties.WIDTH);
    if (widthFactor == null) {
        Float heightFactor = styleManager.getFactorStyle(elementStyle, StyleProperties.HEIGHT);
        widthFactor = (heightFactor != null) ? heightFactor * 10.0f : 1.0f;
    }
    widthFactor = Math.max(1.0f, Math.min(10.0f, widthFactor));
    gc.setLineWidth(widthFactor.intValue());
    /* Draw the arrow */
    Point newEndpoint = drawArrowHead(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height, widthFactor, gc);
    gc.drawLine(rect.x, rect.y, newEndpoint.x, newEndpoint.y);
    gc.setLineWidth(old);
    gc.setAlpha(prevAlpha);
    if (!Boolean.TRUE.equals(styleManager.getStyle(elementStyle, ITimeEventStyleStrings.annotated()))) {
        fPostDrawArrows.add(new PostDrawEvent(event, rect));
    }
    return true;
}