Java Code Examples for org.eclipse.swt.graphics.Transform#scale()
The following examples show how to use
org.eclipse.swt.graphics.Transform#scale() .
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: SwtUniversalImageBitmap.java From hop with Apache License 2.0 | 6 votes |
@Override protected Image renderRotated( Device device, int width, int height, double angleRadians ) { Image result = new Image( device, width * 2, height * 2 ); GC gc = new GC( result ); int bw = bitmap.getBounds().width; int bh = bitmap.getBounds().height; Transform affineTransform = new Transform( device ); affineTransform.translate( width, height ); affineTransform.rotate( (float) Math.toDegrees( angleRadians ) ); affineTransform.scale( (float) zoomFactor * width / bw, (float) zoomFactor * height / bh ); gc.setTransform( affineTransform ); gc.drawImage( bitmap, 0, 0, bw, bh, -bw / 2, -bh / 2, bw, bh ); gc.dispose(); return result; }
Example 2
Source File: TagCloud.java From gef with Eclipse Public License 2.0 | 6 votes |
private void zoom(double s) { checkWidget(); if (selectionLayerImage == null) return; if (s < 0.1) s = 0.1; if (s > 3) s = 3; int width = (int) (selectionLayerImage.getBounds().width * s); int height = (int) (selectionLayerImage.getBounds().height * s); if (width == 0 || height == 0) return; zoomLayerImage = new Image(getDisplay(), width, height); Transform tf = new Transform(getDisplay()); tf.scale((float) s, (float) s); GC gc = new GC(zoomLayerImage); gc.setTransform(tf); gc.drawImage(selectionLayerImage, 0, 0); gc.dispose(); tf.dispose(); currentZoom = s; updateScrollbars(); redraw(); }
Example 3
Source File: SwtUniversalImageBitmap.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Override protected Image renderRotated( Device device, int width, int height, double angleRadians ) { Image result = new Image( device, width * 2, height * 2 ); GC gc = new GC( result ); int bw = bitmap.getBounds().width; int bh = bitmap.getBounds().height; Transform affineTransform = new Transform( device ); affineTransform.translate( width, height ); affineTransform.rotate( (float) Math.toDegrees( angleRadians ) ); affineTransform.scale( (float) 1.0 * width / bw, (float) 1.0 * height / bh ); gc.setTransform( affineTransform ); gc.drawImage( bitmap, 0, 0, bw, bh, -bw / 2, -bh / 2, bw, bh ); gc.dispose(); return result; }
Example 4
Source File: SWTGraphics2D.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * Applies a scale transform. * * @param scaleX the scale factor along the x-axis. * @param scaleY the scale factor along the y-axis. */ public void scale(double scaleX, double scaleY) { Transform swtTransform = new Transform(this.gc.getDevice()); this.gc.getTransform(swtTransform); swtTransform.scale((float) scaleX, (float) scaleY); this.gc.setTransform(swtTransform); swtTransform.dispose(); }
Example 5
Source File: ScalePrint.java From nebula with Eclipse Public License 2.0 | 5 votes |
public void paint(GC gc, int x, int y) { Transform oldTransform = getOldTransform(); gc.getTransform(oldTransform); Transform transform = getTransform(); gc.getTransform(transform); transform.translate(x, y); transform.scale((float) scale, (float) scale); gc.setTransform(transform); target.paint(gc, 0, 0); gc.setTransform(oldTransform); }
Example 6
Source File: GraphUtils.java From n4js with Eclipse Public License 1.0 | 5 votes |
public static void drawArrowHead(GC gc, Point referencePoint, Point p) { final double angle = Math.atan2(p.y - referencePoint.y, p.x - referencePoint.x) * 180.0 / Math.PI; final Transform tf = new Transform(gc.getDevice()); tf.rotate(Double.valueOf(angle).floatValue()); tf.scale(7, 3); final float[] pnts = new float[] { -1, 1, -1, -1 }; tf.transform(pnts); gc.drawLine(Math.round(p.x), Math.round(p.y), Math.round(p.x + pnts[0]), Math.round(p.y + pnts[1])); gc.drawLine(Math.round(p.x), Math.round(p.y), Math.round(p.x + pnts[2]), Math.round(p.y + pnts[3])); tf.dispose(); }
Example 7
Source File: VisualisationCanvas.java From n4js with Eclipse Public License 1.0 | 5 votes |
protected void doPaint(GC gc, PaintEvent event) { gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE)); gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK)); gc.fillRectangle(event.x, event.y, event.width, event.height); if (graph != null) { final Transform tf = new Transform(gc.getDevice()); tf.translate(-offsetX, -offsetY); tf.scale(scale, scale); gc.setTransform(tf); if (graphNeedsLayout) { graph.layout(); graphNeedsLayout = false; } graph.getNodes().forEach(n -> n.paint(gc)); gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE)); gc.setTransform(null); tf.dispose(); if (hawkEye_active && hawkEye_target != null) { final int w = Math.round(getSize().x / hawkEye_oldScale * scale); final int h = Math.round(getSize().y / hawkEye_oldScale * scale); gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE)); gc.setAlpha(64); gc.fillRectangle( (int) hawkEye_target.x - w / 2, (int) hawkEye_target.y - h / 2, w, h); gc.setAlpha(255); } } }
Example 8
Source File: SWTGraphics2D.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * Applies a scale transform. * * @param scaleX the scale factor along the x-axis. * @param scaleY the scale factor along the y-axis. */ public void scale(double scaleX, double scaleY) { Transform swtTransform = new Transform(this.gc.getDevice()); this.gc.getTransform(swtTransform); swtTransform.scale((float) scaleX, (float) scaleY); this.gc.setTransform(swtTransform); swtTransform.dispose(); }
Example 9
Source File: SWTGraphics2D.java From SIMVA-SoS with Apache License 2.0 | 5 votes |
/** * Applies a scale transform. * * @param scaleX the scale factor along the x-axis. * @param scaleY the scale factor along the y-axis. */ public void scale(double scaleX, double scaleY) { Transform swtTransform = new Transform(this.gc.getDevice()); this.gc.getTransform(swtTransform); swtTransform.scale((float) scaleX, (float) scaleY); this.gc.setTransform(swtTransform); swtTransform.dispose(); }
Example 10
Source File: SWTGraphics2D.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
/** * Applies a scale transform. * * @param scaleX the scale factor along the x-axis. * @param scaleY the scale factor along the y-axis. */ public void scale(double scaleX, double scaleY) { Transform swtTransform = new Transform(this.gc.getDevice()); this.gc.getTransform(swtTransform); swtTransform.scale((float) scaleX, (float) scaleY); this.gc.setTransform(swtTransform); swtTransform.dispose(); }
Example 11
Source File: SWTGraphics2D.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Applies a scale transform. * * @param scaleX the scale factor along the x-axis. * @param scaleY the scale factor along the y-axis. */ public void scale(double scaleX, double scaleY) { Transform swtTransform = new Transform(this.gc.getDevice()); this.gc.getTransform(swtTransform); swtTransform.scale((float) scaleX, (float) scaleY); this.gc.setTransform(swtTransform); swtTransform.dispose(); }
Example 12
Source File: SWTGraphics2D.java From astor with GNU General Public License v2.0 | 5 votes |
public void scale(double scaleX, double scaleY) { Transform swtTransform = new Transform(this.gc.getDevice()); this.gc.getTransform(swtTransform); swtTransform.scale((float) scaleX, (float) scaleY); this.gc.setTransform(swtTransform); swtTransform.dispose(); }
Example 13
Source File: SWTGraphics2D.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Applies a scale transform. * * @param scaleX the scale factor along the x-axis. * @param scaleY the scale factor along the y-axis. */ public void scale(double scaleX, double scaleY) { Transform swtTransform = new Transform(this.gc.getDevice()); this.gc.getTransform(swtTransform); swtTransform.scale((float) scaleX, (float) scaleY); this.gc.setTransform(swtTransform); swtTransform.dispose(); }
Example 14
Source File: GanttChartPrintJob.java From nebula with Eclipse Public License 2.0 | 4 votes |
public void run() { if (printer.startJob(jobName)) { GC gc = new GC(printer); int currentPage = 1; for (GanttChart ganttChart : this.ganttCharts) { Image printerImage = null; if (printer.getPrinterData().scope == PrinterData.SELECTION) { //the user selected to only print the selected area //as this is quite difficult in GanttChart, we specify that //this means to print the visible area //but it is possible to configure via settings what "visible" //area means: // - really only the visible area horizontally and vertically // - only the horizontal visible area, but vertically everything printerImage = ganttChart.getSettings().printSelectedVerticallyComplete() ? ganttChart.getGanttComposite().getVerticallyFullImage() : ganttChart.getGanttComposite().getImage(); } else { printerImage = ganttChart.getGanttComposite().getFullImage(); } final Rectangle printerClientArea = PrintUtils.computePrintArea(printer); final Point scaleFactor = PrintUtils.computeScaleFactor(printer); final Point pageCount = PrintUtils.getPageCount(printer, printerImage); // Print pages Left to Right and then Top to Down for (int verticalPageNumber = 0; verticalPageNumber < pageCount.y; verticalPageNumber++) { for (int horizontalPageNumber = 0; horizontalPageNumber < pageCount.x; horizontalPageNumber++) { // Calculate bounds for the next page int printerClientAreaHeight = ganttChart.getSettings().printFooter() ? (printerClientArea.height - PrintUtils.FOOTER_HEIGHT_IN_PRINTER_DPI) : printerClientArea.height; Rectangle printBounds = new Rectangle((printerClientArea.width / scaleFactor.x) * horizontalPageNumber, (printerClientAreaHeight / scaleFactor.y) * verticalPageNumber, printerClientArea.width / scaleFactor.x, printerClientAreaHeight / scaleFactor.y); if (shouldPrint(printer.getPrinterData(), currentPage)) { printer.startPage(); Transform printerTransform = new Transform(printer); // Adjust for DPI difference between display and printer printerTransform.scale(scaleFactor.x, scaleFactor.y); // Adjust for margins printerTransform.translate(printerClientArea.x / scaleFactor.x, printerClientArea.y / scaleFactor.y); // GanttChart will not automatically print the pages at the left margin. // Example: page 1 will print at x = 0, page 2 at x = 100, page 3 at x = 300 // Adjust to print from the left page margin. i.e x = 0 printerTransform.translate(-1 * printBounds.x, -1 * printBounds.y); gc.setTransform(printerTransform); int imgWidthClipping = printBounds.width; if (((horizontalPageNumber * printBounds.width)+printBounds.width) > printerImage.getImageData().width) { imgWidthClipping = printerImage.getImageData().width - (horizontalPageNumber * printBounds.width); } int imgHeightClipping = printBounds.height; if (((verticalPageNumber * printBounds.height)+printBounds.height) > printerImage.getImageData().height) { imgHeightClipping = printerImage.getImageData().height - (verticalPageNumber * printBounds.height); } gc.drawImage(printerImage, horizontalPageNumber * printBounds.width, verticalPageNumber * printBounds.height, imgWidthClipping, imgHeightClipping, printBounds.x, printBounds.y, imgWidthClipping, imgHeightClipping); if (ganttChart.getSettings().printFooter()) printFooter(gc, ganttChart, currentPage, printBounds); printer.endPage(); printerTransform.dispose(); } currentPage++; } } printerImage.dispose(); } printer.endJob(); gc.dispose(); //only dispose the printer after the print job is done if it is configured to do so //this configuration enables the possibility to reuse a printer for several jobs if (disposePrinter) printer.dispose(); } }
Example 15
Source File: ViewLattice.java From arx with Apache License 2.0 | 4 votes |
/** * Draws a node. * * @param g */ private void drawNodes(final GC g) { // Prepare Rectangle bounds = new Rectangle(0, 0, (int)nodeWidth, (int)nodeHeight); Transform transform = new Transform(g.getDevice()); // Set style g.setLineWidth(STROKE_WIDTH_NODE); g.setFont(font); // Draw nodes for (List<ARXNode> level : lattice) { for (ARXNode node : level) { // Obtain coordinates double[] center = (double[]) node.getAttributes().get(ATTRIBUTE_CENTER); bounds.x = (int)(center[0] - nodeWidth / 2d); bounds.y = (int)(center[1] - nodeHeight / 2d); // Clipping if (bounds.intersects(new Rectangle(0, 0, screen.x, screen.y))) { // Retrieve/compute text rendering data SerializablePath path = (SerializablePath) node.getAttributes().get(ATTRIBUTE_PATH); Point extent = (Point) node.getAttributes().get(ATTRIBUTE_EXTENT); if (path == null || path.getPath() == null) { String text = (String) node.getAttributes().get(ATTRIBUTE_LABEL); path = new SerializablePath(new Path(canvas.getDisplay())); path.getPath().addString(text, 0, 0, font); node.getAttributes().put(ATTRIBUTE_PATH, path); extent = g.textExtent(text); node.getAttributes().put(ATTRIBUTE_EXTENT, extent); } // Degrade if too far away if (bounds.width <= 4) { g.setBackground(getInnerColor(node)); g.setAntialias(SWT.OFF); g.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height); // Draw real node } else { // Fill background g.setBackground(getInnerColor(node)); g.setAntialias(SWT.OFF); if (node != getSelectedNode()) { g.fillOval(bounds.x, bounds.y, bounds.width, bounds.height); } else { g.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height); } // Draw line g.setLineWidth(getOuterStrokeWidth(node, bounds.width)); g.setForeground(getOuterColor(node)); g.setAntialias(SWT.ON); if (node != getSelectedNode()) { g.drawOval(bounds.x, bounds.y, bounds.width, bounds.height); } else { g.drawRectangle(bounds.x, bounds.y, bounds.width, bounds.height); } // Draw text if (bounds.width >= 20) { // Enable anti-aliasing g.setTextAntialias(SWT.ON); // Compute position and factor float factor1 = (bounds.width * 0.7f) / (float)extent.x; float factor2 = (bounds.height * 0.7f) / (float)extent.y; float factor = Math.min(factor1, factor2); int positionX = bounds.x + (int)(((float)bounds.width - (float)extent.x * factor) / 2f); int positionY = bounds.y + (int)(((float)bounds.height - (float)extent.y * factor) / 2f); // Initialize transformation transform.identity(); transform.translate(positionX, positionY); transform.scale(factor, factor); g.setTransform(transform); // Draw and reset g.setBackground(COLOR_BLACK); g.fillPath(path.getPath()); g.setTransform(null); g.setTextAntialias(SWT.OFF); } } } } } // Clean up transform.dispose(); }