Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCG/Icon with CGContext
Function:
Required plugins for this example: MBS MacCG Plugin, MBS Picture Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCG/Icon with CGContext
This example is the version from Fri, 30th May 2013.
Project "Icon with CGContext.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
EventHandler Sub Open() Backdrop = GetIcon(SpecialFolder.Desktop, 512, 512, true) End EventHandler
Function GetIcon(f as folderitem, w as integer, h as integer, WantAlphaPicture as Boolean = false) As picture const DrawNormal=0 const DrawNoImage=2 const DrawNoMask=4 const DrawSelected=&h8000 // get icon dim i as new iconmbs(f) if i.Valid then if TargetCocoa and WantAlphaPicture then // Cocoa only: Make Picture with alpha channel dim p as new Picture(w, h) dim c as CGBitmapContextMBS = CGBitmapContextMBS.CreateWithPicture(p) c.ClearRect CGMakeRectMBS(0,0,w,h) // draw icon i.DrawIconCGContext(c.Handle, 0,0,w,h,0,0,DrawNormal,&c000000) c.Flush Return p end if // Cocoa or Carbon: Make Picture with mask // make bitmap context dim c as new CGPictureContextMBS(w,h) c.ClearRect CGMakeRectMBS(0,0,w,h) // draw icon i.DrawIconCGContext(c.Handle, 0,0,w,h,0,0,DrawNormal,&c000000) c.Flush // and copy to picture Return c.CopyPictureWithMask end if End Function
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project

Feedback, Comments & Corrections

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




Links
MBS Xojo tutorial videos