Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dim infoText as string = "TextHighlight version 1.0.2"
- dim oldText as string
- dim console as string
- dim color_mode as array[String]
- dim geomId as string
- dim baseColor, color1, color2, color3 as color
- dim char1, char2, char3 as string
- color_mode.Push(" Disabled ")
- color_mode.Push(" Text ")
- sub OnInitParameters()
- RegisterInfoText(infoText)
- RegisterParameterText("console", "", 500, 100)
- RegisterRadioButton("ColoringOn", "Coloring ", 0, color_mode)
- RegisterParameterColor("baseColor", "Base Color", CColor(1.0, 1.0, 1.0, 1.0))
- RegisterParameterString("char_1", "Character 1", "@", 15, 15, "")
- RegisterParameterColor("color_1", "Color 1", CColor(1.0, 1.0, 1.0, 1.0))
- RegisterParameterString("char_2", "Character 2", "#", 15, 15, "")
- RegisterParameterColor("color_2", "Color 2", CColor(1.0, 1.0, 1.0, 1.0))
- RegisterParameterString("char_3", "Character 3", "http", 15, 15, "")
- RegisterParameterColor("color_3", "Color 3", CColor(1.0, 1.0, 1.0, 1.0))
- end sub
- sub OnGuiStatus()
- select case GetParameterInt("ColoringOn")
- case 0
- SendGuiParameterShow("baseColor", HIDE)
- SendGuiParameterShow("char_1", HIDE)
- SendGuiParameterShow("color_1", HIDE)
- SendGuiParameterShow("char_2", HIDE)
- SendGuiParameterShow("color_2", HIDE)
- SendGuiParameterShow("char_3", HIDE)
- SendGuiParameterShow("color_3", HIDE)
- case 1
- SendGuiParameterShow("baseColor", SHOW)
- SendGuiParameterShow("char_1", SHOW)
- SendGuiParameterShow("color_1", SHOW)
- SendGuiParameterShow("char_2", SHOW)
- SendGuiParameterShow("color_2", SHOW)
- SendGuiParameterShow("char_3", SHOW)
- SendGuiParameterShow("color_3", SHOW)
- end select
- end sub
- sub OnParameterChanged(parameterName As String)
- select case parameterName
- case "console"
- this.Geometry.Text = GetParameterString("console")
- end select
- ColorChars()
- end sub
- sub OnExecPerField()
- dim changed = false
- dim newText = this.Geometry.Text
- if newText <> oldText then
- oldText = newText
- changed = true
- end if
- if changed then
- this.ScriptPluginInstance.SetParameterString("console",newText)
- end if
- end sub
- sub OnInit()
- console = GetParameterString("console")
- if (console <> "") then
- this.Geometry.RegisterChangedCallback()
- ColorChars()
- end if
- end sub
- sub OnGeometryChanged(geom As Geometry)
- ColorChars()
- end sub
- sub ColorChars()
- select case GetParameterInt("ColoringOn")
- case 0
- baseColor = CColor(1.0, 1.0, 1.0, 1.0)
- color1 = CColor(1.0, 1.0, 1.0, 1.0)
- color2 = CColor(1.0, 1.0, 1.0, 1.0)
- color3 = CColor(1.0, 1.0, 1.0, 1.0)
- char1 = ""
- char2 = ""
- char3 = ""
- case 1
- baseColor = GetParameterColor("baseColor")
- color1 = GetParameterColor("color_1")
- color2 = GetParameterColor("color_2")
- color3 = GetParameterColor("color_3")
- char1 = GetParameterString("char_1")
- char2 = GetParameterString("char_2")
- char3 = GetParameterString("char_3")
- end select
- geomId = "#" & this.Geometry.VizId
- dim text = this.Geometry.Text
- dim lines as Array[String]
- text.split("\r\n", lines)
- dim lineCount = 0
- for each line in lines
- dim colorChar1 = false
- dim colorChar2 = false
- dim colorChar3 = false
- dim bytePos = 0
- dim i = 0
- do while bytePos < Len(line)
- dim charLen = 1
- dim ch2 as string = ""
- if bytePos + 1 < Len(line) then
- ch2 = line.GetSubstring(bytePos, 2)
- end if
- dim char as string = line.GetSubstring(bytePos, 1)
- if IsDoubleByteChar(ch2) then
- char = ch2
- charLen = 2
- end if
- dim target = lineCount + 1 & "." & i
- ApplyColor(target, baseColor)
- if char = " " then
- colorChar1 = false
- colorChar2 = false
- colorChar3 = false
- elseif bytePos + Len(char1) <= Len(line) and line.GetSubstring(bytePos, Len(char1)) = char1 then
- colorChar1 = true
- elseif bytePos + Len(char2) <= Len(line) and line.GetSubstring(bytePos, Len(char2)) = char2 then
- colorChar2 = true
- elseif bytePos + Len(char3) <= Len(line) and line.GetSubstring(bytePos, Len(char3)) = char3 then
- colorChar3 = true
- end if
- if colorChar1 then
- ApplyColor(target, color1)
- elseif colorChar2 then
- ApplyColor(target, color2)
- elseif colorChar3 then
- ApplyColor(target, color3)
- end if
- bytePos = bytePos + charLen
- i = i + 1
- loop
- lineCount = lineCount + 1
- next
- end sub
- sub ApplyColor(target as String, color as color)
- System.SendCommand(geomId & "*PROP*COLOR SET " & target & " " & ColorToText(color))
- System.SendCommand(geomId & "*PROP*ALPHA SET " & target & " " & AlphaToText(color))
- end sub
- function IsDoubleByteChar(char as String) as Boolean
- dim utf2Chars as array[string]
- utf2Chars.Push("á")
- utf2Chars.Push("ä")
- utf2Chars.Push("č")
- utf2Chars.Push("ď")
- utf2Chars.Push("é")
- utf2Chars.Push("í")
- utf2Chars.Push("ĺ")
- utf2Chars.Push("ľ")
- utf2Chars.Push("ň")
- utf2Chars.Push("ó")
- utf2Chars.Push("ô")
- utf2Chars.Push("ŕ")
- utf2Chars.Push("š")
- utf2Chars.Push("ť")
- utf2Chars.Push("ú")
- utf2Chars.Push("ý")
- utf2Chars.Push("ž")
- utf2Chars.Push("ě")
- utf2Chars.Push("ů")
- utf2Chars.Push("Á")
- utf2Chars.Push("Ä")
- utf2Chars.Push("Č")
- utf2Chars.Push("Ď")
- utf2Chars.Push("É")
- utf2Chars.Push("Í")
- utf2Chars.Push("Ĺ")
- utf2Chars.Push("Ľ")
- utf2Chars.Push("Ň")
- utf2Chars.Push("Ó")
- utf2Chars.Push("Ô")
- utf2Chars.Push("Ŕ")
- utf2Chars.Push("Š")
- utf2Chars.Push("Ť")
- utf2Chars.Push("Ú")
- utf2Chars.Push("Ý")
- utf2Chars.Push("Ž")
- utf2Chars.Push("Ě")
- utf2Chars.Push("Ů")
- for i = 0 to utf2Chars.ubound
- if char = utf2Chars[i] then
- IsDoubleByteChar = true
- exit function
- end if
- next
- IsDoubleByteChar = false
- end function
- function ColorToText(ccolor as color) as String
- ColorToText = cStr(ccolor.red) & " " & cStr(ccolor.green) & " " & cStr(ccolor.blue)
- end function
- function AlphaToText(ccolor as color) as String
- AlphaToText = cStr(ccolor.alpha * 100)
- end function
Add Comment
Please, Sign In to add comment