Exemplo n.º 1
0
 /**
  * Adds to the receiver a circular or elliptical arc that lies within the specified rectangular
  * area.
  *
  * <p>The resulting arc begins at <code>startAngle</code> and extends for <code>arcAngle</code>
  * degrees. Angles are interpreted such that 0 degrees is at the 3 o'clock position. A positive
  * value indicates a counter-clockwise rotation while a negative value indicates a clockwise
  * rotation.
  *
  * <p>The center of the arc is the center of the rectangle whose origin is (<code>x</code>, <code>
  * y</code>) and whose size is specified by the <code>width</code> and <code>height</code>
  * arguments.
  *
  * <p>The resulting arc covers an area <code>width + 1</code> pixels wide by <code>height + 1
  * </code> pixels tall.
  *
  * @param x the x coordinate of the upper-left corner of the arc
  * @param y the y coordinate of the upper-left corner of the arc
  * @param width the width of the arc
  * @param height the height of the arc
  * @param startAngle the beginning angle
  * @param arcAngle the angular extent of the arc, relative to the start angle
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  *     </ul>
  */
 public void addArc(
     float x, float y, float width, float height, float startAngle, float arcAngle) {
   if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
   NSAffineTransform transform = NSAffineTransform.transform();
   transform.translateXBy(x + width / 2f, y + height / 2f);
   transform.scaleXBy(width / 2f, height / 2f);
   NSBezierPath path = NSBezierPath.bezierPath();
   NSPoint center = new NSPoint();
   float sAngle = -startAngle;
   float eAngle = -(startAngle + arcAngle);
   path.appendBezierPathWithArcWithCenter_radius_startAngle_endAngle_clockwise_(
       center, 1, sAngle, eAngle, arcAngle > 0);
   path.transformUsingAffineTransform(transform);
   handle.appendBezierPath(path);
 }
Exemplo n.º 2
0
 /**
  * Adds to the receiver the pattern of glyphs generated by drawing the given string using the
  * given font starting at the point (x, y).
  *
  * @param string the text to use
  * @param x the x coordinate of the starting point
  * @param y the y coordinate of the starting point
  * @param font the font to use
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the font is null
  *       <li>ERROR_INVALID_ARGUMENT - if the font has been disposed
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  *     </ul>
  */
 public void addString(String string, float x, float y, Font font) {
   if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
   if (font == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   NSString str = NSString.stringWith(string);
   NSTextStorage textStorage = ((NSTextStorage) new NSTextStorage().alloc());
   textStorage.initWithString_(str);
   NSLayoutManager layoutManager = (NSLayoutManager) new NSLayoutManager().alloc().init();
   NSTextContainer textContainer = (NSTextContainer) new NSTextContainer().alloc();
   NSSize size = new NSSize();
   size.width = Float.MAX_VALUE;
   size.height = Float.MAX_VALUE;
   textContainer.initWithContainerSize(size);
   textStorage.addLayoutManager(layoutManager);
   layoutManager.addTextContainer(textContainer);
   NSRange range = new NSRange();
   range.length = str.length();
   textStorage.beginEditing();
   textStorage.addAttribute(OS.NSFontAttributeName(), font.handle, range);
   textStorage.endEditing();
   range = layoutManager.glyphRangeForTextContainer(textContainer);
   if (range.length != 0) {
     int glyphs = OS.malloc(4 * range.length * 2);
     layoutManager.getGlyphs(glyphs, range);
     NSBezierPath path = NSBezierPath.bezierPath();
     NSPoint point = new NSPoint();
     point.x = x;
     point.y = y;
     path.moveToPoint(point);
     path.appendBezierPathWithGlyphs(glyphs, range.length, font.handle);
     NSAffineTransform transform = NSAffineTransform.transform();
     transform.scaleXBy(1, -1);
     transform.translateXBy(0, -((2 * y) + textStorage.size().height));
     path.transformUsingAffineTransform(transform);
     OS.free(glyphs);
     handle.appendBezierPath(path);
   }
   textContainer.release();
   layoutManager.release();
   textStorage.release();
 }