Multicolored text

Share your advanced PureBasic knowledge/code with the community.
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

Multicolored text

Post 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 
    
Last edited by einander on Sat Jun 23, 2007 2:04 pm, edited 2 times in total.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Multicolored text

Post by PB »

Line 21: LoadFont() can't be called inside a StartDrawing()/StopDrawing() block.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Wow!

Very nice effect :D

Many thanks for sharing.

cheers
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

Post by einander »

@PB: Thanks, fixed.
Post Reply