I've driving my brain crazy for the last 3-4 days trying to understand why some of my code isn't working.
Here's a purified functional adaptation, except that in the original code the more complex UI is created with the DialogXML lib and the procedure is called inside a thread. This procedure is exactly the same as the original. That's why I haven't translated the variable names, to avoid making mistakes.
Code: Select all
DebugLevel 5
;UsePNGImageEncoder()
Enumeration Fenetres
#CGP_FENPRINCIPALE
EndEnumeration
Enumeration Gadgets
#GAD_FP_ZD_GALERIE
#GAD_FP_IMG_0
EndEnumeration
Enumeration Polices
#POLICE
EndEnumeration
Enumeration Images
#IMG_TEXTEEXEMPLE
EndEnumeration
Global.u HauteurPoliceSysteme
NomPolice.s=""
FichierPolice.s=""
#TEXTETEST="ABCDEFGH abcdefgh ÀCÉÏÔ àçéïô 012345 ?!€$+={([A"
#COUL_TEXTETITRE=#White
#COUL_FONDTEXTETITRE=#Red
#COUL_TEXTEEXEMPLE=#Black
#COUL_FONDTEXTEEXEMPLE=#White
CompteurGadget.u=0:HauteurImage.u=0:PositionY.u=4:HauteurTexte.u=0:LargeurTexte.u=0
Global FacteurEchelleX.f=DesktopScaledX(100)/100
Global FacteurEchelleY.f=DesktopScaledY(100)/100
;
#GAD_FP_IMG_POLICE=50
Procedure.u Fc_Affichage_ImagePolice(ArgFichier.s,ArgNomPolice.s,ArgStyle.u,ArgTexteComplement.s,ArgCompteur.u,ArgPositionY.l)
Debug #PB_Compiler_Procedure+" (Fichier="+ArgFichier+",NomPolice="+ArgNomPolice+",TexteComplement="+ArgTexteComplement+",Compteur="+ArgCompteur+",PositionY="+ArgPositionY+")",5
Protected.u PositionY,HauteurImage,LargeurTexte,HauteurTexte,NoGadget=#GAD_FP_IMG_POLICE+ArgCompteur,Style
If RegisterFontFile(ArgFichier)
If ArgStyle&1:Style=#PB_Font_Italic:EndIf ; Italique
If ArgStyle>>1&1:Style|#PB_Font_Underline:EndIf ; Souligné
If ArgStyle>>4&1:Style|#PB_Font_StrikeOut:EndIf ; Barré
If ArgStyle>>5&1:Style|#PB_Font_Bold:EndIf ; Gras
LoadFont(#POLICE,ArgNomPolice,24,Style)
StartDrawing(WindowOutput(0))
DrawingFont(FontID(#POLICE))
LargeurTexte=TextWidth(#TEXTETEST):HauteurTexte=TextHeight(#TEXTETEST)
StopDrawing()
PositionY=HauteurTexte+8:HauteurImage=HauteurPoliceSysteme+8+PositionY
If CreateImage(#IMG_TEXTEEXEMPLE,792*FacteurEchelleX,HauteurImage,32,#COUL_FONDTEXTEEXEMPLE)
StartDrawing(ImageOutput(#IMG_TEXTEEXEMPLE))
DrawingMode(#PB_2DDrawing_Transparent)
Box(0,0,792*FacteurEchelleX,HauteurPoliceSysteme+8,#COUL_FONDTEXTETITRE)
DrawText(10,4,ArgNomPolice+" "+ArgTexteComplement,#COUL_TEXTETITRE)
DrawingFont(FontID(#POLICE))
DrawText(8,HauteurPoliceSysteme+12,#TEXTETEST,#COUL_TEXTEEXEMPLE)
StopDrawing()
OpenGadgetList(#GAD_FP_ZD_GALERIE)
ImageGadget(NoGadget,4,ArgPositionY/FacteurEchelleY,792,HauteurImage,ImageID(#IMG_TEXTEEXEMPLE))
GadgetToolTip(NoGadget,Str(ArgCompteur)+" • "+ArgFichier)
SetGadgetData(NoGadget,ArgCompteur)
CloseGadgetList()
;SaveImage(#IMG_TEXTEEXEMPLE,"C:\Temp\Temp"+Str(ArgCompteur)+".png",#PB_ImagePlugin_PNG)
FreeImage(#IMG_TEXTEEXEMPLE)
EndIf
FreeFont(#POLICE)
ProcedureReturn HauteurImage
EndIf
EndProcedure
If OpenWindow(#CGP_FENPRINCIPALE, 0, 0, 800, 200, "Exemple...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ScrollAreaGadget(#GAD_FP_ZD_GALERIE,4,4,792,192,792,192)
;
StartDrawing(WindowOutput(#CGP_FENPRINCIPALE))
HauteurPoliceSysteme=TextHeight("Ly")
StopDrawing()
For Compteur.a=0 To 5
Select Compteur
Case 0:NomPolice.s="Arial":FichierPolice.s="C:\WINDOWS\Fonts\ARIAL.TTF":Style.u=64
Case 1:NomPolice.s="Arial":FichierPolice.s="C:\WINDOWS\Fonts\ARIALBD.TTF":Style=32
Case 2:NomPolice.s="Arial":FichierPolice.s="C:\WINDOWS\Fonts\ARIALBI.TTF":Style=33
Case 3:NomPolice.s="Arial":FichierPolice.s="C:\WINDOWS\Fonts\ARIALI.TTF":Style=1
Case 4:NomPolice.s="Arial Black":FichierPolice.s="C:\WINDOWS\Fonts\ARIBLK.TTF":Style=64
Case 5:NomPolice.s="Arial Narrow":FichierPolice.s="C:\WINDOWS\Fonts\ARIALNBI.TTF":Style=33
EndSelect
HauteurImage=Fc_Affichage_ImagePolice(FichierPolice,NomPolice,Style,"",CompteurGadget,PositionY)
If HauteurImage
PositionY+HauteurImage
CompteurGadget+1
EndIf
Next
SetGadgetAttribute(#GAD_FP_ZD_GALERIE,#PB_ScrollArea_InnerHeight,PositionY/FacteurEchelleY)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
Procedure.u Fc_Affichage_ImagePolice2(ArgFichier.s,ArgNomPolice.s,ArgStyle.u,ArgTexteComplement.s,ArgCompteur.u,ArgPositionY.l)
Debug #PB_Compiler_Procedure+" (Fichier="+ArgFichier+",NomPolice="+ArgNomPolice+",TexteComplement="+ArgTexteComplement+",Compteur="+ArgCompteur+",PositionY="+ArgPositionY+")",5
Protected.u PositionY,HauteurImage,LargeurTexte,HauteurTexte,Style
If RegisterFontFile(ArgFichier)
If ArgStyle&1:Style=#PB_Font_Italic:EndIf ; Italique
If ArgStyle>>1&1:Style|#PB_Font_Underline:EndIf ; Souligné
If ArgStyle>>4&1:Style|#PB_Font_StrikeOut:EndIf ; Barré
If ArgStyle>>5&1:Style|#PB_Font_Bold:EndIf ; Gras
LoadFont(#POLICE,ArgNomPolice,24,Style)
StartDrawing(WindowOutput(0))
DrawingFont(FontID(#POLICE))
LargeurTexte=TextWidth(#TEXTETEST):HauteurTexte=TextHeight(#TEXTETEST)
StopDrawing()
PositionY=HauteurTexte+8:HauteurImage=HauteurPoliceSysteme+8+PositionY
If CreateImage(#IMG_TEXTEEXEMPLE,792*FacteurEchelleX,HauteurImage,32,#COUL_FONDTEXTEEXEMPLE)
StartDrawing(ImageOutput(#IMG_TEXTEEXEMPLE))
DrawingMode(#PB_2DDrawing_Transparent)
Box(0,0,792*FacteurEchelleX,HauteurPoliceSysteme+8,#COUL_FONDTEXTETITRE)
DrawText(10,4,ArgNomPolice+" "+ArgTexteComplement,#COUL_TEXTETITRE)
DrawingFont(FontID(#POLICE))
DrawText(8,HauteurPoliceSysteme+12,#TEXTETEST,#COUL_TEXTEEXEMPLE)
StopDrawing()
UsePNGImageEncoder()
ImageGadget(#GAD_FP_IMG_0+ArgCompteur,4,ArgPositionY/FacteurEchelleY,792,HauteurImage,ImageID(#IMG_TEXTEEXEMPLE))
GadgetToolTip(#GAD_FP_IMG_0+ArgCompteur,ArgFichier)
EndIf
FreeFont(#POLICE)
FreeImage(#IMG_TEXTEEXEMPLE)
ProcedureReturn HauteurImage
EndIf
EndProcedure
The problem in my complete code is that, while the images are created correctly, the ImageGadgets don't appear, even though an ID is returned with a Debug (not 0).
I've tried all kinds of manipulations, with no results.
I'm beginning to wonder whether this might be due to the fact that the gadget creation procedure is launched inside the thread (as many calls as there are gadgets to create).
Is this the case? If so, how can gadgets be created from within a thread?



