Package org.eclipse.swt.graphics

Examples of org.eclipse.swt.graphics.Path


      gc.setLineCap(lineCap); // round line ends
      gc.setAntialias(antialias); // smooth jagged edges
      gc.setTextAntialias(antialias); // smooth jagged edges

      // draw the circles
      Path path = new Path(device);
      path.addArc((width - diameter) / 2, (height - diameter) / 2, diameter, diameter, 0, 360);
      path
          .addArc((width - diameter + 50) / 2, (height - diameter + 50) / 2, diameter - 50, diameter - 50, 0,
              360);
      gc.drawPath(path);
      gc.setBackground(device.getSystemColor(SWT.COLOR_RED));
      gc.fillPath(path);
      path.dispose();

      Point point = gc.stringExtent(new Integer(nextNumber).toString());
      int textWidth = point.x;
      int textHeight = point.y;
View Full Code Here


    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);
    path.quadTo(200 + quadDiffX, 150 + quadDiffY, 400 + quadEndDiffX, 0 + quadEndDiffY);
    gc.drawPath(path);
    path.dispose();

    gc.setTransform(null);
    gc.setForeground(device.getSystemColor(SWT.COLOR_GRAY));
    gc.drawRectangle(quadHndl.x + (int) quadXPos, quadHndl.y + (int) quadYPos, quadHndl.width, quadHndl.height);
    gc.drawRectangle(quadEndHndl.x + (int) quadXPos, quadEndHndl.y + (int) quadYPos, quadEndHndl.width,
View Full Code Here

    gc.setLineWidth(5);
    gc.setForeground(device.getSystemColor(SWT.COLOR_BLACK));

    // arc
    Path path = new Path(device);
    path.addArc((width - 250) / 2, (height - 400) / 2, 500, 400, 90, 180);
    if (closeButton.getSelection())
      path.close();
    if (fillButton.getSelection())
      gc.fillPath(path);
    if (drawButton.getSelection())
      gc.drawPath(path);
    path.dispose();

    // shape on left
    Transform transform = new Transform(device);
    transform.translate((width - 250) / 4, height / 2 - 150);
    gc.setTransform(transform);
    transform.dispose();
    path = new Path(device);
    path.cubicTo(-150, 100, 150, 200, 0, 300);
    if (closeButton.getSelection())
      path.close();
    if (fillButton.getSelection())
      gc.fillPath(path);
    if (drawButton.getSelection())
      gc.drawPath(path);
    path.dispose();
    gc.setTransform(null);

    // shape on right
    path = new Path(device);
    path.moveTo(3 * (width - 250) / 4 - 25 + 250, height / 2);
    path.lineTo(3 * (width - 250) / 4 + 50 + 250, height / 2 - 200);
    path.lineTo(3 * (width - 250) / 4 + 50 + 250, height / 2 + 50);
    path.lineTo(3 * (width - 250) / 4 - 25 + 250, height / 2 + 150);
    path.lineTo(3 * (width - 250) / 4 + 25 + 250, height / 2 + 50);
    if (closeButton.getSelection())
      path.close();
    if (fillButton.getSelection())
      gc.fillPath(path);
    if (drawButton.getSelection())
      gc.drawPath(path);
    path.dispose();

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

    GC gc = new GC(image);
    Rectangle rect = image.getBounds();

    Pattern pattern1 = new Pattern(device, rect.x, rect.y, rect.width / 2f, rect.height / 2f, color1, color2);
    gc.setBackgroundPattern(pattern1);
    Path path = new Path(device);
    path.addRectangle(0, 0, width / 4f, height / 4f);
    path.addRectangle(width / 4f, height / 4f, width / 4f, height / 4f);
    gc.fillPath(path);
    path.dispose();

    Pattern pattern2 = new Pattern(device, rect.width, 0, rect.width / 2f, rect.height / 2f, color1, color2);
    gc.setBackgroundPattern(pattern2);
    path = new Path(device);
    path.addRectangle(width / 4f, 0, width / 4f, height / 4f);
    path.addRectangle(0, height / 4f, width / 4f, height / 4f);
    gc.fillPath(path);
    path.dispose();

    gc.dispose();
    pattern1.dispose();
    pattern2.dispose();
    return image;
View Full Code Here

  public Shell open(final Display display) {
    final Shell shell = new Shell(display);
    shell.setText(AdvancedGraphics.RESOURCE_BUNDLE.getString("AdvancedGraphics")); //$NON-NLS-1$
    try {
      Path path = new Path(display);
      path.dispose();
    } catch (SWTException e) {
      MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
      dialog.setText(AdvancedGraphics.RESOURCE_BUNDLE.getString("Warning")); //$NON-NLS-1$
      dialog.setMessage(AdvancedGraphics.RESOURCE_BUNDLE.getString("LibNotFound")); //$NON-NLS-1$
      dialog.open();
      shell.dispose();
      return null;
    }
    FontData fd = shell.getFont().getFontData()[0];
    final Font font = new Font(display, fd.getName(), 96, SWT.BOLD | SWT.ITALIC);
    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();
    shell.addListener(SWT.Dispose, new Listener() {
View Full Code Here

        transform.translate(((Float) bc[j].prevx.get(bc[j].prevx.size() - (i + 1))).floatValue(),
            ((Float) bc[j].prevy.get(bc[j].prevy.size() - (i + 1))).floatValue());
        gc.setTransform(transform);
        transform.dispose();

        Path path = new Path(device);
        path.addArc(0, 0, bc[j].ball_size, bc[j].ball_size, 0, 360);
        gc.setAlpha(255 - i * 255 / bc[j].capacity);
        gc.setBackground(bc[j].colors[0]);
        gc.fillPath(path);
        gc.drawPath(path);
        path.dispose();
      }
  }
View Full Code Here

    if (!example.checkAdvancedGraphics())
      return;
    Device device = gc.getDevice();

    // top triangle
    Path path = new Path(device);
    path.moveTo(width / 2, 0);
    path.lineTo(width / 2 + 100, 173);
    path.lineTo(width / 2 - 100, 173);
    path.lineTo(width / 2, 0);

    // bottom triangle
    Path path2 = new Path(device);
    path2.moveTo(width / 2, height);
    path2.lineTo(width / 2 + 100, height - 173);
    path2.lineTo(width / 2 - 100, height - 173);
    path2.lineTo(width / 2, height);

    // left triangle
    Path path3 = new Path(device);
    path3.moveTo(0, height / 2);
    path3.lineTo(173, height / 2 - 100);
    path3.lineTo(173, height / 2 + 100);
    path3.lineTo(0, height / 2);

    // right triangle
    Path path4 = new Path(device);
    path4.moveTo(width, height / 2);
    path4.lineTo(width - 173, height / 2 - 100);
    path4.lineTo(width - 173, height / 2 + 100);
    path4.lineTo(width, height / 2);

    // circle
    Path path5 = new Path(device);
    path5.moveTo((width - 200) / 2, (height - 200) / 2);
    path5.addArc((width - 200) / 2, (height - 200) / 2, 200, 200, 0, 360);

    // top rectangle
    Path path6 = new Path(device);
    path6.addRectangle((width - 40) / 2, 175, 40, (height - 200) / 2 - 177);

    // bottom rectangle
    Path path7 = new Path(device);
    path7.addRectangle((width - 40) / 2, (height - 200) / 2 + 202, 40, height - 175 - ((height - 200) / 2 + 202));

    // left rectangle
    Path path8 = new Path(device);
    path8.addRectangle(175, (height - 40) / 2, (width - 200) / 2 - 177, 40);

    // right rectangle
    Path path9 = new Path(device);
    path9.addRectangle((width - 200) / 2 + 202, (height - 40) / 2, width - 175 - ((width - 200) / 2 + 202), 40);

    path.addPath(path2);
    path.addPath(path3);
    path.addPath(path4);
    path.addPath(path5);
    path.addPath(path6);
    path.addPath(path7);
    path.addPath(path8);
    path.addPath(path9);
    gc.setClipping(path);

    Pattern pattern = null;
    if (background.getBgColor1() != null)
      gc.setBackground(background.getBgColor1());
    else if (background.getBgImage() != null) {
      pattern = new Pattern(device, background.getBgImage());
      gc.setBackgroundPattern(pattern);
    }

    gc.setLineWidth(2);
    gc.fillRectangle((width - rectWidth) / 2, (height - rectHeight) / 2, rectWidth, rectHeight);
    gc.drawPath(path);

    if (pattern != null)
      pattern.dispose();

    path9.dispose();
    path8.dispose();
    path7.dispose();
    path6.dispose();
    path5.dispose();
    path4.dispose();
View Full Code Here

    Transform transform = new Transform(device);
    transform.translate(0, translateY);
    gc.setTransform(transform);
    transform.dispose();

    Path path = new Path(device);
    path.addRectangle(0, 0, width, 50);
    Pattern pattern = new Pattern(device, 0, 0, width, 50, device.getSystemColor(SWT.COLOR_BLUE), 0x7f, device
        .getSystemColor(SWT.COLOR_RED), 0x7f);
    gc.setBackgroundPattern(pattern);
    gc.fillPath(path);
    gc.drawPath(path);
    path.dispose();

    // vertical rectangle
    transform = new Transform(device);
    transform.translate(translateX, 0);
    gc.setTransform(transform);
    transform.dispose();

    path = new Path(device);
    path.addRectangle(0, 0, 50, height);
    pattern.dispose();
    pattern = new Pattern(device, 0, 0, 50, height, device.getSystemColor(SWT.COLOR_DARK_CYAN), 0x7f, device
        .getSystemColor(SWT.COLOR_WHITE), 0x7f);
    gc.setBackgroundPattern(pattern);
    gc.fillPath(path);
    gc.drawPath(path);
    path.dispose();

    // diagonal rectangle from bottom right corner
    Rectangle rect = new Rectangle(0, 0, 50, height);
    transform = new Transform(device);
    transform.translate(width - diagTranslateX1, height / 2 - diagTranslateY1);

    // rotate on center of rectangle
    transform.translate(rect.width / 2, rect.height / 2);
    transform.rotate(45);
    transform.translate(-rect.width / 2, -rect.height / 2);
    gc.setTransform(transform);
    transform.dispose();

    path = new Path(device);
    path.addRectangle(rect.x, rect.y, rect.width, rect.height);
    pattern.dispose();
    pattern = new Pattern(device, rect.x, rect.y, rect.width, rect.height, device
        .getSystemColor(SWT.COLOR_DARK_GREEN), 0x7f, device.getSystemColor(SWT.COLOR_DARK_MAGENTA), 0x7f);
    gc.setBackgroundPattern(pattern);
    gc.fillPath(path);
    gc.drawPath(path);
    path.dispose();

    // diagonal rectangle from top right corner
    transform = new Transform(device);
    transform.translate(width - diagTranslateX2, height / 2 - diagTranslateY2);

    // rotate on center of rectangle
    transform.translate(rect.width / 2, rect.height / 2);
    transform.rotate(-45);
    transform.translate(-rect.width / 2, -rect.height / 2);
    gc.setTransform(transform);
    transform.dispose();

    path = new Path(device);
    path.addRectangle(rect.x, rect.y, rect.width, rect.height);
    pattern.dispose();
    pattern = new Pattern(device, rect.x, rect.y, rect.width, rect.height, device
        .getSystemColor(SWT.COLOR_DARK_RED), 0x7f, device.getSystemColor(SWT.COLOR_YELLOW), 0x7f);
    gc.setBackgroundPattern(pattern);
    gc.fillPath(path);
    gc.drawPath(path);
    pattern.dispose();
    path.dispose();
  }
View Full Code Here

    gc.drawString(text, randX, randY, true);
    font.dispose();

    // gray donut
    gc.setAlpha(100);
    Path path = new Path(device);
    path.addArc((width - diameter) / 2, (height - diameter) / 2, diameter, diameter, 0, 360);
    path.close();
    path.addArc((width - diameter + 25) / 2, (height - diameter + 25) / 2, diameter - 25, diameter - 25, 0, 360);
    path.close();
    gc.setBackground(device.getSystemColor(SWT.COLOR_GRAY));
    gc.fillPath(path);
    gc.drawPath(path);
    path.dispose();
  }
View Full Code Here

   */
  public static Path pathIterator2Path(PathIterator iter)
  {
    float [] coords = new float[6];
   
    Path path = new Path(Display.getDefault());
   
    while (!iter.isDone())
    {
      int type = iter.currentSegment(coords);

      switch (type)
      {
        case  PathIterator.SEG_MOVETO:
            path.moveTo(coords[0], coords[1]);
            break;

        case  PathIterator.SEG_LINETO:
            path.lineTo(coords[0],coords[1]);
            break;

        case  PathIterator.SEG_CLOSE:
            path.close();
            break;

        case  PathIterator.SEG_QUADTO:
            path.quadTo(coords[0],coords[1],coords[2],coords[3]);
            break;

        case  PathIterator.SEG_CUBICTO:
            path.cubicTo(coords[0], coords[1],coords[2],coords[3],coords[4],coords[5]);
            break;
      }
       
      iter.next();
    }
View Full Code Here

TOP

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

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.