vizrtexample

TextHighlight version 1.0.2

Jun 17th, 2024 (edited)
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. dim infoText as string = "TextHighlight version 1.0.2"
  2. dim oldText as string
  3. dim console as string
  4. dim color_mode as array[String]
  5. dim geomId as string
  6. dim baseColor, color1, color2, color3 as color
  7. dim char1, char2, char3 as string
  8.  
  9. color_mode.Push("    Disabled    ")
  10. color_mode.Push("      Text      ")
  11.  
  12. sub OnInitParameters()
  13.     RegisterInfoText(infoText)
  14.     RegisterParameterText("console", "", 500, 100)
  15.     RegisterRadioButton("ColoringOn", "Coloring           ", 0, color_mode)  
  16.     RegisterParameterColor("baseColor", "Base Color", CColor(1.0, 1.0, 1.0, 1.0))
  17.     RegisterParameterString("char_1", "Character 1", "@", 15, 15, "")
  18.     RegisterParameterColor("color_1", "Color 1", CColor(1.0, 1.0, 1.0, 1.0))
  19.     RegisterParameterString("char_2", "Character 2", "#", 15, 15, "")
  20.     RegisterParameterColor("color_2", "Color 2", CColor(1.0, 1.0, 1.0, 1.0))
  21.     RegisterParameterString("char_3", "Character 3", "http", 15, 15, "")
  22.     RegisterParameterColor("color_3", "Color 3", CColor(1.0, 1.0, 1.0, 1.0))  
  23. end sub
  24.  
  25. sub OnGuiStatus()
  26.     select case GetParameterInt("ColoringOn")  
  27.         case 0
  28.             SendGuiParameterShow("baseColor", HIDE)
  29.             SendGuiParameterShow("char_1", HIDE)
  30.             SendGuiParameterShow("color_1", HIDE)
  31.             SendGuiParameterShow("char_2", HIDE)
  32.             SendGuiParameterShow("color_2", HIDE)
  33.             SendGuiParameterShow("char_3", HIDE)
  34.             SendGuiParameterShow("color_3", HIDE)
  35.         case 1
  36.             SendGuiParameterShow("baseColor", SHOW)
  37.             SendGuiParameterShow("char_1", SHOW)
  38.             SendGuiParameterShow("color_1", SHOW)
  39.             SendGuiParameterShow("char_2", SHOW)
  40.             SendGuiParameterShow("color_2", SHOW)
  41.             SendGuiParameterShow("char_3", SHOW)
  42.             SendGuiParameterShow("color_3", SHOW)
  43.     end select
  44. end sub
  45.  
  46. sub OnParameterChanged(parameterName As String)
  47.     select case parameterName
  48.         case "console"
  49.             this.Geometry.Text = GetParameterString("console")
  50.         end select
  51.     ColorChars()
  52. end sub
  53.  
  54. sub OnExecPerField()
  55.     dim changed = false
  56.     dim newText = this.Geometry.Text
  57.     if newText <> oldText then
  58.         oldText = newText
  59.         changed = true
  60.     end if  
  61.     if changed then
  62.         this.ScriptPluginInstance.SetParameterString("console",newText)
  63.     end if
  64. end sub
  65.  
  66. sub OnInit()
  67.     console = GetParameterString("console")
  68.     if (console <> "") then
  69.         this.Geometry.RegisterChangedCallback()
  70.         ColorChars()
  71.     end if  
  72. end sub
  73.  
  74. sub OnGeometryChanged(geom As Geometry)
  75.     ColorChars()  
  76. end sub
  77.  
  78. sub ColorChars()
  79.     select case GetParameterInt("ColoringOn")
  80.         case 0
  81.             baseColor = CColor(1.0, 1.0, 1.0, 1.0)
  82.             color1 = CColor(1.0, 1.0, 1.0, 1.0)
  83.             color2 = CColor(1.0, 1.0, 1.0, 1.0)
  84.             color3 = CColor(1.0, 1.0, 1.0, 1.0)
  85.             char1 = ""
  86.             char2 = ""
  87.             char3 = ""
  88.         case 1
  89.             baseColor = GetParameterColor("baseColor")
  90.             color1 = GetParameterColor("color_1")
  91.             color2 = GetParameterColor("color_2")
  92.             color3 = GetParameterColor("color_3")
  93.             char1 = GetParameterString("char_1")
  94.             char2 = GetParameterString("char_2")
  95.             char3 = GetParameterString("char_3")
  96.     end select
  97.  
  98.     geomId = "#" & this.Geometry.VizId
  99.     dim text = this.Geometry.Text
  100.     dim lines as Array[String]
  101.     text.split("\r\n", lines)
  102.  
  103.     dim lineCount = 0
  104.  
  105.     for each line in lines
  106.         dim colorChar1 = false
  107.         dim colorChar2 = false
  108.         dim colorChar3 = false
  109.  
  110.         dim bytePos = 0
  111.         dim i = 0
  112.  
  113.         do while bytePos < Len(line)
  114.             dim charLen = 1
  115.             dim ch2 as string = ""
  116.             if bytePos + 1 < Len(line) then
  117.                 ch2 = line.GetSubstring(bytePos, 2)
  118.             end if
  119.  
  120.             dim char as string = line.GetSubstring(bytePos, 1)
  121.             if IsDoubleByteChar(ch2) then
  122.                 char = ch2
  123.                 charLen = 2
  124.             end if
  125.  
  126.             dim target = lineCount + 1 & "." & i
  127.             ApplyColor(target, baseColor)
  128.  
  129.             if char = " " then
  130.                colorChar1 = false
  131.                colorChar2 = false
  132.                colorChar3 = false
  133.             elseif bytePos + Len(char1) <= Len(line) and line.GetSubstring(bytePos, Len(char1)) = char1 then
  134.                colorChar1 = true
  135.             elseif bytePos + Len(char2) <= Len(line) and line.GetSubstring(bytePos, Len(char2)) = char2 then
  136.                colorChar2 = true
  137.             elseif bytePos + Len(char3) <= Len(line) and line.GetSubstring(bytePos, Len(char3)) = char3 then
  138.                colorChar3 = true
  139.             end if
  140.  
  141.             if colorChar1 then
  142.                ApplyColor(target, color1)
  143.             elseif colorChar2 then
  144.                ApplyColor(target, color2)
  145.             elseif colorChar3 then
  146.                ApplyColor(target, color3)
  147.             end if
  148.  
  149.             bytePos = bytePos + charLen
  150.             i = i + 1
  151.         loop
  152.  
  153.         lineCount = lineCount + 1
  154.     next
  155. end sub
  156.  
  157. sub ApplyColor(target as String, color as color)
  158.     System.SendCommand(geomId & "*PROP*COLOR SET " & target & " " & ColorToText(color))
  159.     System.SendCommand(geomId & "*PROP*ALPHA SET " & target & " " & AlphaToText(color))
  160. end sub
  161.  
  162. function IsDoubleByteChar(char as String) as Boolean
  163.     dim utf2Chars as array[string]
  164.     utf2Chars.Push("á")
  165.     utf2Chars.Push("ä")
  166.     utf2Chars.Push("č")
  167.     utf2Chars.Push("ď")
  168.     utf2Chars.Push("é")
  169.     utf2Chars.Push("í")
  170.     utf2Chars.Push("ĺ")
  171.     utf2Chars.Push("ľ")
  172.     utf2Chars.Push("ň")
  173.     utf2Chars.Push("ó")
  174.     utf2Chars.Push("ô")
  175.     utf2Chars.Push("ŕ")
  176.     utf2Chars.Push("š")
  177.     utf2Chars.Push("ť")
  178.     utf2Chars.Push("ú")
  179.     utf2Chars.Push("ý")
  180.     utf2Chars.Push("ž")
  181.     utf2Chars.Push("ě")
  182.     utf2Chars.Push("ů")
  183.     utf2Chars.Push("Á")
  184.     utf2Chars.Push("Ä")
  185.     utf2Chars.Push("Č")
  186.     utf2Chars.Push("Ď")
  187.     utf2Chars.Push("É")
  188.     utf2Chars.Push("Í")
  189.     utf2Chars.Push("Ĺ")
  190.     utf2Chars.Push("Ľ")
  191.     utf2Chars.Push("Ň")
  192.     utf2Chars.Push("Ó")
  193.     utf2Chars.Push("Ô")
  194.     utf2Chars.Push("Ŕ")
  195.     utf2Chars.Push("Š")
  196.     utf2Chars.Push("Ť")
  197.     utf2Chars.Push("Ú")
  198.     utf2Chars.Push("Ý")
  199.     utf2Chars.Push("Ž")
  200.     utf2Chars.Push("Ě")
  201.     utf2Chars.Push("Ů")
  202.  
  203.     for i = 0 to utf2Chars.ubound
  204.         if char = utf2Chars[i] then
  205.             IsDoubleByteChar = true
  206.             exit function
  207.         end if
  208.     next
  209.  
  210.     IsDoubleByteChar = false
  211. end function
  212.  
  213. function ColorToText(ccolor as color) as String
  214.     ColorToText = cStr(ccolor.red) & " " & cStr(ccolor.green) & " " & cStr(ccolor.blue)
  215. end function
  216.  
  217. function AlphaToText(ccolor as color) as String
  218.     AlphaToText = cStr(ccolor.alpha * 100)
  219. end function
  220.  
Add Comment
Please, Sign In to add comment