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
Var p As ptr = g.Handle(Graphics.HandleTypes.CGContextRef)
Var c As CGContextMBS = CGContextMBS.contextWithCGContext(p)
#Else
Var h As Integer = g.Handle(g.HandleTypeCGContextRef)
Var 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.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
Var pathPrinted as FolderItem=GetFolderItem("test.pdf")

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

'get default page format and print settings and attach it to the print settings
Var thePageFormat as CPMPageFormatMBS = NewCPMPageFormatMBS
Var 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
Var thePdfDocument as CGPDFDocumentMBS = pathPrinted.OpenAsCGPDFDocumentMBS

' limit page counts to the one we have
Var 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
Var PrintRect as CPMRectMBS =thePageFormat.AdjustedPageSize
Var CGRect as CGRectMBS =CGMakeRectMBS(PrintRect.left, PrintRect.top, PrintRect.Width, PrintRect.Height)
thePrintSession.BeginPage(thePageFormat, nil)
Var 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

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

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

Var 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

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

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

Var 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
Var pic as new Picture(500, 500)

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

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

// draw ellipse
Var 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
Var 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.

CGContextMBS.fillRoundedRect(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.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Fills a round rectangle.
Example
Var c as CGContextMBS

c=window1.CGContextMBS

// fill in red
c.SetRGBFillColor 1,0,0,1
c.fillRoundedRect 100,100,100,100,20,20

// draw in green
c.SetRGBStrokeColor 0,1,0,1
c.strokeRoundedRect 100,100,100,100,20,20

CGContextMBS.Flush

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Updates the screen to show the current content.

Like UpdateNow in the RB window class.

CGContextMBS.frameArc(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.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Draws an arc.
Example
Var c as CGContextMBS

c=window1.CGContextMBS

// fill in red
c.SetRGBFillColor 1,0,0,1
c.paintArc 100,100,100,100,50,90

// draw in green
c.SetRGBStrokeColor 0,1,0,1
c.frameArc 100,100,100,100,50,90

angles are in degree.

CGContextMBS.frameOval(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.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Draws an oval.
Example
Var c as CGContextMBS

c=window1.CGContextMBS

// fill in red
c.SetRGBFillColor 1,0,0,1
c.paintOval 100,100,100,100

// draw in green
c.SetRGBStrokeColor 0,1,0,1
c.frameOval 100,100,100,100

CGContextMBS.frameRect(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.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Draws the frame for the rectangle.
Example
Var c as CGContextMBS

c=window1.CGContextMBS

// fill in red
c.SetRGBFillColor 1,0,0,1
c.paintRect 100,100,100,100

// draw in green
c.SetRGBStrokeColor 0,1,0,1
c.frameRect 100,100,100,100

Some examples using this method:

CGContextMBS.GetClipBoundingBox as CGRectMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 11.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the bounding box of a clipping path.

Returns the bounding box of the clipping path, specified in user space.

The bounding box is the smallest rectangle completely enclosing all points in the clipping path, including control points for any Bezier curves in the path.

Available in Mac OS X v10.3 and later.

CGContextMBS.GetCTM as CGAffineTransformMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 4.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Return the current graphics state's transformation matrix.

Returns nil on any error.

CGContextMBS.GetPathBoundingBox as CGRectMBS

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

The bounding box is the smallest rectangle completely enclosing all points in the path, including control points for Bezier and quadratic curves.

CGContextMBS.GetPathCurrentPoint as CGPointMBS

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

CGContextMBS.GetTextPosition as CGPointMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 4.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Return the current user-space point at which text will be drawn to (x,y).

Returns nil on any problem.

Next items

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


The biggest plugin in space...