UTMenu
Class UTFadeTextArea

source: e:\games\UnrealTournament\UTMenu\Classes\UTFadeTextArea.uc
Core.Object
   |
   +--UWindow.UWindowBase
      |
      +--UWindow.UWindowWindow
         |
         +--UWindow.UWindowDialogControl
            |
            +--UWindow.UWindowTextAreaControl
               |
               +--UWindow.UWindowWrappedTextArea
                  |
                  +--UTMenu.UTFadeTextArea
Direct Known Subclasses:None

class UTFadeTextArea
extends UWindow.UWindowWrappedTextArea


Variables
 int CurrentPendingString
 float FadeFactor
 int FadeLines
 float FadeTime[32]
 font MyFont
 string PendingString[20]
 NumLines, PrintLines
 int ScrollingOffset
 bNowAutoScrolling, bMousePassThrough


Function Summary
 void AddString(Canvas C, int Index)
 void AddText(string S)
 void BeforePaint(Canvas C, float X, float Y)
 bool CheckMousePassThrough(float X, float Y)
 void Clear()
 void Created()
 bool LocalWrappedClipText(Canvas C, float X, float Y, int I, string S, optional bool, optional bool)
 void Paint(Canvas C, float X, float Y)
 void Tick(float Delta)



Source Code


00001	class UTFadeTextArea extends UWindowWrappedTextArea;
00002	
00003	var float FadeTime[32];
00004	var font MyFont;
00005	
00006	var int ScrollingOffset;
00007	var int NumLines, PrintLines;
00008	
00009	var bool bAutoScrolling, bNowAutoScrolling, bMousePassThrough;
00010	
00011	var int CurrentPendingString;
00012	var string PendingString[20];
00013	
00014	var int FadeLines;
00015	
00016	var float FadeFactor;
00017	
00018	function Created()
00019	{
00020		Super.Created();
00021	}
00022	
00023	function BeforePaint( Canvas C, float X, float Y)
00024	{
00025		local int i;
00026	
00027		C.Font = MyFont;
00028		for (i=0; i<20; i++)
00029		{
00030			if (PendingString[i] != "")
00031			{
00032				AddString(C, i);
00033				PendingString[i] = "";
00034			}
00035		}
00036	}
00037	
00038	function Paint( Canvas C, float X, float Y )
00039	{
00040		local int i, j, Line;
00041		local int TempHead, TempTail;
00042		local float XL, YL;
00043		local bool bNextLine;
00044	
00045		C.Font = MyFont;
00046		C.DrawColor = TextColor;
00047	
00048		TextSize(C, "TEST", XL, YL);
00049		VisibleRows = WinHeight / YL;
00050	
00051		TempHead = Head;
00052		TempTail = Tail;
00053		Line = TempTail + ScrollingOffset;
00054	
00055		bNextLine = True;
00056		for (i=0; i<NumLines; i++)
00057		{
00058			bNextLine = LocalWrappedClipText(C, 0, YL*i, Line, TextArea[Line], false, bNextLine);
00059			Line++;
00060		}
00061	
00062		if (bNowAutoScrolling)
00063		{
00064			if (FadeLines-1 == VisibleRows+ScrollingOffset)
00065				ScrollingOffset++;
00066		}
00067	
00068		C.DrawColor.R = 255;
00069		C.DrawColor.G = 255;
00070		C.DrawColor.B = 255;
00071	}
00072	
00073	function Tick(float Delta)
00074	{
00075		local int i;
00076	
00077		FadeLines = 0;
00078		// Update FadeTime
00079		for (i=0; i<NumLines; i++)
00080		{
00081			if (FadeTime[i] >= 0.0) {
00082				FadeLines++;
00083				FadeTime[i] += Delta*FadeFactor;
00084			} else if (FadeTime[i] == -2.0) {
00085				FadeLines++;
00086			}
00087		}
00088		if ((NumLines != 0) && (FadeTime[NumLines-1] == -2.0))
00089			bNowAutoScrolling = False;
00090	}
00091	
00092	function AddText(string S)
00093	{
00094		PendingString[CurrentPendingString] = S;
00095		CurrentPendingString++;
00096	}
00097	
00098	function AddString(Canvas C, int Index)
00099	{
00100		local string S, Out, Temp, Line;
00101		local int WordBoundary, TotalPos;
00102		local float W, H;
00103		local float X, Y;
00104		local float LineSize;
00105		local bool bSentry;
00106	
00107		S = PendingString[Index];
00108	
00109		// Early out for small lines.
00110		TextSize(C, S, X, Y);
00111		if (X < WinWidth)
00112		{
00113			NumLines++;
00114			Super.AddText(S);
00115			return;
00116		}
00117	
00118		// Cut up large lines.
00119		X = 0;
00120		bSentry = True;
00121		while( bSentry )
00122		{
00123			// Get the line to be drawn.
00124			if(Out == "")
00125				Out = S;
00126	
00127			// Find the word boundary.
00128			WordBoundary = InStr(Out, " ");
00129					
00130			// Get the current word.
00131			C.SetPos(0, 0);
00132			if(WordBoundary == -1)
00133				Temp = Out;
00134			else
00135				Temp = Left(Out, WordBoundary)$" ";
00136			TotalPos += WordBoundary;
00137	
00138			TextSize(C, Temp, W, H);
00139	
00140			if(W+X > WinWidth)
00141			{
00142				NumLines++;
00143				Super.AddText(Line);
00144				Line = "";
00145				X = 0;
00146			}
00147			Line = Line$Temp;
00148			X += W;
00149	
00150			Out = Mid(Out, Len(Temp));
00151			if (Out == "")
00152				bSentry = False;
00153		}
00154		NumLines++;
00155		Super.AddText(Line);
00156	}
00157	
00158	function bool LocalWrappedClipText(Canvas C, float X, float Y, int I, coerce string S, optional bool bCheckHotkey, optional bool bInitFadeTime)
00159	{
00160		local float FadeCount, X2, Y2, XL, YL;
00161		local int FadeChar, FadeLength;
00162	
00163		if (S == "")
00164			return true;
00165	
00166		C.Style = 3;
00167	
00168		if (FadeTime[I] == -1.0 && bInitFadeTime)
00169		{
00170			// If first update, just set the FadeTime to zero.
00171			FadeTime[I] = 0.0;
00172			return false;
00173		} else if (FadeTime[I] == -2.0) {
00174			ClipText(C, X, Y, S, bCheckHotKey);
00175			return true;
00176		}
00177	
00178		for ( FadeChar = 0; FadeTime[I] - (FadeChar * 0.1) > 0.0; FadeChar++ )
00179		{
00180			FadeCount = FadeTime[I] - (FadeChar * 0.1);
00181			if ((FadeChar == Len(S) - 1) && (255 * (1.0 - FadeCount) < 0))
00182				FadeTime[I] = -2.0;
00183	
00184			C.DrawColor.R = Min(255 * (0.0 + FadeCount), TextColor.R);
00185			C.DrawColor.G = Min(255 * (0.0 + FadeCount), TextColor.G);
00186			C.DrawColor.B = Min(255 * (0.0 + FadeCount), TextColor.B);
00187			ClipText(C, X+X2, Y+Y2, Mid(S, FadeChar, 1));
00188			TextSize(C, Left(S, FadeChar+1), XL, YL);
00189			X2 = XL;
00190	
00191			FadeLength = XL;
00192		}
00193		C.Style = 1;
00194		TextSize(C, S, XL, YL);
00195		if (XL == FadeLength)
00196			return true;
00197	
00198		return false;
00199	}
00200	
00201	function Clear()
00202	{
00203		local int i;
00204	
00205		Super.Clear();
00206		for (i=0; i<750; i++) {
00207			TextArea[i] = "";
00208		}
00209		for (i=0; i<32; i++) {
00210			FadeTime[i] = -1.0;
00211		}
00212	
00213		ScrollingOffset = 0;
00214	
00215		if (bAutoScrolling)
00216			bNowAutoScrolling = True;
00217	
00218		NumLines = 0;
00219		CurrentPendingString = 0;
00220	}
00221	
00222	function bool CheckMousePassThrough(float X, float Y)
00223	{
00224		if (bMousePassThrough)
00225			return True;
00226		else
00227			return False;
00228	}
00229	
00230	defaultproperties
00231	{
00232	     FadeTime(0)=-1.000000
00233	     FadeFactor=2.000000
00234	}

End Source Code