Fantasy text color in webgadget and forum

Share your advanced PureBasic knowledge/code with the community.
moricode
User
User
Posts: 94
Joined: Thu May 25, 2023 3:55 am

Fantasy text color in webgadget and forum

Post by moricode »

A fantasy color style for your webgadget ui (Web UI) in application or even use to post color stylish text in phpForum ,
have fun .

usage:
copy your text from any notepad and paste it in the input box , or type and edit your text directly there ,
then right click mouse to popup menu , select color style as you wish , see the preview ,
the generated BB code is automatically copied in clipboard , you can paste it directly to forum post.




Example :
Horizontal Rainbow Color
A fantasy color style for your webgadget ui in application or even use to post color stylish text in phpForum , have fun .


Vertical Rainbow color :
Forum Text Color Styler V0.4 SAMPLE TEXT 1
Forum Text Color Styler V0.4 SAMPLE TEXT 2
Forum Text Color Styler V0.4 SAMPLE TEXT 3
Forum Text Color Styler V0.4 SAMPLE TEXT 4
Forum Text Color Styler V0.4 SAMPLE TEXT 5
Forum Text Color Styler V0.4 SAMPLE TEXT 6
Forum Text Color Styler V0.4 SAMPLE TEXT 7
Forum Text Color Styler V0.4 SAMPLE TEXT 8
Forum Text Color Styler V0.4 SAMPLE TEXT 9
Forum Text Color Styler V0.4 SAMPLE TEXT 10




Fading color:
(Holizotal gradient Dark to Light)
copy your text from any notepad and paste it in the input box , or type and edit your text directly there ,
then right click mouse to popup menu , select color style as you wish , see the preview ,
the generated BB code is automatically copied in clipboard , you can paste it directly to forum post.



Random Color:
A fantasy color style for your webgadget ui in application or even use to post color stylish text in phpForum , have fun .


two color morphing :
A fantasy color style for your webgadget ui in application or even use to post color stylish text in phpForum , have fun .



Example
F a n t a i s i e S o f t w a r e




and many more


Image


Image


download compiled binary ForumText04.zip
ForumText04.zip


Or you can compile yourself PB 5.6x , 5.7x

Code: Select all

; ----------------------------------------------------------------------------------
; Forum Text Color Formater v0.4 for BB CODE forum 
; ----------------------------------------------------------------------------------
; syntax update to PB 5.72
; ----------------------------------------------------------------------------------
; Add # in color code [color=#FF0000] , some bbcode need the #
; Add closer [/color] for each open [color=] , phpForum BBcode need to close every color block




; ======================================================================================
; ----- [Color Style] ------
; == Vertical Effect ==
#V_Black_White = 0 ; Type 0= Solid Fade light gradient  (Black to White) ; same as Type 1
#V_Fade_Color1 = 1; Type 1= (Start Color) Darken to Lighter
; Type 2= Lighter to Darken (Start color)
#V_Gradient_2Color = 3; Type 3= vertical Two Color Morph               ;Start color >> Center color AVG >> End Color
#V_Rainbow_Color = 4; Type 4= Rainbow Color                          ;D\arken >> Lighter >> Darken
#V_Random_Color = 5; Type 5= Random Color                           ;Center Light
; Type 6= Center Dark
; Type 7= Wave dark > light > dark > light ....each 3 line

; === Horizontal effect  ====
#H_Black_White = 100; Type 100= Solid black Fade to white gradient  (Black to White) ; same as Type 1 
#H_Fade_Color1 = 101; Type 101= (Start Color) Darken to Lighter
; Type 102= Lighter to Darken (Start color)
#H_Gradient_2Color = 103; Type 103= Two Color Morph ;Start color >> Center color AVG >> End Color
#H_Rainbow_Color = 104; Type 104= Darken >> Lighter >> Darken
#H_Random_Color = 105; Type 105= Center Light
; Type 106= Center Dark
; Type 107= Wave dark > light > dark > light ....each 3 line
; ======================================================================================

Enumeration 
   #Label1
   #Label2
   #Label3
   #InputText
   #RawColorCode
   #IEPreview
   #Color1
   #Color2
EndEnumeration

Global previewFile$ 
Global StartColor = $5203CC
Global EndColor = $FB6300

#AppTitle$ = "Forum Text Color Styler V0.4"
Global HtmlHeader$ = "<meta http-equiv="+Chr(34)+"Content-Type"+Chr(34)+" Content="+Chr(34)+"text/html"+Chr(59)+ "charset=utf-8"+Chr(34)+">"+"<title>Forum Text Color Styler V0.3 Preview Content</title>"

Global filename$ = GetCurrentDirectory()+"temp.htm"

Procedure.s Color_styler (Type) 
   Protected t.s,R,G,B,RS.s,R2,G2,B2,MR.f,MG.f,MB.f,Rain.f,rain2.f,rain3.f
   
   R=Red(StartColor) : G=Green(StartColor) : B=Blue(StartColor)
   R2=Red(EndColor) : G2=Green(EndColor) : B2=Blue(EndColor)
   
   a=CountGadgetItems(#InputText)
   IF a = 0 : MessageRequester("Warning","No input text, please type or paste from clipboard.") : ProcedureReturn : ENDIF
   Rain=Int(a/3)
   
   CR=(245-R)/a
   CG=(245-G)/a
   CCB=(245-B)/a
   
   ma=(a/2)

   CR2=(245-R2)/a
   CG2=(245-G2)/a
   CB2=(245-B2)/a
   
   Select Type
      Case #V_Black_White
      Case #V_Fade_Color1  
         ; ==========================================================================
         For i=0 To a-1
            t+ "[color=#"+RSet(Hex(R+CR*i),2,"0")+RSet(Hex(G+CG*i),2,"0")+RSet(Hex(B+CCB*i),2,"0")+"]"
            t+ GetGadgetItemText(#InputText, i, 0)+#CRLF$
         t+"[/color]"  ; color closer
         Next i
;         t+"[/color]"
         ; ==========================================================================
      Case 2
      Case #V_Gradient_2Color ; vertical two color Morph
         ; ==========================================================================         
         For i=0 To a-1
            MR=(R*((a-i-1)/a))+R2*((i)/(a-1))/2
            MG=(G*((a-i-1)/a))+G2*((i)/(a-1))/2
            MB=(B*((a-i-1)/a))+B2*((i)/(a-1))/2
            t+ "[color=#"+RSet(Hex(MR),2,"0")
            t+RSet(Hex(MG),2,"0")
            t+RSet(Hex(MB),2,"0")+"]"
            t+ GetGadgetItemText(#InputText, i, 0)+#CRLF$
         t+"[/color]"
         Next i
         ; ==========================================================================
      Case #V_Rainbow_Color 
         ; ==========================================================================         
         Rain=Int(a/3)
         
         For i=0 To Rain 
            MR=255*((Rain-i)/Rain)   ;begin full red to reduce to no red at position 1/3
            MG=255*(i/Rain)          ; increace
            MB=0
            
            t+ "[color=#"+RSet(Hex(MR),2,"0")
            t+RSet(Hex(MG),2,"0")
            t+RSet(Hex(MB),2,"0")+"]"
            t+ GetGadgetItemText(#InputText, i, 0)+#CRLF$
         t+"[/color]"
         Next i
         
         rain2=Rain+Rain ; second rain
         
         For i=Rain+1 To rain2 
            MR=0;(R*((a-i-1)/a))+R2*((i)/(a-1))/2
            MG=255*((rain2-i+1)/Rain)  ; reduce
            MB=255*((i-Rain-1)/Rain)   ; increace
            
            t+ "[color=#"+RSet(Hex(MR),2,"0")
            t+RSet(Hex(MG),2,"0")
            t+RSet(Hex(MB),2,"0")+"]"
            t+ GetGadgetItemText(#InputText, i, 0)+#CRLF$
         t+"[/color]"
         Next i
         
         rain3=rain2+Rain
         
         For i=rain2+1 To a-1
            MR=255*((i-rain2-1)/Rain)  ; increace
            MG= 0                      ; (G*((a-i-1)/a))+G2*((i)/(a-1))/2
            MB=255*((rain3-i+1)/Rain)  ; reduce
            
            t+ "[color=#"+RSet(Hex(MR),2,"0")
            t+RSet(Hex(MG),2,"0")
            t+RSet(Hex(MB),2,"0")+"]"
            t+ GetGadgetItemText(#InputText, i, 0)+#CRLF$
         t+"[/color]"
         Next i
         
;         t+"[/color]"
         ; ==========================================================================
      Case #V_Random_Color   
         ; ==========================================================================
         For i=0 To a-1
            t+ "[color=#"+RSet(Hex(Random(180)+20),2,"0")+RSet(Hex(Random(180)+20),2,"0")+RSet(Hex(Random(180)+20),2,"0")+"]"
            t+ GetGadgetItemText(#InputText, i, 0)+#CRLF$
          t+"[/color]"
        Next i
;         t+"[/color]"
         ; ==========================================================================
      Case 6
      Case 7
      Case #H_Fade_Color1  
         ; ==========================================================================
         For i= 0 To a-1
            RS= GetGadgetItemText(#InputText, i, 0)
            IF l<Len(RS): l=Len(RS): ENDIF
            CR=(255-R)/l
            CG=(255-G)/l
            CCB=(255-B)/l
            For j= 0 To l-1 ; Step 2
               IF Mid(RS,j+1,1)<>" "
                  t+ "[color=#"+RSet(Hex(R+CR*j),2,"0")+RSet(Hex(G+CG*j),2,"0")+RSet(Hex(B+CCB*j),2,"0")+"]"
                  t+ Mid(RS,j+1,1) 
         t+"[/color]"
               ELSE
                  t+" "
               ENDIF
            Next j
            t+#CRLF$
         Next i
;         t+"[/color]"
         ; ==========================================================================
      Case 102
      Case #H_Gradient_2Color   ;  Horizontal Two color Morph
         ; ==========================================================================
         For j=0 To a-1
            RS= GetGadgetItemText(#InputText, j, 0)
            IF l<Len(RS): l=Len(RS): ENDIF
            
            For i=0 To l-1
               MR=(R*((l-i-1)/l))+R2*((i)/(l-1))/2
               MG=(G*((l-i-1)/l))+G2*((i)/(l-1))/2
               MB=(B*((l-i-1)/l))+B2*((i)/(l-1))/2
               IF Mid(RS,i+1,1)<>" "
                  t+ "[color=#"+RSet(Hex(MR),2,"0")+RSet(Hex(MG),2,"0")+RSet(Hex(MB),2,"0")+"]"
                  t+ Mid(RS,i+1,1) 
         t+"[/color]"
               ELSE
                  t+" "
               ENDIF 
            Next i
            t+#CRLF$
         Next j
;         t+"[/color]"
         ; ==========================================================================
      Case #H_Rainbow_Color  
         ; ==========================================================================         
         For j=0 To a-1
            RS= GetGadgetItemText(#InputText, j, 0)
            IF l<Len(RS): l=Len(RS): ENDIF       ; take the longest for ever line

            Rain=Int(l/3)
            
            For i=0 To Rain 
               MR=255*((Rain-i)/Rain)   ;begin full red to reduce to no red at position 1/3
               MG=255*(i/Rain)          ; increace
               MB=0
               IF Mid(RS,i+1,1)<>" "
                  t+ "[color=#"+RSet(Hex(MR),2,"0")+RSet(Hex(MG),2,"0")+RSet(Hex(MB),2,"0")+"]"
                  t+ Mid(RS,i+1,1) 
         t+"[/color]"
               ELSE
                  t+" "
               ENDIF 
            Next i
            
            rain2=Rain+Rain ; second rain
            
            For i=Rain+1 To rain2 
               MR=0;(R*((a-i-1)/a))+R2*((i)/(a-1))/2
               MG=255*((rain2-i+1)/Rain)  ; reduce
               MB=255*((i-Rain-1)/Rain)   ; increace
               IF Mid(RS,i+1,1)<>" "
                  t+ "[color=#"+RSet(Hex(MR),2,"0")+RSet(Hex(MG),2,"0")+RSet(Hex(MB),2,"0")+"]"
                  t+ Mid(RS,i+1,1) 
         t+"[/color]"
               ELSE
                  t+" "
               ENDIF 
            Next i
            
            rain3=rain2+Rain
            
            For i=rain2+1 To l-1
               MR=255*((i-rain2-1)/Rain)  ; increace
               MG= 0                      ; (G*((a-i-1)/a))+G2*((i)/(a-1))/2
               MB=255*((rain3-i+1)/Rain)  ; reduce
               IF Mid(RS,i+1,1)<>" "
                  t+ "[color=#"+RSet(Hex(MR),2,"0")+RSet(Hex(MG),2,"0")+RSet(Hex(MB),2,"0")+"]"
                  t+ Mid(RS,i+1,1) 
          t+"[/color]"
              ELSE
                  t+" "
               ENDIF 
            Next i
            
            t+Chr(13)+Chr(10)
         Next j
  ;       t+"[/color]"
         ; ==========================================================================
      Case #H_Random_Color  
         ; ==========================================================================         
         For j=0 To a-1
            RS= GetGadgetItemText(#InputText, j, 0)
            l=Len(RS)
            For i=0 To l-1
               IF Mid(RS,i+1,1)<>" "
                  t+ "[color=#"+RSet(Hex(Random(200)),2,"0")+RSet(Hex(Random(200)),2,"0")+RSet(Hex(Random(200)),2,"0")+"]"
                  t+ Mid(RS,i+1,1) 
         t+"[/color]"
               ELSE
                  t+" "
               ENDIF 
            Next i
            t+#CRLF$
         Next j
;         t+"[/color]"
         ; ==========================================================================         
   EndSelect
   
   ProcedureReturn t
   
EndProcedure

Procedure Preview_Html_Color(Style)
   OutText$ = Color_styler (Style)
   
   SetGadgetText(#RawColorCode, OutText$)
   SetClipboardText(OutText$)
   
   CreateFile(0,filename$,#PB_File_SharedWrite|#PB_File_SharedRead)
   
   previewText$=ReplaceString(OutText$,"[color","<font color")
   previewText$=ReplaceString(previewText$,"[/color]","</font>")
   previewText$=ReplaceString(previewText$,"]",">")
   previewText$=ReplaceString(previewText$,Chr(13),"<br>")

   WriteString(0,HtmlHeader$+previewText$)
   CloseFile(0)
   
   SetGadgetText(#IEPreview , filename$)
   SetGadgetState(#IEPreview,#PB_Web_Refresh)
EndProcedure

;===========================================================================

IF FileSize(filename$)>0
   previewFile$ = filename$
ELSE
   previewFile$ = ""
ENDIF

IF OpenWindow(0, 100, 100, 780, 580, #AppTitle$+" ---  By atmori y2006 m11 d24",#PB_Window_MinimizeGadget)
   IF CreatePopupMenu(0)  
      MenuItem(1, "Paste")   
      MenuItem(2, "Copy")
      MenuBar()
      MenuItem(3,"Vertical gradient  Dark to Light")
      MenuItem(4,"Holizotal gradient Dark to Light")
      MenuBar()
      MenuItem(5,"Vertical Two Color gradient  Morph")
      MenuItem(6,"Horizontal Two Color gradient  Morph")
      MenuBar()
      MenuItem(7,"Vertical Rainbow Color ")
      MenuItem(8,"Horizontal Rainbow Color")
      MenuBar()
      MenuItem(9," | Vertical Random Color ")
      MenuItem(10," -- Horizontal Random Color")
      MenuBar()
      MenuItem(11,"Use Sample Text")
      MenuBar()
   ENDIF
   
   ; --------------
   TextGadget(#Label1,5,0,100,20,"INPUT TEXT :" )
   EditorGadget(#InputText, 8, 20, 500, 120) 
   SetGadgetColor(#InputText,#PB_Gadget_BackColor,RGB($DC,$F1,$FC))
   ; --------------
   TextGadget(#Label2,5,150,100,20,"BB CODE :")
   EditorGadget(#RawColorCode, 8,170 , 500, 100) 
   ; --------------    
   TextGadget(#Label3,5,280,100,20,"IE PREVIEW :")
   
   WebGadget(#IEPreview,5,300,770,250,previewFile$)
   
   HyperLinkGadget(#Color1,550,25,70,70,"Start",0)
   SetGadgetColor(#Color1,#PB_Gadget_BackColor,StartColor)
   
   HyperLinkGadget(#Color2,650,25,70,70,"END",0)
   SetGadgetColor(#Color2,#PB_Gadget_BackColor,EndColor)
   
   TextGadget(#PB_Any,  550, 105, 200, 25, "Click on color box to set color")
   TextGadget(#PB_Any,  550, 150, 200, 25, "Menu: Use Right mouse popup menu ")
   
   Repeat
      Select WaitWindowEvent()   
         Case #WM_RBUTTONDOWN   
            DisplayPopupMenu(0, WindowID(0)) 
            
         Case #PB_Event_Gadget
            Select EventGadget()
               Case #Color1   ; set start Color 
                  ac=ColorRequester(StartColor)
                  IF ac>-1:StartColor=ac:ENDIF
                  SetGadgetColor(#Color1,#PB_Gadget_BackColor,StartColor)
               Case #Color2   ; set End Color 
                  ac=ColorRequester(EndColor)
                  IF ac>-1:EndColor=ac:ENDIF
                  SetGadgetColor(#Color2,#PB_Gadget_BackColor,EndColor)
            EndSelect
            
         Case #PB_Event_Menu
            Select EventMenu()
               Case 1
                  SetGadgetText(#InputText, GetClipboardText())
               Case 2
                  SetClipboardText( GetGadgetText(#RawColorCode))
               Case 3
                  Preview_Html_Color(#V_Fade_Color1)
               Case 4 
                  Preview_Html_Color(#H_Fade_Color1)
               Case 5
                  Preview_Html_Color(#V_Gradient_2Color)
               Case 6
                  Preview_Html_Color(#H_Gradient_2Color)
               Case 7
                  Preview_Html_Color(#V_Rainbow_Color)
               Case 8
                  Preview_Html_Color(#H_Rainbow_Color)
               Case 9 
                  Preview_Html_Color(#V_Random_Color)
               Case 10
                  Preview_Html_Color(#H_Random_Color)
               Case 11
                  ClearGadgetItems(#InputText)
                  For i= 1 To 10 
                     AddGadgetItem(#InputText,i,#AppTitle$+" SAMPLE TEXT "+Str(i))
                  Next i
            EndSelect
            
         Case #PB_Event_CloseWindow
            End
      EndSelect
   ForEver
ENDIF

End


   
moricode
User
User
Posts: 94
Joined: Thu May 25, 2023 3:55 am

Re: Fantasy text color in webgadget and forum

Post by moricode »

BarryG
Addict
Addict
Posts: 3330
Joined: Thu Apr 18, 2019 8:17 am

Re: Fantasy text color in webgadget and forum

Post by BarryG »

Looks good, thanks!
Post Reply