Beispiel #1
0
    protected void paintFigure(Graphics graphics) {
      int alpha = 0x60;
      graphics.setAntialias(SWT.ON);
      if (control != null && !control.isDisposed() && control.isEnabled()) {
        graphics.setAlpha(0xff);
      } else {
        graphics.setAlpha(0x90);
      }
      Rectangle r = getBounds();
      Path shape = new Path(Display.getCurrent());
      float corner = Math.max(2, (vertical ? r.width : r.height) / 2);
      SWTUtils.addRoundedRectangle(shape, r.x, r.y, r.width - 1, r.height - 1, corner);

      Pattern pattern =
          new Pattern(
              Display.getCurrent(), //
              r.x,
              r.y, //
              vertical ? r.right() - 1 : r.x, //
              vertical ? r.y : r.bottom() - 1, //
              ColorConstants.gray,
              alpha, //
              ColorConstants.lightGray,
              alpha);
      graphics.setBackgroundPattern(pattern);
      graphics.fillPath(shape);
      graphics.setBackgroundPattern(null);
      pattern.dispose();

      graphics.setAlpha(alpha);
      graphics.setForegroundColor(ColorConstants.gray);
      graphics.drawPath(shape);
      shape.dispose();
    }
Beispiel #2
0
 /**
  * Sets the clip region.
  *
  * @param clip the clip.
  */
 @Override
 public void setClip(Shape clip) {
   if (clip == null) {
     return;
   }
   Path clipPath = toSwtPath(clip);
   this.gc.setClipping(clipPath);
   clipPath.dispose();
 }
Beispiel #3
0
 /**
  * Fills the specified shape using the current paint.
  *
  * @param shape the shape ({@code null} not permitted).
  * @see #getPaint()
  * @see #draw(Shape)
  */
 @Override
 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
   // colors
   switchColors();
   this.gc.fillPath(path);
   switchColors();
   path.dispose();
 }
  /**
   * Create horizontal line
   *
   * @param display - active {@link Display}
   * @param g - active {@link ViewportGraphics}
   * @param sx - Square width
   * @param lw - line width
   * @param current - Current square coordinate (corner)
   * @param next - Next square coordinate (corner)
   * @param gap - Gap where label is inserted (pixels)
   * @param bold - flag controlling line width
   * @param lines - already created square lines
   * @return 'next' coordinate
   */
  private Point horz(
      Display display,
      ViewportGraphics g,
      int sx,
      int lw,
      Point current,
      Point next,
      boolean gap,
      boolean bold,
      List<Line> lines) {

    // Initialize
    List<Path> paths = new ArrayList<Path>(2);

    // Create first segment
    Path path = new Path(display);

    // Move to last point
    path.moveTo(current.x, current.y);

    // Insert gap?
    if (gap) {

      // Calculate gap/2
      int offset = Math.max(1, g.getFontHeight());

      // End first segment before mid-point
      Point p = offset(current, next, -offset);
      path.lineTo(p.x, p.y);
      paths.add(path);

      // Create second segment
      path = new Path(display);

      // Move past mid-point
      p = offset(current, next, offset);
      path.moveTo(p.x, p.y);
    }

    // Close path
    path.lineTo(next.x - (bold ? 2 * lw : lw), next.y);
    paths.add(path);
    lines.add(new Line(paths, bold ? 2 * lw : lw));

    // Finished
    return gap ? offset(current, next, 0) : next;
  }
  @Override
  protected void outlineShape(Graphics graphics) {
    graphics.setAntialias(SWT.ON);

    final int lineWidth = getLineWidth();

    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);
  }
Beispiel #6
0
 /**
  * Converts an AWT {@code Shape} into a SWT {@code Path}.
  *
  * @param shape the shape ({@code null} not permitted).
  * @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();
   }
   return path;
 }
 /**
  * Convert an AWT Shape to an SWT Path.
  *
  * @param shape
  * @return the SWT Path or <code>null</code> if <code>shape == null</code>
  */
 private Path convertToPath(Shape shape) {
   if (shape == null) {
     return null;
   }
   Path path = new Path(_gc.getDevice());
   PathIterator iter = shape.getPathIterator(null);
   float[] coords = new float[6];
   while (!iter.isDone()) {
     int op = iter.currentSegment(coords);
     switch (op) {
       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;
     }
     iter.next();
   }
   return path;
 }
 public void setClip(Shape s) {
   Path path = convertToPath(s);
   if (path == null) {
     _gc.setClipping((Rectangle) null);
   } else {
     _gc.setClipping(path);
   }
   if (_clippingPath != null) {
     _clippingPath.dispose();
   }
   _clippingPath = path;
   _clippingArea = (s == null ? null : new Area(s));
 }
 /** Clean used resources. */
 public void clean() {
   if (_clippingPath != null) {
     _gc.setClipping((Rectangle) null);
     _clippingPath.dispose();
     _clippingPath = null;
     _clippingArea = null;
   }
   if (_color != null) {
     _color.dispose();
     _color = null;
   }
   if (_transform != null) {
     _gc.setTransform(null);
     _transform.dispose();
   }
 }
Beispiel #10
0
 public Path(Device device, Path path, float flatness) {
   super(device);
   if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   flatness = Math.max(0, flatness);
   if (flatness == 0) {
     handle = new NSBezierPath(path.handle.copy().id);
   } else {
     float defaultFlatness = NSBezierPath.defaultFlatness();
     NSBezierPath.setDefaultFlatness(flatness);
     handle = path.handle.bezierPathByFlatteningPath();
     NSBezierPath.setDefaultFlatness(defaultFlatness);
   }
   if (handle == null) SWT.error(SWT.ERROR_NO_HANDLES);
   init();
 }
Beispiel #11
0
 /**
  * Applies the specified clip.
  *
  * @param s the shape for the clip.
  */
 @Override
 public void clip(Shape s) {
   Path path = toSwtPath(s);
   this.gc.setClipping(path);
   path.dispose();
 }
Beispiel #12
0
  /** Draw the icon */
  protected void drawIcon(Graphics graphics) {
    graphics.setLineWidth(1);
    graphics.setForegroundColor(ColorConstants.black);
    graphics.setBackgroundColor(ColorConstants.black);

    Point pt = getIconOrigin();

    Path path = new Path(null);

    graphics.setLineWidthFloat(1.2f);
    path.addArc(pt.x, pt.y, 13, 13, 0, 360);

    graphics.drawPath(path);
    path.dispose();

    graphics.fillOval(pt.x + 5, pt.y + 5, 4, 4);

    graphics.setLineWidth(1);

    path = new Path(null);

    path.moveTo(pt.x - 2, pt.y + 6.5f);
    path.lineTo(pt.x + 15, pt.y + 6.5f);

    path.moveTo(pt.x + 6.5f, pt.y - 2);
    path.lineTo(pt.x + 6.5f, pt.y + 15);

    path.moveTo(pt.x + 0.5f, pt.y + 0.5f);
    path.lineTo(pt.x + 12.5f, pt.y + 12.5f);

    path.moveTo(pt.x + 0.5f, pt.y + 12.5f);
    path.lineTo(pt.x + 12.5f, pt.y + 0.5f);

    graphics.drawPath(path);
    path.dispose();
  }
Beispiel #13
0
 /**
  * Adds to the receiver the path described by the parameter.
  *
  * @param path the path to add to the receiver
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the parameter is null
  *       <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  *     </ul>
  */
 public void addPath(Path path) {
   if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
   if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   handle.appendBezierPath(path.handle);
 }
  /** Draw the icon */
  protected void drawIcon(Graphics graphics) {
    graphics.pushState();

    graphics.setLineWidthFloat(1);
    graphics.setForegroundColor(isEnabled() ? ColorConstants.black : ColorConstants.gray);

    Point pt = getIconOrigin();

    Path path = new Path(null);

    path.addArc(pt.x, pt.y, 5, 5, 0, 360);
    path.addArc(pt.x + 2, pt.y - 8, 5, 5, 0, 360);
    path.addArc(pt.x + 10, pt.y - 8, 5, 5, 0, 360);
    path.addArc(pt.x + 8, pt.y, 5, 5, 0, 360);

    path.moveTo(pt.x + 3, pt.y);
    path.lineTo(pt.x + 4, pt.y - 3);

    path.moveTo(pt.x + 11, pt.y);
    path.lineTo(pt.x + 12, pt.y - 3);

    path.moveTo(pt.x + 5, pt.y + 2.5f);
    path.lineTo(pt.x + 8, pt.y + 2.5f);

    path.moveTo(pt.x + 7, pt.y - 5.5f);
    path.lineTo(pt.x + 10, pt.y - 5.5f);

    graphics.drawPath(path);
    path.dispose();

    graphics.popState();
  }
Beispiel #15
0
 /**
  * Draws the outline of the specified shape using the current stroke and paint settings.
  *
  * @param shape the shape ({@code null} not permitted).
  * @see #getPaint()
  * @see #getStroke()
  * @see #fill(Shape)
  */
 @Override
 public void draw(Shape shape) {
   Path path = toSwtPath(shape);
   this.gc.drawPath(path);
   path.dispose();
 }
 public void fill(Shape s) {
   Path p = convertToPath(s);
   _gc.fillPath(p);
   p.dispose();
 }
 protected Path createPointPath(Device device) {
   Point point = geom.getShell().getPoint(0);
   Path path = new Path(device);
   path.addRectangle(point.getX() - 2, point.getY() - 2, 4, 4);
   return path;
 }