copied code
Posted: Thu Dec 31, 2020 1:32 am
Or so
Code updated 01_01_2021
DPI aware supported for high quality text outputs on all desktop scalings - Razor knife sharp !
Clipping added.
Code simplifications and enhancements for easy using.
Code updated 02_01_2021
Special new FontWizzard_Direct_BF Module with OpenGLGadget support created
for all OS and added here directly runnable
Have fun
(Linux can not grab the PB Logo from the PB Program path, but it works also fine)
In the row : MacOS - Linux - Windows
Code updated 01_01_2021
DPI aware supported for high quality text outputs on all desktop scalings - Razor knife sharp !
Clipping added.
Code simplifications and enhancements for easy using.
Code updated 02_01_2021
Special new FontWizzard_Direct_BF Module with OpenGLGadget support created
for all OS and added here directly runnable
Have fun
(Linux can not grab the PB Logo from the PB Program path, but it works also fine)
In the row : MacOS - Linux - Windows
Code: Select all
; FontWizzard_Direct_BF
DeclareModule FontWizzard_Direct_BF
EnableExplicit
Declare GetTextWidth_FW(text$, font_ID=-1) ; Get text width - Multiline supported
Declare GetTextHeight_FW(text$, font_ID=-1) ; Get text width - Multiline supported
Declare GetTextLineHeight_BF(font_ID=-1) ; Get text line height
Declare GetTextLinesAmount_BF(text$) ; Get amount text lines
; Text output position for ImageBasedGadget_FW - You must deactivate again
; This function move the text cursor to create space for an image on a ImageBasedGadget_FW
Declare SetGadgetCursor_FW(SetGadgetCursor_X_FW_=0, SetGadgetCursor_Y_FW_=0)
; Get the actual text output position X for DrawText_FW
Declare GetCursor_X_FW()
; Get the actual text output position Y for DrawText_FW
Declare GetCursor_Y_FW()
; Set the actual text output position X for DrawText_FW
Declare SetCursor_X_FW(GetCursor_X_FW_)
; Set the actual text output position Y for DrawText_FW
Declare SetCursor_Y_FW(GetCursor_Y_FW_)
; Insert an image into the ImageBasedGadget - You must deactivate again
; To deactivate simply set the image ID to -1
Declare AddImage_1_FW(Image_1_ID_FW_=-1,
Image_1_x_FW_=0,
Image_1_y_FW_=0,
Image_1_width_FW_=0,
Image_1_height_FW_=0,
Image_1_alpha_FW_=255)
; Insert an image into the ImageBasedGadget - You must deactivate again
; To deactivate simply set the image ID to -1
Declare AddImage_2_FW(Image_2_ID_FW_=-1,
Image_2_x_FW_=0,
Image_2_y_FW_=0,
Image_2_width_FW_=0,
Image_2_height_FW_=0,
Image_2_alpha_FW_=255)
; Insert an image into the ImageBasedGadget - You must deactivate again
; To deactivate simply set the image ID to -1
Declare AddImage_3_FW(Image_3_ID_FW_=-1,
Image_3_x_FW_=0,
Image_3_y_FW_=0,
Image_3_width_FW_=0,
Image_3_height_FW_=0,
Image_3_alpha_FW_=255)
; Add a frame to all outputs - Padding is automatically adjusted - Alpha channel sensitive - Sample $8000FFFF
Declare AddFrame_FW(AddFrame_Size_FW_=0, AddFrame_Color_FW_=0)
; Activate screen output for DrawText_FW - You must deactivate again
Declare ActivateScreenOutput_FW(screen_output_=0)
Declare OpenGLGadgetFlipBuffers_FW(gadget_ID) ; Flip Buffers OpenGLGadget
Declare SetColorOpenGLGadget_FW(background_color) ; OpenGLGadget color
; DrawText_FW create as output a image - You must deactivate again
; 1 create a image
; 2 create a vertical mirrored image
; 3 create a horizontal mirrored image
; 4 create a horizontal and vertical mirrored image
Declare CreateImage_FW(CreateImage_FW_=0)
; You can also add images to the text output
; The additional image size is not limited and can be larger than the text and the background
; If CreateImage_FW activated, the parameter output_ID is ignored
Declare DrawText_FW(output_ID,
font$,
font_flag,
output_x,
output_y,
output_width,
output_height,
text_color=#Black,
text_adjustment=0,
background_color=-1,
text$=" ",
padding_x=0,
padding_y=0,
resize_factor.f=1)
; Create and output a DrawTextImage_FW on a OpenGLGadget
; Set CreateImage_FW above for mirrored outputs
Declare CreateImage_FW(CreateImage_FW_=0)
Declare DrawGLTextImage_FW(gadget_ID, ; Gadget ID
font$, ; Font
font_flag, ; Font flag
output_x, ; Output x
output_y, ; Output y
output_width, ; Output width
output_height, ; Output height
text_color=#White, ; Text color - Alpha channel sensitive
text_adjustment=1, ; Text adjustment - 0=center - 1=left - 2=right
background_color=-1, ; Background color - Alpha channel sensitive
text$="", ; Text
padding_x=0, ; Padding x
padding_y=0, ; Padding y
resize_factor.f=1.0) ; Resize factor - float
Declare PresetFontsize_FW(PresetFontsize_FW_=0) ; Preset a fontsize - You must deactivate again
Declare PresetMinFontsize_FW(PresetMinFontsize_FW_=0) ; Set the smallest font size - You must deactivate again
Declare PresetMaxFontsize_FW(PresetMaxFontsize_FW_=0) ; Sets the largest font size - You must deactivate again
EndDeclareModule
Module FontWizzard_Direct_BF
; FontWizzard_Direct_GL_BF - All OS - by Saki
; For outputs on screen, images, canvas, OpenGLGadget
; Padding can also be used to create text zoom effects
; The padding can also be specified negatively for very small buttons
; Set a little Padding, this pervent the OS word wrap on multi line ButtonGadgets
#min_padding_x=25
CompilerIf #PB_Compiler_OS=#PB_OS_Linux And Subsystem("gtk2")
#min_padding_y=9
CompilerElse
#min_padding_y=5
CompilerEndIf
Structure gadget_bf
gadget_ID.i
font_ID.i
image_ID.i
EndStructure
Global NewList gadget_bf.gadget_bf()
Global screen_output, PresetFontsize_FW, PresetMinFontsize_FW, PresetMaxFontsize_FW
Global SetGadgetCursor_X_FW, SetGadgetCursor_Y_FW, GetCursor_X_FW, GetCursor_Y_FW
Global Image_1_ID_FW, Image_1_x_FW, Image_1_y_FW, Image_1_width_FW, Image_1_height_FW, Image_1_alpha_FW
Global Image_2_ID_FW, Image_2_x_FW, Image_2_y_FW, Image_2_width_FW, Image_2_height_FW, Image_2_alpha_FW
Global Image_3_ID_FW, Image_3_x_FW, Image_3_y_FW, Image_3_width_FW, Image_3_height_FW, Image_3_alpha_FW
Global AddFrame_Size_FW, AddFrame_Color_FW, CreateImage_FW, FromDrawGLTextImage_FW
Global Rx.d=DesktopResolutionX()
Global Ry.d=DesktopResolutionY()
If Not InitSprite() : MessageRequester(" ERROR", "InitSprite fails"+#LF$+#LF$+"The tool is terminated") : End : EndIf
Procedure.s Replace_LineBreaks_to_LF(text$)
If FindString(text$, #CR$)
text$=ReplaceString(text$, #CRLF$, #LF$)
text$=ReplaceString(text$, #LFCR$, #LF$)
ReplaceString(text$, #CR$, #LF$, #PB_String_InPlace)
EndIf
ProcedureReturn text$
EndProcedure
Procedure GetTextWidth_FW(text$, font_ID=-1)
Protected lf, i, ii, iii
Static image_ID
If Not IsImage(image_ID)
image_ID=CreateImage(#PB_Any, 16, 16)
If Not image_ID : ProcedureReturn -6
EndIf
EndIf
text$=Replace_LineBreaks_to_LF(text$)
lf=CountString(text$, #LF$)
If Not StartDrawing(ImageOutput(image_ID))
ProcedureReturn -4
FreeImage(image_ID)
EndIf
If IsFont(font_ID)
DrawingFont(FontID(font_ID))
EndIf
If lf
lf+1
For i=1 To lf
ii=TextWidth(StringField(text$, i, #LF$))
If ii>iii : iii=ii : EndIf
Next i
Else
iii=TextWidth(text$)
EndIf
StopDrawing()
ProcedureReturn iii
EndProcedure
Procedure GetTextHeight_FW(text$, font_ID=-1)
Protected lf, i
Static image_ID
If Not IsImage(image_ID)
image_ID=CreateImage(#PB_Any, 16, 16)
If Not image_ID : ProcedureReturn -6
EndIf
EndIf
text$=Replace_LineBreaks_to_LF(text$)
lf=CountString(text$, #LF$)+1
If Not StartDrawing(ImageOutput(image_ID))
ProcedureReturn -4
FreeImage(image_ID)
EndIf
If IsFont(font_ID)
DrawingFont(FontID(font_ID))
EndIf
i=TextHeight(" ")*lf
StopDrawing()
ProcedureReturn i
EndProcedure
Procedure GetTextLineHeight_BF(font_ID=-1)
Protected result
Static image_ID
If Not IsImage(image_ID)
image_ID=CreateImage(#PB_Any, 16, 16)
If Not image_ID : ProcedureReturn -6
EndIf
EndIf
If Not StartDrawing(ImageOutput(image_ID))
ProcedureReturn -4
FreeImage(image_ID)
EndIf
If IsFont(font_ID)
DrawingFont(FontID(font_ID))
EndIf
result=TextHeight(" ")
StopDrawing()
ProcedureReturn result
EndProcedure
Procedure GetTextLinesAmount_BF(text$)
text$=Replace_LineBreaks_to_LF(text$)
ProcedureReturn CountString(text$, #LF$)+1
EndProcedure
Procedure Calculate_fitted_Font_FW(text$,
width_rectangle,
height_rectangle,
font$,
font_flag,
padding_x=0,
padding_y=0,
resize_factor.f=1)
If resize_factor<=0 : resize_factor=1 : EndIf
If text$="" : ProcedureReturn 0 : EndIf
Macro common_calculate_fitted_font
font_ID=LoadFont(#PB_Any, font$, max_needed_font_size, font_flag)
text_width=GetTextWidth_FW(text$, font_ID)*resize_factor
text_height=GetTextHeight_FW(text$, font_ID)*resize_factor
EndMacro
Protected font_ID, max_needed_font_size, text_width, text_height
If PresetMinFontsize_FW>1
max_needed_font_size=PresetMinFontsize_FW
EndIf
If PresetFontsize_FW>0
font_ID=LoadFont(#PB_Any, font$, PresetFontsize_FW, font_flag)
Else
Repeat
max_needed_font_size+1
font_ID=LoadFont(#PB_Any, font$, max_needed_font_size, font_flag)
text_width=GetTextWidth_FW(text$, font_ID)*resize_factor
text_height=GetTextHeight_FW(text$, font_ID)*resize_factor
If IsFont(font_ID)
FreeFont(font_ID)
EndIf
If PresetMaxFontsize_FW>0
If max_needed_font_size>PresetMaxFontsize_FW
Break
EndIf
EndIf
If text_width>width_rectangle-padding_x Or text_height>height_rectangle-padding_y
Break
EndIf
ForEver
If max_needed_font_size>1
max_needed_font_size-1
EndIf
font_ID=LoadFont(#PB_Any, font$, max_needed_font_size, font_flag)
EndIf
ProcedureReturn font_ID
EndProcedure
Procedure AddFrame_FW(AddFrame_Size_FW_=0, AddFrame_Color_FW_=0)
AddFrame_Size_FW=AddFrame_Size_FW_
AddFrame_Color_FW=AddFrame_Color_FW_
ProcedureReturn 1
EndProcedure
Procedure ActivateScreenOutput_FW(screen_output_=0)
screen_output=screen_output_
EndProcedure
Procedure OpenGLGadgetFlipBuffers_FW(gadget_ID) ; Flip Buffers OpenGLGadget
SetGadgetAttribute(gadget_ID, #PB_OpenGL_FlipBuffers, #True)
ProcedureReturn 1
EndProcedure
Procedure SetColorOpenGLGadget_FW(background_color) ; OpenGLGadget color
glEnable_(#GL_BLEND)
glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE_MINUS_SRC_ALPHA)
glClearColor_(Red(background_color)/255, Green(background_color)/255, Blue(background_color)/255, 1)
glClear_(#GL_COLOR_BUFFER_BIT)
ProcedureReturn 1
EndProcedure
Procedure CreateImage_FW(CreateImage_FW_=0)
CreateImage_FW=CreateImage_FW_
ProcedureReturn CreateImage_FW
EndProcedure
Procedure DrawText_FW(output_ID,
Font$,
font_flag,
output_x,
output_y,
output_width,
output_height,
text_color=#Black,
text_adjustment=0,
background_color=-1,
text$=" ",
padding_x=0,
padding_y=0,
resize_factor.f=1)
If CreateImage_FW
Protected image=2
Else
If Not screen_output
If IsImage(output_ID) ; Image
image=1
ElseIf IsSprite(output_ID) ; PB sprite
Protected sprite=1
ElseIf IsGadget(output_ID) ; Canvas
Protected canvas=1
ElseIf IsWindow(output_ID) ; Window
Protected window=1
Else
ProcedureReturn -11
EndIf
EndIf
EndIf
If resize_factor<=0 : resize_factor=1 : EndIf
If text$="" : text$=" " : EndIf
If output_width<1 : output_width=1 : EndIf
If output_height<1 : output_height=1 : EndIf
padding_x+#min_padding_x
padding_y+#min_padding_y
If canvas
padding_x*Rx
padding_y*Ry
EndIf
If AddFrame_Size_FW>0
padding_x+AddFrame_Size_FW*2
padding_y+AddFrame_Size_FW*2
EndIf
Protected font_ID=Calculate_fitted_Font_FW(text$,
output_width,
output_height,
font$,
font_flag,
padding_x,
padding_y,
resize_factor)
If Not IsFont(font_ID) : ProcedureReturn -9 : EndIf
Protected i, ii, iii, line_width, string_field$
Protected lf=CountString(Replace_LineBreaks_to_LF(text$), #LF$)
Protected text_height=GetTextHeight_FW(text$, font_ID)
If text_adjustment
Protected text_width=GetTextWidth_FW(text$, font_ID)
EndIf
Protected GetCursor_X
Protected GetCursor_Y
Macro text_adjustment_2(text_line)
Select text_adjustment
Case 0 ; centered
GetCursor_X=(output_width/2-line_width/2)+output_x
Case 1 ; Left
GetCursor_X=(output_width/2-text_width/2)+output_x
Case 2 ; Right
GetCursor_X=(output_width/2+text_width/2-line_width)+output_x
EndSelect
GetCursor_Y=((output_height-text_height)/2+ii)+output_y
If Not init
init=1
GetCursor_X_FW=GetCursor_X+text_width
GetCursor_Y_FW=GetCursor_Y+text_height
EndIf
DrawText(GetCursor_X,
GetCursor_Y,
text_line,
text_color)
EndMacro
Protected temp_image_1_ID
Macro add_image_1_fw_1
If Image_1_Width_FW>0 And Image_1_Height_FW>0
If IsImage(Image_1_ID_FW)
temp_image_1_ID=CopyImage(Image_1_ID_FW, #PB_Any)
If Not temp_image_1_ID
ProcedureReturn-6
EndIf
ResizeImage(temp_image_1_ID,
Image_1_Width_FW,
Image_1_Height_FW)
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawAlphaImage(ImageID(temp_image_1_ID),
Image_1_x_FW+output_x,
Image_1_y_FW+output_y,
Image_1_alpha_FW)
FreeImage(temp_image_1_ID)
EndIf
EndIf
EndMacro
Protected temp_image_2_ID
Macro add_image_2_fw_1
If Image_2_Width_FW>0 And Image_2_Height_FW>0
If IsImage(Image_2_ID_FW)
temp_image_2_ID=CopyImage(Image_2_ID_FW, #PB_Any)
If Not temp_image_2_ID
ProcedureReturn-6
EndIf
ResizeImage(temp_image_2_ID,
Image_2_Width_FW,
Image_2_Height_FW)
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawAlphaImage(ImageID(temp_image_2_ID),
Image_2_x_FW+output_x,
Image_2_y_FW+output_y,
Image_2_alpha_FW)
FreeImage(temp_image_2_ID)
EndIf
EndIf
EndMacro
Protected temp_image_3_ID
Macro add_image_3_fw_1
If Image_3_Width_FW>0 And Image_3_Height_FW>0
If IsImage(Image_3_ID_FW)
temp_image_3_ID=CopyImage(Image_3_ID_FW, #PB_Any)
If Not temp_image_3_ID
ProcedureReturn-6
EndIf
ResizeImage(temp_image_3_ID,
Image_3_Width_FW,
Image_3_Height_FW)
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawAlphaImage(ImageID(temp_image_3_ID),
Image_3_x_FW+output_x,
Image_3_y_FW+output_y,
Image_3_alpha_FW)
FreeImage(temp_image_3_ID)
EndIf
EndIf
EndMacro
If screen_output
Protected result=StartDrawing(ScreenOutput())
Else
If Not Alpha(text_color)
text_color|$FF000000
EndIf
Protected image_ID=CreateImage(#PB_Any, output_width, output_height, 32, #PB_Image_Transparent)
If image=2 : output_ID=image_ID : EndIf
If image
result=StartDrawing(ImageOutput(output_ID))
ElseIf sprite
result=StartDrawing(SpriteOutput(output_ID))
ElseIf canvas
result=StartDrawing(CanvasOutput(output_ID))
Else
result=StartDrawing(WindowOutput(output_ID))
EndIf
EndIf
If Not result
FreeFont(font_ID)
ProcedureReturn -11
EndIf
Protected AddFrame_Color_FW_=AddFrame_Color_FW
If Not Alpha(AddFrame_Color_FW_) : AddFrame_Color_FW_|$FF000000 : EndIf
CompilerIf #PB_Compiler_OS<>#PB_OS_Windows
If FromDrawGLTextImage_FW
text_color=RGBA(Blue(text_color), Green(text_color), Red(text_color), Alpha(text_color))
background_color=RGBA(Blue(background_color), Green(background_color), Red(background_color), Alpha(background_color))
AddFrame_Color_FW_=RGBA(Blue(AddFrame_Color_FW_), Green(AddFrame_Color_FW_), Red(AddFrame_Color_FW_), Alpha(AddFrame_Color_FW_))
EndIf
CompilerEndIf
If Not Alpha(background_color) : background_color=$FF000000|background_color : EndIf
FromDrawGLTextImage_FW=1
If Not screen_output
If Alpha(background_color) And background_color<>-1
DrawingMode(#PB_2DDrawing_AllChannels)
EndIf
EndIf
If background_color<>-1
Box(output_x, output_y, output_width, output_height, background_color)
EndIf
add_image_1_fw_1
add_image_2_fw_1
add_image_3_fw_1
If AddFrame_Size_FW
If Alpha(AddFrame_Color_FW)
DrawingMode(#PB_2DDrawing_Outlined|#PB_2DDrawing_AlphaBlend)
Else
DrawingMode(#PB_2DDrawing_Outlined)
EndIf
For iii=0 To (AddFrame_Size_FW-1)
Box(output_x+iii,output_y+iii, output_width-iii*2, output_height-iii*2, AddFrame_Color_FW_)
Next iii
EndIf
DrawingFont(FontID(font_ID))
DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Transparent)
Protected line_height=TextHeight(" ")
Protected init
If lf
lf+1
For i=1 To lf
string_field$=StringField(text$, i, #LF$)
line_width=TextWidth(string_field$)
text_adjustment_2(string_field$)
ii+line_height
Next i
Else
text_adjustment=0
line_width=TextWidth(text$)
text_adjustment_2(text$)
EndIf
StopDrawing()
FreeFont(font_ID)
If image=2
ProcedureReturn image_ID
EndIf
ProcedureReturn 1
EndProcedure
Procedure DrawGLTextImage_FW(gadget_ID, ; Gadget ID
font$, ; Font
font_flag, ; Font flag
output_x, ; Output x
output_y, ; Output y
output_width, ; Output width
output_height, ; Output height
text_color=#White, ; Text color - Alpha channel sensitive
text_adjustment=1, ; Text adjustment - 0=center - 1=left - 2=right
background_color=-1, ; Background color - Alpha channel sensitive
text$="", ; Text
padding_x=0, ; Padding x
padding_y=0, ; Padding y
resize_factor.f=1.0) ; Resize factor - float
If output_x<0 : Protected output_x_=output_x : output_x=0 : EndIf : If output_y<0 : Protected output_y_=output_y : output_y=0 : EndIf
output_width*DesktopResolutionX() : output_height*DesktopResolutionX()
CompilerIf #PB_Compiler_OS=#PB_OS_Windows
CreateImage_FW(1)
CompilerElse
CreateImage_FW(2)
CompilerEndIf
If Not Alpha(background_color) : background_color=$FF000000|background_color : EndIf
FromDrawGLTextImage_FW=1
Protected image_ID=DrawText_FW(-1, ; output_ID
font$, ; Font
font_flag, ; Font flag
output_x_, ; Output x pos
output_y_, ; Output y pos
output_width, ; Output width
output_height, ; Output height
text_color, ; Text color
text_adjustment, ; Text adjustment - 0=center - 1=left - 2=right
background_color, ; Background_color - Ignore = -1 - Alpha channel sensitive - Sample $8000FFFF
Text$, ; Text
padding_x, ; Padding x
padding_y, ; Padding y
resize_factor) ; resize_factor.f
FromDrawGLTextImage_FW=1
If Not IsImage(image_ID) : ProcedureReturn 0 : EndIf
Protected temporary_image_ID=CreateImage(#PB_Any, output_width, output_height, 32, #PB_Image_Transparent)
If Not temporary_image_ID
FreeImage(image_ID)
ProcedureReturn 0
EndIf
If Not StartVectorDrawing(ImageVectorOutput(temporary_image_ID))
FreeImage(image_ID)
FreeImage(temporary_image_ID)
EndIf
Select CreateImage_FW
Case 2
FlipCoordinatesY(VectorOutputHeight()/2)
Case 3
FlipCoordinatesX(VectorOutputWidth()/2)
Case 4
FlipCoordinatesX(VectorOutputWidth()/2)
FlipCoordinatesY(VectorOutputHeight()/2)
EndSelect
MovePathCursor(0, 0)
DrawVectorImage(ImageID(image_ID))
StopVectorDrawing()
If StartDrawing(ImageOutput(temporary_image_ID))
glPushMatrix_()
glOrtho_(0, GadgetWidth(gadget_ID), GadgetHeight(gadget_ID), 0, 0, 1)
glRasterPos2i_(output_x, output_y+output_height/DesktopResolutionX())
glDrawPixels_(output_width, output_height, #GL_BGRA_EXT, #GL_UNSIGNED_BYTE, DrawingBuffer())
glPopMatrix_()
StopDrawing()
Else
FreeImage(image_ID)
FreeImage(temporary_image_ID)
ProcedureReturn 0
EndIf
FreeImage(image_ID)
FreeImage(temporary_image_ID)
ProcedureReturn 1
EndProcedure
Procedure SetGadgetCursor_FW(SetGadgetCursor_X_FW_=0, SetGadgetCursor_Y_FW_=0)
SetGadgetCursor_X_FW=SetGadgetCursor_X_FW_
SetGadgetCursor_Y_FW=SetGadgetCursor_Y_FW_
ProcedureReturn 1
EndProcedure
Procedure GetCursor_X_FW()
ProcedureReturn GetCursor_X_FW
EndProcedure
Procedure GetCursor_Y_FW()
ProcedureReturn GetCursor_Y_FW
EndProcedure
Procedure SetCursor_X_FW(GetCursor_X_FW_)
GetCursor_X_FW=GetCursor_X_FW_
ProcedureReturn GetCursor_X_FW
EndProcedure
Procedure SetCursor_Y_FW(GetCursor_Y_FW_)
GetCursor_Y_FW=GetCursor_Y_FW_
ProcedureReturn GetCursor_Y_FW
EndProcedure
Procedure AddImage_1_FW(Image_1_ID_FW_=-1,
Image_1_x_FW_=0,
Image_1_y_FW_=0,
Image_1_width_FW_=0,
Image_1_height_FW_=0,
Image_1_alpha_FW_=255)
Image_1_ID_FW=Image_1_ID_FW_
Image_1_x_FW=Image_1_x_FW_
Image_1_y_FW=Image_1_y_FW_
Image_1_width_FW=Image_1_width_FW_
Image_1_height_FW=Image_1_height_FW_
Image_1_alpha_FW=Image_1_alpha_FW_
ProcedureReturn Image_1_ID_FW
EndProcedure
Procedure AddImage_2_FW(Image_2_ID_FW_=-1,
Image_2_x_FW_=0,
Image_2_y_FW_=0,
Image_2_width_FW_=0,
Image_2_height_FW_=0,
Image_2_alpha_FW_=255)
Image_2_ID_FW=Image_2_ID_FW_
Image_2_x_FW=Image_2_x_FW_
Image_2_y_FW=Image_2_y_FW_
Image_2_width_FW=Image_2_width_FW_
Image_2_height_FW=Image_2_height_FW_
Image_2_alpha_FW=Image_2_alpha_FW_
ProcedureReturn Image_1_ID_FW
EndProcedure
Procedure AddImage_3_FW(Image_3_ID_FW_=-1,
Image_3_x_FW_=0,
Image_3_y_FW_=0,
Image_3_width_FW_=0,
Image_3_height_FW_=0,
Image_3_alpha_FW_=255)
Image_3_ID_FW=Image_3_ID_FW_
Image_3_x_FW=Image_3_x_FW_
Image_3_y_FW=Image_3_y_FW_
Image_3_width_FW=Image_3_width_FW_
Image_3_height_FW=Image_3_height_FW_
Image_3_alpha_FW=Image_3_alpha_FW_
ProcedureReturn Image_3_ID_FW
EndProcedure
Procedure PresetFontsize_FW(PresetFontsize_FW_=0)
PresetFontsize_FW=PresetFontsize_FW_
ProcedureReturn PresetFontsize_FW
EndProcedure
Procedure PresetMinFontsize_FW(PresetMinFontsize_FW_=0)
PresetMinFontsize_FW=PresetMinFontsize_FW_
ProcedureReturn PresetMinFontsize_FW
EndProcedure
Procedure PresetMaxFontsize_FW(PresetMaxFontsize_FW_=0)
PresetMaxFontsize_FW=PresetMaxFontsize_FW_
ProcedureReturn PresetMaxFontsize_FW
EndProcedure
EndModule
UseModule FontWizzard_Direct_BF
; ############## Simple OpenGLGadget FontWizzard_BF Demo - DPI aware - All OS ############
; The FontWizzard_BF Module - You can found here :
; https://www.purebasic.fr/english/viewtopic.php?f=12&t=76338
EnableExplicit
Define image_1_ID=LoadImage(#PB_Any, #PB_Compiler_Home+"/Examples/Sources/Data/PureBasicLogo.bmp")
Define window_ID=OpenWindow(#PB_Any, 0, 0, 500, 370, "FW Text on a OpenGLGadget", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
Define gadget_ID=OpenGLGadget(#PB_Any, 0, 0, WindowWidth(window_ID), WindowHeight(window_ID))
; ----------------------------------------------------------
Repeat
SetColorOpenGLGadget_FW(#Blue) ; OpenGLGadget color
Define text$="Hello World"+#LF$+"This is a advanced text output"
; Add a frame to all outputs - Padding is automatically adjusted - Alpha channel sensitive - Sample $8000FFFF
AddFrame_FW(2*DesktopResolutionX(), $FF0000FF) ; AddFrame_Size_FW, AddFrame_Color_FW
DrawGLTextImage_FW(gadget_ID, ; Gadget ID
"", ; Font
#PB_Font_Bold, ; Font flag
100, ; Output x pos
20, ; Output y pos
300, ; Output width
60, ; Output height
#White, ; Text color
1, ; Text adjustment - 0=center - 1=left - 2=right
-1, ; Background_color - Ignore = -1 - Alpha channel sensitive - Sample $8000FFFF
text$, ; Text
25, ; Padding x
5, ; Padding y
1.0) ; Resize factor
text$="Hello World"+#LF$+"This is a automaticaly fitted text output"+#LF$+"Try any Text"
AddFrame_FW() ; Remove the frame
DrawGLTextImage_FW(gadget_ID, ; Gadget ID
"Georgia", ; Font
#PB_Font_Bold, ; Font flag
10, ; Output x pos
110, ; Output y pos
480, ; Output width
90, ; Output height
#Red, ; Text color
0, ; Text adjustment - 0=center - 1=left - 2=right
-1, ; Background_color - Ignore = -1 - Alpha channel sensitive - Sample $8000FFFF
text$, ; Text
-25, ; Padding x
5, ; Padding y
1.0) ; Resize factor
text$+#LF$+#LF$+"Have fun"
AddFrame_FW(3*DesktopResolutionX(), #Red) ; AddFrame_Size_FW, AddFrame_Color_FW
AddImage_1_FW(image_1_ID,
252*DesktopResolutionX(), ; x pos
88*DesktopResolutionX(), ; y pos
140*DesktopResolutionX(), ; Width
25*DesktopResolutionX(), ; Height
255) ; Alpha
DrawGLTextImage_FW(gadget_ID, ; Gadget ID
"Georgia", ; Font
#PB_Font_Bold, ; Font flag
50, ; Output x pos
230, ; Output y pos
400, ; Output width
120, ; Output height
#Blue, ; Text color
0, ; Text adjustment - 0=center - 1=left - 2=right
#Green, ; Background_color - Ignore = -1 - Alpha channel sensitive - Sample $8000FFFF
text$, ; Text
25, ; Padding x
5, ; Padding y
1.0) ; Resize factor
AddImage_1_FW() ; Remove additional image 1
OpenGLGadgetFlipBuffers_FW(gadget_ID) ; Flip Buffers OpenGLGadget - Get the output
Until WaitWindowEvent()=#PB_Event_CloseWindow