GetGadgetFont(#PB_Default) for Mac Os

Share your advanced PureBasic knowledge/code with the community.
mestnyi
Addict
Addict
Posts: 999
Joined: Mon Nov 25, 2013 6:41 am

GetGadgetFont(#PB_Default) for Mac Os

Post by mestnyi »

Code: Select all

Macro PB(Function)
  Function
EndMacro

Macro GetGadgetFont(_gadget_)
  GetGadgetFont_(_gadget_)
EndMacro

Procedure.i GetGadgetFont_(Gadget.i)
  Protected FontID = PB(GetGadgetFont)(Gadget)
  
  If Gadget =- 1 And Not FontID
    Protected fs.CGFloat 
    CocoaMessage(@fs, 0, "NSFont systemFontSize") : fs - 1
    FontID = CocoaMessage(0, 0, "NSFont systemFontOfSize:@", @fs) 
  EndIf
  
  ProcedureReturn FontID
EndProcedure

If OpenWindow(0, 0, 0, 222, 130+40, "SetGadgetFont", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If LoadFont(0, "Arial", 16)
    SetGadgetFont(#PB_Default, FontID(0))   ; Set the loaded Arial 16 font as new standard
  EndIf
  ButtonGadget(0, 10, 10, 200, 30, "Button - Arial 16")
  
  SetGadgetFont(#PB_Default, #PB_Default)
  
  CanvasGadget(2, 10, 130, 200, 30 )
  
  text.s = "Button - Arial 6"
  FontID = GetGadgetFont(#PB_Default)
  Debug FontID
  
  If StartDrawing(CanvasOutput(2))
    If FontID
      DrawingFont(FontID)
    EndIf
    
    DrawingMode(#PB_2DDrawing_Transparent)
    DrawText((200-TextWidth(text))/2, (30-TextHeight(text))/2, text, 0)
    StopDrawing()
  EndIf
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: GetGadgetFont(#PB_Default) for Mac Os

Post by Olli »

Even if I have no Mac, I added your tip on the french forum.
Post Reply