Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

Next items

NSGraphicsMBS.addClip(path as NSBezierPathMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 12.5 Yes No No Yes, macOS only No
Function: 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.
Notes: This method uses the current winding rule to determine the clipping shape of the receiver. This method does not affect the receiver's path.

Feedback, Comments & Corrections

NSGraphicsMBS.boundingRectWithSize(text as NSAttributedStringMBS, size as NSSizeMBS, options as Integer = 0) as NSRectMBS
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 12.4 Yes No No Yes, macOS only No
Function: 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
dim a as NSAttributedStringMBS = NSAttributedStringMBS.attributedStringWithString("Hello World")
dim m as NSMutableAttributedStringMBS = a.mutableCopy

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

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

MsgBox r.String
Notes:
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:

Feedback, Comments & Corrections

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 Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 11.3 Yes No No Yes, macOS only No
Function: 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:
Dim NSGraphics as New NSGraphicsMBS()
dim size as NSSizeMBS = new NSSizeMBS(100,100)
dim text as string = "Hello World. How are you? I'm fine. This is just a test string."
dim options as Integer = NSGraphics.NSStringDrawingUsesLineFragmentOrigin
Dim rect as NSRectMBS = NSGraphics.boundingRectWithSize(text, size, options)

MsgBox str(Rect.Width)+" "+str(Rect.Height)
Notes:
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:

Feedback, Comments & Corrections

NSGraphicsMBS.clipRect(r as NSRectMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 12.5 Yes No No Yes, macOS only No
Function: Intersects the specified rectangle with the clipping path of the current graphics context and makes the resulting shape the current clipping path
Notes: r: The rectangle to intersect with the current clipping path.

Feedback, Comments & Corrections

NSGraphicsMBS.concat(transform as NSAffineTransformMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 15.1 Yes No No Yes, macOS only No
Function: Concats this transform to the current transform of the graphics environment.

Feedback, Comments & Corrections

NSGraphicsMBS.ConcatTransform(NSAffineTransform as Variant)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 12.2 Yes No No Yes, macOS only No
Function: Appends the receiver's matrix to the current transformation matrix stored in the current graphics context, replacing the current transformation matrix with the result.
Notes:
Please use saveGraphicsState so you can restore the state before applying matrix for other drawings.

Concatenation is performed by matrix multiplication.

If this method is invoked from within an NSView drawRect method, then the current transformation matrix is an accumulation of the screen, window, and any superview's transformation matrices. Invoking this method defines a new user coordinate system whose coordinates are mapped into the former coordinate system according to the receiver's transformation matrix. To undo the concatenation, you must invert the receiver's matrix and invoke this method again.

NSAffineTransform must be a NSAffineTransformMBS object.

Feedback, Comments & Corrections

NSGraphicsMBS.Constructor
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 10.3 Yes No No Yes, macOS only No
Function: Initializes the current graphics context of the current thread.

See also:

Feedback, Comments & Corrections

NSGraphicsMBS.Constructor(targetImage as NSBitmapImageRepMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 12.3 Yes No No Yes, macOS only No
Function: Creates a new graphics context for drawing into a bitmap image representation.
Example:
dim n as new NSImageMBS(300,300)
dim r as new NSBitmapImageRepMBS(300, 300, 8, 4, true, NSColorSpaceMBS.NSCalibratedRGBColorSpace, 4*300, 32)

dim g as new NSGraphicsMBS(r)
g.SetColorRGB 1.0,0,0,0.5
g.fillRect 0, 0, 100, 100
g = nil // flush
n.addRepresentation r

Backdrop = n.CopyPictureWithMask
Notes:
Please make sure the graphics object is destroyed (Set to nil) so the drawings flush to the image.
Returns nil on any error.

See also:

Feedback, Comments & Corrections

NSGraphicsMBS.Constructor(targetImage as NSImageMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 12.3 Yes No No Yes, macOS only No
Function: Creates a new graphics context for drawing into an image.
Example:
// make new image
dim myImage as new NSImageMBS(500,500)
dim myGraphics as new NSGraphicsMBS(myImage)

// make logo image
dim myPicture as Picture = LogoMBS(500)
dim anotherImage as new NSImageMBS(myPicture)

// draw logo image to new image
myGraphics.drawInRect(anotherImage, 0, 0, myImage.width, myImage.height, 0, 0, anotherImage.width, anotherImage.height, myGraphics.NSCompositeSourceOver, 1.0)
myGraphics = nil // flush drawing

// save to file
dim f as FolderItem = SpecialFolder.Desktop.Child("test.jpg")
dim b as BinaryStream = BinaryStream.Create(f, True)
if b<>nil then
b.Write myImage.JPEGRepresentation
b.Close
end if
Notes: Please make sure the graphics object is destroyed (Set to nil) so the drawings flush to the image.

See also:

Feedback, Comments & Corrections

NSGraphicsMBS.Constructor(targetView as NSViewMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 11.3 Yes No No Yes, macOS only No
Function: Creates a new graphics context for drawing into a Cocoa view.
Notes: Please make sure the graphics object is destroyed (Set to nil) so the drawings flush to the window.

See also:

Feedback, Comments & Corrections

NSGraphicsMBS.Constructor(targetWindow as NSWindowMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 10.3 Yes No No Yes, macOS only No
Function: Creates a new graphics context for drawing into a window.

See also:

Feedback, Comments & Corrections

NSGraphicsMBS.Constructor(targetWindow as window)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 10.3 Yes No No No No
Function: Creates a new graphics context for drawing into a window.

See also:

Feedback, Comments & Corrections

NSGraphicsMBS.drawAtPoint(image as NSImageMBS, x as Double, y as Double, sx as Double, sy as Double, sw as Double, sh as Double, Operation as Integer, fraction as Double)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 7.7 Yes No No Yes, macOS only No
Function: Draws all or part of the image at the specified point in the current coordinate system.
Notes:
x/y: The location in the current coordinate system at which to draw the image.
sx/sy/sw/sh: The source rectangle specifying the portion of the image you want to draw. The coordinates of this rectangle are specified in the image's own coordinate system. If you pass in zeros, the entire image is drawn.
operation: The compositing operation to use when drawing the image. See the NSCompositingOperation constants.
fraction: The opacity of the image, specified as a value from 0.0 to 1.0. Specifying a value of 0.0 draws the image as fully transparent while a value of 1.0 draws the image as fully opaque. Values greater than 1.0 are interpreted as 1.0.

The image content is drawn at its current resolution and is not scaled unless the CTM of the current coordinate system itself contains a scaling factor. The image is otherwise positioned and oriented using the current coordinate system.

For Operation you use the Composite constants in this class.
In the Cocoa world the y axis is reversed. y=0 is on the bottom.

See also:

Feedback, Comments & Corrections

NSGraphicsMBS.drawAtPoint(text as NSAttributedStringMBS, point as NSPointMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 12.4 Yes No No Yes, macOS only No
Function: Draws the receiver with its font and other display attributes at the given point in the currently focused view.
Example:
// create Hello World in red
dim a as NSAttributedStringMBS = NSAttributedStringMBS.attributedStringWithString("Hello World")
dim m as NSMutableAttributedStringMBS = a.mutableCopy

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

// put it in a textarea
TextArea1.NSTextViewMBS.textStorage.setAttributedString m

// draw in Canvas
dim g as new NSGraphicsMBS(Canvas1.NSViewMBS)

g.drawAtPoint m, new NSPointMBS(20,20)
Notes:
point: The point in the current view to draw the text.

The width (height for vertical layout) of the rendering area is unlimited, unlike drawInRect, which uses a bounding rectangle. As a result, this method renders the text in a single line.

Don't invoke this method when no NSView is focused.

See also:

Feedback, Comments & Corrections

NSGraphicsMBS.drawAtPoint(text as string, point as NSPointMBS, DicAttributes as dictionary = nil)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 11.3 Yes No No Yes, macOS only No
Function: Draws the text with the font and other display characteristics of the given attributes, at the specified point in the currently focused view.
Notes:
Point: The origin for the bounding box for drawing the string. If the focused view is flipped, the origin is the upper-left corner of the drawing bounding box; otherwise, the origin is the lower-left corner.
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.

The width (height for vertical layout) of the rendering area is unlimited, unlike drawInRect, which uses a bounding rectangle. As a result, this method renders the text in a single line.

You should only invoke this method when an NSView object has focus.

See also:

Feedback, Comments & Corrections

NSGraphicsMBS.drawInRect(image as NSImageMBS, x as Double, y as Double, w as Double, h as Double, sx as Double, sy as Double, sw as Double, sh as Double, Operation as Integer, fraction as Double)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 7.7 Yes No No Yes, macOS only No
Function: draws the image into the given rectangle with the given source rectangle and the given mode.
Example:
// make new image
dim myImage as new NSImageMBS(500,500)
dim myGraphics as new NSGraphicsMBS(myImage)

// make logo image
dim myPicture as Picture = LogoMBS(500)
dim anotherImage as new NSImageMBS(myPicture)

// draw logo image to new image
myGraphics.drawInRect(anotherImage, 0, 0, myImage.width, myImage.height, 0, 0, anotherImage.width, anotherImage.height, myGraphics.NSCompositeSourceOver, 1.0)
myGraphics = nil // flush

// save to file
dim f as FolderItem = SpecialFolder.Desktop.Child("test.jpg")
dim b as BinaryStream = BinaryStream.Create(f, True)
if b<>nil then
b.Write myImage.JPEGRepresentation
b.Close
end if
Notes:
For Operation you use the Composite constants in this class.
In the Cocoa world the y axis is reversed. y=0 is on the bottom.

See also:

Feedback, Comments & Corrections

NSGraphicsMBS.drawInRect(text as NSAttributedStringMBS, rect as NSRectMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 12.4 Yes No No Yes, macOS only No
Function: Draws the attributed string within the given rectangle in the currently view, clipping the text layout to this rectangle.
Example:
// create Hello World in red
dim a as NSAttributedStringMBS = NSAttributedStringMBS.attributedStringWithString("Hello World")
dim m as NSMutableAttributedStringMBS = a.mutableCopy

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

// put it in a textarea
TextArea1.NSTextViewMBS.textStorage.setAttributedString m

// draw in Canvas
dim g as new NSGraphicsMBS(Canvas1.NSViewMBS)

g.drawInRect m, new NSRectMBS(20,20, 100, 100)
Notes:
rect: The rectangle in which to draw.

Text is drawn within rect according to its line sweep direction; for example, Arabic text will begin at the right edge and potentially be clipped on the left.

The rect parameter determines how many glyphs are typeset within the width of a line, but it's possible for a portion of a glyph to appear outside the area of rect if the image bounding box of the particular glyph exceeds its typographic bounding box.

If the focus view is flipped, the text origin is set at the upper-left corner of the drawing bounding box; otherwise the origin is set at the lower-left corner. For text rendering, whether the view coordinates are flipped or not doesn't affect the flow of line layout, which goes from top to bottom. However, it affects the interpretation of the text origin. So, for example, if the rect argument is {0.0, 0.0, 100.0, 100.0}, the text origin is {0.0, 0.0} when the view coordinates are flipped and {0.0, 100.0} when not.

Don't invoke this method when no NSView is focused.

See also:

Feedback, Comments & Corrections

NSGraphicsMBS.drawInRect(text as string, rect as NSRectMBS, DicAttributes as dictionary = nil)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 11.3 Yes No No Yes, macOS only No
Function: Draws the text with the font and other display characteristics of the given attributes, within the specified rectangle in the currently focused NSView.
Notes:
text: The text to draw.
Rect: The rectangle in which to draw the string.
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.

The rendering area is bounded by rect, unlike drawAtPoint, which has an unlimited width. As a result, this method renders the text in multiple lines.

You should only invoke this method when an NSView has focus.

See also:

Feedback, Comments & Corrections

NSGraphicsMBS.drawPicture(image as Picture, x as Double, y as Double, w as Double, h as Double, sx as Double, sy as Double, sw as Double, sh as Double, Operation as Integer, fraction as Double)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 17.1 Yes No No No No
Function: Draws a picture.
Notes: Same as drawInRect with NSImageMBS, but using picture.

Feedback, Comments & Corrections

NSGraphicsMBS.drawRect(x as Double, y as Double, w as Double, h as Double)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 7.7 Yes No No Yes, macOS only No
Function: Draws a rectangle with the current color.
Notes: In the Cocoa world the y axis is reversed. y=0 is on the bottom.

Feedback, Comments & Corrections

NSGraphicsMBS.DrawWindowBackground(x as Double, y as Double, w as Double, h as Double)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 11.3 Yes No No Yes, macOS only No
Function: Draws the window's default background pattern into the specified rectangle of the currently focused view.
Notes: Pass the rectangle (in the current coordinate system) in which to draw the window's background pattern.

Feedback, Comments & Corrections

NSGraphicsMBS.drawWithRect(text as NSAttributedStringMBS, rect as NSRectMBS, options as Integer)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 12.4 Yes No No Yes, macOS only No
Function: Draws the receiver with the specified options, within the given rectangle in the current graphics context.
Example:
// create Hello World in red
dim a as NSAttributedStringMBS = NSAttributedStringMBS.attributedStringWithString("Hello World")
dim m as NSMutableAttributedStringMBS = a.mutableCopy

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

// put it in a textarea
TextArea1.NSTextViewMBS.textStorage.setAttributedString m

// draw in Canvas
dim g as new NSGraphicsMBS(Canvas1.NSViewMBS)

g.drawWithRect m, new NSRectMBS(20,20, 100, 100), g.NSStringDrawingUsesLineFragmentOrigin
Notes:
rect: The rectangle specifies the rendering origin in the current graphics context.
options: The string drawing options. See NSStringDrawingOptions for the available options..

The rect argument's origin field specifies the rendering origin. The point is interpreted as the baseline origin by default. With NSStringDrawingUsesLineFragmentOrigin, it is interpreted as the upper left corner of the line fragment rect. The size field specifies the text container size. The width part of the size field specifies the maximum line fragment width if larger than 0.0. The height defines the maximum size that can be occupied with text if larger than 0.0 and NSStringDrawingUsesLineFragmentOrigin is specified. If NSStringDrawingUsesLineFragmentOrigin is not specified, height is ignored and considered to be single-line rendering (NSLineBreakByWordWrapping and NSLineBreakByCharWrapping are treated as NSLineBreakByClipping).

You should only invoke this method when there is a current graphics context.
Available in OS X v10.4 and later.

Feedback, Comments & Corrections

NSGraphicsMBS.eraseRect(x as Double, y as Double, w as Double, h as Double)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 7.7 Yes No No Yes, macOS only No
Function: Erases a rectangle with the current color.
Notes: In the Cocoa world the y axis is reversed. y=0 is on the bottom.

Feedback, Comments & Corrections

NSGraphicsMBS.fill(path as NSBezierPathMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 12.5 Yes No No Yes, macOS only No
Function: Paints the region enclosed by the receiver's path.
Example:
dim n as new NSImageMBS(300, 300)
dim g as new NSGraphicsMBS(n)

g.setFillColor NSColorMBS.redColor

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

g = nil

window1.Backdrop = n.CopyPicture // black image with red color rect
Notes:
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).

Feedback, Comments & Corrections

NSGraphicsMBS.fillRect(r as NSRectMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 12.5 Yes No No Yes, macOS only No
Function: Fills the specified rectangular path with the current fill color.
Example:
dim n as new NSImageMBS(300, 300)
dim g as new NSGraphicsMBS(n)

g.setFillColor NSColorMBS.redColor

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

g = nil

window1.Backdrop = n.CopyPicture // black image with red color rectangle
Notes:
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:

Feedback, Comments & Corrections

NSGraphicsMBS.fillRect(x as Double, y as Double, w as Double, h as Double)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 7.7 Yes No No Yes, macOS only No
Function: Fills a rectangle with the current color.
Notes: In the Cocoa world the y axis is reversed. y=0 is on the bottom.

See also:

Feedback, Comments & Corrections

NSGraphicsMBS.fillRect(x as Double, y as Double, w as Double, h as Double, operation as Integer)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 11.3 Yes No No Yes, macOS only No
Function: Fills a rectangle using the current fill color and the specified compositing operation.
Notes: See NSComposite* constants.

See also:

Feedback, Comments & Corrections

NSGraphicsMBS.flushGraphics
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 10.3 Yes No No Yes, macOS only No
Function: Forces any buffered operations or data to be sent to the receiver's destination.
Notes: 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.

Feedback, Comments & Corrections

NSGraphicsMBS.graphicsPort as Variant
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacCocoa Plugin 10.3 Yes No No Yes, macOS only No
Function: Returns the low-level, platform-specific graphics context represented by the receiver.
Notes: In Mac OS X, this is the Core Graphics context, a CGContextMBS object.

Feedback, Comments & Corrections

Next items

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




Links
MBS Xojo Plugins