Page 1 of 1

Multicolored text

Posted: Sat Jun 23, 2007 1:20 pm
by einander

Code: Select all

;Simple Multicolored Text
;by einander
;
Macro GetCharPos(STR,Po) :  TextWidth(Left(STR,Po-1)) : EndMacro

Procedure CharRGB(x,y,A$,POS,TextRGB,BackRGB)
    DrawText(GetCharPos(A$,POS)+x ,y,Mid(A$,POS,1),TextRGB,BackRGB) 
EndProcedure

Macro RRGB:Random(#White):EndMacro

;<<<<<<<<<<<<<<<<<<<< Test It <<<<<<<<<<<<<<<<<<
CreateGadgetList(OpenWindow(0, 100, 100,700,500 ,"Simple Multicolored Text"))
Wi=WindowWidth(0):He=WindowHeight(0)
ImGad=ImageGadget(#PB_Any,0,0,0,0,0)
IMG=CreateImage(#PB_Any,Wi,He,32)

Text$="Multicolored text example"
FontID=FontID(LoadFont(-1,"arial",36))
 
StartDrawing(ImageOutput(IMG))
DrawingFont(FontID)
For POS= 1 To Len(Text$)
    CharRGB(100,50,Text$,POS,RRGB,RRGB)
    CharRGB(100,150,"Black background",POS,RRGB,0)
    CharRGB(100,250,"Multicolored background",POS,#White,RRGB) 
Next
T$="Invert selected text color"
DrawText(100,350,T$,#Blue,#Cyan) 
For POS= 8 To 15
    CharRGB(100,350,T$,POS,#Cyan,#Blue) ; overwrite selection
Next

StopDrawing()
SetGadgetState(ImGad,ImageID(IMG))
   
Repeat :Until WaitWindowEvent()=#PB_Event_CloseWindow 
    

Re: Multicolored text

Posted: Sat Jun 23, 2007 1:26 pm
by PB
Line 21: LoadFont() can't be called inside a StartDrawing()/StopDrawing() block.

Posted: Sat Jun 23, 2007 1:57 pm
by rsts
Wow!

Very nice effect :D

Many thanks for sharing.

cheers

Posted: Sat Jun 23, 2007 2:06 pm
by einander
@PB: Thanks, fixed.