[MaxGUI] setgadgetfont working example? On canvas?

BlitzMax Forums/BlitzMax Beginners Area/[MaxGUI] setgadgetfont working example? On canvas?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Here's my understanding:

SetGadgetFont requires a GuiFont, except for the canvas (which is really a graphical item) which uses ImageFont. The ways to load these two are different: LoadImageFont wants the filename (where the file needs to be renamed to the Windows name of the font if it isn't already) while LoadGuiFont just wants the Windows font name without the ".ttf". LoadGuiFont only works if the font is loaded in Windows (i.e. shows up in Windows' font list), while LoadImageFont can load the .ttf whether it's loaded in Windows or not.

Copy Arial.ttf to the same folder as this example for LoadImageFont to work:

Strict

Local win:TGadget = CreateWindow( "", 0,0, 400,200 )
Local can:TGadget = CreateCanvas( 0,0, 400,80, win )
SetGraphics CanvasGraphics( can )
SetBlend ALPHABLEND

DrawText "This is default font", 10,10
Local iFont:TImageFont = LoadImageFont( "Arial.ttf", 24 )
SetImageFont iFont
DrawText "This should be Arial (and bigger)", 10,40
Flip

Local but1:TGadget = CreateButton( "default font", 10,90, 80,30, win )
Local but2:TGadget = CreateButton( "Arial", 110,90, 80,30, win )
Local gFont:TGuiFont = LoadGuiFont( "Arial", 24 )
SetGadgetFont but2, gFont

Repeat
	WaitEvent
Until EventID() = EVENT_WINDOWCLOSE





(Sorry, I haven't messed with Incbin.)