2017-10-20 02:00:49 +00:00
|
|
|
Class KFGUI_TextLable extends KFGUI_Base;
|
|
|
|
|
|
|
|
var() protected string Text;
|
|
|
|
var() color TextColor;
|
|
|
|
var() Canvas.FontRenderInfo TextFontInfo;
|
|
|
|
var() byte FontScale,AlignX,AlignY; // Alignment, 0=Left/Up, 1=Center, 2=Right/Down
|
|
|
|
|
|
|
|
var transient Font InitFont;
|
|
|
|
var transient float OldSize[2],InitOffset[2],InitFontScale;
|
|
|
|
|
|
|
|
function InitSize()
|
|
|
|
{
|
|
|
|
local byte i;
|
|
|
|
local float XL,YL,TS;
|
|
|
|
|
|
|
|
OldSize[0] = CompPos[2];
|
|
|
|
OldSize[1] = CompPos[3];
|
|
|
|
|
|
|
|
i = Min(FontScale+Owner.CurrentStyle.DefaultFontSize,Owner.CurrentStyle.MaxFontScale);
|
2020-11-28 20:04:55 +00:00
|
|
|
while(true)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
Canvas.Font = Owner.CurrentStyle.PickFont(i,TS);
|
2020-11-28 20:04:55 +00:00
|
|
|
if(TextFontInfo.bClipText)
|
2017-10-20 02:00:49 +00:00
|
|
|
Canvas.TextSize(Text,XL,YL,TS,TS);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Canvas.SetPos(0,0);
|
2020-11-28 20:04:55 +00:00
|
|
|
if(TS==1)
|
2017-10-20 02:00:49 +00:00
|
|
|
Canvas.StrLen(Text,XL,YL);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Canvas.SetClip(CompPos[2]/TS,CompPos[3]); // Hacky, since StrLen has no TextSize support.
|
|
|
|
Canvas.StrLen(Text,XL,YL);
|
|
|
|
XL*=TS;
|
|
|
|
YL*=TS;
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 20:04:55 +00:00
|
|
|
if(i==0 || (XL<(CompPos[2]*0.99) && YL<(CompPos[3]*0.99)))
|
2017-10-20 02:00:49 +00:00
|
|
|
break;
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
Canvas.SetClip(CompPos[0]+CompPos[2],CompPos[1]+CompPos[3]);
|
|
|
|
InitFont = Canvas.Font;
|
|
|
|
InitFontScale = TS;
|
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
switch(AlignX)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
InitOffset[0] = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
InitOffset[0] = FMax((CompPos[2]-XL)*0.5,0.f);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
InitOffset[0] = CompPos[2]-(XL+1);
|
|
|
|
}
|
2020-11-28 20:04:55 +00:00
|
|
|
switch(AlignY)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
InitOffset[1] = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
InitOffset[1] = FMax((CompPos[3]-YL)*0.5,0.f);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
InitOffset[1] = CompPos[3]-YL;
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 20:04:55 +00:00
|
|
|
function SetText(string S)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:04:55 +00:00
|
|
|
if(Text==S)
|
2017-10-20 02:00:49 +00:00
|
|
|
return;
|
|
|
|
Text = S;
|
|
|
|
OldSize[0] = -1; // Force to refresh.
|
|
|
|
}
|
|
|
|
final function string GetText()
|
|
|
|
{
|
|
|
|
return Text;
|
|
|
|
}
|
|
|
|
|
|
|
|
function DrawMenu()
|
|
|
|
{
|
2020-11-28 20:04:55 +00:00
|
|
|
if(Text=="")
|
2017-10-20 02:00:49 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Need to figure out best fitting font.
|
2020-11-28 20:04:55 +00:00
|
|
|
if(OldSize[0]!=CompPos[2] || OldSize[1]!=CompPos[3])
|
2017-10-20 02:00:49 +00:00
|
|
|
InitSize();
|
|
|
|
|
|
|
|
Canvas.Font = InitFont;
|
|
|
|
Canvas.SetPos(InitOffset[0],InitOffset[1]);
|
|
|
|
Canvas.DrawColor = TextColor;
|
|
|
|
Canvas.DrawText(Text,,InitFontScale,InitFontScale,TextFontInfo);
|
|
|
|
}
|
|
|
|
function bool CaptureMouse()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultproperties
|
|
|
|
{
|
|
|
|
Text="Label"
|
|
|
|
TextColor=(R=255,G=255,B=255,A=255)
|
|
|
|
TextFontInfo=(bClipText=false,bEnableShadow=true)
|
|
|
|
FontScale=1
|
|
|
|
bCanFocus=false
|
|
|
|
}
|