Blitz3D+ Command Reference

SetButtonIcon button,icon_strip,icon[,placement][,size]

Parameters

button - push, default or cancel button handle

icon_strip - icon strip handle from LoadIconStrip; 0 removes the button's icon

icon - index of the icon in the strip, counting from 0 at the left; -1 removes the button's icon

placement (optional) - where the icon goes:
0: before the text (default)
1: above the text

size (optional) - width and height of the icon in logical pixels, up to 256; 0 uses the strip's own icon size (default)

Description

Shows an icon from an icon strip on a push button.

Pictures make a button easier to find at a glance: a trash can on Delete, or a little cube on a button that adds a cube to your level. Put the icon before the text for an ordinary button, or above it for a tile in a palette of choices. A button with no text shows just its icon, centred - give it a tooltip with SetGadgetToolTip so its purpose is still clear.

The size is in logical pixels, like gadget positions, so the icon grows with the window on high-DPI monitors. The runtime resamples the icon to suit each monitor's scale, including when the window moves to another monitor. For icons that stay sharp at every scale, draw the strip larger than you show it - 128-pixel icons shown at size 32 look crisp up to four times normal scale. Strips with an alpha channel, such as transparent PNGs, keep their soft edges; other strips use their top-left colour as the transparent colour, as in LoadIconStrip.

The button takes its own copy of the icon, so you can FreeIconStrip once every button has its icon. A disabled button shows its icon greyed out. Icons work with every button appearance, including the native one. ButtonPreferredWidth and ButtonPreferredHeight include the icon; they do not resize the button, so apply them with SetGadgetShape:

strip=LoadIconStrip("shapes.png")
button=CreateButton("Cube",20,20,1,1,window)
SetButtonAppearance button,2
SetButtonIcon button,strip,0
SetGadgetShape button,20,20,ButtonPreferredWidth(button),ButtonPreferredHeight(button)

Check boxes and radio buttons cannot show icons. An icon index outside the strip, a placement other than 0 or 1, or a size outside 0 to 256 causes a runtime error.

The World Editor's Add object panel is a complete example: see scene_controls.bb and editor_style.bb.


See also: LoadIconStrip, SetButtonAppearance, SetButtonPadding, ButtonPreferredWidth, ButtonPreferredHeight, CreateButton.

Index