Package org.eclipse.swt.graphics

Examples of org.eclipse.swt.graphics.Transform


    Font font = new Font(device, CurvesSWTTab.getPlatformFont(), 16, SWT.ITALIC);
    gc.setFont(font);
    gc.setLineWidth(2);

    Transform transform;

    // ----- letter s -----
    sXPos = 4 * width / 16;
    sYPos = (height - 150) / 2;

    transform = new Transform(device);
    transform.translate(sXPos, sYPos);
    gc.setTransform(transform);
    transform.dispose();

    gc.setForeground(device.getSystemColor(SWT.COLOR_DARK_BLUE));
    gc.drawString(GraphicsExample.getResourceString("Cubic"), 0, 175, true);

    Path path = new Path(device);
    path.cubicTo(-200 + sDiffX1, 50 + sDiffY1, 200 + sDiffX2, 100 + sDiffY2, 0, 150);
    gc.drawPath(path);
    path.dispose();

    // draw the spline points
    gc.setTransform(null);
    gc.drawRectangle(sRect1.x + (int) sXPos, sRect1.y + (int) sYPos, sRect1.width, sRect1.height);
    gc.drawRectangle(sRect2.x + (int) sXPos, sRect2.y + (int) sYPos, sRect2.width, sRect2.height);

    // ----- letter w -----
    wXPos = 6 * width / 16;
    wYPos = (height - 150) / 2;

    transform = new Transform(device);
    transform.translate(wXPos, wYPos);
    gc.setTransform(transform);
    transform.dispose();

    gc.setForeground(device.getSystemColor(SWT.COLOR_GRAY));
    gc.drawString(GraphicsExample.getResourceString("Quadratic"), 0, -50, true);
    gc.drawString(GraphicsExample.getResourceString("Quadratic"), 110, -50, true);

    path = new Path(device);
    path.quadTo(100 + wDiffX1, 300 + wDiffY1, 100, 0);
    path.quadTo(100 + wDiffX2, 300 + wDiffY2, 200, 0);
    gc.drawPath(path);
    path.dispose();

    gc.setTransform(null);
    gc.drawRectangle(wRect1.x + (int) wXPos, wRect1.y + (int) wYPos, wRect1.width, wRect1.height);
    gc.drawRectangle(wRect2.x + (int) wXPos, wRect2.y + (int) wYPos, wRect2.width, wRect2.height);

    // ----- top of letter t -----
    topTXPos = 11 * width / 16;
    topTYPos = (height - 150) / 2;

    transform = new Transform(device);
    transform.translate(topTXPos, topTYPos);
    gc.setTransform(transform);
    transform.dispose();

    gc.setForeground(device.getSystemColor(SWT.COLOR_YELLOW));
    gc.drawString(GraphicsExample.getResourceString("Cubic"), 25, -50, true);

    path = new Path(device);
    path.cubicTo(33 + tTopDiffX1, -20 + tTopDiffY1, 66 + tTopDiffX2, 20 + tTopDiffY2, 100, 0);
    gc.drawPath(path);
    path.dispose();

    gc.setTransform(null);
    gc.drawRectangle(tTopRect1.x + (int) topTXPos, tTopRect1.y + (int) topTYPos, tTopRect1.width, tTopRect1.height);
    gc.drawRectangle(tTopRect2.x + (int) topTXPos, tTopRect2.y + (int) topTYPos, tTopRect2.width, tTopRect2.height);

    // ----- vertical bar of letter t -----
    botTXPos = 12 * width / 16;
    botTYPos = (height - 150) / 2;

    transform = new Transform(device);
    transform.translate(botTXPos, botTYPos);
    gc.setTransform(transform);
    transform.dispose();

    gc.setForeground(device.getSystemColor(SWT.COLOR_RED));
    gc.drawString(GraphicsExample.getResourceString("Cubic"), 0, 175, true);

    path = new Path(device);
View Full Code Here


    Image image = GraphicsExample.loadImage(device, GraphicsExample.class, "houses.png");
    Rectangle bounds = image.getBounds();

    // top
    Transform transform = new Transform(device);
    transform.translate((width - bounds.width) / 2, (height - bounds.height) / 2);
    transform.scale(1, -1);
    gc.setTransform(transform);

    // draw the original image
    gc.drawImage(image, 0, 0);

    transform.dispose();

    // bottom
    transform = new Transform(device);
    transform.translate((width - bounds.width) / 2, 2 * bounds.height + (height - bounds.height) / 2);
    transform.scale(1, -1);
    gc.setTransform(transform);

    // draw the original image
    gc.drawImage(image, 0, 0);

    transform.dispose();

    // left
    transform = new Transform(device);
    transform.translate((width - bounds.width) / 2, (height - bounds.height) / 2);
    transform.scale(-1, 1);
    gc.setTransform(transform);

    // draw the original image
    gc.drawImage(image, 0, 0);

    transform.dispose();

    // right
    transform = new Transform(device);
    transform.translate(2 * bounds.width + (width - bounds.width) / 2, (height - bounds.height) / 2);
    transform.scale(-1, 1);
    gc.setTransform(transform);

    // draw the original image
    gc.drawImage(image, 0, 0);

    transform.dispose();

    gc.setTransform(null);
    gc.drawImage(image, (width - bounds.width) / 2, (height - bounds.height) / 2);
    image.dispose();
  }
View Full Code Here

      return;
    Device device = gc.getDevice();

    Image image = GraphicsExample.loadImage(device, GraphicsExample.class, "ace_club.jpg");

    Transform transform = new Transform(device);

    // scale image
    transform.scale(scaleSpinnerX.getSelection() / 100f, scaleSpinnerY.getSelection() / 100f);

    // rotate on center of image
    Rectangle rect = image.getBounds();
    transform.translate(rect.width / 2, rect.height / 2);
    transform.rotate(rotateSpinner.getSelection());
    transform.translate(-rect.width / 2, -rect.height / 2);

    if (invertButton.getSelection())
      transform.invert();

    gc.setTransform(transform);

    gc.drawImage(image, 0, 0);
    gc.drawRoundRectangle(0, 0, image.getBounds().width, image.getBounds().height, 22, 22);
    transform.dispose();
    image.dispose();
  }
View Full Code Here

      pattern = new Pattern(device, foreground.getBgImage());
      gc.setForegroundPattern(pattern);
    }

    // draw petals for the spiral
    Transform transform;
    int n = petalSpinner.getSelection();
    for (int i = 0; i < n; i++) {
      transform = new Transform(device);
      transform.translate(width / 2, height / 2);
      transform.rotate(-(angle + 360 / n * i));
      gc.setTransform(transform);
      gc.drawArc(0, 0, width / 3, height / 6, 0, 180);
      transform.dispose();
    }

    if (pattern != null)
      pattern.dispose();
  }
View Full Code Here

    gc.setAntialias(SWT.ON);
    gc.setAlpha(alphaSpinner.getSelection());

    // rotate on center
    Transform transform = new Transform(device);
    transform.translate(width / 2, height / 2);
    transform.rotate(-angle);
    transform.translate(-width / 2, -height / 2);
    gc.setTransform(transform);
    transform.dispose();

    // choose the smallest between height and width
    int diameter = height < width ? height : width;

    Path path = new Path(device);
View Full Code Here

      // draw the number
      gc.drawString(new Integer(nextNumber).toString(), (width - textWidth) / 2, (height - textHeight) / 2, true);

      // draw the rotating arm
      Transform transform = new Transform(device);
      transform.translate(width / 2, height / 2);
      transform.rotate(angle);
      gc.setTransform(transform);
      gc.setForeground(device.getSystemColor(SWT.COLOR_RED));
      gc.drawLine(0, 0, diameter / 2, 0);
      transform.dispose();

      font.dispose();
    }
  }
View Full Code Here

    clubWidth = ace_club.getBounds().width;
    diamondWidth = ace_diamond.getBounds().width;
    heartWidth = ace_hearts.getBounds().width;
    spadeHeight = ace_spade.getBounds().height;

    Transform transform;

    // ace of clubs
    transform = new Transform(device);
    transform.translate((int) movClubX, (int) movClubY);
    transform.scale(scaleWidth, scaleWidth);

    // rotate on center of image
    Rectangle rect = ace_club.getBounds();
    transform.translate(rect.width / 2, rect.height / 2);
    transform.rotate(rotationAngle);
    transform.translate(-rect.width / 2, -rect.height / 2);

    gc.setTransform(transform);
    transform.dispose();
    gc.drawImage(ace_club, 0, 0);

    // ace of diamonds
    transform = new Transform(device);
    transform.translate((int) movDiamondX, (int) movDiamondY);
    transform.scale(scaleWidth, scaleWidth);
    gc.setTransform(transform);
    transform.dispose();
    gc.drawImage(ace_diamond, 0, 0);

    // ace of hearts
    transform = new Transform(device);
    transform.translate(movHeart, height / 2);
    transform.scale(heartScale, 0.5f * scale);
    gc.setTransform(transform);
    transform.dispose();
    gc.drawImage(ace_hearts, 0, 0);

    // ace of spades
    transform = new Transform(device);
    transform.translate(movSpade, movSpade);
    transform.scale(0.5f * scale, spadeScale);
    gc.setTransform(transform);
    transform.dispose();
    gc.drawImage(ace_spade, 0, 0);
  }
View Full Code Here

    Font font = new Font(device, CurvesTab.getPlatformFont(), 16, SWT.ITALIC);
    gc.setFont(font);
    gc.setLineWidth(5);

    Transform transform;

    // ----- cubic curve -----
    cubXPos = width / 5;
    cubYPos = height / 3;

    transform = new Transform(device);
    transform.translate(cubXPos, cubYPos);
    gc.setTransform(transform);
    transform.dispose();

    gc.setForeground(device.getSystemColor(SWT.COLOR_RED));
    gc.drawString(GraphicsExample.getResourceString("Cubic"), 25, -70, true);

    Path path = new Path(device);
    path.cubicTo(133 + cubDiffX1, -60 + cubDiffY1, 266 + cubDiffX2, 60 + cubDiffY2, 400 + cubEndDiffX,
        0 + cubEndDiffY);
    gc.drawPath(path);
    path.dispose();

    gc.setTransform(null);
    gc.setForeground(device.getSystemColor(SWT.COLOR_DARK_BLUE));
    gc.drawRectangle(cubHndl1.x + (int) cubXPos, cubHndl1.y + (int) cubYPos, cubHndl1.width, cubHndl1.height);
    gc.drawRectangle(cubHndl2.x + (int) cubXPos, cubHndl2.y + (int) cubYPos, cubHndl2.width, cubHndl2.height);
    gc.drawRectangle(cubEndHndl.x + (int) cubXPos, cubEndHndl.y + (int) cubYPos, cubEndHndl.width,
        cubEndHndl.height);

    // ----- quadratic curve -----
    quadXPos = width / 5;
    quadYPos = 2 * height / 3;

    transform = new Transform(device);
    transform.translate(quadXPos, quadYPos);
    gc.setTransform(transform);
    transform.dispose();

    gc.setForeground(device.getSystemColor(SWT.COLOR_GREEN));
    gc.drawString(GraphicsExample.getResourceString("Quadratic"), 0, -50, true);

    path = new Path(device);
View Full Code Here

    // write some text below the original image
    String text = GraphicsExample.getResourceString("OriginalImg"); //$NON-NLS-1$
    Point size = gc.stringExtent(text);
    gc.drawString(text, (width - size.x) / 2, 25 + bounds.height, true);

    Transform transform = new Transform(device);
    transform.translate((width - (bounds.width * scaleX + 10) * 4) / 2, 25 + bounds.height + size.y
        + (height - (25 + bounds.height + size.y + bounds.height * scaleY)) / 2);
    transform.scale(scaleX, scaleY);

    // --- draw strings ---
    float[] point = new float[2];
    text = GraphicsExample.getResourceString("None"); //$NON-NLS-1$
    size = gc.stringExtent(text);
    point[0] = (scaleX * bounds.width + 5 - size.x) / (2 * scaleX);
    point[1] = bounds.height;
    transform.transform(point);
    gc.drawString(text, (int) point[0], (int) point[1], true);

    text = GraphicsExample.getResourceString("Low"); //$NON-NLS-1$
    size = gc.stringExtent(text);
    point[0] = (scaleX * bounds.width + 5 - size.x) / (2 * scaleX) + bounds.width;
    point[1] = bounds.height;
    transform.transform(point);
    gc.drawString(text, (int) point[0], (int) point[1], true);

    text = GraphicsExample.getResourceString("Default"); //$NON-NLS-1$
    size = gc.stringExtent(text);
    point[0] = (scaleX * bounds.width + 5 - size.x) / (2 * scaleX) + 2 * bounds.width;
    point[1] = bounds.height;
    transform.transform(point);
    gc.drawString(text, (int) point[0], (int) point[1], true);

    text = GraphicsExample.getResourceString("High"); //$NON-NLS-1$
    size = gc.stringExtent(text);
    point[0] = (scaleX * bounds.width + 5 - size.x) / (2 * scaleX) + 3 * bounds.width;
    point[1] = bounds.height;
    transform.transform(point);
    gc.drawString(text, (int) point[0], (int) point[1], true);

    gc.setTransform(transform);
    transform.dispose();

    // --- draw images ---

    // no interpolation
    gc.setInterpolation(SWT.NONE);
View Full Code Here

    final Image image = AdvancedGraphics.loadImage(display, AdvancedGraphics.class, "irmaos.jpg");
    final Rectangle rect = image.getBounds();
    shell.addListener(SWT.Paint, new Listener() {
      public void handleEvent(Event event) {
        GC gc = event.gc;
        Transform tr = new Transform(display);
        tr.translate(rect.width / 4, rect.height / 2);
        tr.rotate(-30);
        if (image != null)
          gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width, rect.height);
        gc.setAlpha(100);
        gc.setTransform(tr);
        Path path = new Path(display);
        path.addString("SWT", 0, 0, font);
        gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
        gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
        gc.fillPath(path);
        gc.drawPath(path);
        tr.dispose();
        path.dispose();
      }
    });
    shell.setSize(shell.computeSize(rect.width, rect.height));
    shell.open();
View Full Code Here

TOP

Related Classes of org.eclipse.swt.graphics.Transform

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.