Platforms to show: All Mac Windows Linux Cross-Platform

Back to CGContextMBS class.

Previous items

CGContextMBS.IsPathEmpty as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns true if the context's path contains no elements.

CGContextMBS.MoveToPoint(x as Double, y as Double)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Append a straight line segment from the current point to (x, y).

CGContextMBS.paintArc(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
Fills 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.paintOval(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
Fills 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.paintRect(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
Fills 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

CGContextMBS.PathContainsPoint(point as CGPointMBS, mode as Integer) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Return true if point is contained in the current path of context.

A point is contained within a contexts path if it is inside the painted region when the path is stroked or filled with opaque colors using the path drawing mode mode. point is specified is user space.

Requires Mac OS X 10.4.

CGContextMBS.ReplacePathWithStrokedPath

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 8.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Replace the path in context with the stroked version of the path, using the parameters of context to calculate the stroked path.

The resulting path is created such that filling it with the appropriate color will produce the same results as stroking the original path. You can use this path in the same way you can use the path of any context; for example, you can clip to the stroked version of a path by calling this function followed by a call to "ClipPath".
Requires Mac OS X 10.4.

CGContextMBS.RotateCTM(angle as Double)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Rotate the current graphics state's transformation matrix (the CTM) by 'angle' radians.
Example
// Rotate a picture not on the edge of the context:

Var c as CGImageMBS
Var f as FolderItem
Var d as CGDataProviderMBS
Var cg as CGContextMBS
Var r as CGRectMBS

f=SpecialFolder.Desktop.Child("IMAG0001.JPG")

d=CGDataProviderMBS.CreateWithFile(f)
c=CGCreateImageFromJPEGDataProviderMBS(d,nil,true,0)

cg=window1.CGContextMBS

r=CGMakeRectMBS(-c.Width/2,-c.Height/2,c.Width,c.Height)
cg.TranslateCTM Width/2,Height/2
cg.RotateCTM Slider1.Value/180.0*3.14
cg.DrawPicture c,r

cg.Flush

Some examples using this method:

CGContextMBS.TextMatrix as CGAffineTransformMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
property CoreGraphics MBS MacCG Plugin 4.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Return the text matrix.

Returns nil on any error.
(Read and Write computed property)

CGContextMBS.TextPosition as CGPointMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
property CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
User-space point at which text will be drawn to (x,y).

(Read and Write computed property)

Some examples using this property:

CGContextMBS.TranslateCTM(tx as Double, ty as Double)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
Translate the current graphics state's transformation matrix (the CTM) by (tx,ty).
Example
// Rotate a PDF page

// our files
Var sourcefile as FolderItem = SpecialFolder.Desktop.Child("test.pdf")
Var destfile as FolderItem = SpecialFolder.Desktop.Child("rotated.pdf")

// open PDF
Var pdf as CGPDFDocumentMBS = sourcefile.OpenAsCGPDFDocumentMBS

// query media size of first page
Var r as CGRectMBS = pdf.MediaBox(1)

// create new PDF
Var c as CGContextMBS = destfile.NewCGPDFDocumentMBS(r,"title","Author","Creator")

// create rotated rectangle
Var nr as new CGRectMBS(0,0,r.Height,r.Width)

// create new page
c.BeginPage nr
c.SaveGState

const pi = 3.14159265

// rotate by 90°
c.RotateCTM pi*1.5

// fix origin
c.TranslateCTM -r.width,0

// draw PDF
c.DrawCGPDFDocument pdf,r,1

// cleanup
c.RestoreGState
c.EndPage

c = nil

// show in PDF viewer
destfile.Launch

Some examples using this method:

Previous items

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


The biggest plugin in space...