Platforms to show: All Mac Windows Linux Cross-Platform

/MacControls/Toolbar/Toolbar with retina Icons


You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacControls/Toolbar/Toolbar with retina Icons

This example is the version from Fri, 22th Oct 2015.

Project "Toolbar with retina Icons.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control myToolbar Inherits Toolbar1
ControlInstance myToolbar Inherits Toolbar1
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control CheckBox1 Inherits CheckBox
ControlInstance CheckBox1 Inherits CheckBox
EventHandler Sub Action() dim v as Variant = myToolbar.Item(0) dim it as ToolButton = v it.enabled = me.Value // start timer to implement retina image // as xojo recreates the toolbar item SetImageTimer.Mode = 1 End EventHandler
End Control
Control SetImageTimer Inherits Timer
ControlInstance SetImageTimer Inherits Timer
EventHandler Sub Action() // now get toolbar item dim nt as NSToolbarMBS = self.NSToolbarMBS dim items() as NSToolbarItemMBS = nt.items dim ti as NSToolbarItemMBS = items(0) // assign new picture ti.image = RetinaIcon End EventHandler
End Control
EventHandler Sub Open() // Xojo icon dim v as Variant = myToolbar.Item(0) dim it as ToolButton = v it.Icon = NewPictureInColor(&cFF0000, 32, 32) // now via plugin // make two images, a green one for retina and a blue one for non retina dim gp as Picture = NewPictureInColor(&c00FF00, 64, 64) // double sized! dim bp as Picture = NewPictureInColor(&c0000FF, 32, 32) // convert to NSImage via plugin dim gn as new NSImageMBS(gp) dim bn as new NSImageMBS(bp) // look what representations we have and pick first one from blue picture dim representations() as NSImageRepMBS = bn.Representations dim representation as NSImageRepMBS = Representations(0) // now move the representation from blue to green 'bn.removeRepresentation representation gn.addRepresentation representation // green image has now two representations // set size to 32x32 which makes 64x64 representation the one for retina gn.setSize 32, 32 // now get toolbar item dim nt as NSToolbarMBS = self.NSToolbarMBS dim items() as NSToolbarItemMBS = nt.items dim ti as NSToolbarItemMBS = items(0) // assign new picture ti.image = gn RetinaIcon = gn End EventHandler
Function NewPictureInColor(c as color, w as integer, h as integer) As Picture dim p as new Picture(w, h) dim g as Graphics = p.Graphics g.ForeColor = c g.FillRect 0, 0, w, h Return p End Function
Property RetinaIcon As NSImageMBS
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
SetRetina
End SetRetina
Class Toolbar1 Inherits Toolbar
ToolbarItem ToolItem1
End Class
End Project

See also:

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


The biggest plugin in space...