コード例 #1
0
ファイル: Path.java プロジェクト: andreyvit/yoursway-swt
 /**
  * Sets the current point of the receiver to the point specified by (x, y). Note that this starts
  * a new sub path.
  *
  * @param x the x coordinate of the new end point
  * @param y the y coordinate of the new end point
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  *     </ul>
  */
 public void moveTo(float x, float y) {
   if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
   NSPoint pt = new NSPoint();
   pt.x = x;
   pt.y = y;
   handle.moveToPoint(pt);
 }
コード例 #2
0
ファイル: Path.java プロジェクト: andreyvit/yoursway-swt
 /**
  * Constructs a new empty Path.
  *
  * <p>This operation requires the operating system's advanced graphics subsystem which may not be
  * available on some platforms.
  *
  * @param device the device on which to allocate the path
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
  *     </ul>
  *
  * @exception SWTError
  *     <ul>
  *       <li>ERROR_NO_HANDLES if a handle for the path could not be obtained
  *     </ul>
  *
  * @see #dispose()
  */
 public Path(Device device) {
   super(device);
   handle = NSBezierPath.bezierPath();
   if (handle == null) SWT.error(SWT.ERROR_NO_HANDLES);
   handle.retain();
   handle.moveToPoint(new NSPoint());
   init();
 }
コード例 #3
0
ファイル: Path.java プロジェクト: andreyvit/yoursway-swt
 /**
  * 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();
 }