Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS Picture Plugin, MBS MacCG Plugin, MBS MacCF 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 Tue, 21th Jan 2019.
Project "Icon with CGContext.xojo_binary_project"
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 pic as new Picture(w,h)
dim c as CGBitmapContextMBS = CGBitmapContextMBS.CreateWithPicture(pic)
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 pic
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
The items on this page are in the following plugins: MBS MacCG Plugin.