UBrowser
Class UBrowserColorIRCTextArea

source: e:\games\UnrealTournament\UBrowser\Classes\UBrowserColorIRCTextArea.uc
Core.Object
   |
   +--UWindow.UWindowBase
      |
      +--UWindow.UWindowWindow
         |
         +--UWindow.UWindowDialogControl
            |
            +--UWindow.UWindowDynamicTextArea
               |
               +--UWindow.UWindowHTMLTextArea
                  |
                  +--UBrowser.UBrowserColorIRCTextArea
Direct Known Subclasses:None

class UBrowserColorIRCTextArea
extends UWindow.UWindowHTMLTextArea



Function Summary
 UWindowDynamicTextRow AddText(string Text)
     
// Converts to IRC codes to HTML and uses the HTML renderer.
// ***SLOW***
 string GetColorString(int Num)
 void LaunchUnrealURL(string URL)
 bool MultiInStr(string Text, string In, out int)
 void ProcessText(out string, out string, out byte, out byte, out byte)
 void RMouseUp(float X, float Y)



Source Code


00001	class UBrowserColorIRCTextArea expands UWindowHTMLTextArea;
00002	
00003	// Converts to IRC codes to HTML and uses the HTML renderer.
00004	// ***SLOW***
00005	
00006	function UWindowDynamicTextRow AddText(string Text)
00007	{
00008		local UWindowDynamicTextRow R;
00009		local string OutText, NextBlock;
00010		local byte BoldState, UnderlineState, ColorState;
00011		
00012		ReplaceText(Text, "&", "&");
00013		ReplaceText(Text, ">", ">");
00014		ReplaceText(Text, "<", "&lt;");
00015	
00016		OutText = "";
00017		while(Text != "")
00018		{
00019			ProcessText(Text, NextBlock, BoldState, UnderlineState, ColorState);
00020			OutText = OutText $ NextBlock;
00021		}
00022		
00023		if(BoldState != 0)
00024			OutText = OutText $ "</b>";
00025		if(UnderlineState != 0)
00026			OutText = OutText $ "</u>";
00027		if(ColorState != 0)
00028			OutText = OutText $ "</font>";
00029	
00030		R = Super.AddText(OutText);
00031		UBrowserIRCPageBase(OwnerWindow).AddedText();
00032		return R;
00033	}
00034	
00035	function LaunchUnrealURL(string URL)
00036	{
00037		Super.LaunchUnrealURL(URL);
00038	
00039		GetParent(class'UWindowFramedWindow').Close();
00040		Root.Console.CloseUWindow();
00041	}
00042	
00043	function RMouseUp(float X, float Y)
00044	{
00045		local UBrowserIRCPageBase P;
00046		local float GX, GY;
00047	
00048		P = UBrowserIRCPageBase(GetParent(class'UBrowserIRCPageBase'));
00049		WindowToGlobal(X, Y, GX, GY);
00050		P.GlobalToWindow(GX, GY, X, Y);
00051		P.RMouseUp(X, Y);
00052	}
00053	
00054	function ProcessText(out string Text, out string NextBlock, out byte BoldState, out byte UnderlineState, out byte ColorState)
00055	{
00056		local int i;
00057		local string FG, BG;
00058		local bool bColor, bUnderline, bBold, bNormal, bReverse;
00059	
00060		i = InStr(Text, "http://");
00061		MultiInStr(Text, "www.", i);
00062		MultiInStr(Text, "unreal://", i);
00063		MultiInStr(Text, "ftp://", i);
00064		MultiInStr(Text, "ftp.", i);
00065		MultiInStr(Text, "telnet://", i);
00066		bBold =  MultiInStr(Text, Chr(2), i);
00067		bColor = MultiInStr(Text, Chr(3), i);
00068		if(bColor)
00069			bBold = False;
00070		bNormal = MultiInStr(Text, Chr(15), i);
00071		if(bNormal)
00072		{
00073			bBold = False;
00074			bColor = False;
00075		}
00076		bReverse = MultiInStr(Text, Chr(22), i);
00077		if(bReverse)
00078		{
00079			bBold = False;
00080			bColor = False;
00081			bNormal = False;
00082		}
00083		bUnderline = MultiInStr(Text, Chr(31), i);
00084		if(bUnderline)
00085		{
00086			bBold = False;
00087			bColor = False;
00088			bNormal = False;
00089			bReverse = False;
00090		}
00091	
00092		if(i == -1)
00093		{
00094			NextBlock = Text;
00095			Text = "";
00096		}
00097		else
00098		if(i == 0)
00099		{
00100			if(bUnderline || bBold || bNormal || bReverse)
00101				i = 1;
00102			else
00103			if(bColor)
00104			{
00105				for(i = 1;i<Len(Text);i++)
00106					if(InStr(",0123456789", Mid(Text, i, 1)) == -1)
00107						break;
00108				if(i == Len(Text))
00109					i = -1;
00110			}
00111			else
00112			{
00113				i = InStr(Text, " ");
00114				MultiInStr(Text, Chr(2), i);
00115				MultiInStr(Text, Chr(3), i);
00116				MultiInStr(Text, Chr(15), i);
00117				MultiInStr(Text, Chr(31), i);
00118			}
00119			if(i == -1)
00120			{
00121				NextBlock = Text;
00122				Text = "";
00123			}
00124			else
00125			{
00126				NextBlock = Left(Text, i);
00127				Text = Mid(Text, i);
00128			}				
00129	
00130			if(bColor)
00131			{
00132				NextBlock = Mid(NextBlock, 1);
00133				if(NextBlock == "")
00134				{
00135					if(ColorState != 0)
00136						NextBlock = "</font>";
00137					ColorState = 0;
00138				}
00139				else
00140				{
00141					ColorState = 1;
00142					i = InStr(NextBlock, ",");
00143					if(i == -1)
00144						FG = GetColorString(Int(NextBlock));
00145					else
00146					{
00147						FG = GetColorString(Int(Left(NextBlock, i)));
00148						BG = GetColorString(Int(Mid(NextBlock, i + 1)));
00149					}
00150					if(FG == "")
00151						FG = "#ffffff";
00152					if(BG == "")
00153						NextBlock = "<font color="$FG$">";
00154					else
00155						NextBlock = "<font color="$FG$" bgcolor="$BG$">";
00156				}
00157			}
00158			else if(bUnderline)
00159			{
00160				if(UnderlineState != 0)
00161					NextBlock = "</u>";	
00162				else
00163					NextBlock = "<u>";
00164				UnderlineState = 1-UnderlineState;
00165			}
00166			else
00167			if(bBold)
00168			{
00169				if(BoldState != 0)
00170					NextBlock = "</b>";	
00171				else
00172					NextBlock = "<b>";
00173				BoldState = 1-BoldState;
00174				
00175			}
00176			else
00177			if(bNormal)
00178			{
00179				NextBlock = "";
00180				if(BoldState != 0)
00181					NextBlock = "</b>";	
00182				BoldState = 0;
00183				if(UnderlineState != 0)
00184					NextBlock = "</b>";	
00185				UnderlineState = 0;
00186				if(ColorState != 0)
00187					NextBlock = "</font>";	
00188				ColorState = 0;
00189			}
00190			else
00191			if(bReverse)
00192			{
00193				if(ColorState != 0)
00194					NextBlock = "</font>";
00195				else
00196					NextBlock = "<font color=#000000 bgcolor=#ffffff>";
00197				ColorState = 1 - ColorState;
00198			}
00199			else
00200				NextBlock = "<a href=\""$NextBlock$"\">"$NextBlock$"</a>";
00201		}
00202		else
00203		{
00204			NextBlock = Left(Text, i);
00205			Text = Mid(Text, i);
00206		}
00207	}
00208	
00209	function bool MultiInStr(string Text, string In, out int i)
00210	{
00211		local int j;
00212	
00213		j = InStr(Text, In);
00214		if(i == -1 || j == -1)
00215			i = Max(i, j);
00216		else
00217			i = Min(i, j);
00218	
00219		return j!=-1 && i==j;
00220	}
00221	
00222	function string GetColorString(int Num)
00223	{
00224		switch(Num)
00225		{
00226		case 0:return "#ffffff"; 
00227		case 1:return "#000000"; 
00228		case 2:return "#0000ff"; 
00229		case 3:return "#00ff00"; 
00230		case 4:return "#ff0000"; 
00231		case 5:return "#7f0000"; 
00232		case 6:return "#7f007f"; 
00233		case 7:return "#ff7f00"; 
00234		case 8:return "#ffff00"; 
00235		case 9:return "#00ff00"; 
00236		case 10:return "#00ffff"; 
00237		case 11:return "#00ffff"; 
00238		case 12:return "#0000ff"; 
00239		case 13:return "#ff00ff"; 
00240		case 13:return "#ff00ff"; 
00241		case 14:return "#7f7f7f"; 
00242		case 15:return "#c0c0c0"; 
00243		}
00244		return "";
00245	}
00246	
00247	defaultproperties
00248	{
00249	     MaxLines=500
00250	     bTopCentric=False
00251	     bVariableRowHeight=False
00252	}

End Source Code