/** * Adds to the receiver a quadratic curve based on the parameters. * * @param cx the x coordinate of the control point of the spline * @param cy the y coordinate of the control point of the spline * @param x the x coordinate of the end point of the spline * @param y the y coordinate of the end point of the spline * @exception SWTException * <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed * </ul> */ public void quadTo(float cx, float cy, float x, float y) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); NSPoint pt = new NSPoint(); pt.x = x; pt.y = y; NSPoint ct = new NSPoint(); ct.x = cx; ct.y = cy; handle.curveToPoint(pt, ct, ct); }
/** * Adds to the receiver a cubic bezier curve based on the parameters. * * @param cx1 the x coordinate of the first control point of the spline * @param cy1 the y coordinate of the first control of the spline * @param cx2 the x coordinate of the second control of the spline * @param cy2 the y coordinate of the second control of the spline * @param x the x coordinate of the end point of the spline * @param y the y coordinate of the end point of the spline * @exception SWTException * <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed * </ul> */ public void cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); NSPoint pt = new NSPoint(); pt.x = x; pt.y = y; NSPoint ct1 = new NSPoint(); ct1.x = cx1; ct1.y = cy1; NSPoint ct2 = new NSPoint(); ct2.x = cx2; ct2.y = cy2; handle.curveToPoint(pt, ct1, ct2); }
/** * 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); }
/** * Returns <code>true</code> if the specified point is contained by the receiver and false * otherwise. * * <p>If outline is <code>true</code>, the point (x, y) checked for containment in the receiver's * outline. If outline is <code>false</code>, the point is checked to see if it is contained * within the bounds of the (closed) area covered by the receiver. * * @param x the x coordinate of the point to test for containment * @param y the y coordinate of the point to test for containment * @param gc the GC to use when testing for containment * @param outline controls whether to check the outline or contained area of the path * @return <code>true</code> if the path contains the point and <code>false</code> otherwise * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the gc is null * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed * </ul> * * @exception SWTException * <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed * </ul> */ public boolean contains(float x, float y, GC gc, boolean outline) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); // gc.checkGC(GC.LINE_CAP | GC.LINE_JOIN | GC.LINE_STYLE | GC.LINE_WIDTH); // TODO outline NSPoint point = new NSPoint(); point.x = x; point.y = y; return handle.containsPoint(point); }
void drawRectangles(NSWindow window, Rectangle[] rects, boolean erase) { NSGraphicsContext context = window.graphicsContext(); NSGraphicsContext.static_saveGraphicsState(); NSGraphicsContext.setCurrentContext(context); context.saveGraphicsState(); Point parentOrigin; if (parent != null) { parentOrigin = display.map(parent, null, 0, 0); } else { parentOrigin = new Point(0, 0); } context.setCompositingOperation(erase ? OS.NSCompositeClear : OS.NSCompositeSourceOver); NSRect rectFrame = new NSRect(); NSPoint globalPoint = new NSPoint(); double /*float*/ screenHeight = display.getPrimaryFrame().height; for (int i = 0; i < rects.length; i++) { Rectangle rect = rects[i]; rectFrame.x = rect.x + parentOrigin.x; rectFrame.y = screenHeight - (int) ((rect.y + parentOrigin.y) + rect.height); rectFrame.width = rect.width; rectFrame.height = rect.height; globalPoint.x = rectFrame.x; globalPoint.y = rectFrame.y; globalPoint = window.convertScreenToBase(globalPoint); rectFrame.x = globalPoint.x; rectFrame.y = globalPoint.y; if (erase) { rectFrame.width++; rectFrame.height++; NSBezierPath.fillRect(rectFrame); } else { rectFrame.x += 0.5f; rectFrame.y += 0.5f; NSBezierPath.strokeRect(rectFrame); } } if (!erase) context.flushGraphics(); context.restoreGraphicsState(); NSGraphicsContext.static_restoreGraphicsState(); }
/** * 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(); }