SetGadgetFont

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by julianbury.

Hello, Brains Trust :wink:
I cannot seem to make the font work.
Can you see where I am going astray?
The crunchpoint is at line 52 ...

Code: Select all

;==========
; BIG Calc
;==========

#Window_Main=0
#TimesFont  =1
#Up         =100
#Down       =101
#Escape     =257
#Tab        =13100

maxg        =48 ;0 to 48 gadget IDs
maxx        =2  ;0 to  2 columns
maxy        =15 ;0 to 15 rows

Dim pos(maxx+1,maxy+1)

If OpenWindow(#Window_Main,165,0,800,25*17,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"BIG Calc")
  If CreateGadgetList(WindowID())
    FontID.l = LoadFont(#TimesFont, "Times New Roman", 12,#PB_Font_Bold | #PB_Font_HighQuality)
    id=0
    For y=0 To maxy
      xpos=1
      ypos=y*25
      StringGadget(id,xpos,ypos,100,24,"id="+Str(id)+":  name")
      pos(0,y)=GadgetID(id)
      id+1

      xpos=101
      ypos=y*25
      StringGadget(id,xpos,ypos,200,24,"id="+Str(id)+":  result")
      pos(1,y)=GadgetID(id)
      id+1

      xpos=302
      ypos=y*25
      StringGadget(id,xpos,ypos,497,24,"id="+Str(id)+":  calculation")
      pos(2,y)=GadgetID(id)
      id+1
    Next
    xpos=1
    ypos=25*16+4
    TextGadget(id,xpos,ypos,797,24,"id="+Str(id)+":  Displaying the calculation here as formatted For the parser, for input error detection",#PB_Text_Center)
    pos(0,y)=GadgetID(id)
    AddKeyboardShortcut(#Window_Main,#PB_Shortcut_Up,#Up)
    AddKeyboardShortcut(#Window_Main,#PB_Shortcut_Down,#Down)
    AddKeyboardShortcut(#Window_Main,#PB_Shortcut_Tab,#Tab)
    AddKeyboardShortcut(#Window_Main,#PB_Shortcut_Escape,#Escape)
  EndIf

  For id=0 To maxg
    SetGadgetFont(id,#TimesFont)
  Next

  xpos=2
  ypos=0
EndIf


ActivateGadget(2)

Repeat
  EventID=WaitWindowEvent()
  SetGadgetText(48,Str(EventID))

  ;discover the string with the focus 
  If EventID=#PB_Event_Menu
    For x=0 To maxx
      For y=0 To maxy
        If GetFocus_()=pos(x,y)
          xpos=x
          ypos=y
        EndIf
      Next
    Next

    ;I would never have thought to lookup "MenuID"!
    em=EventMenuID()
    Select em
      Case #Up
        ypos-1
        If yposmaxy:ypos=0:EndIf
      Case #Tab
        xpos+1
        If xpos>maxx:xpos=0:EndIf
      Case #Escape
        End
    EndSelect
    SetFocus_(pos(xpos,ypos))
  EndIf
Until EventID=#PB_Event_CloseWindow

End

Julian ^00^
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.

Use either FontID() or the variable FontID instead of #TimesFont in the SetGadgetFont() command.. When all the gadgets use the same font or if most of them use the same font it might be a good thing to use the SetGadgetFont() command with the #PB_Default constant, in that case use the command before you create the gadgets.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by julianbury.

Thank you. Thats done it. The crucial bit now reads ...

Code: Select all

  FontID.l = LoadFont(#TimesFont, "Times New Roman", 12)
  For id=0 To maxg
    SetGadgetFont(id,FontID.l)
  Next
The final small problem (before the BIG bad parser problem)
is to get StringGadget background color changes working,
so I can do focus highlighting. Can you suggest any way to do that?

Incidently, I compiled the project just now
and it works fine and is only 11.5 kilobytes!
That is astoundingly small. I am really impressed! BIG time :D


Julian ^00^
Post Reply