Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCG/CoreGraphics Bitmap
Required plugins for this example: MBS MacCG Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCG/CoreGraphics Bitmap
This example is the version from Thu, 16th Nov 2016.
Project "CoreGraphics Bitmap.rbp"
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class Window1 Inherits Window
EventHandler Sub Open() dim c as CGPictureContextMBS dim r as CGRectMBS dim p as Picture dim n,i,k,w as integer dim g as Graphics const size=500.0 r=CGMakeRectMBS(0,0,size,size) // Create the context c=new CGPictureContextMBS(size,size) if c.Handle=0 then // failed beep end if // First color background in white c.SetRGBFillColor 1.0,1.0,1.0,1.0 c.FillRect r c.SetRGBFillColor 0.0,0.0,0.0, 1.0 c.SelectFont "Times New Roman", 18.0, 1.0 c.ShowTextAtPoint "Hello World in Times New Roman",10,100 c.SetRGBFillColor 0.4, 0.7, 0.9, 1.0 c.SelectFont "Helvetica", 36.0, 1.0 c.SetTextDrawingMode 5 c.ShowTextAtPoint "revenge of the razorback frogs",0,r.height/2 c.SetRGBFillColor 0.4, 0.7, 0.9, 1.0 c.FillRect r c.SetLineWidth 2 DrawStarburst c,size // We've finished rendering the page c.Flush w=size/2 p = new Picture(size,w,32) // we don't need a larger mask p.Graphics.ForeColor=rgb(0,0,0) p.Graphics.fillrect 0,0,size,size k=0 n=255 g=p.Graphics for i=0 to 255 g.ForeColor=rgb(n,n,n) g.fillrect 0,k,w,1 n=n-1 k=k+1 next if c.SetMask(p) then end if Backdrop=MakePicture(c.CopyPicture,c.CopyPictureMask) End EventHandler
Sub DrawStarburst(c as cgcontextmbs, size as single) dim kFullCircleInRadians as single dim rotation as single kFullCircleInRadians = 3.14159265358979323846 * 2.0 // Draw 50 lines as a starburst c.SetLineWidth 2 rotation = 0.0 while rotation<kFullCircleInRadians // Start a new path c.BeginPath // Save the graphics state so we can start with a // fresh rotation each time c.SaveGState // // Translate the CTM to the center of the page, then // rotate the CTM by our current translation. Note // that order is important -- if you rotate the CTM // before the translation, the translation coordinates // will be rotated. In this example, we want to draw // in the center of the page, so we translate before // we rotate. // c.TranslateCTM size * 0.5, size * 0.5 c.RotateCTM rotation // // Draw a simple horizontal line // - First, set the current point to 0,0 // - Second, add the horizontal line // (We now have a path consisting of a horizontal line) // - Third, stroke the line to paint it onto the page // c.MoveToPoint 0.0, 0.0 c.AddLineToPoint size * 0.5, 0.0 c.StrokePath // Restore the graphics state c.RestoreGState rotation = rotation+ (kFullCircleInRadians/200.0) wend End Sub
Function MakePicture(p as picture,m as picture) As picture dim n as Picture if m=nil then Return p else n = new Picture(p.Width,p.Height,32) n.Graphics.DrawPicture p,0,0 n.Mask.Graphics.DrawPicture m,0,0 Return n end if End Function
End Class
Class App Inherits Application
End Class
End Project

See also:

Feedback, Comments & Corrections

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

MBS Xojo PDF Plugins