Platforms to show: All Mac Windows Linux Cross-Platform

Back to NSGraphicsMBS class.

NSGraphicsMBS.addClip(path as NSBezierPathMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 12.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Intersects the area enclosed by the receiver's path with the clipping path of the current graphics context and makes the resulting shape the current clipping path.

This method uses the current winding rule to determine the clipping shape of the receiver. This method does not affect the receiver's path.

NSGraphicsMBS.boundingRectWithSize(text as NSAttributedStringMBS, size as NSSizeMBS, options as Integer = 0) as NSRectMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 12.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Calculates and returns bounding rectangle for the receiver drawn using the options specified, within the given rectangle in the current graphics context.
Example
// create Hello World in red
Var a as NSAttributedStringMBS = NSAttributedStringMBS.attributedStringWithString("Hello World")
Var m as NSMutableAttributedStringMBS = a.mutableCopy

m.addAttribute(a.NSForegroundColorAttributeName, NSColorMBS.redColor, new NSRangeMBS(0, m.length))

// query size
Var g as new NSGraphicsMBS(Canvas1.NSViewMBS)
Var r as NSRectMBS = g.boundingRectWithSize(m, new NSSizeMBS(canvas1.Width, canvas1.Height), g.NSStringDrawingUsesLineFragmentOrigin)

MsgBox r.String

size: The size of the rectangle to draw in.
options: The string drawing options.

Returns the bounding rectangle in the current graphics context.
The origin of the rectangle returned from this method is the first glyph origin.

See also:

NSGraphicsMBS.boundingRectWithSize(text as string, size as NSSizeMBS, options as Integer = 0, DicAttributes as dictionary = nil) as NSRectMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Calculates and returns the bounding rect for the text drawn using the given options and display characteristics, within the specified rectangle in the current graphics context.
Example
Var NSGraphics as New NSGraphicsMBS()
Var size as NSSizeMBS = new NSSizeMBS(100,100)
Var text as string = "Hello World. How are you? I'm fine. This is just a test string."
Var options as Integer = NSGraphics.NSStringDrawingUsesLineFragmentOrigin
Var rect as NSRectMBS = NSGraphics.boundingRectWithSize(text, size, options)

MsgBox str(Rect.Width)+" "+str(Rect.Height)

text: the text to use for calculation.
size: The size of the rectangle to draw in.
options: String drawing options.
attributes: A dictionary of text attributes to be applied to the string. These are the same attributes that can be applied to an NSAttributedString object, but in the case of Strings, the attributes apply to the entire string, rather than ranges within the string.

Returns the bounding rect for the receiver drawn using the given options and display characteristics. The rect origin returned from this method is the first glyph origin.

Available in Mac OS X v10.4 and later.

See NSStringDrawing* constants. Use NSStringDrawingUsesLineFragmentOrigin to switch to multiline mode.

See also:

NSGraphicsMBS.eraseRect(x as Double, y as Double, w as Double, h as Double)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 7.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Erases a rectangle with the current color.

In the Cocoa world the y axis is reversed. y=0 is on the bottom.

NSGraphicsMBS.fill(path as NSBezierPathMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 12.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Paints the region enclosed by the receiver's path.
Example
Var n as new NSImageMBS(300, 300)
Var g as new NSGraphicsMBS(n)

g.setFillColor NSColorMBS.redColor

Var r as NSRectMBS = NSMakeRectMBS(50, 50, 100, 100)
Var b as NSBezierPathMBS = NSBezierPathMBS.bezierPathWithRect(r)
g.fill(b)

g = nil

window1.Backdrop = n.CopyPicture // black image with red color rect

This method fills the path using the current fill color and the receiver's current winding rule. If the path contains any open subpaths, this method implicitly closes them before painting the fill region.

The painted region includes the pixels right up to, but not including, the path line itself. For paths with large line widths, this can result in overlap between the fill region and the stroked path (which is itself centered on the path line).

NSGraphicsMBS.fillRect(r as NSRectMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 12.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Fills the specified rectangular path with the current fill color.
Example
Var n as new NSImageMBS(300, 300)
Var g as new NSGraphicsMBS(n)

g.setFillColor NSColorMBS.redColor

Var r as new NSRectMBS(10,10,200,200)
g.fillRect(r)

g = nil

window1.Backdrop = n.CopyPicture // black image with red color rectangle

r: A rectangle in the current coordinate system.

This method fills the specified region immediately. This method uses the compositing operation returned by the compositingOperation method of NSGraphicsContext.

See also:

NSGraphicsMBS.fillRect(x as Double, y as Double, w as Double, h as Double)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 7.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Fills a rectangle with the current color.

In the Cocoa world the y axis is reversed. y=0 is on the bottom.

See also:

NSGraphicsMBS.fillRect(x as Double, y as Double, w as Double, h as Double, operation as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Fills a rectangle using the current fill color and the specified compositing operation.

See NSComposite* constants.

See also:

NSGraphicsMBS.flushGraphics

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Forces any buffered operations or data to be sent to the receiver's destination.

Graphics contexts use buffers to queue pending operations but for efficiency reasons may not always empty those buffers immediately. This method forces the buffers to be emptied.

Some examples using this method:

NSGraphicsMBS.graphicsPort as Variant

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the low-level, platform-specific graphics context represented by the receiver.

In Mac OS X, this is the Core Graphics context, a CGContextMBS object.

NSGraphicsMBS.highlightRect(x as Double, y as Double, w as Double, h as Double)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 7.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Highlights the rectangle.

In the Cocoa world the y axis is reversed. y=0 is on the bottom.

NSGraphicsMBS.imageInterpolation as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
property Cocoa Drawing MBS MacCocoa Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
The interpolation behavior.

Note that this value is not part of the graphics state, so it cannot be reset using restoreGraphicsState.
(Read and Write computed property)

NSGraphicsMBS.invalidate

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Invalides the graphics object.

NSGraphicsMBS.isDrawingToScreen as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a Boolean value that indicates whether the drawing destination is the screen.

True if the drawing destination is the screen, otherwise false.

A return value of false may mean that the drawing destination is a printer, but the destination may also be a PDF or EPS file. If this method returns false, you can call attributes to see if additional information is available about the drawing destination.

NSGraphicsMBS.isFlipped as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a Boolean value that indicates the receiver's flipped state.

True if the receiver is flipped, otherwise false.

The state is determined by sending isFlipped to the receiver's view that has focus. If no view has focus, returns false unless the receiver is instantiated using graphicsContextWithGraphicsPort:flipped: specifying true as the flipped parameter.

Available in Mac OS X v10.4 and later.

NSGraphicsMBS.restoreGraphicsState

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Removes the receiver's graphics state from the top of the graphics state stack and makes the next graphics state the current graphics state.

This method must have been preceded with a saveGraphicsState message to add the graphics state to the stack. Invocations of saveGraphicsState and restoreGraphicsState methods may be nested.

Restoring the graphics state restores such attributes as the current drawing style, transformation matrix, color, and font of the original graphics state.

Some examples using this method:

NSGraphicsMBS.TranslateCoordinates(x as Double, y as Double)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 12.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Moves coordinate system so the next drawing commands will use different starting point.

Use saveGraphicsState and restoreGraphicsState so you can restore the old state.

Some examples using this method:

The items on this page are in the following plugins: MBS MacCocoa Plugin.


The biggest plugin in space...