Code : Tout sélectionner
Structure sText
text$
x.w
y.w
h.w
w.w
size.w
color.i
bgcolor.i
FondId.a
fontname$
fontflag.i
EndStructure
Global NewList Text.sText()
Procedure AddText(text$,x,y,fontname$,size.w,color.i, fontflag,bgcolor=-1)
AddElement(text())
text()\text$ = text$
text()\x = x
text()\y = y
text()\size = size
text()\fontname$ = fontname$
text()\color = color
text()\fontflag = fontflag
text()\bgcolor = bgcolor
EndProcedure
Procedure AddtextVector(text$,x,y)
With text()
If \fontflag>-1
LoadFont(0, \fontname$, \size, \fontflag)
Else
LoadFont(0, \fontname$, \size)
EndIf
id = ListIndex(text())
If ListSize(text()) >0 And id >0
For i=0 To id-1
SelectElement(text(),i)
w + text()\w
Next
SelectElement(text(),id)
EndIf
VectorFont(FontID(0),\size)
h = VectorTextHeight(\text$,#PB_VectorText_Baseline)
; h2 = VectorTextHeight(\text$,#PB_VectorText_Visible)
\h = h
\w = VectorTextWidth(\text$)
x1 = x+\x+w
y1 = y+\y-h
; draw box
If \bgcolor<> -1
AddPathBox(x1,y1,\w,h)
VectorSourceColor(\bgcolor)
FillPath()
EndIf
; draw text
VectorSourceColor(\color)
MovePathCursor(x1, y1)
DrawVectorText(\Text$)
FreeFont(0)
EndWith
EndProcedure
Procedure DrawTextVector(x,y)
ForEach text()
AddtextVector(text$,x,y)
Next
EndProcedure
If OpenWindow(0, 0, 0, 800, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 800, 200)
y = 0
x = 0
AddText("Le rapide renard ",x,y, "Impact",30,RGBA(100, 0, 0, 255),#PB_Font_Bold,RGBA(0,0,0,80))
AddText("brun sauta par ",x,y, "arial",20,RGBA(255, 0, 0, 255),-1,RGBA(0,255,0,80))
AddText("dessus le chien paresseux.",x,y, "comic sans ms",15,RGBA(255, 0, 255, 255),#PB_Font_Italic,RGBA(255,255,0,255))
If StartVectorDrawing(CanvasVectorOutput(0))
DrawTextVector(10,40)
StopVectorDrawing()
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf