Platforms to show: All Mac Windows Linux Cross-Platform

Back to NSGraphicsMBS class.

NSGraphicsMBS.saveGraphicsState

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Saves the graphics state of the current graphics context.

This method pushes the context onto the per-thread stack.

Some examples using this method:

NSGraphicsMBS.ScaleCoordinates(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
Scales coordinate system so the next drawing commands will use different scaling.

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

Some examples using this method:

NSGraphicsMBS.set(transform as NSAffineTransformMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 15.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the current transform of the graphics environment.

NSGraphicsMBS.setClip(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
Replaces the clipping path of the current graphics context with the area inside the receiver's path.

You should avoid using this method as a way of adjusting the clipping path, as it may expand the clipping path beyond the bounds set by the enclosing view. If you do use this method, be sure to save the graphics state prior to modifying the clipping path and restore the graphics state when you are done.

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

Some examples using this method:

NSGraphicsMBS.setColor(c as NSColorMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 9.8 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the color of subsequent drawing to the color that the receiver represents.

NSGraphicsMBS.SetColorBW(white as Double, alpha as Double = 1.0)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 7.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the color to a BW color.

Values range is from 0.0 to 1.0.
Alpha 0.0 is invisible and alpha 1.0 is visible.

NSGraphicsMBS.SetColorCMYK(cyan as Double, magenta as Double, yellow as Double, black as Double, alpha as Double = 1.0)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 7.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the color to a CMYK color.

Values range is from 0.0 to 1.0.
Alpha 0.0 is invisible and alpha 1.0 is visible.

NSGraphicsMBS.SetColorHSV(hue as Double, saturation as Double, brightness as Double, alpha as Double = 1.0)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 7.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the color to an HSV color.

Values range is from 0.0 to 1.0.

NSGraphicsMBS.setCurrentContext

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 14.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets this context to be the current.

Some examples using this method:

NSGraphicsMBS.setFillColor(c as NSColorMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 9.8 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the fill color of subsequent drawing to the receiver's color.

NSGraphicsMBS.setStrokeColor(c as NSColorMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 9.8 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the stroke color of subsequent drawing to the receiver's color.

NSGraphicsMBS.SetTransform(NSAffineTransform as Variant)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 12.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the current transformation matrix to the receiver's transformation matrix.

Please use saveGraphicsState so you can restore the state before applying matrix for other drawings.

The current transformation is stored in the current graphics context and is applied to subsequent drawing operations. You should use this method sparingly because it removes the existing transformation matrix, which is an accumulation of transformation matrices for the screen, window, and any superviews. Instead use the concat method to add this transformation matrix to the current transformation matrix.

NSAffineTransform must be a NSAffineTransformMBS object.

NSGraphicsMBS.shouldAntialias as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
property Cocoa Drawing MBS MacCocoa Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Whether the receiver should use antialiasing.

This value is part of the graphics state and is restored by restoreGraphicsState.
(Read and Write computed property)

NSGraphicsMBS.sizeWithAttributes(text as string, DicAttributes as dictionary = nil) as NSSizeMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the bounding box size the text occupies when drawn with the given attributes.
Example
Var NSGraphics as New NSGraphicsMBS()
Var NSStringWidth as Double = NSGraphics.sizeWithAttributes("Hello World").Width

MsgBox("StringWidth from NSGraphicsMBS: " + Str(NSStringWidth))

Var REALGraphics as Graphics = window1.Graphics
Var REALStringWidth as Double = REALGraphics.StringWidth("Hello World")

MsgBox("StringWidth from REAL Graphics: " + Str(REALStringWidth))

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 box size the receiver occupies when drawn with attributes.

Some examples using this method:

NSGraphicsMBS.stroke(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
Draws a line along the receiver's path using the current stroke color and drawing attributes.
Example
Var n as new NSImageMBS(300, 300)
Var g as new NSGraphicsMBS(n)

g.setStrokeColor NSColorMBS.redColor

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

g = nil

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

The drawn line is centered on the path with its sides parallel to the path segment. This method uses the current drawing attributes associated with the receiver. If a particular attribute is not set for the receiver, this method uses the corresponding default attribute.

NSGraphicsMBS.strokeLine(point1 as NSPointMBS, point2 as NSPointMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 12.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Strokes a line between two points using the current stroke color and the default drawing attributes.
Example
Var n as new NSImageMBS(300, 300)
Var g as new NSGraphicsMBS(n)

g.setStrokeColor NSColorMBS.redColor

Var p1 as new NSPointMBS(10,10)
Var p2 as new NSPointMBS(50,50)
g.strokeLine(p1,p2)

g = nil

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

point1: The starting point of the line.
point2: The ending point of the line.

This method strokes the specified path immediately.

See also:

Some examples using this method:

NSGraphicsMBS.strokeLine(x1 as Double, y1 as Double, x2 as Double, y2 as Double)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacCocoa Plugin 12.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Strokes a line.

See also:

NSGraphicsMBS.strokeRect(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
Strokes the path of the specified rectangle using the current stroke color and the default drawing attributes.
Example
Var n as new NSImageMBS(300, 300)
Var g as new NSGraphicsMBS(n)

g.setStrokeColor NSColorMBS.redColor

Var r as NSRectMBS = NSMakeRectMBS(50, 50, 100, 100)
g.strokeRect(r)

g = nil

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

r: A rectangle in the current coordinate system.

The path is drawn beginning at the rectangle's origin and proceeding in a counterclockwise direction. This method strokes the specified path immediately.

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


The biggest plugin in space...