-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFLabel.uc
232 lines (193 loc) · 4.83 KB
/
FLabel.uc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/* ========================================================
* Copyright 2012-2013 Eliot van Uytfanghe
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ========================================================
* FLabel: A rich featured text component.
* ======================================================== */
class FLabel extends FComponent;
/* LIST OF FONTS
Font'EngineFonts.SmallFont'
Font'EngineFonts.TinyFont'
MultiFont'UI_Fonts.MultiFonts.MF_HugeFont'
MultiFont'UI_Fonts.MultiFonts.MF_HudSmall'
MultiFont'UI_Fonts_Final.HUD.MF_Medium'
*/
var(Label, Display) privatewrite string Text;
var deprecated Color TextColor;
var deprecated Font TextFont;
var deprecated const FontRenderInfo TextRenderInfo;
var deprecated const Vector2D TextFontScaling;
var(Label, Display) enum EDecoration
{
D_None,
D_Underlined,
D_Overlined
} TextDecoration;
var(Label, Display) int TextDecorationSize;
var(Label, Display) Color TextDecorationColor;
var(Label, Display) enum EHAlign
{
TA_Left,
TA_Center,
TA_Right
} TextAlign;
var(Label, Display) enum EVAlign
{
TA_Top,
TA_Center,
TA_Bottom
} TextVAlign;
var(Label, Positioning) Vector2D RelativeOffset;
var(Label, Positioning) bool bAutoSize;
var private bool bAutoSized;
delegate OnTextChanged( FComponent sender );
function Free()
{
super.Free();
OnTextChanged = none;
}
protected function InitializeComponent()
{
super.InitializeComponent();
if( Text != "" )
{
LocalizeText();
}
}
final private function LocalizeText()
{
const LOCALIZEDTAG = "@";
local int idx;
local array<string> group;
local string s;
idx = InStr( Text, LOCALIZEDTAG );
if( idx != INDEX_NONE )
{
s = Mid( Text, idx + Len( LOCALIZEDTAG ) );
group = SplitString( s, "." );
Text = Localize( group[1], group[2], group[0] );
}
}
final function int GetCharacterIndexAt( float charPosX )
{
local int xl, yl;
local int i, charIndex;
local string s;
charIndex = INDEX_NONE;
if( charPosX >= 0.0 )
{
for( i = 0; i < Len( Text ); ++ i )
{
s = Left( Text, i );
FLabelStyle(Style).TextFont.GetStringHeightAndWidth( s, yl, xl );
if( charPosX >= xl )
{
charIndex = i + 1;
}
}
}
return charIndex;
}
protected function RenderComponent( Canvas C )
{
super.RenderComponent( C );
RenderLabel( C, PosX, PosY, SizeX, SizeY, FLabelStyle(Style).TextColor );
}
final protected function RenderLabel( Canvas C, float X, float Y, float W, float H, Color drawColor, optional out float XL, optional out float YL )
{
local float AX, AY;
// local float cX, cY;
local FLabelStyle sty;
sty = FLabelStyle(Style);
X += RelativeOffset.X;
Y += RelativeOffset.Y;
C.Font = sty.TextFont != none ? sty.TextFont : C.GetDefaultCanvasFont();
if( bClipComponent )
{
C.TextSize( Text, XL, YL );
}
else
{
C.StrLen( Text, XL, YL );
}
if( bAutoSize && !bAutoSized )
{
// ALT: XL/Parent.GetWidth() or just XL.
SetSize( XL/GetWidth()*RelativeSize.X, YL/GetHeight()*RelativeSize.Y );
bAutoSized = true;
}
switch( TextAlign )
{
case TA_Left:
AX = X;
break;
case TA_Center:
AX = X + W * 0.5 - XL * 0.5;
break;
case TA_Right:
AX = X + W - XL;
break;
}
switch( TextVAlign )
{
case TA_Top:
AY = Y;
break;
case TA_Center:
AY = (Y + H * 0.5 - YL * 0.5);
break;
case TA_Bottom:
AY = Y + H - YL;
break;
}
C.SetPos( AX, AY );
C.DrawColor = drawColor;
C.DrawText( Text, false, sty.TextFontScaling.X, sty.TextFontScaling.Y, sty.TextRenderInfo );
switch( TextDecoration )
{
case D_Underlined:
C.SetPos( AX, AY + YL - TextDecorationSize );
C.DrawColor = TextDecorationColor;
C.DrawRect( XL, TextDecorationSize, C.DefaultTexture );
break;
case D_Overlined:
C.SetPos( AX, AY + YL * 0.5 - TextDecorationSize * 0.5 );
C.DrawColor = TextDecorationColor;
C.DrawRect( XL, TextDecorationSize, C.DefaultTexture );
break;
}
}
function SetText( coerce string newText )
{
Text = newText;
LocalizeText();
bAutoSized = false;
OnTextChanged( self );
}
defaultproperties
{
RelativePosition=(X=0.01,Y=0.01)
RelativeSize=(X=0.4,Y=0.18)
RelativeOffset=(X=0.0,Y=0.0)
Text="Label"
TextAlign=TA_Left
TextVAlign=TA_Center
TextDecorationSize=1
TextDecorationColor=(R=255,G=255,B=255,A=255)
bEnabled=`devmode
StyleNames.Add(Label)
StyleClass=class'FLabelStyle'
bEnableClick=false
bEnableCollision=false
}