/** * Creates a new instance. * * @param parent the parent. * @param style the style. */ public SWTStrokeCanvas(Composite parent, int style) { super(parent, style); addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { BasicStroke stroke = (BasicStroke) getStroke(); if (stroke != null) { int x, y; Rectangle rect = getClientArea(); x = (rect.width - 100) / 2; y = (rect.height - 16) / 2; Transform swtTransform = new Transform(e.gc.getDevice()); e.gc.getTransform(swtTransform); swtTransform.translate(x, y); e.gc.setTransform(swtTransform); swtTransform.dispose(); e.gc.setBackground(getDisplay().getSystemColor( SWT.COLOR_BLACK)); e.gc.setLineWidth((int) stroke.getLineWidth()); e.gc.drawLine(10, 8, 90, 8); } } }); }
public void render(XCalendar popup, GC gc) { final XCalendarModel model = popup.getModel(); final XCalendarTheme theme = model.getTheme(); final Transform t = new Transform(gc.getDevice()); // try (final XCalendarFrame frame = new XCalendarFrame(gc, t)) { // Rectangle area = new Rectangle((area = popup.getClientArea()).x, area.y, area.width - 1, area.height - 1); gc.setAdvanced(true); gc.setAntialias(SWT.ON); gc.setBackground(theme.getBackground(true, false, false, false)); gc.fillRectangle(area); gc.setForeground(theme.getGrid(true)); gc.drawRectangle(area); List<XCalendarWidget> widgets = popup.getWidgets(); for(XCalendarWidget widget:widgets) widget.render(frame); } }
@Override public synchronized Image onMove(MouseEvent event) { Image ret = super.onMove(event); points.add(event.x); points.add(event.y); Color color = graphicsContext.getBackground(); graphicsContext.setBackground(shadowColor); graphicsContext.setForeground(shadowColor); int[] pointArr = new int[points.size()]; for (int i = 0; i < pointArr.length; i++) { pointArr[i] = points.get(i); } Transform transform = new Transform(graphicsContext.getDevice()); transform.translate(1,1); graphicsContext.setTransform(transform); graphicsContext.drawPolyline(pointArr); graphicsContext.setTransform(null); transform.dispose(); graphicsContext.setBackground(color); graphicsContext.setForeground(color); graphicsContext.drawPolyline(pointArr); return ret; }
public TreeViewOverview(Composite parent) { super(parent, SWT.NONE); mModel = TreeViewModel.getModel(); mModel.addTreeChangeListener(this); loadResources(); addPaintListener(mPaintListener); addMouseListener(mMouseListener); addMouseMoveListener(mMouseMoveListener); addListener(SWT.Resize, mResizeListener); addDisposeListener(mDisposeListener); mTransform = new Transform(Display.getDefault()); mInverse = new Transform(Display.getDefault()); loadAllData(); }
public PixelPerfectLoupe(Composite parent) { super(parent, SWT.NONE); mModel = PixelPerfectModel.getModel(); mModel.addImageChangeListener(this); addPaintListener(mPaintListener); addMouseListener(mMouseListener); addMouseWheelListener(mMouseWheelListener); addDisposeListener(mDisposeListener); addKeyListener(mKeyListener); mCrosshairColor = new Color(Display.getDefault(), new RGB(255, 94, 254)); mTransform = new Transform(Display.getDefault()); imageLoaded(); }
public TreeView(Composite parent) { super(parent, SWT.NONE); mModel = TreeViewModel.getModel(); mModel.addTreeChangeListener(this); addPaintListener(mPaintListener); addMouseListener(mMouseListener); addMouseMoveListener(mMouseMoveListener); addMouseWheelListener(mMouseWheelListener); addListener(SWT.Resize, mResizeListener); addDisposeListener(mDisposeListener); addKeyListener(mKeyListener); loadResources(); mTransform = new Transform(Display.getDefault()); mInverse = new Transform(Display.getDefault()); loadAllData(); }
public static Image paintToImage(DrawableViewNode tree) { Image image = new Image(Display.getDefault(), (int) Math.ceil(tree.bounds.width), (int) Math .ceil(tree.bounds.height)); Transform transform = new Transform(Display.getDefault()); transform.identity(); transform.translate((float) -tree.bounds.x, (float) -tree.bounds.y); Path connectionPath = new Path(Display.getDefault()); GC gc = new GC(image); // Can't use Display.getDefault().getSystemColor in a non-UI thread. Color white = new Color(Display.getDefault(), 255, 255, 255); Color black = new Color(Display.getDefault(), 0, 0, 0); gc.setForeground(white); gc.setBackground(black); gc.fillRectangle(0, 0, image.getBounds().width, image.getBounds().height); gc.setTransform(transform); paintRecursive(gc, transform, tree, null, connectionPath); gc.drawPath(connectionPath); gc.dispose(); connectionPath.dispose(); white.dispose(); black.dispose(); return image; }
private void drawDestinationDiagIncreasingLeft(ChessSquare square, Color color, int width, GC gc) { int squareSide = square.getSize().x; Transform tr = new Transform(gc.getDevice()); tr.translate(squareSide, 0); gc.setTransform(tr); tr.rotate(135); gc.setTransform(tr); gc.setBackground(color); gc.fillPolygon(getDiagDestinationPolygon(squareSide, width)); tr.dispose(); gc.setTransform(null); }
private void drawDestinationDiagIncreasingRight(ChessSquare square, Color color, int width, GC gc) { int squareSide = square.getSize().x; Transform tr = new Transform(gc.getDevice()); tr.translate(0, squareSide); gc.setTransform(tr); tr.rotate(-45); gc.setTransform(tr); gc.setBackground(color); gc.fillPolygon(getDiagDestinationPolygon(squareSide, width)); tr.dispose(); gc.setTransform(null); }
private void drawDestinationHorizontalLeft(ChessSquare square, Color color, int width, GC gc) { int squareSide = square.getSize().x; Transform tr = new Transform(gc.getDevice()); tr.translate(squareSide, squareSide / 2.0F); gc.setTransform(tr); tr.rotate(180); gc.setTransform(tr); gc.setBackground(color); gc.fillPolygon(getDestinationPolygon(squareSide, width)); tr.dispose(); gc.setTransform(null); }
private void drawDestinationVerticalDown(ChessSquare square, Color color, int width, GC gc) { int squareSide = square.getSize().x; Transform tr = new Transform(gc.getDevice()); tr.translate(squareSide / 2.0F, 0); gc.setTransform(tr); tr.rotate(90); gc.setTransform(tr); gc.setBackground(color); gc.fillPolygon(getDestinationPolygon(squareSide, width)); tr.dispose(); gc.setTransform(null); }
private void drawDestinationVerticalUp(ChessSquare square, Color color, int width, GC gc) { int squareSide = square.getSize().x; Transform tr = new Transform(gc.getDevice()); tr.translate(squareSide / 2.0F, squareSide); gc.setTransform(tr); tr.rotate(-90); gc.setTransform(tr); gc.setBackground(color); gc.fillPolygon(getDestinationPolygon(squareSide, width)); tr.dispose(); gc.setTransform(null); }
private void drawOriginDiagDecreasingLeft(ChessSquare square, Color color, int width, GC gc) { int squareSide = square.getSize().x; Transform tr = new Transform(gc.getDevice()); tr.translate(squareSide / 2.0F, squareSide / 2.0F); gc.setTransform(tr); tr.rotate(-135); gc.setTransform(tr); gc.setBackground(color); gc.fillPolygon(getOriginDiagPolygon(squareSide, width)); tr.dispose(); gc.setTransform(null); }
private void drawOriginDiagDecreasingRight(ChessSquare square, Color color, int width, GC gc) { int squareSide = square.getSize().x; Transform tr = new Transform(gc.getDevice()); tr.translate(squareSide / 2.0F, squareSide / 2.0F); gc.setTransform(tr); tr.rotate(45); gc.setTransform(tr); gc.setBackground(color); gc.fillPolygon(getOriginDiagPolygon(squareSide, width)); tr.dispose(); gc.setTransform(null); }
private void drawOriginDiagIncreasingLeft(ChessSquare square, Color color, int width, GC gc) { int squareSide = square.getSize().x; Transform tr = new Transform(gc.getDevice()); tr.translate(squareSide / 2.0F, squareSide / 2.0F); gc.setTransform(tr); tr.rotate(135); gc.setTransform(tr); gc.setBackground(color); gc.fillPolygon(getOriginDiagPolygon(squareSide, width)); tr.dispose(); gc.setTransform(null); }
private void drawOriginDiagIncreasingRight(ChessSquare square, Color color, int width, GC gc) { int squareSide = square.getSize().x; Transform tr = new Transform(gc.getDevice()); tr.translate(squareSide / 2.0F, squareSide / 2.0F); gc.setTransform(tr); tr.rotate(-45); gc.setTransform(tr); gc.setBackground(color); gc.fillPolygon(getOriginDiagPolygon(squareSide, width)); tr.dispose(); gc.setTransform(null); }
/** * Creates a new instance. * * @param parent * the parent. * @param style * the style. */ public SWTStrokeCanvas(final Composite parent, final int style) { super(parent, style); addPaintListener(e -> { final BasicStroke stroke = getStroke(); if (stroke != null) { int x, y; final Rectangle rect = getClientArea(); x = (rect.width - 100) / 2; y = (rect.height - 16) / 2; final Transform swtTransform = new Transform(e.gc.getDevice()); e.gc.getTransform(swtTransform); swtTransform.translate(x, y); e.gc.setTransform(swtTransform); swtTransform.dispose(); e.gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_BLACK)); e.gc.setLineWidth((int) stroke.getLineWidth()); e.gc.drawLine(10, 8, 90, 8); } }); }
@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; }
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(new Double(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(); }
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); } } }
/** * Converts an AWT transform into the equivalent SWT transform. * * @param awtTransform the AWT transform. * * @return The SWT transform. */ private Transform toSwtTransform(AffineTransform awtTransform) { Transform t = new Transform(gc.getDevice()); double[] matrix = new double[6]; awtTransform.getMatrix(matrix); t.setElements((float) matrix[0], (float) matrix[1], (float) matrix[2], (float) matrix[3], (float) matrix[4], (float) matrix[5]); return t; }
public void translate(int x, int y) { Transform swtTransform = new Transform(gc.getDevice()); gc.getTransform(swtTransform); swtTransform.translate(x, y); gc.setTransform(swtTransform); swtTransform.dispose(); }
public void rotate(double theta) { Transform swtTransform = new Transform(gc.getDevice()); gc.getTransform(swtTransform); swtTransform.rotate( (float) (theta * 180 / Math.PI)); gc.setTransform(swtTransform); swtTransform.dispose(); }
public void scale(double scaleX, double scaleY) { Transform swtTransform = new Transform(gc.getDevice()); gc.getTransform(swtTransform); swtTransform.scale((float) scaleX, (float) scaleY); gc.setTransform(swtTransform); swtTransform.dispose(); }
public void transform(AffineTransform Tx) { Transform swtTransform = new Transform(gc.getDevice()); gc.getTransform(swtTransform); swtTransform.multiply(toSwtTransform(Tx)); gc.setTransform(swtTransform); swtTransform.dispose(); }
/** * Returns the current transform. * * @return The current transform. */ public AffineTransform getTransform() { Transform swtTransform = new Transform(this.gc.getDevice()); this.gc.getTransform(swtTransform); AffineTransform awtTransform = toAwtTransform(swtTransform); swtTransform.dispose(); return awtTransform; }
/** * Concatenates the specified transform to the existing transform. * * @param t the transform. */ public void transform(AffineTransform t) { Transform swtTransform = new Transform(this.gc.getDevice()); this.gc.getTransform(swtTransform); swtTransform.multiply(getSwtTransformFromPool(t)); this.gc.setTransform(swtTransform); swtTransform.dispose(); }
/** * Applies a translation. * * @param x the translation along the x-axis. * @param y the translation along the y-axis. */ public void translate(int x, int y) { Transform swtTransform = new Transform(this.gc.getDevice()); this.gc.getTransform(swtTransform); swtTransform.translate(x, y); this.gc.setTransform(swtTransform); swtTransform.dispose(); }
/** * 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(); }