2022-09-03 17:26:40 +00:00
|
|
|
class KFGUI_TextLable extends KFGUI_Base;
|
2021-06-12 20:11:37 +00:00
|
|
|
|
2020-01-10 13:14:11 +00:00
|
|
|
var() protected string Text;
|
|
|
|
var() color TextColor;
|
|
|
|
var() Canvas.FontRenderInfo TextFontInfo;
|
2021-06-13 02:54:35 +00:00
|
|
|
var() byte AlignX, AlignY; // Alignment, 0=Left/Up, 1=Center, 2=Right/Down
|
2020-01-10 13:14:11 +00:00
|
|
|
var() float FontScale;
|
|
|
|
var() bool bUseOutline;
|
|
|
|
var() int OutlineSize;
|
|
|
|
|
|
|
|
var transient Font InitFont;
|
2021-06-13 02:54:35 +00:00
|
|
|
var transient float OldSize[2], InitOffset[2], InitFontScale;
|
2020-01-10 13:14:11 +00:00
|
|
|
|
|
|
|
function InitSize()
|
|
|
|
{
|
2021-06-13 02:54:35 +00:00
|
|
|
local float XL, YL, TS;
|
2020-01-10 13:14:11 +00:00
|
|
|
|
2021-05-16 09:40:02 +00:00
|
|
|
OldSize[0] = CompPos[2];
|
|
|
|
OldSize[1] = CompPos[3];
|
2020-01-10 13:14:11 +00:00
|
|
|
|
2021-05-16 09:40:02 +00:00
|
|
|
TS = Owner.CurrentStyle.GetFontScaler();
|
|
|
|
TS *= FontScale;
|
|
|
|
|
2021-06-13 03:00:19 +00:00
|
|
|
while (true)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
Canvas.Font = Owner.CurrentStyle.MainFont;
|
2021-06-13 02:53:33 +00:00
|
|
|
if (TextFontInfo.bClipText)
|
2021-06-13 02:54:35 +00:00
|
|
|
Canvas.TextSize(Text, XL, YL, TS, TS);
|
2021-05-16 09:40:02 +00:00
|
|
|
else
|
|
|
|
{
|
2021-06-13 02:54:35 +00:00
|
|
|
Canvas.SetPos(0, 0);
|
2021-06-13 02:53:33 +00:00
|
|
|
if (TS == 1)
|
2021-06-13 02:54:35 +00:00
|
|
|
Canvas.StrLen(Text, XL, YL);
|
2021-05-16 09:40:02 +00:00
|
|
|
else
|
|
|
|
{
|
2021-06-13 02:54:35 +00:00
|
|
|
Canvas.SetClip(CompPos[2]/TS, CompPos[3]); // Hacky, since StrLen has no TextSize support.
|
|
|
|
Canvas.StrLen(Text, XL, YL);
|
2021-05-16 09:40:02 +00:00
|
|
|
XL*=TS;
|
|
|
|
YL*=TS;
|
|
|
|
}
|
|
|
|
}
|
2021-06-13 02:53:33 +00:00
|
|
|
if ((XL < (CompPos[2]*0.99) && YL < (CompPos[3]*0.99)))
|
2021-05-16 09:40:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
TS -= 0.001;
|
|
|
|
}
|
2021-06-13 02:54:35 +00:00
|
|
|
Canvas.SetClip(CompPos[0]+CompPos[2], CompPos[1]+CompPos[3]);
|
2021-05-16 09:40:02 +00:00
|
|
|
InitFont = Canvas.Font;
|
|
|
|
InitFontScale = TS;
|
|
|
|
|
2021-06-13 03:00:19 +00:00
|
|
|
switch (AlignX)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
InitOffset[0] = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
2021-06-13 02:54:35 +00:00
|
|
|
InitOffset[0] = FMax((CompPos[2]-XL)*0.5, 0.f);
|
2021-05-16 09:40:02 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
InitOffset[0] = CompPos[2]-(XL+1);
|
|
|
|
}
|
2021-06-13 03:00:19 +00:00
|
|
|
switch (AlignY)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
InitOffset[1] = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
2021-06-13 02:54:35 +00:00
|
|
|
InitOffset[1] = FMax((CompPos[3]-YL)*0.5, 0.f);
|
2021-05-16 09:40:02 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
InitOffset[1] = CompPos[3]-YL;
|
|
|
|
}
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
2021-06-13 03:00:19 +00:00
|
|
|
function SetText(string S)
|
2020-01-10 13:14:11 +00:00
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (Text == S)
|
2021-05-16 09:40:02 +00:00
|
|
|
return;
|
|
|
|
Text = S;
|
|
|
|
OldSize[0] = -1; // Force to refresh.
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
final function string GetText()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
return Text;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function DrawMenu()
|
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (Text == "")
|
2021-05-16 09:40:02 +00:00
|
|
|
return;
|
2020-01-10 13:14:11 +00:00
|
|
|
|
2021-05-16 09:40:02 +00:00
|
|
|
// Need to figure out best fitting font.
|
2021-06-13 02:53:33 +00:00
|
|
|
if (OldSize[0] != CompPos[2] || OldSize[1] != CompPos[3])
|
2021-05-16 09:40:02 +00:00
|
|
|
InitSize();
|
2020-01-10 13:14:11 +00:00
|
|
|
|
2021-05-16 09:40:02 +00:00
|
|
|
Canvas.Font = InitFont;
|
|
|
|
Canvas.DrawColor = TextColor;
|
2021-06-13 02:53:33 +00:00
|
|
|
if (bUseOutline)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:54:35 +00:00
|
|
|
Owner.CurrentStyle.DrawTextShadow(Text, InitOffset[0], InitOffset[1], OutlineSize, InitFontScale);
|
2021-05-16 09:40:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-13 02:54:35 +00:00
|
|
|
Canvas.SetPos(InitOffset[0], InitOffset[1]);
|
|
|
|
Canvas.DrawText(Text, ,InitFontScale, InitFontScale, TextFontInfo);
|
2021-05-16 09:40:02 +00:00
|
|
|
}
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
function bool CaptureMouse()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
return false;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
defaultproperties
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
Text="Label"
|
2021-06-13 02:54:35 +00:00
|
|
|
TextColor=(R=255, G=255, B=255, A=255)
|
|
|
|
TextFontInfo=(bClipText=false, bEnableShadow=true)
|
2021-05-16 09:40:02 +00:00
|
|
|
FontScale=1.f
|
|
|
|
OutlineSize=1
|
|
|
|
bCanFocus=false
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|