So larger font sizes can be used and the resulting output looks smooth, but when many text has to be used, the creation of the images takes quite a while. This method can be seen below in the CreateButtonText procedure (you have to change the 'smooth' constant to '1' or '2' to see its effect).
So I am searching for a possibility to get smoother text without creating to much stress for the cpu. A have another simple approach (only for black text for now) which could speed up the whole thing, it could be seen in the NicerButtonText function below (which is active, while smooth=0). You can set the binary 'nicebutton' constant to '%1111' if you want to affect all text boxes.
Code: Select all
#Smooth=0; set to 1 (or 2) to get smoother text
#NiceButton=%0100; set '1' for all buttons to get nicer (while smooth=0)
#ButtonText="ABCD"
#Button=64
Procedure NicerButtonText(n,size,Text.s); new attempt to get a finer text
Protected x,y,z
CreateImage(n,size,size,32)
StartDrawing(ImageOutput(n))
DrawingFont(FontID(0))
DrawText((size-TextWidth(Text))>>1,(size-TextHeight("Wg"))>>1,Text,$ffffffff,0)
DrawingMode(#PB_2DDrawing_AllChannels)
For y=0 To size-1
For x=0 To size-1
z=Red(Point(x,y))
Plot(x,y,z*$1000000+(255-z)*$10101)
; something like Plot(x,y,z&$FFFFFF|$1000000*(Red(z)+Blue(z)+Green(z))/3) for keeping the color
Next x
Next y
StopDrawing()
EndProcedure
Procedure CreateButtonText(n,size,Text.s); my "traditional" method
size<<#Smooth
CreateImage(n,size,size,32|#PB_Image_Transparent)
StartDrawing(ImageOutput(n))
DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Transparent)
DrawingFont(FontID(0))
DrawText((size-TextWidth(Text))>>1,(size-TextHeight("Wg"))>>1,Text,$ff000000)
StopDrawing()
size>>#Smooth
ResizeImage(n,size,size)
EndProcedure
Procedure Main()
Protected c.s
WinID=OpenWindow(0,0,0,#Button<<2,#Button,"ABCD",#PB_Window_ScreenCentered|#PB_Window_Invisible|#PB_Window_SystemMenu)
LoadFont(0,"Trebuchet MS",MulDiv_(#Button<<#Smooth,4,5))
For i=0 To 3
c=Mid(#ButtonText,i+1,1)
If #Smooth=0 And (8>>i)&#NiceButton<>0
NicerButtonText(i,#Button,c)
Else
CreateButtonText(i,#Button,c)
EndIf
ButtonImageGadget(i,i*#Button,0,#Button,#Button,ImageID(i))
Next i
HideWindow(0,0)
quit=0
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
i=EventGadget()
NicerButtonText(i,#Button,Mid(#ButtonText,i+1,1))
ButtonImageGadget(i,i*#Button,0,#Button,#Button,ImageID(i))
Case #WM_CHAR,#PB_Event_CloseWindow
quit=1
EndSelect
Until quit
EndProcedure
Main()