Core.Object | +--UWindow.UWindowBase | +--UWindow.UWindowWindow | +--UWindow.UWindowDialogControl | +--UWindow.UWindowTextAreaControl
Font
AbsoluteFont
int
BufSize
float
LastDrawTime
string
Prompt
TextArea[750]
UWindowVScrollBar
VertSB
Lines,
VisibleRows
bool
bCursor
bScrollOnResize
bScrollable
bShowCaret
void
AddText(string NewLine)
BeforePaint(Canvas C, float X, float Y)
Clear()
Created()
Paint(Canvas C, float X, float Y)
Resized()
SetAbsoluteFont(Font F)
SetPrompt(string NewPrompt)
SetScrollable(bool newScrollable)
00001 class UWindowTextAreaControl extends UWindowDialogControl; 00002 00003 var string TextArea[750]; 00004 var string Prompt; 00005 var int Font; 00006 var Font AbsoluteFont; 00007 var int BufSize; 00008 var int Head, Tail, Lines, VisibleRows; 00009 00010 var bool bCursor; 00011 var bool bScrollable; 00012 var bool bShowCaret; 00013 var bool bScrollOnResize; 00014 00015 var UWindowVScrollBar VertSB; 00016 var float LastDrawTime; 00017 00018 function Created() 00019 { 00020 Super.Created(); 00021 LastDrawTime = GetLevel().TimeSeconds; 00022 } 00023 00024 function SetScrollable(bool newScrollable) 00025 { 00026 bScrollable = newScrollable; 00027 if(newScrollable) 00028 { 00029 VertSB = UWindowVScrollbar(CreateWindow(class'UWindowVScrollbar', WinWidth-12, 0, 12, WinHeight)); 00030 VertSB.bAlwaysOnTop = True; 00031 } 00032 else 00033 { 00034 if (VertSB != None) 00035 { 00036 VertSB.Close(); 00037 VertSB = None; 00038 } 00039 } 00040 } 00041 00042 function BeforePaint( Canvas C, float X, float Y ) 00043 { 00044 Super.BeforePaint(C, X, Y); 00045 00046 if(VertSB != None) 00047 { 00048 VertSB.WinTop = 0; 00049 VertSB.WinHeight = WinHeight; 00050 VertSB.WinWidth = LookAndFeel.Size_ScrollbarWidth; 00051 VertSB.WinLeft = WinWidth - LookAndFeel.Size_ScrollbarWidth; 00052 } 00053 } 00054 00055 function SetAbsoluteFont(Font F) 00056 { 00057 AbsoluteFont = F; 00058 } 00059 00060 function Paint( Canvas C, float X, float Y ) 00061 { 00062 local int i, j, Line; 00063 local int TempHead, TempTail; 00064 local float XL, YL; 00065 local float W, H; 00066 00067 if(AbsoluteFont != None) 00068 C.Font = AbsoluteFont; 00069 else 00070 C.Font = Root.Fonts[Font]; 00071 00072 C.DrawColor.R = 255; 00073 C.DrawColor.G = 255; 00074 C.DrawColor.B = 255; 00075 00076 TextSize(C, "TEST", XL, YL); 00077 VisibleRows = WinHeight / YL; 00078 00079 TempHead = Head; 00080 TempTail = Tail; 00081 Line = TempHead; 00082 TextArea[Line] = Prompt; 00083 00084 if(Prompt == "") 00085 { 00086 Line--; 00087 if(Line < 0) 00088 Line += BufSize; 00089 } 00090 00091 if(bScrollable) 00092 { 00093 if (VertSB.MaxPos - VertSB.Pos >= 0) 00094 { 00095 Line -= VertSB.MaxPos - VertSB.Pos; 00096 TempTail -= VertSB.MaxPos - VertSB.Pos; 00097 00098 if(Line < 0) 00099 Line += BufSize; 00100 if(TempTail < 0) 00101 TempTail += BufSize; 00102 } 00103 } 00104 00105 if(!bCursor) 00106 { 00107 bShowCaret = False; 00108 } 00109 else 00110 { 00111 if((GetLevel().TimeSeconds > LastDrawTime + 0.3) || (GetLevel().TimeSeconds < LastDrawTime)) 00112 { 00113 LastDrawTime = GetLevel().TimeSeconds; 00114 bShowCaret = !bShowCaret; 00115 } 00116 } 00117 00118 for(i=0; i<VisibleRows+1; i++) 00119 { 00120 ClipText(C, 2, WinHeight-YL*(i+1), TextArea[Line]); 00121 if(Line == Head && bShowCaret) 00122 { 00123 // Draw cursor.. 00124 TextSize(C, TextArea[Line], W, H); 00125 ClipText(C, W, WinHeight-YL*(i+1), "|"); 00126 } 00127 00128 if(TempTail == Line) 00129 break; 00130 00131 Line--; 00132 if(Line < 0) 00133 Line += BufSize; 00134 } 00135 } 00136 00137 function AddText(string NewLine) 00138 { 00139 local int i; 00140 00141 TextArea[Head] = NewLine; 00142 Head = (Head + 1)%BufSize; 00143 00144 if(Head == Tail) 00145 Tail = (Tail + 1)%BufSize; 00146 00147 // Calculate lines for scrollbar. 00148 Lines = Head - Tail; 00149 if(Lines < 0) 00150 Lines += BufSize; 00151 00152 if(bScrollable) 00153 { 00154 VertSB.SetRange(0, Lines, VisibleRows); 00155 VertSB.Pos = VertSB.MaxPos; 00156 } 00157 } 00158 00159 function Resized() 00160 { 00161 if(bScrollable) 00162 { 00163 VertSB.SetRange(0, Lines, VisibleRows); 00164 if(bScrollOnResize) 00165 VertSB.Pos = VertSB.MaxPos; 00166 } 00167 } 00168 00169 function SetPrompt(string NewPrompt) 00170 { 00171 Prompt = NewPrompt; 00172 } 00173 00174 function Clear() 00175 { 00176 TextArea[0] = ""; 00177 Head = 0; 00178 Tail = 0; 00179 } 00180 00181 defaultproperties 00182 { 00183 BufSize=750 00184 bScrollOnResize=True 00185 }