func_maxgui_lookupguifont.rst 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. .. _func_maxgui_lookupguifont:
  2. =============
  3. LookupGuiFont
  4. =============
  5. LookupGuiFont -
  6. Description
  7. ===========
  8. .. code-block:: blitzmax
  9. LookupGuiFont:TGuiFont( pFontType% = GUIFONT_SYSTEM, pFontSize:Double = 0, pFontStyle% = 0 )
  10. Returns a suitable GUI font that best matches the type of font specified.
  11. If the current MaxGUI driver doesn't return a suitable GUI font, then
  12. a hard-coded fall-back font is returned instead, depending upon the platform:
  13. @pFontType can take one of the following constants:
  14. [ @Constant | @{Windows Fall-Back} | @{Mac OS X Fall-Back} | @{Linux Fall-Back} | @Description
  15. * GUIFONT_SYSTEM | MS Shell Dlg | Lucida Grande | FreeSerif | Default font used to draw gadgets by the OS.
  16. * GUIFONT_SERIF | Times New Roman | Times New Roman | FreeSerif | Serif font.
  17. * GUIFONT_SANSSERIF | Arial | Helvetica | FreeSans | Sans Serif font.
  18. * GUIFONT_SCRIPT | Comic Sans MS | Comic Sans MS | TSCu_Comic | Handwriting style font.
  19. * GUIFONT_MONOSPACED | Consolas/Courier New | Courier | Courier | Fixed width font typically used for coding.
  20. ]
  21. @pFontSize specifies the font size the font should be loaded with. If this value is less than or equal to 0, then
  22. the current MaxGUI driver chooses a suitable size, or a hard-coded alternative is used (usually 10/11/12pt).
  23. @pFontStyle specifies any addition font styles the font should be loaded with. A combination of any of the
  24. following flags can be used:
  25. [ @Constant | @{Font Style}
  26. * FONT_BOLD | Bold
  27. * FONT_ITALIC | Italic
  28. * FONT_UNDERLINE | Underlined
  29. * FONT_STRIKETHROUGH | StrikeThrough
  30. ]
  31. %{Note: FONT_STRIKETHROUGH isn't fully supported by all gadgets/platforms.}
  32. See Also: #RequestFont, #FontName, #FontSize and #FontStyle
  33. Parameters
  34. ==========
  35. Return Values
  36. =============
  37. A suitable new @TGuiFont instance matched with the parameters supplied.
  38. Examples
  39. ========
  40. .. code-block:: blitzmax
  41. ' lookupguifont.bmx
  42. Strict
  43. Import MaxGUI.Drivers
  44. AppTitle = "LookupGuiFont() Example"
  45. Const strSampleText$ = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nulla eget mauris quis dolor "+..
  46. "ullamcorper dapibus. Duis facilisis ullamcorper metus. Pellentesque eget enim. Vivamus auctor hendrerit turpis. " + ..
  47. "Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae
  48. Vivamus tincidunt leo quis urna."
  49. Const intWindowFlags% = WINDOW_TITLEBAR|WINDOW_RESIZABLE|WINDOW_STATUS|WINDOW_CLIENTCOORDS
  50. Global wndMain:TGadget = CreateWindow( AppTitle, 100, 100, 500, 300, Null, intWindowFlags )
  51. SetMinWindowSize( wndMain, ClientWidth(wndMain), ClientHeight(wndMain) )
  52. Global lstFontTypes:TGadget = CreateListBox(0,0,200,ClientHeight(wndMain),wndMain)
  53. SetGadgetLayout lstFontTypes,EDGE_ALIGNED,EDGE_CENTERED,EDGE_ALIGNED,EDGE_ALIGNED
  54. AddGadgetItem lstFontTypes, "GUIFONT_SYSTEM", GADGETITEM_DEFAULT, -1, "Default OS font.", LookupGuiFont(GUIFONT_SYSTEM)
  55. AddGadgetItem lstFontTypes, "GUIFONT_SERIF", 0, -1, "Serif font.", LookupGuiFont(GUIFONT_SERIF)
  56. AddGadgetItem lstFontTypes, "GUIFONT_SANSSERIF", 0, -1, "Sans serif font.", LookupGuiFont(GUIFONT_SANSSERIF)
  57. AddGadgetItem lstFontTypes, "GUIFONT_SCRIPT", 0, -1, "Script/handwriting font.", LookupGuiFont(GUIFONT_SCRIPT)
  58. AddGadgetItem lstFontTypes, "GUIFONT_MONOSPACED", 0, -1, "Fixed width/coding font.", LookupGuiFont(GUIFONT_MONOSPACED)
  59. Global txtPreview:TGadget = CreateTextArea(200,0,300,ClientHeight(wndMain),wndMain,TEXTAREA_WORDWRAP|TEXTAREA_READONLY)
  60. SetGadgetLayout txtPreview,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_ALIGNED
  61. SetTextAreaText( txtPreview, strSampleText )
  62. Global strFontString$
  63. ChooseFont( LookupGuiFont() )
  64. Repeat
  65. Select WaitEvent()
  66. Case EVENT_APPTERMINATE, EVENT_WINDOWCLOSE
  67. End
  68. Case EVENT_GADGETACTION, EVENT_GADGETSELECT
  69. Select EventSource()
  70. Case lstFontTypes
  71. If EventData() >= 0 Then
  72. ChooseFont( TGuiFont(GadgetItemExtra( lstFontTypes, EventData() )) )
  73. EndIf
  74. EndSelect
  75. EndSelect
  76. SetStatusText( wndMain, strFontString + "~t~t" + CurrentEvent.ToString() + " " )
  77. Forever
  78. Function ChooseFont( pFont:TGuiFont )
  79. SetGadgetFont( txtPreview, pFont )
  80. strFontString$ = FontName(pFont) + ", " + Int(FontSize(pFont)) + "pt"
  81. EndFunction
  82. See Also
  83. ========