Seite 1 von 1

FontID()-Beispiel aus PB-Hilfe

Verfasst: 08.01.2007 22:00
von marco2007
Hi,

folgendes Problem habe ich:

1. Wozu das UsedFont im PB-Beispiel?

Code: Alles auswählen

  If OpenWindow(0, 0, 0, 222, 130, "FontID()", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
    ButtonGadget(0, 10, 10, 200, 30, "Anklicken zum Ändern des Fonts...")
    Font1 = LoadFont(#PB_Any, "Arial"  ,  8, #PB_Font_Bold) 
    Font2 = LoadFont(#PB_Any, "Verdana", 12, #PB_Font_StrikeOut) 
    UsedFont = 1
  EndIf 
  
  Repeat 
    Event = WaitWindowEvent()
  
    If Event = #PB_Event_Gadget
      If EventGadget() = 0
        If UsedFont = 1 
          SetGadgetFont(0, FontID(Font2)) 
          UsedFont = 2
        Else
          SetGadgetFont(0, FontID(Font1)) 
          UsedFont = 1
        EndIf
      EndIf
    EndIf
  Until Event = #PB_Event_CloseWindow  
2.
kurz:
If UsedFont=2
usedFont=1
endif


Danke
Marco

Verfasst: 08.01.2007 22:04
von a14xerus
um den benutzen font zu switchen.
Wie du erkennst, sind da 2 fonts geladen
Um das benutzen mehrere Fonts zu demonstrieren wird hier zwischen den 2 fonts gewechselt.
Dabei wird die Variable als "hilfe" benutzt.
Mit dem font selber hat das nichts zu tun

Verfasst: 08.01.2007 22:58
von marco2007
Danke

Die usedFont-Strategie (Status setzen) ist irgendwie interessant.
Mein Code hat aber keine Nachteile, oder?

Code: Alles auswählen

  Enumeration
  #gad
  EndEnumeration
   
  If OpenWindow(0, 0, 0, 222, 130, "FontID()", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
    ButtonGadget(#gad, 10, 10, 200, 30, "Anklicken zum Ändern des Fonts...")
    Font1 = LoadFont(#PB_Any, "Arial"  ,  8, #PB_Font_Bold) 
    Font2 = LoadFont(#PB_Any, "Verdana", 12, #PB_Font_StrikeOut) 
  EndIf 
  
  Repeat 
    Event = WaitWindowEvent()
  
    If Event = #PB_Event_Gadget
      If EventGadget() = 0
        If GetGadgetFont(#gad)=FontID(Font1)
          SetGadgetFont(#gad, FontID(Font2)) 
         Else
          SetGadgetFont(#gad, FontID(Font1)) 

        EndIf
      EndIf
    EndIf
  Until Event = #PB_Event_CloseWindow  

Verfasst: 08.01.2007 23:59
von Fluid Byte
Du brauchst kein GetGadgetFont(). Welcher Schrifttyp gearde gewählt ist weisst anhand vom boolschen Flag:

Code: Alles auswählen

OpenWindow(0,0,0,222,130,"FontID()", #PB_Window_SystemMenu | 1)
CreateGadgetList(WindowID(0))
ButtonGadget(0,10,10,200,30,"Anklicken zum Ändern des Fonts...")

LoadFont(0,"Arial", 8,#PB_Font_Bold)
LoadFont(1,"Verdana",12,#PB_Font_StrikeOut)

Repeat
	Event = WaitWindowEvent()
	
	If Event = #PB_Event_Gadget And EventGadget() = 0
		bCustomFont = 1 - bCustomFont
		
		If bCustomFont
			SetGadgetFont(0,FontID(0))
		Else
			SetGadgetFont(0,FontID(1))
		EndIf
	EndIf
Until Event = 16 

Verfasst: 09.01.2007 00:17
von ts-soft
Oder kürzer:

Code: Alles auswählen

OpenWindow(0,0,0,222,130,"FontID()", #PB_Window_SystemMenu | 1)
CreateGadgetList(WindowID(0))
ButtonGadget(0,10,10,200,30,"Anklicken zum Ändern des Fonts...")

LoadFont(0,"Arial", 8,#PB_Font_Bold)
LoadFont(1,"Verdana",12,#PB_Font_StrikeOut)

Repeat
  Event = WaitWindowEvent()

  If Event = #PB_Event_Gadget And EventGadget() = 0
    font ! 1
    SetGadgetFont(0,FontID(font))
  EndIf
Until Event = 16

Verfasst: 09.01.2007 23:17
von Andre
Da habt ihr aber mal wieder optimiert :allright:

Ich glaube aber trotzdem, dass ich die Hilfe so lassen sollte, wie sie jetzt ist. Soll ja schließlich in erster Linie den Anfängern helfen, die Profis proggen solche Beispiele ja eh aus dem Kopf... :twisted: