Пример #1
0
 /**
  * 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;
 }
Пример #2
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;
 }
Пример #3
0
 void init(PathData data) {
   byte[] types = data.types;
   float[] points = data.points;
   for (int i = 0, j = 0; i < types.length; i++) {
     switch (types[i]) {
       case SWT.PATH_MOVE_TO:
         moveTo(points[j++], points[j++]);
         break;
       case SWT.PATH_LINE_TO:
         lineTo(points[j++], points[j++]);
         break;
       case SWT.PATH_CUBIC_TO:
         cubicTo(points[j++], points[j++], points[j++], points[j++], points[j++], points[j++]);
         break;
       case SWT.PATH_QUAD_TO:
         quadTo(points[j++], points[j++], points[j++], points[j++]);
         break;
       case SWT.PATH_CLOSE:
         close();
         break;
       default:
         dispose();
         SWT.error(SWT.ERROR_INVALID_ARGUMENT);
     }
   }
 }