KF2-YetAnotherScoreboard/YAS/Classes/KFGUI_Image.uc

146 lines
2.6 KiB
Ucode
Raw Normal View History

2020-01-10 13:14:11 +00:00
Class KFGUI_Image extends KFGUI_Base;
2021-06-12 20:11:37 +00:00
`include(Build.uci)
`include(Logger.uci)
2020-01-10 13:14:11 +00:00
var enum eImageStyle
{
ISTY_Normal,
ISTY_Stretched
2020-01-10 13:14:11 +00:00
} ImageStyle;
var enum eScaleStyle
{
ISTY_Height,
ISTY_Width
2020-01-10 13:14:11 +00:00
} ScaleStyle;
var Color ImageColor;
var Texture Image;
var bool bAlignCenter, bForceUniformSize;
2021-06-13 02:54:35 +00:00
var int X1, Y1, X2, Y2;
2020-01-10 13:14:11 +00:00
var float ImageScale;
function DrawMenu()
{
local float X, Y, XL, YL;
2021-06-13 02:53:33 +00:00
if (Image == None)
return;
DrawBackground(Canvas, CompPos[2], CompPos[3]);
Canvas.DrawColor = ImageColor;
switch (ImageStyle)
{
case ISTY_Normal:
2021-06-13 02:53:33 +00:00
if (X1 != -1)
X = X1;
else X = 0;
2021-06-13 02:53:33 +00:00
if (Y1 != -1)
Y = Y1;
else Y = 0;
2021-06-13 02:53:33 +00:00
if (bForceUniformSize)
{
2021-06-13 02:53:33 +00:00
if (ScaleStyle == ISTY_Height)
{
YL = CompPos[3];
XL = YL;
}
else
{
XL = CompPos[2];
YL = XL;
}
}
else
{
2021-06-13 02:53:33 +00:00
if (Y2 == -1)
YL = FMin(CompPos[3], Image.GetSurfaceHeight());
else YL = (Y2-Y1);
2021-06-13 02:53:33 +00:00
if (X2 == -1)
XL = FMin(CompPos[2], Image.GetSurfaceWidth());
else XL = (X2-X1);
}
2021-06-13 02:53:33 +00:00
if (bAlignCenter)
{
Canvas.SetPos((CompPos[2]/2) - (XL/2), (CompPos[3]/2) - (YL/2));
Canvas.DrawTile(Image, XL, YL, X, Y, Image.GetSurfaceWidth(), Image.GetSurfaceHeight());
}
else
{
Canvas.SetPos(0.f, 0.f);
Canvas.DrawTile(Image, XL, YL, X, Y, Image.GetSurfaceWidth(), Image.GetSurfaceHeight());
}
break;
case ISTY_Stretched:
2021-06-13 02:53:33 +00:00
if (X1 < 0 && X2 < 0 && Y1 < 0 && Y2 < 0 )
Owner.CurrentStyle.DrawTileStretched(Image, 0.f, 0.f, CompPos[2], CompPos[3]);
else
{
2021-06-13 02:53:33 +00:00
if (X1 != -1)
X = X1;
else X = 0;
2021-06-13 02:53:33 +00:00
if (Y1 != -1)
Y = Y1;
else Y = 0;
2021-06-13 02:53:33 +00:00
if (bForceUniformSize)
{
2021-06-13 02:53:33 +00:00
if (ScaleStyle == ISTY_Height)
{
YL = CompPos[3];
XL = YL;
}
else
{
XL = CompPos[2];
YL = XL;
}
}
else
{
2021-06-13 02:53:33 +00:00
if (Y2 == -1)
YL = FMin(CompPos[3], Image.GetSurfaceHeight());
else YL = (Y2-Y1);
2021-06-13 02:53:33 +00:00
if (X2 == -1)
XL = FMin(CompPos[2], Image.GetSurfaceWidth());
else XL = (X2-X1);
}
2021-06-13 02:53:33 +00:00
if (bAlignCenter)
{
Canvas.SetPos((CompPos[2]/2) - (XL/2), (CompPos[3]/2) - (YL/2));
Canvas.DrawTile(Image, CompPos[2], CompPos[3], X, Y, Image.GetSurfaceWidth(), Image.GetSurfaceHeight());
}
else
{
Canvas.SetPos(0.f, 0.f);
Canvas.DrawTile(Image, CompPos[2], CompPos[3], X, Y, Image.GetSurfaceWidth(), Image.GetSurfaceHeight());
}
break;
}
break;
}
2020-01-10 13:14:11 +00:00
}
delegate DrawBackground(Canvas C, float W, Float H);
defaultproperties
{
2021-06-13 02:54:35 +00:00
ImageColor=(R=255, G=255, B=255, A=255)
ImageStyle=ISTY_Normal
X1=-1
X2=-1
Y1=-1
Y2=-1
2020-01-10 13:14:11 +00:00
}