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

The following examples show how to use org.eclipse.swt.graphics.GC#setInterpolation() . 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: SWTGraphicUtil.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns a new scaled image.
 *
 * @param source the image to be scaled
 * @param newWidth new width of the image
 * @param newHeight new height of the image
 * @return a scaled image of the source
 */
public static Image resize(final Image source, final int newWidth, final int newHeight) {
	if (source == null) {
		return null;
	}

	if (source.isDisposed()) {
		SWT.error(SWT.ERROR_WIDGET_DISPOSED);
	}

	final Image scaledImage = new Image(source.getDevice(), newWidth, newHeight);
	final GC gc = new GC(scaledImage);
	gc.setAntialias(SWT.ON);
	gc.setInterpolation(SWT.HIGH);
	gc.drawImage(source, 0, 0, source.getBounds().width, source.getBounds().height, 0, 0, newWidth, newHeight);
	gc.dispose();

	return scaledImage;
}
 
Example 2
Source File: Pics.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * get the system image resized in 16x16 (only used in connectors label provider)
 *
 * @param id
 * @return
 */
public static Image getSystemImage(final int id) {
    final ImageRegistry reg = plugin.getImageRegistry();

    final String imageName = id + "";
    Image result = reg.get(imageName);

    if (result != null && !result.isDisposed()) {//prevent from bad dispose
        return result;
    }
    result = Display.getCurrent().getSystemImage(id);
    final Image scaled = new Image(Display.getDefault(), 16, 16);
    final GC gc = new GC(scaled);
    gc.setAntialias(SWT.ON);
    gc.setInterpolation(SWT.HIGH);
    gc.drawImage(result, 0, 0, result.getBounds().width, result.getBounds().height, 0, 0, 16, 16);
    gc.dispose();
    result = scaled;
    reg.remove(imageName);
    reg.put(imageName, result);
    return result;
}
 
Example 3
Source File: AdvancedGC.java    From swt-bling with MIT License 6 votes vote down vote up
public static void setAdvanced(GC gc, boolean targetSetting) {
    if (targetSetting) {
        try {
            gc.setAdvanced(true);
            gc.setAntialias(SWT.ON);
            gc.setTextAntialias(SWT.ON);
            gc.setInterpolation(SWT.HIGH);
        } catch (SWTException e) {
            if (!loggedAdvanced) {
                log.log(Level.WARNING, "Unable to set advanced drawing", e);
                loggedAdvanced = true;
            }
        }
    } else {
        gc.setAdvanced(false);
    }

}
 
Example 4
Source File: SimpleToolBarEx.java    From SWET with MIT License 5 votes vote down vote up
private Image resize(Image image, int width, int height) {
	Image scaled = new Image(display, width, height);
	GC gc = new GC(scaled);
	gc.setAntialias(SWT.ON);
	gc.setInterpolation(SWT.HIGH);
	gc.drawImage(image, 0, 0, image.getBounds().width, image.getBounds().height,
			0, 0, width, height);
	gc.dispose();
	image.dispose();
	return scaled;
}
 
Example 5
Source File: InteractiveDecorator.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * TODO: move to UtilityClass
 * 
 * This method disposes the input image and returns a new Image.
 * 
 * @param image
 * @param width
 * @param height
 * @return
 */
protected Image resize(Image image, int width, int height) {
	Image scaled = new Image(image.getDevice(), width, height);
	GC gc = new GC(scaled);
	gc.setAntialias(SWT.ON);
	gc.setInterpolation(SWT.HIGH);
	gc.drawImage(image, 0, 0, image.getBounds().width,
			image.getBounds().height, 0, 0, width, height);
	gc.dispose();
	image.dispose();
	return scaled;
}
 
Example 6
Source File: MainSplash.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * Paint.
 *
 * @param gc
 */
private void paint(GC gc) {
	Point size = shell.getSize();
    Point offsets = gc.textExtent(version);
    gc.setAdvanced(true);
    gc.setAntialias(SWT.ON);
    gc.setInterpolation(SWT.ON);
    gc.drawImage(splash, 0,  0, splash.getBounds().width, splash.getBounds().height, 0, 0, size.x,  size.y);
    gc.setForeground(GUIHelper.COLOR_BLACK);
    gc.drawString(version, size.x - (int)offsets.x - 10, size.y - (int)offsets.y - 10, true);
}
 
Example 7
Source File: Gallery.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
void onPaint(GC gc) {
	if (DEBUG)
		System.out.println("paint"); //$NON-NLS-1$

	boolean lowQualityPaint = lowQualityOnUserAction
			&& (translate != lastTranslateValue
					|| (lastControlWidth != getSize().x
							|| lastControlHeight != getSize().y
							|| lastContentHeight != this.gHeight
							|| lastContentWidth != this.gWidth));
	try {
		// Linux-GTK Bug 174932
		if (!SWT.getPlatform().equals(BUG_PLATFORM_LINUX_GTK_174932)) {
			gc.setAdvanced(true);
		}

		if (gc.getAdvanced()) {
			if (lowQualityPaint) {
				gc.setAntialias(SWT.OFF);
				gc.setInterpolation(SWT.OFF);
			} else {
				gc.setAntialias(antialias);
				gc.setInterpolation(interpolation);
			}
		}
		// End of Bug 174932

		Rectangle clipping = gc.getClipping();

		gc.setBackground(this.getBackground());
		drawBackground(gc, clipping.x, clipping.y, clipping.width,
				clipping.height);

		int[] indexes = getVisibleItems(clipping);

		if (indexes != null && indexes.length > 0) {

			// Call preDraw for optimization
			if (groupRenderer != null)
				groupRenderer.preDraw(gc);
			if (itemRenderer != null)
				itemRenderer.preDraw(gc);

			for (int i = indexes.length - 1; i >= 0; i--) {
				if (DEBUG)
					System.out.println("Drawing group " + indexes[i]); //$NON-NLS-1$

				_drawGroup(gc, indexes[i]);
			}

			// Call postDraw for optimization / cleanup
			if (groupRenderer != null)
				groupRenderer.postDraw(gc);
			if (itemRenderer != null)
				itemRenderer.postDraw(gc);
		}
	} catch (Exception e) {
		// We can't let onPaint throw an exception because unexpected
		// results may occur in SWT.
		e.printStackTrace();
	}

	// When lowQualityOnUserAction is enabled, keep last state and wait
	// before updating with a higher quality
	if (lowQualityOnUserAction) {
		lastTranslateValue = translate;
		lastControlWidth = getSize().x;
		lastControlHeight = getSize().y;
		lastContentHeight = gHeight;
		lastContentWidth = gWidth;

		if (lowQualityPaint) {
			// Calling timerExec with the same object just delays the
			// execution (doesn't run twice)
			Display.getCurrent().timerExec(higherQualityDelay, redrawTimer);
		}
	}
}
 
Example 8
Source File: PrintPreview.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void configureAntialiasing(GC printerGC) {
	printerGC.setAdvanced(true);
	printerGC.setAntialias(SWT.ON);
	printerGC.setTextAntialias(SWT.ON);
	printerGC.setInterpolation(SWT.HIGH);
}
 
Example 9
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();

}