Package org.eclipse.swt.graphics

Examples of org.eclipse.swt.graphics.Path


     * @see #getPaint()
     * @see #getStroke()
     * @see #fill(Shape)
     */
    public void draw(Shape shape) {
        Path path = toSwtPath(shape);
        this.gc.drawPath(path);
        path.dispose();
    }
View Full Code Here


     *
     * @see #getPaint()
     * @see #draw(Shape)
     */
    public void fill(Shape shape) {
        Path path = toSwtPath(shape);
        // Note that for consistency with the AWT implementation, it is
        // necessary to switch temporarily the foreground and background
        // colours
        switchColors();
        this.gc.fillPath(path);
        switchColors();
        path.dispose();
    }
View Full Code Here

     * @return The path.
     */
    private Path toSwtPath(Shape shape) {
        int type;
        float[] coords = new float[6];
        Path path = new Path(this.gc.getDevice());
        PathIterator pit = shape.getPathIterator(null);
        while (!pit.isDone()) {
            type = pit.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_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;
                case (PathIterator.SEG_CLOSE):
                    path.close();
                    break;
                default:
                    break;
            }
            pit.next();
View Full Code Here

      org.eclipse.draw2d.geometry.Rectangle fillRectangle =
          new org.eclipse.draw2d.geometry.Rectangle(getBounds());

      if (this.rectPresentation.getCornerRadius() > 0)
      {
        Path path = createPath(fillRectangle, graphics, true, this.rectPresentation.getCornerRadius());
        graphics.clipPath(path);
      }
     
      if (bg instanceof SolidBackgroundDef)
      {
View Full Code Here

  }
 
  private Path createPath(org.eclipse.draw2d.geometry.Rectangle outerBounds, Graphics graphics, boolean isFill,
      int cornerRadius)
  {
    Path path = new Path(null);
   
    float x = outerBounds.x;
    float y = outerBounds.y;
    float height = outerBounds.height;
    float width = outerBounds.width;
    float bottom = y + height;
    float right = x + width;   

    // the half cornersize is the length of the arc,
    // so two time the half cornersize must not be longer than the side
    // itself
    float cornerWidth = cornerRadius;
    float cornerHeight = cornerRadius;
    cornerWidth = (cornerWidth > width) ? width : cornerWidth;
    cornerHeight = (cornerHeight > height) ? height : cornerHeight;

    if (isFill) {
      // adjust corner for the inner path (formula found by experimenting)
      cornerHeight = Math.max(1, cornerHeight - (getLineWidth() + cornerHeight / 64));
      cornerWidth = Math.max(1, cornerWidth - (getLineWidth() + cornerWidth / 64));
    }

    // workaround: path must be usual rectangle, if corner=0
    // otherwise the path is not drawn at all (same happens
    // RoundedRectangles)
    if (cornerHeight <= 0 || cornerWidth <= 0) {
      path.addRectangle(x, y, width, height);
    } else {
      path.moveTo(x, y);
      path.addArc(x, y, cornerWidth, cornerHeight, 90, 90);
      path.addArc(x, bottom - cornerHeight, cornerWidth, cornerHeight, 180, 90);
      path.addArc(right - cornerWidth, bottom - cornerHeight, cornerWidth, cornerHeight, 270, 90);
      path.addArc(right - cornerWidth, y, cornerWidth, cornerHeight, 0, 90);
      path.close();
    }

    return path;
   
  }
View Full Code Here

    Rectangle topAdjusted = transformGenericRectangle(getDeclaration().getTopPad(), shrinkLines);
    Rectangle rightAdjusted = transformGenericRectangle(getDeclaration().getRightPad(), shrinkLines);
    Rectangle bottomAdjusted = transformGenericRectangle(getDeclaration().getBottomPad(), shrinkLines);

    Path path = createPath(topAdjusted, rightAdjusted, bottomAdjusted, (int) corner);
    return path;
  }
View Full Code Here

   *            The corner radius to use for the path.
   * @return A path surrounding the given rectangles and uses the given
   *         corner-radius.
   */
  private Path createPath(Rectangle topOutside, Rectangle rightOutside, Rectangle bottomOutside, int corner) {
    Path path = new Path(null);

    // currently we assume, that the inner corner radius is always half the outer corner radius
    int innerCorner = corner / 2;

    // first shrink all rectangles by the half line-width, so that painting remains inside the given 'outside' rectangles
    Rectangle top = FigureUtil.getAdjustedRectangle(topOutside, 1.0, (int) (getDeclaration().getPadLineWidth() * getZoomLevel()));
    Rectangle right = FigureUtil.getAdjustedRectangle(rightOutside, 1.0, (int) (getDeclaration().getPadLineWidth() * getZoomLevel()));
    Rectangle bottom = FigureUtil.getAdjustedRectangle(bottomOutside, 1.0,
        (int) (getDeclaration().getPadLineWidth() * getZoomLevel()));

    // differenciate the pad styles
    boolean hasTop = top != null;
    boolean hasRight = right != null;
    boolean hasStandardTop = hasTop && getDeclaration().getTopPadStyle().equals(PadStyle.STANDARD);
    boolean hasStandardRight = hasRight && getDeclaration().getRightPadStyle().equals(PadStyle.STANDARD);
    boolean hasAppendageTop = hasTop && getDeclaration().getTopPadStyle().equals(PadStyle.APPENDAGE);
    boolean hasAppendageRight = hasRight && getDeclaration().getRightPadStyle().equals(PadStyle.APPENDAGE);

    // create path

    if (hasStandardTop) {
      // curved line around top(top-right) -> top(top-left) -> top(bottom-left)
      path.addArc(top.getTopRight().x - corner, top.getTopRight().y, corner, corner, 0, 90);
      path.addArc(top.getTopLeft().x, top.getTopLeft().y, corner, corner, 90, 90);
      path.addArc(top.getBottomLeft().x, top.getBottomLeft().y - corner, corner, corner, 180, 90);
    } else if (hasAppendageTop) {
      // curved line around top(top-left) -> top(bottom-left)
      int appendageCorner = Math.min(corner, top.height * 2); // adjust for small sizes
      path.addArc(top.getTopLeft().x, top.getTopLeft().y, appendageCorner, appendageCorner, 90, 90);
      path.lineTo(top.getBottomLeft().x, top.getBottomLeft().y);
    } else { // !hasTop
      // curved line around right(top-left)
      path.addArc(right.getTopLeft().x, right.getTopLeft().y, corner, corner, 90, 90);
    }

    if (hasTop && hasRight) {
      // inside open curve connecting top and right
      path.addArc(right.getLeft().x - innerCorner, top.getBottom().y, innerCorner, innerCorner, 90, -90);
    }

    if (hasStandardRight) {
      if (bottom == null) {
        // curved line around right(bottom-left)
        path.addArc(right.getBottomLeft().x, right.getBottomLeft().y - corner, corner, corner, 180, 90);
      } else {
        // inside open curve connection right and bottom
        path.addArc(right.getLeft().x - innerCorner, bottom.getTop().y - innerCorner, innerCorner, innerCorner, 0, -90);
        // curved line around bottom(top-left) -> bottom(bottom-left) -> bottom(bottom-right)
        path.addArc(bottom.getTopLeft().x, bottom.getTopLeft().y, corner, corner, 90, 90);
        path.addArc(bottom.getBottomLeft().x, bottom.getBottomLeft().y - corner, corner, corner, 180, 90);
        path.addArc(bottom.getBottomRight().x - corner, bottom.getBottomRight().y - corner, corner, corner, 270, 90);
        // outside open curve connection bottom and right
        path.addArc(bottom.getRight().x, right.getBottom().y, corner, corner, 180, -90);
      }

      // curved line around right(bottom-right) -> right(top-right)
      path.addArc(right.getBottomRight().x - corner, right.getBottomRight().y - corner, corner, corner, 270, 90);
      path.addArc(right.getTopRight().x - corner, right.getTopRight().y, corner, corner, 0, 90);
    } else if (hasAppendageRight) {
      // curved line around right(bottom-left) -> right(bottom-right)
      int appendageCorner = Math.min(corner, right.width * 2); // adjust for small sizes
      path.lineTo(right.getBottomLeft().x, right.getBottomLeft().y);
      path.addArc(right.getBottomRight().x - appendageCorner, right.getBottomRight().y - appendageCorner, appendageCorner,
          appendageCorner, 270, 90);
    } else { // !hasRight
      // close curved rectangle around top (bottom-right)
      path.addArc(top.getBottomRight().x - corner, top.getBottomRight().y - corner, corner, corner, 270, 90);
    }

    if (hasStandardTop && hasStandardRight) {
      // outside open curve connecting right and top (appendages have direct line)
      path.addArc(top.getRight().x, right.getTop().y - corner, corner, corner, 270, -90);
    }

    path.close();

    return path;
  }
View Full Code Here

    }
    return ret;
  }

  public static Path getBezierPath(List<BezierPoint> origPoints, boolean isClosed) {
    Path path = new Path(null);
    // make a copy, so that we can change it
    List<BezierPoint> points = new ArrayList<BezierPoint>(origPoints.size() + 2);
    points.addAll(origPoints);

    // Draw simple lines, as bezier-curve doesn't make sense
    if (points.size() < 3 || !hasBezierDistance(origPoints)) {
      if (points.size() != 0) {
        path.moveTo(points.get(0).getX(), points.get(0).getY());
        for (int i = 1; i < points.size(); i++) {
          path.lineTo(points.get(i).getX(), points.get(i).getY());
        }
      }
    } else { // Draw bezier curve

      // Idea for the closed bezier curve:
      // The first two points are added to the end of the point-list.
      // Afterwards the bezier-curve through the points is drawn as usual,
      // except that the first line and the last line are not drawn.

      // Adjust point-list if closing is needed: add the first two points
      // again at the end
      if (isClosed) {
        if (!points.get(points.size() - 1).equals(points.get(0))) { // first
                                      // !=
                                      // last
                                      // =>
                                      // only
                                      // then
                                      // double
                                      // first
                                      // point
          points.add(points.get(0));
        }
        points.add(points.get(1));
      }

      // Initialize the points for calculation
      Point c = points.get(0).createDraw2dPoint(); // the current
                              // control-point
      Point q = points.get(1).createDraw2dPoint(); // the point following
                              // the current
      // control-point
      Point r = new Point();
      Point s = new Point();

      // If not closed, draw the first line from the first point to r,
      // otherwise move to r
      determineBezierPoints(c, q, r, s, points.get(0).getBezierDistanceAfter(), points.get(1).getBezierDistanceBefore());
      if (!isClosed) {
        path.moveTo(points.get(0).getX(), points.get(0).getY());
        path.lineTo(r.x, r.y);
      } else {
        path.moveTo(r.x, r.y);
      }

      for (int index = 2; index < points.size(); index++) {
        // Move c and q one position forward
        c.setLocation(q);
        points.get(index).copyToDraw2dPoint(q);

        // Update r and s
        determineBezierPoints(c, q, r, s, points.get(index - 1).getBezierDistanceAfter(), points.get(index)
            .getBezierDistanceBefore());

        // draw the curve
        path.quadTo(c.x, c.y, s.x, s.y);
        path.lineTo(r.x, r.y);
      }

      // If not closed, draw the final line from r to the last point,
      // otherwise do nothing
      if (!isClosed) {
        // Draw the final line from r to the last point.
        path.lineTo(points.get(points.size() - 1).getX(), points.get(points.size() - 1).getY());
      }
    }

    // The algorithm already takes care, that the line ends again at the
    // start-point.
    // But a final path.close() takes care of drawing problems.
    if (isClosed) {
      path.close();
    }

    return path;
  }
View Full Code Here

    PointList points = FigureUtil.getAdjustedPointList(getPoints(), zoom, lineWidth);

    List<BezierPoint> bezierPoints = getBezierPoints(points, zoom);
    boolean isClosed = bezierPoints.get(0).equals(bezierPoints.get(bezierPoints.size() - 1));

    Path path = FigureUtil.getBezierPath(bezierPoints, isClosed);
    return path;
  }
View Full Code Here

    int oldLineWidth = graphics.getLineWidth();
    graphics.setLineWidth(lineWidth);

    // get Path
    Rectangle pathbounds = getBounds();
    Path path = createPath(pathbounds, graphics);

    graphics.drawPath(path);

    // reset Graphics
    path.dispose();
    graphics.setLineWidth(oldLineWidth);
  }
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.