FontID()-Beispiel aus PB-Hilfe

Für allgemeine Fragen zur Programmierung mit PureBasic.
marco2007
Beiträge: 906
Registriert: 26.10.2006 13:19
Kontaktdaten:

FontID()-Beispiel aus PB-Hilfe

Beitrag 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
Windows 11 - PB 6.03 x64
_________________________________
a14xerus
Beiträge: 1440
Registriert: 14.12.2005 15:51
Wohnort: Aachen

Beitrag 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
marco2007
Beiträge: 906
Registriert: 26.10.2006 13:19
Kontaktdaten:

Beitrag 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  
Windows 11 - PB 6.03 x64
_________________________________
Benutzeravatar
Fluid Byte
Beiträge: 3110
Registriert: 27.09.2006 22:06
Wohnort: Berlin, Mitte

Beitrag 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 
Benutzeravatar
ts-soft
Beiträge: 22292
Registriert: 08.09.2004 00:57
Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel
Wohnort: Berlin

Beitrag 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
PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.
Bild
Benutzeravatar
Andre
PureBasic Team
Beiträge: 1765
Registriert: 11.09.2004 16:35
Computerausstattung: MacBook Core2Duo mit MacOS 10.6.8
Lenovo Y50 i7 mit Windows 10
Wohnort: Saxony / Deutscheinsiedel
Kontaktdaten:

Beitrag 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:
Bye,
...André
(PureBasicTeam::Docs - PureArea.net | Bestellen:: PureBasic | PureVisionXP)
Antworten