void drawItem(GC gc, boolean drawFocus) { int headerHeight = parent.getBandHeight(); Display display = getDisplay(); gc.setForeground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND)); gc.setBackground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT)); gc.fillGradientRectangle(x, y, width, headerHeight, true); if (expanded) { gc.setForeground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT)); gc.drawLine(x, y + headerHeight, x, y + headerHeight + height - 1); gc.drawLine(x, y + headerHeight + height - 1, x + width - 1, y + headerHeight + height - 1); gc.drawLine(x + width - 1, y + headerHeight + height - 1, x + width - 1, y + headerHeight); } int drawX = x; if (image != null) { drawX += ExpandItem.TEXT_INSET; if (imageHeight > headerHeight) { gc.drawImage(image, drawX, y + headerHeight - imageHeight); } else { gc.drawImage(image, drawX, y + (headerHeight - imageHeight) / 2); } drawX += imageWidth; } if (text.length() > 0) { drawX += ExpandItem.TEXT_INSET; Point size = gc.stringExtent(text); gc.setForeground(parent.getForeground()); gc.drawString(text, drawX, y + (headerHeight - size.y) / 2, true); } int chevronSize = ExpandItem.CHEVRON_SIZE; drawChevron(gc, x + width - chevronSize, y + (headerHeight - chevronSize) / 2); if (drawFocus) { gc.drawFocus(x + 1, y + 1, width - 2, headerHeight - 2); } }
public void backOperatoin(KeyEvent e) { if ((e.stateMask & SWT.CTRL) != 0) { if (e.keyCode == 'z') { // CTRL + z if (imagesList != null && imagesList.size() > 0) { int size = imagesList.size(); // 取出最后一个元素 image = imagesList.get(size - 1); // 显示到Canvas中 if (image != null) { gc.drawImage( image, 0, 0, image.getImageData().width, image.getImageData().height, 0, 0, 320, 480); // gc.drawImage(image, 0, 0); } // 删除该元素 imagesList.remove(size - 1); setParams(0, 0, 0, 0); // System.out.println(imagesList.size()); } else { canvasDrawImage(gc); } } } }
/** * Draws the rotated text. * * @param gc the graphics context * @param text the text * @param x the x coordinate * @param y the y coordinate * @param angle the angle */ private void drawRotatedText(GC gc, String text, float x, float y, int angle) { int textWidth = gc.textExtent(text).x; int textHeight = gc.textExtent(text).y; // create image to draw text Image image = new Image(Display.getCurrent(), textWidth, textHeight); GC tmpGc = new GC(image); tmpGc.setForeground(getForeground()); tmpGc.setBackground(gc.getBackground()); tmpGc.setFont(getFont()); tmpGc.drawText(text, 0, 0); // set transform to rotate Transform transform = new Transform(gc.getDevice()); transform.translate(x, y); transform.rotate(360 - angle); gc.setTransform(transform); // draw the image on the rotated graphics context gc.drawImage(image, 0, 0); // dispose resources tmpGc.dispose(); transform.dispose(); image.dispose(); gc.setTransform(null); }
@SuppressWarnings("deprecation") private void doOverlayImage(GC gc) { Point2D lowerLeft = new Point2D.Double(overlayEnvelope.getMinX(), overlayEnvelope.getMinY()); worldToScreen.transform(lowerLeft, lowerLeft); Point2D upperRight = new Point2D.Double(overlayEnvelope.getMaxX(), overlayEnvelope.getMaxY()); worldToScreen.transform(upperRight, upperRight); Rectangle bounds = overlayImage.getBounds(); if (overlayDoXor) { gc.setXORMode(true); } gc.drawImage( overlayImage, // 0, // 0, // bounds.width, // bounds.height, // (int) lowerLeft.getX(), // (int) upperRight.getY(), // (int) (upperRight.getX() - lowerLeft.getX()), // (int) Math.abs(upperRight.getY() - lowerLeft.getY()) // ); if (overlayDoXor) { gc.setXORMode(false); } }
private void drawClipImage(GC gc, Image image, int ix, int iy, Rectangle repaintRegion) { if (repaintRegion != null) { ix -= repaintRegion.x; iy -= repaintRegion.y; } gc.drawImage(image, ix, iy); }
// @see // org.gudy.azureus2.ui.swt.views.table.TableCellSWTPaintListener#cellPaint(org.eclipse.swt.graphics.GC, org.gudy.azureus2.plugins.ui.tables.TableCell) public void cellPaint(GC gc, TableCellSWT cell) { VuzeActivitiesEntry entry = (VuzeActivitiesEntry) cell.getDataSource(); if (entry instanceof VuzeActivitiesEntryBuddy) { VuzeActivitiesEntryBuddy entryBuddy = (VuzeActivitiesEntryBuddy) entry; VuzeBuddy buddy = entryBuddy.getBuddy(); if (buddy instanceof VuzeBuddySWT) { VuzeBuddySWT buddySWT = (VuzeBuddySWT) buddy; Image imgAvatar = buddySWT.getAvatarImage(); if (imgAvatar != null) { Rectangle cellBounds = cell.getBounds(); Rectangle imgBounds = imgAvatar.getBounds(); int dstWidth = cellBounds.width - 4; int dstHeight = dstWidth; gc.drawImage( imgAvatar, 0, 0, imgBounds.width, imgBounds.height, cellBounds.x + ((cellBounds.width - dstWidth) / 2), cellBounds.y + ((cellBounds.height - dstWidth) / 2), dstWidth, dstHeight); } } } }
public void paint( GC gc, boolean hover, Hashtable resourceTable, boolean selected, SelectionData selData, Rectangle repaintRegion) { Image image = getImage(resourceTable); int iwidth = 0; int iheight = 0; if (image != null) { Rectangle rect = image.getBounds(); iwidth = rect.width + (isSelectable() ? 2 : 0); iheight = rect.height + (isSelectable() ? 2 : 0); } else return; Rectangle bounds = getBounds(); int ix = bounds.x + (isSelectable() ? 1 : 0); int iy = bounds.y + (isSelectable() ? 1 : 0); if (selData != null) { int leftOffset = selData.getLeftOffset(bounds.height); int rightOffset = selData.getRightOffset(bounds.height); boolean firstRow = selData.isFirstSelectionRow(bounds.y, bounds.height); boolean lastRow = selData.isLastSelectionRow(bounds.y, bounds.height); boolean selectedRow = selData.isSelectedRow(bounds.y, bounds.height); if (selectedRow) { if ((firstRow && leftOffset > ix) || (lastRow && rightOffset < ix + iwidth / 2)) { drawClipImage(gc, image, ix, iy, repaintRegion); } else { Color savedBg = gc.getBackground(); gc.setBackground(selData.bg); int sx = ix; int sy = iy; if (repaintRegion != null) { sx -= repaintRegion.x; sy -= repaintRegion.y; } gc.fillRectangle(sx, sy, iwidth, iheight); Image selImage = getSelectedImage(resourceTable, selData); gc.drawImage(selImage, sx, sy); gc.setBackground(savedBg); } } else drawClipImage(gc, image, ix, iy, repaintRegion); } else drawClipImage(gc, image, ix, iy, repaintRegion); if (selected) { int fx = bounds.x; int fy = bounds.y; if (repaintRegion != null) { fx -= repaintRegion.x; fy -= repaintRegion.y; } Color fg = gc.getForeground(); gc.setForeground(gc.getBackground()); // Clean up to avoid canceling out XOR if it is already // selected. gc.drawRectangle(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1); gc.setForeground(fg); gc.drawFocus(fx, fy, bounds.width, bounds.height); } }
private void onPaint(GC gc) { Rectangle clientArea = getClientArea(); gc.setClipping(clientArea); gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_GRAY)); int boxSize = 10; int maxCol = clientArea.width / boxSize + 1; int maxRow = clientArea.height / boxSize + 1; for (int r = 0; r < maxRow; r++) { for (int c = 0; c < maxCol; c++) { if (r % 2 == c % 2) { gc.fillRectangle(c * boxSize, r * boxSize, boxSize, boxSize); } } } if (image == null || image.isDisposed()) { return; } Rectangle imageBounds = image.getBounds(); int x = -getHorizontalBar().getSelection(); int y = -getVerticalBar().getSelection(); if (clientArea.width > imageBounds.width) { x += (clientArea.width - imageBounds.width) / 2; } if (clientArea.height > imageBounds.height) { y += (clientArea.height - imageBounds.height) / 2; } gc.drawImage(image, x, y); }
void paintCanvas(Event event) { canvas.setCursor(null); int index = list.getSelectionIndex(); if (index == -1) return; GC gc = event.gc; Object object = objects[index]; if (object instanceof Color) { if (((Color) object).isDisposed()) return; gc.setBackground((Color) object); gc.fillRectangle(canvas.getClientArea()); return; } if (object instanceof Cursor) { if (((Cursor) object).isDisposed()) return; canvas.setCursor((Cursor) object); return; } if (object instanceof Font) { if (((Font) object).isDisposed()) return; gc.setFont((Font) object); FontData[] array = gc.getFont().getFontData(); StringBuffer sb = new StringBuffer(); String lf = text.getLineDelimiter(); for (int i = 0; i < array.length; i++) { FontData data = array[i]; String style = "NORMAL"; // $NON-NLS-1$ int bits = data.getStyle(); if (bits != 0) { if ((bits & SWT.BOLD) != 0) style = "BOLD "; // $NON-NLS-1$ if ((bits & SWT.ITALIC) != 0) style += "ITALIC"; // $NON-NLS-1$ } sb.append(data.getName()) .append(" ") .append(data.getHeight()) // $NON-NLS-1$ .append(" ") .append(style) .append(lf); // $NON-NLS-1$ } gc.drawString(sb.toString(), 0, 0); return; } // NOTHING TO DRAW FOR GC // if (object instanceof GC) { // return; // } if (object instanceof Image) { if (((Image) object).isDisposed()) return; gc.drawImage((Image) object, 0, 0); return; } if (object instanceof Region) { if (((Region) object).isDisposed()) return; String string = ((Region) object).getBounds().toString(); gc.drawString(string, 0, 0); return; } }
@Override public void paintChild(MapValues map, GC gc, Location each) { // draw semi-transparent background gc.setAlpha(196); gc.fillOval(each.px - diameter / 2, each.py - diameter / 2, diameter, diameter); gc.setAlpha(255); // draw image gc.drawImage(image, each.px - bounds.width / 2, each.py - bounds.height / 2); }
/** * This drawing function handles drawing the tile image at the specified zoom level. It will * attempt to use a cached copy, but will rescale if the requested zoom does not equal the current * cache zoom. * * @param gc Graphics instance to draw to * @param x x-coord to draw tile at * @param y y-coord to draw tile at * @param zoom Zoom level to draw the tile */ public void drawRaw(GC gc, int x, int y, double zoom) { Image img = getScaledImage(zoom); if (img != null) { Rectangle bounds = img.getBounds(); gc.drawImage(img, x, y - bounds.height); } else { // TODO: Allow drawing IDs when no image data exists as a // config option } }
/** * Create an image. The image is added to a cache kept by this provider and is disposed of when * this provider is disposed of. * * @param name the image name. * @param rightImage * @param leftImage * @return the image. */ @Nonnull private Image createImage(@Nonnull final String[] names) { final StringBuilder builder = new StringBuilder(); for (final String string : names) { builder.append(string); } final String name = builder.toString(); if (_imageCache.containsKey(name)) { return _imageCache.get(name); } Image leftImage; Image rightImage; int width; Image dualImage; if (names.length == 2) { leftImage = loadImage(AlarmTreePreference.RES_ICON_PATH.getValue() + "/" + names[0] + ".gif"); rightImage = loadImage(AlarmTreePreference.RES_ICON_PATH.getValue() + "/" + names[1] + ".gif"); width = leftImage.getBounds().width / 3 + 2 + rightImage.getBounds().width; dualImage = new Image(leftImage.getDevice(), width, leftImage.getBounds().height); final GC gc = new GC(dualImage); if (names[1].equals("checked")) { gc.drawImage(leftImage, leftImage.getBounds().width / 3 + 2, 0); gc.drawImage(rightImage, 2, 0); } else { gc.drawImage(leftImage, 0, 0); gc.drawImage(rightImage, leftImage.getBounds().width / 3 + 2, 0); } gc.dispose(); } else { leftImage = loadImage(AlarmTreePreference.RES_ICON_PATH.getValue() + "/" + names[0] + ".gif"); width = leftImage.getBounds().width / 3 + 2 + leftImage.getBounds().width; dualImage = new Image(leftImage.getDevice(), width, leftImage.getBounds().height); final GC gc = new GC(dualImage); gc.drawImage(leftImage, leftImage.getBounds().width / 3 + 2, 0); gc.dispose(); } _imageCache.put(name, dualImage); return dualImage; }
private void drawVersionWarning(GC gc, Display display) { gc.setBackground(versionWarningBackgroundColor); gc.setForeground(versionWarningForegroundColor); gc.fillRectangle(290, 231, 367, 49); gc.drawRectangle(290, 231, 367, 49); gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK)); gc.drawImage(exclamation_image, 304, 243); gc.setFont(devWarningFont); gc.drawText( BaseMessages.getString(PKG, "SplashDialog.DevelopmentWarning"), 335, 241); // $NON-NLS-1$ }
private Image createOverlayImg(Image mainImg, Image overlay) { Image resultImg = new Image(Display.getCurrent(), mainImg, SWT.IMAGE_COPY); GC gc = new GC(resultImg); try { gc.drawImage(overlay, -2, 1); } finally { gc.dispose(); } return resultImg; }
/** * Returns an {@link Image} composed of a base image decorated by another image. * * @param baseImage the base {@link Image} that should be decorated * @param decorator the {@link Image} to decorate the base image * @param corner the corner to place decorator image * @return the resulting decorated {@link Image} */ public static Image decorateImage( final Image baseImage, final Image decorator, final int corner) { if (corner <= 0 || corner >= LAST_CORNER_KEY) { throw new IllegalArgumentException("Wrong decorate corner"); } Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner]; if (cornerDecoratedImageMap == null) { cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>(); m_decoratedImageMap[corner] = cornerDecoratedImageMap; } Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage); if (decoratedMap == null) { decoratedMap = new HashMap<Image, Image>(); cornerDecoratedImageMap.put(baseImage, decoratedMap); } // Image result = decoratedMap.get(decorator); if (result == null) { Rectangle bib = baseImage.getBounds(); Rectangle dib = decorator.getBounds(); // result = new Image(Display.getCurrent(), bib.width, bib.height); // GC gc = new GC(result); gc.drawImage(baseImage, 0, 0); if (corner == TOP_LEFT) { gc.drawImage(decorator, 0, 0); } else if (corner == TOP_RIGHT) { gc.drawImage(decorator, bib.width - dib.width, 0); } else if (corner == BOTTOM_LEFT) { gc.drawImage(decorator, 0, bib.height - dib.height); } else if (corner == BOTTOM_RIGHT) { gc.drawImage(decorator, bib.width - dib.width, bib.height - dib.height); } gc.dispose(); // decoratedMap.put(decorator, result); } return result; }
/** * @param image * @param width * @param height * @return */ private Image resize(Image image, int width) { int height = (int) (width / ((float) image.getImageData().width / (float) image.getImageData().height)); Image scaled = new Image(Display.getDefault(), 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; }
private void drawFinalImage(Image swtImage) { Display display = getDisplay(); // this is only done if an overlay image exists // create a new image Image tmpImage = new Image(display, curPaintArea.width, curPaintArea.height); GC tmpGc = new GC(tmpImage); tmpGc.setBackground(white); tmpGc.fillRectangle(0, 0, curPaintArea.width, curPaintArea.height); if (swtImage != null) { // set the alpha to the new image tmpGc.setAlpha(alpha); /* * draw the background image into it * (this means everything but the overlay image) */ tmpGc.drawImage(swtImage, imageOrigin.x, imageOrigin.y); /* * set the alpha back to opaque so it doesn't influence the * overlay image */ tmpGc.setAlpha(255); } if (overlayImage != null) { // finally draw the overlay image on top doOverlayImage(tmpGc); } // draw the created new image on the pane if (gc != null && !gc.isDisposed()) gc.drawImage(tmpImage, imageOrigin.x, imageOrigin.y); if (tmpImage != null && !tmpImage.isDisposed()) { tmpImage.dispose(); tmpImage = null; } if (tmpGc != null && !tmpGc.isDisposed()) { tmpGc.dispose(); tmpGc = null; } }
/* Paint function */ private void paint(GC gc) { Rectangle clientRect = getClientArea(); // Canvas' painting area if (sourceImage != null) { Rectangle imageRect = SWTUtil.inverseTransformRect(transform, clientRect); int gap = 2; // find a better start point to render imageRect.x -= gap; imageRect.y -= gap; imageRect.width += 2 * gap; imageRect.height += 2 * gap; Rectangle imageBound = sourceImage.getBounds(); imageRect = imageRect.intersection(imageBound); Rectangle destRect = SWTUtil.transformRect(transform, imageRect); if (screenImage != null) screenImage.dispose(); screenImage = new Image(getDisplay(), clientRect.width, clientRect.height); GC newGC = new GC(screenImage); newGC.setClipping(clientRect); newGC.drawImage( sourceImage, imageRect.x, imageRect.y, imageRect.width, imageRect.height, destRect.x, destRect.y, destRect.width, destRect.height); newGC.dispose(); gc.drawImage(screenImage, 0, 0); } else { gc.setClipping(clientRect); gc.fillRectangle(clientRect); initScrollBars(); } }
/** * Performs the skin draw operation. * * @param gcUsedToDraw The gc object associated with the skin composite that is used to draw the * images */ private void drawSkin(GC gcUsedToDraw, IAndroidKey changedKey) { if (currentSkinImage == null) { IAndroidEmulatorInstance instance = UIHelper.getInstanceAssociatedToControl(this); ImageData initialSkinImage = getImageData(false, false); setSkinImage(initialSkinImage, null, false); applyLayout(instance.getCurrentLayout()); if (scrollBarsUsed) { synchronizeScrollBars(); } } if (displayRectangle != null) { int srcXPos, srcYPos, srcWidth, srcHeight; int destXPos, destYPos, destWidth, destHeight; if (changedKey == null) { srcXPos = displayRectangle.x; srcYPos = displayRectangle.y; srcWidth = displayRectangle.width; srcHeight = displayRectangle.height; destXPos = 0; destYPos = 0; destWidth = Math.min(currentSkinImage.getImageData().width, displayRectangle.width); destHeight = Math.min(currentSkinImage.getImageData().height, displayRectangle.height); } else { srcXPos = ((int) (changedKey.getKeyArea().x > 0 ? changedKey.getKeyArea().x * zoomFactor : 0)); srcYPos = ((int) (changedKey.getKeyArea().y > 0 ? changedKey.getKeyArea().y * zoomFactor : 0)); srcWidth = ((int) (changedKey.getKeyArea().width * zoomFactor)); srcHeight = ((int) (changedKey.getKeyArea().height * zoomFactor)); destXPos = srcXPos - displayRectangle.x; destYPos = srcYPos - displayRectangle.y; destWidth = srcWidth; destHeight = srcHeight; } gcUsedToDraw.drawImage( currentSkinImage, srcXPos, srcYPos, srcWidth, srcHeight, destXPos, destYPos, destWidth, destHeight); } }
private void drawEQImage(GC gc) { if (ibuffer != null) { synchronized (ibuffer) { if (AXIS_PADDING + (MINIMUM_UNIT_HEIGHT * size) > winYSize) { scroll.setMinSize( canvas.computeSize(SWT.DEFAULT, AXIS_PADDING + (MINIMUM_UNIT_HEIGHT * size))); } else { scroll.setMinSize(canvas.computeSize(SWT.DEFAULT, winYSize)); } if (ibuffer.isDisposed() == false) { gc.drawImage(ibuffer, 0, 0); } } } }
private void paint(PaintEvent event) { GC gc = event.gc; // fonts are disposed when calendar is disposed Font used = null; if (CalendarCombo.OS_CARBON) { used = mSettings.getCarbonDrawFont(); if (used != null) gc.setFont(used); } else if (CalendarCombo.OS_WINDOWS) { used = mSettings.getWindowsMonthPopupDrawFont(); if (used != null) gc.setFont(used); } // double buffering. this could be triple buffering if the platform does // it automatically, windows XP does not seem to however // basically, we draw all the updates onto an Image in memory, then we // transfer the contents thereof onto the canvas. // that way there is 0 flicker, which is the desired effect. if (mCreated && mEnableDoubleBuffering) { try { Image buffer = new Image(Display.getDefault(), super.getBounds()); GC gc2 = new GC(buffer); drawOntoGC(gc2); // transfer the image buffer onto this canvas // just drawImage(buffer, w, h) didn't work, so we do the whole // source transfer call Rectangle b = getBounds(); gc.drawImage(buffer, 0, 0, b.width, b.height, 0, 0, b.width, b.height); // dispose the buffer, very important or we'll run out of // address space for buffered images buffer.dispose(); gc2.dispose(); } catch (IllegalArgumentException iea) { // seems to come here for some reason when we switch phases // while the gantt chart is being viewed, I'm not sure why // but no time to figure it out for the demo.. so instead of // buffering, just draw it onto the GC drawOntoGC(gc); } } else { drawOntoGC(gc); mCreated = true; } // don't dispose font, they are disposed when the CalendarCombo are disposed }
public void canvasDrawImage(GC gc) { try { FileInputStream input = new FileInputStream(new File("./workspace/" + file)); ImageData imageData = new ImageData(input); image = new Image(Display.getDefault(), imageData); this.realHeight = imageData.height; this.realWidth = imageData.width; gc.drawImage(image, 0, 0, imageData.width, imageData.height, 0, 0, 320, 480); input.close(); imagesList.add(image); } catch (Exception e) { e.printStackTrace(); } }
private static Image getFlagRect(Image oFlag) { // Color background = GUIPI.getColor(GUIPI.windowColor); int size = Math.max(oFlag.getBounds().height, oFlag.getBounds().width); // Rectangle rect = new Rectangle(0,0,size,size); Image i = new Image(oFlag.getDevice(), size, size); GC gc = new GC(i); gc.setBackground(oFlag.getDevice().getSystemColor(SWT.COLOR_WHITE)); gc.fillRectangle(0, 0, size, size); gc.drawImage( oFlag, (size - oFlag.getBounds().width) / 2, (size - oFlag.getBounds().height) / 2); gc.dispose(); ImageData id = i.getImageData(); id.transparentPixel = id.palette.getPixel(new RGB(255, 255, 255)); i.dispose(); return new Image(oFlag.getDevice(), id); }
void paint(PaintEvent e) { GC gc = e.gc; Point size = comp.getSize(); if (curveColor == null) curveColor = e.display.getSystemColor(SWT.COLOR_BLACK); int h = size.y; int[] simpleCurve = new int[] {0, h - 1, 1, h - 1, 2, h - 2, 2, 1, 3, 0}; // draw border gc.setForeground(curveColor); gc.setAdvanced(true); if (gc.getAdvanced()) { gc.setAntialias(SWT.ON); } gc.drawPolyline(simpleCurve); Rectangle bounds = ((Control) e.widget).getBounds(); bounds.x = bounds.y = 0; Region r = new Region(); r.add(bounds); int[] simpleCurveClose = new int[simpleCurve.length + 4]; System.arraycopy(simpleCurve, 0, simpleCurveClose, 0, simpleCurve.length); int index = simpleCurve.length; simpleCurveClose[index++] = bounds.width; simpleCurveClose[index++] = 0; simpleCurveClose[index++] = bounds.width; simpleCurveClose[index++] = bounds.height; r.subtract(simpleCurveClose); Region clipping = new Region(); gc.getClipping(clipping); r.intersect(clipping); gc.setClipping(r); Image b = toolParent.getBackgroundImage(); if (b != null && !b.isDisposed()) gc.drawImage(b, 0, 0); r.dispose(); clipping.dispose(); // // gc.fillRectangle(bounds); // Rectangle mappedBounds = e.display.map(comp, comp.getParent(), // bounds); // ((Composite) toolParent).drawBackground(gc, bounds.x, bounds.y, // bounds.width, // bounds.height, mappedBounds.x, mappedBounds.y); }
private Image resize(Image source) { Rectangle sourceBounds = source.getBounds(); boolean width = sourceBounds.width > sourceBounds.height; // calculate the new factor float factor = width ? 16 / (float) sourceBounds.width : 16 / (float) sourceBounds.height; // calculate the dimensions int newW = width ? 16 : Math.round(factor * sourceBounds.width); int newH = width ? Math.round(factor * sourceBounds.height) : 16; Image target = new Image(source.getDevice(), newW, newH); GC targetGC = new GC(target); targetGC.drawImage(source, 0, 0, sourceBounds.width, sourceBounds.height, 0, 0, newW, newH); targetGC.dispose(); source.dispose(); return target; }
public Image captureImage(Control control) { Rectangle rectangle = control.getBounds(); Display display = control.getDisplay(); Image image = null; if (control instanceof Shell) { Shell shell = (Shell) control; shell.layout(); Point parentLocation = control.toDisplay(0, 0); image = getImage(control, rectangle.width, rectangle.height, false); rectangle.x = parentLocation.x; rectangle.y = parentLocation.y; GC myImageGC = new GC(image); try { for (Control child : shell.getChildren()) { Rectangle childBounds = child.getBounds(); // bug of SWT on Win32, child bounds is not correct in the Window is not in the ToolBar int x = (rectangle.width - childBounds.width) / 2; int y = (rectangle.height - childBounds.height) - x; childBounds.x = rectangle.x + x; childBounds.y = rectangle.y + y; if (!rectangle.intersects(childBounds)) continue; // Child is completely outside parent. Image childImage = new Image(display, child.getBounds()); GC gc = new GC(childImage); child.print(gc); DisposeUtil.dispose(gc); try { myImageGC.drawImage(childImage, x, y); } finally { childImage.dispose(); } } } finally { myImageGC.dispose(); } } else { image = defaultCapture(control); } return image; }
public void drawImage(FSImage image, int x, int y) { Image img = ((SWTFSImage) image).getImage(); if (img == null) { int width = image.getWidth(); int height = image.getHeight(); Color oldBG = _gc.getBackground(); Color oldFG = _gc.getForeground(); _gc.setBackground(_gc.getDevice().getSystemColor(SWT.COLOR_WHITE)); _gc.setForeground(_gc.getDevice().getSystemColor(SWT.COLOR_BLACK)); _gc.fillRectangle(x, y, width, height); _gc.drawRectangle(x, y, width, height); _gc.drawLine(x, y, x + width - 1, y + height - 1); _gc.drawLine(x, y + height - 1, x + width - 1, y); _gc.setBackground(oldBG); _gc.setForeground(oldFG); } else { Rectangle bounds = img.getBounds(); _gc.drawImage( img, 0, 0, bounds.width, bounds.height, x, y, image.getWidth(), image.getHeight()); } }
LRESULT wmDrawChild(long /*int*/ wParam, long /*int*/ lParam) { DRAWITEMSTRUCT struct = new DRAWITEMSTRUCT(); OS.MoveMemory(struct, lParam, DRAWITEMSTRUCT.sizeof); if (image != null) { GCData data = new GCData(); data.device = display; GC gc = GC.win32_new(struct.hDC, data); /* * Bug in Windows. When a bitmap is included in the * menu bar, the HDC seems to already include the left * coordinate. The fix is to ignore this value when * the item is in a menu bar. */ int x = (parent.style & SWT.BAR) != 0 ? MARGIN_WIDTH * 2 : struct.left; Image image = getEnabled() ? this.image : new Image(display, this.image, SWT.IMAGE_DISABLE); gc.drawImage(image, x, struct.top + MARGIN_HEIGHT); if (this.image != image) image.dispose(); gc.dispose(); } if (parent.foreground != -1) OS.SetTextColor(struct.hDC, parent.foreground); return null; }
protected void drawImage() { if (imageData != null) { int deltaX = (canvas.getSize().x - imageData.width) / 2; int deltaY = (canvas.getSize().y - imageData.height) / 2; image.dispose(); image = new Image(Display.getCurrent(), imageData); bgImage.dispose(); bgImage = new Image(Display.getCurrent(), canvas.getSize().x, canvas.getSize().y); GC gc = new GC(bgImage); gc.drawImage(image, deltaX, deltaY); gc.setLineWidth(3); gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); Vector3f coords0 = implementor .getCamera() .getWorldCoordinates( new Vector2f( implementor.getCanvas().getSize().x / 2, implementor.getCanvas().getSize().y / 2), 0); Vector3f coords1 = implementor .getCamera() .getWorldCoordinates( new Vector2f( implementor.getCanvas().getSize().x / 2, implementor.getCanvas().getSize().y / 2), 1); Vector3f direction = coords0.subtract(coords1).normalizeLocal(); coords0.subtractLocal(direction.mult(coords0.y / direction.y)); Vector3f coords = mapCamera.getScreenCoordinates(coords0); gc.drawRectangle(deltaX + (int) coords.x - 25, 200 + deltaY - (int) coords.y - 25, 50, 50); canvas.setBackgroundImage(bgImage); gc.dispose(); } }
/** * Paints the region specified of the canvas onto the given Graphics Context. * * @param gc graphics onto within painting should occur * @param x left of the dirty region * @param y top of the dirty region * @param w width of the dirty region * @param h height of the dirty region */ public void paintComponent(final GC gc, final int x, final int y, final int w, final int h) { PDebug.startProcessingOutput(); GC imageGC = null; Graphics2D g2 = null; if (doubleBuffered) { imageGC = new GC(backBuffer); g2 = new SWTGraphics2D(imageGC, getDisplay()); } else { g2 = new SWTGraphics2D(gc, getDisplay()); } g2.setColor(Color.white); g2.setBackground(Color.white); final Rectangle rect = getBounds(); g2.fillRect(0, 0, rect.width, rect.height); // This fixes a problem with standard debugging of region management in // SWT if (PDebug.debugRegionManagement) { final Rectangle r = gc.getClipping(); final Rectangle2D r2 = new Rectangle2D.Double(r.x, r.y, r.width, r.height); g2.setBackground(PDebug.getDebugPaintColor()); g2.fill(r2); } // create new paint context and set render quality final PPaintContext paintContext = new PPaintContext(g2); if (getInteracting() || getAnimating()) { if (interactingRenderQuality > animatingRenderQuality) { paintContext.setRenderQuality(interactingRenderQuality); } else { paintContext.setRenderQuality(animatingRenderQuality); } } else { paintContext.setRenderQuality(defaultRenderQuality); } // paint Piccolo2D camera.fullPaint(paintContext); // if switched state from animating to not animating invalidate // the entire screen so that it will be drawn with the default instead // of animating render quality. if (animatingOnLastPaint && !getAnimating()) { repaint(); } animatingOnLastPaint = getAnimating(); final boolean region = PDebug.debugRegionManagement; PDebug.debugRegionManagement = false; PDebug.endProcessingOutput(g2); PDebug.debugRegionManagement = region; if (doubleBuffered) { gc.drawImage(backBuffer, 0, 0); // Dispose of the allocated image gc imageGC.dispose(); } }