Platforms to show: All Mac Windows Linux Cross-Platform

Back to CGContextMBS class.

Next items

CGContextMBS.addArcToPath(x as Double, y as Double, w as Double, h as Double, startAngle as Integer, arcAngle as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 8.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Adds an arc to the current path.

CGContextMBS.AddEllipseInRect(r as CGRectMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Add an ellipse inside rect to the current path of context.

See the function CGPathMBS.AddEllipseInRect for more information on how the path for the ellipse is constructed.
Requires Mac OS X 10.4.

CGContextMBS.addOvalToPath(x as Double, y as Double, w as Double, h as Double)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 8.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Adds an oval to the current path.

CGContextMBS.AddPath(path as CGPathMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Add path to the path of context.

The points in path are transformed by the CTM of context before they are added.
Requires Mac OS X 10.2.

CGContextMBS.addRoundedRectToPath(x as Double, y as Double, w as Double, h as Double, arcWidth as Double, arcHeight as Double)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 8.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Adds a round rectangle to the current path.

CGContextMBS.BeginPage(mediabox as CGRectMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Begin a new page.

CGContextMBS.BeginPath

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Begin a new path. The old path is discarded.
Example
#If XojoVersion >= 2019.02 Then
Dim p As ptr = g.Handle(Graphics.HandleTypes.CGContextRef)
Dim c As CGContextMBS = CGContextMBS.contextWithCGContext(p)
#Else
Dim h As Integer = g.Handle(g.HandleTypeCGContextRef)
Dim c As CGContextMBS = CGContextMBS.contextWithCGContext(h)
#EndIf

c.SetGrayStrokeColor(0,1)
c.SetGrayFillColor(0,1)
c.BeginPath
c.SetLineWidth 0.5
c.MoveToPoint 50, 550
c.AddLineToPoint 100, 600
c.StrokePath
c.Flush
c = nil

Note that a context has a double path in use at any time: a path is not part of the graphics state.

Some examples using this method:

CGContextMBS.BeginTransparencyLayer(auxiliaryInfo as Dictionary = nil)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 12.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Begin a transparency layer in context.

All subsequent drawing operations until a corresponding EndTransparencyLayer are composited into a fully transparent backdrop (which is treated as a separate destination buffer from the context). After the transparency layer is ended, the result is composited into the context using the global alpha and shadow state of the context. This operation respects the clipping region of the context. After a call to this function, all of the parameters in the graphics state remain unchanged with the exception of the following:

- The global alpha is set to 1.
- The shadow is turned off.
- The blend mode is set to 'kCGBlendModeNormal'.

Ending the transparency layer restores these parameters to the values they had before BeginTransparencyLayer was called. Transparency layers may be nested.

CGContextMBS.BeginTransparencyLayerWithRect(r as CGRectMBS, auxiliaryInfo as Dictionary = nil)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 12.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Begin a transparency layer in context.

This function is identical to BeginTransparencyLayer except that the content of the transparency layer will be bounded by rect (specified in user space).

CGContextMBS.clearRect(rect as CGRectMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Clears the background.

Remeber that in CoreGraphics the position 0/0 is in the bottom left corner. In Xojo 0/0 is in the top left corner.

CGContextMBS.clip

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Clips the current path.

Intersect the context's path with the current clip path and use the resulting path as the clip path for subsequent rendering operations. Use the winding-number fill rule for deciding what's inside the path.

CGContextMBS.ClipToMask(rect as CGRectMBS, mask as CGImageMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 11.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Maps a mask into the specified rectangle and intersects it with the current clipping area of the graphics context.

rect: The rectangle to map the mask parameter to.
mask: An image or an image mask. If mask is an image, then it must be in the DeviceGray color space, may not have an alpha component, and may not be masked by an image mask or masking color.

If the mask parameter is an image mask, then Quartz clips in a manner identical to the behavior seen with the function DrawImage—the mask indicates an area to be left unchanged when drawing. The source samples of the image mask determine which points of the clipping area are changed, acting as an "inverse alpha" value. If the value of a source sample in the image mask is S, then the corresponding point in the current clipping area is multiplied by an alpha value of (1–S). For example, if S is 1 then the point in the clipping area becomes transparent. If S is 0, the point in the clipping area is unchanged.

If the mask parameter is an image, then mask acts like an alpha mask and is blended with the current clipping area. The source samples of mask determine which points of the clipping area are changed. If the value of the source sample in mask is S, then the corresponding point in the current clipping area is multiplied by an alpha of S. For example, if S is 0, then the point in the clipping area becomes transparent. If S is 1, the point in the clipping area is unchanged.

Available in Mac OS X v10.4 and later.

CGContextMBS.clipToRect(rect as CGRectMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Clips the current path.

Intersect the current clipping path with 'rect'. Note that this function resets the context's path to the empty path.

CGContextMBS.Close

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 15.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Closes the context.

Same as destructor later, but running now when you call method.

CGContextMBS.closePath

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Close the current subpath of the context's path.

CGContextMBS.ConcatCTM(transform as CGAffineTransformMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 4.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Concatenate the current graphics state's transformation matrix (the CTM) with the affine transform 'transform'.

CGContextMBS.Constructor(g as graphics)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 20.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a new CGContextMBS object drawing to the existing graphics object.
Example
Dim p As New Picture(200, 200)
Dim g As Graphics = p.Graphics

// Clear image with white
g.ForeColor = &cFFFFFF
g.FillRect 0, 0, g.Width, g.Height

Dim c As New CGContextMBS(g)

c.SetRGBFillColor(1, 0, 0)

// coordinates are swapped in CGContext, so y = 20 means 20 pixels from bottom of picture!

Const x = 10
Const y = 20
Const w = 120
Const h = 100

c.FillRect New CGRectMBS(x, y, w, h)

Self.Backdrop = p

Raises exception if we fail to get the CGContext from Xojo.
Works on macOS and iOS.

See also:

CGContextMBS.Constructor(handle as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 13.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a new CGContextMBS object based on a CGContextRef.

The CGContext is retained.

See also:

CGContextMBS.Constructor(pic as Picture)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 20.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a new CGContextMBS object drawing to the existing Picture object.
Example
Dim p As New Picture(100,100)
Dim pg As New CGContextMBS(p)
break // inspect in debugger

Raises exception, if the picture is not a bitmap picture.
Works on macOS and iOS.

See also:

CGContextMBS.CopyPath as CGPathMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 11.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a Quartz path object built from the current path information in a graphics context.

Available in Mac OS X v10.6 and later.

CGContextMBS.DrawCGPDFDocument(pdf as Variant, rect as CGRectMBS, page as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Draw 'page' in 'document' in the rectangular area specified by 'rect'.
Example
'get a print session

// print this PDF
dim pathPrinted as FolderItem=GetFolderItem("test.pdf")

dim thePrintSession as CPMPrintSessionMBS = NewCPMPrintSessionMBS
if thePrintSession = nil then Return

'get default page format and print settings and attach it to the print settings
dim thePageFormat as CPMPageFormatMBS = NewCPMPageFormatMBS
dim thePrintSettings as CPMPrintSettingsMBS = NewCPMPrintSettingsMBS
thePrintSession.DefaultPageFormat thePageFormat
thePrintSession.DefaultPrintSettings thePrintSettings

'show the print dialog
if not thePrintSession.PrintDialog(thePrintSettings,thePageFormat) then return

'open the file which will be printed
dim thePdfDocument as CGPDFDocumentMBS = pathPrinted.OpenAsCGPDFDocumentMBS

' limit page counts to the one we have
dim LastPage as Integer = thePdfDocument.PageCount
if thePrintSettings.LastPage<lastpage then
lastpage=thePrintSettings.LastPage
end if

' you get better progress bar if you tell how many pages will come
thePrintSettings.LastPage=lastpage

'begin the printing
thePrintSession.BeginDocument(thePrintSettings, thePageFormat)

'loop over the number of copies
for currentCopy as Integer = 1 to thePrintSettings.Copies

'loop over the pages
for currentPage as Integer = thePrintSettings.FirstPage to LastPage

'prepage the page
dim PrintRect as CPMRectMBS =thePageFormat.AdjustedPageSize
dim CGRect as CGRectMBS =CGMakeRectMBS(PrintRect.left, PrintRect.top, PrintRect.Width, PrintRect.Height)
thePrintSession.BeginPage(thePageFormat, nil)
dim thePrintContext as CGContextMBS = thePrintSession.PageContext
if thePrintContext = Nil then return

'print the page
thePrintContext.DrawCGPDFDocument thePdfDocument, CGRect, currentPage

'end the page
thePrintContext = nil
thePrintSession.EndPage
next

next

'end the printing
thePrintSession.EndDocument

Pass a CGPDFDocumentMBS object for the pdf argument.
The media box of the page is scaled, if necessary, to fit into 'rect'.

Some examples using this method:

CGContextMBS.DrawLayerAtPoint(Point as CGPointMBS, layer as CGLayerMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 12.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Draws the contents of a CGLayer object at the specified point.

context: The graphics context associated with the layer.
point: The location, in current user space coordinates, to use as the origin for the drawing.
layer: The layer whose contents you want to draw.

Calling the function DrawLayerAtPoint is equivalent to calling the function DrawLayerInRect with a rectangle that has its origin at point and its size equal to the size of the layer.

Available in Mac OS X version 10.4 and later.

CGContextMBS.DrawLayerInRect(rect as CGRectMBS, layer as CGLayerMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 12.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Draws the contents of a CGLayer object into the specified rectangle.

context: The graphics context associated with the layer.
rect: The rectangle, in current user space coordinates, to draw to.
layer: The layer whose contents you want to draw.

The contents are scaled, if necessary, to fit into the rectangle.
Available in Mac OS X version 10.4 and later.

CGContextMBS.DrawLinearGradient(gradient as CGGradientMBS, startPoint as CGPointMBS, endPoint as CGPointMBS, options as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 11.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Paints a gradient fill that varies along the line defined by the provided starting and ending points.

gradient: A CGGradient object.
startPoint: The coordinate that defines the starting point of the gradient.
endPoint: The coordinate that defines the ending point of the gradient.
options: Option flags (kCGGradientDrawsBeforeStartLocation or kCGGradientDrawsAfterEndLocation) that control whether the fill is extended beyond the starting or ending point.

The color at location 0 in the CGGradient object is mapped to the starting point. The color at location 1 in the CGGradient object is mapped to the ending point. Colors are linearly interpolated between these two points based on the location values of the gradient. The option flags control whether the gradient is drawn before the start point or after the end point.

Available in Mac OS X v10.5 and later.

Some examples using this method:

CGContextMBS.DrawPath(mode as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Draw the context's path using drawing mode 'mode'.

CGContextMBS.DrawPicture(pic as CGImageMBS, rect as CGRectMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Draws a CGImageMBS at the given position.
Example
// put inside window paint event

dim c as CGContextMBS
if TargetCocoa then
c = GetCurrentCGContextMBS
else
c = window1.CGContextMBS
end if

dim logo as Picture = logoMBS(500)
dim image as CGImageMBS = CGCreateImageMBS(logo)

dim r as CGRectMBS = CGMakeRectMBS(0,0,g.Width,g.Height)

c.DrawPicture image, r

Remeber that in CoreGraphics the position 0/0 is in the bottom left corner. In Xojo 0/0 is in the top left corner.

CGContextMBS.DrawRadialGradient(gradient as CGGradientMBS, startCenter as CGPointMBS, startRadius as Double, endCenter as CGPointMBS, endRadius as Double, options as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 11.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Paints a gradient fill that varies along the area defined by the provided starting and ending circles.

gradient: A CGGradient object.
startCenter: The coordinate that defines the center of the starting circle.
startRadius: The radius of the starting circle.
endCenter: The coordinate that defines the center of the ending circle.
endRadius: The radius of the ending circle.
options: Option flags (kCGGradientDrawsBeforeStartLocation or kCGGradientDrawsAfterEndLocation) that control whether the gradient is drawn before the starting circle or after the ending circle.

The color at location 0 in the CGGradient object is mapped to the circle defined by startCenter and startRadius. The color at location 1 in the CGGradient object is mapped to the circle defined by endCenter and endRadius. Colors are linearly interpolated between the starting and ending circles based on the location values of the gradient. The option flags control whether the gradient is drawn before the start point or after the end point.

Available in Mac OS X v10.5 and later.

Some examples using this method:

CGContextMBS.DrawShading(shading as CGShadingMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 6.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Fills the clipping path of a context with the specified shading.

shading: A Quartz shading. Quartz retains this object; upon return, you may safely release it.
Available in Mac OS X version 10.2 and later.

CGContextMBS.DrawTiledImage(pic as CGImageMBS, rect as CGRectMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 11.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Repeatedly draws an image, scaled to the provided rectangle, to fill the current clip region.
Example
// put inside window paint event

dim c as CGContextMBS
if TargetCocoa then
c = GetCurrentCGContextMBS
else
c = window1.CGContextMBS
end if

dim logo as Picture = logoMBS(50)
dim image as CGImageMBS = CGCreateImageMBS(logo)

dim r as CGRectMBS = CGMakeRectMBS(0,0,50,50)

c.DrawTiledImage image, r

rect: A rectangle that specifies the origin and size of the destination tile. Quartz scales the image—disproportionately, if necessary—to fit the bounds specified by the rect parameter.

image: The image to draw.

Quartz draws the scaled image starting at the origin of the rectangle in user space, then moves to a new point (horizontally by the width of the tile and/or vertically by the height of the tile), draws the scaled image, moves again, draws again, and so on, until the current clip region is tiled with copies of the image. Unlike patterns, the image is tiled in user space, so transformations applied to the CTM affect the final result.

Available in Mac OS X v10.5 and later.

CGContextMBS.EndPage

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
End the current page.

CGContextMBS.EndTransparencyLayer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 11.1 ✅ Yes ❌ No ❌ No ✅ Yes All
End a tranparency layer.

CGContextMBS.EOClip

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Clips the current path.

Intersect the context's path with the current clip path and use the resulting path as the clip path for subsequent rendering operations. Use the even-odd fill rule for deciding what's inside the path.

Some examples using this method:

CGContextMBS.EOFillPath

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Fill the context's path using the even-odd fill rule. Any open subpath of the path is implicitly closed.

Some examples using this method:

CGContextMBS.FillEllipseInRect(rect as CGRectMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Fill an ellipse (an oval) inside rect.
Example
// a new picture in RB
dim pic as new Picture(500, 500)

// and create CGBitmapContextMBS pointing to it
dim b as CGBitmapContextMBS = CGBitmapContextMBS.CreateWithPicture(pic)

// color set to full red
b.SetRGBFillColor 1.0, 0.0, 0.0, 1.0

// draw ellipse
dim r as CGRectMBS = CGRectMBS.Make(0, 0, 500, 500)
b.FillEllipseInRect r

// flush drawings
b.Flush

// and show
Backdrop = pic

Requires Mac OS X 10.4.

Some examples using this method:

CGContextMBS.FillPath

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Fill the context's path using the winding-number fill rule. Any open subpath of the path is implicitly closed.

CGContextMBS.FillRect(rect as CGRectMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Fills the background with current fill color.
Example
// put in window.paint event
dim c as CGContextMBS

c=window1.CGContextMBS

c.RotateCTM 0.1
c.SetRGBFillColor 0,0,1,0.5
c.FillRect CGMakeRectMBS(0,0,100,100)

c.Flush

Remeber that in CoreGraphics the position 0/0 is in the bottom left corner. In Xojo 0/0 is in the top left corner.

Next items

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


The biggest plugin in space...