draw rect refactoring

This commit is contained in:
GenZmeY 2021-06-13 13:53:19 +03:00
parent 50ad0d6a97
commit 5c702007bd

View File

@ -19,6 +19,22 @@ var transient ScoreboardExtHUD HUDOwner;
var Font MainFont, NumberFont, InfiniteFont; var Font MainFont, NumberFont, InfiniteFont;
var Color BlurColor, BlurColor2; var Color BlurColor, BlurColor2;
enum ECornerPosition
{
ECP_TopLeft,
ECP_TopRight,
ECP_BottomLeft,
ECP_BottomRight
};
enum ECornerShape
{
ECS_Corner,
ECS_BeveledCorner,
ECS_VerticalCorner,
ECS_HorisontalCorner
};
struct FColorInfo struct FColorInfo
{ {
var name Code; var name Code;
@ -493,8 +509,146 @@ final function DrawWhiteBox(float XS, float YS, optional bool bClip)
Canvas.DrawTile(ItemTex, XS, YS, 19, 45, 1,1, ,bClip); Canvas.DrawTile(ItemTex, XS, YS, 19, 45, 1,1, ,bClip);
} }
final function DrawCornerSmart(int CornerPosition, int CornerShape, int Edge, out float X, out float Y, out int NeedFill)
{
switch (CornerPosition)
{
case ECP_TopLeft:
NeedFill = int(CornerShape != ECS_VerticalCorner);
switch (CornerShape)
{
case ECS_Corner:
Canvas.SetPos(X, Y);
DrawWhiteBox(Edge, Edge);
X = X + Edge;
Y = Y;
return;
case ECS_BeveledCorner:
Canvas.SetPos(X, Y);
DrawCornerTex(Edge, 0);
X = X + Edge;
Y = Y;
return;
case ECS_VerticalCorner:
Canvas.SetPos(X, Y - Edge);
DrawCornerTex(Edge, 1);
X = X + Edge;
Y = Y;
return;
case ECS_HorisontalCorner:
Canvas.SetPos(X - Edge, Y);
DrawCornerTex(Edge, 2);
X = X;
Y = Y;
return;
}
case ECP_TopRight:
NeedFill = int(false);
switch (CornerShape)
{
case ECS_Corner:
Canvas.SetPos(X, Y);
DrawWhiteBox(Edge, Edge);
X = X + Edge;
Y = Y;
return;
case ECS_BeveledCorner:
Canvas.SetPos(X, Y);
DrawCornerTex(Edge, 1);
X = X + Edge;
Y = Y + Edge;
return;
case ECS_VerticalCorner:
Canvas.SetPos(X, Y - Edge);
DrawCornerTex(Edge, 0);
X = X + Edge;
Y = Y;
return;
case ECS_HorisontalCorner:
Canvas.SetPos(X, Y);
DrawCornerTex(Edge, 3);
X = X + Edge;
Y = Y + Edge;
return;
}
case ECP_BottomLeft:
NeedFill = int(CornerShape != ECS_VerticalCorner);
switch (CornerShape)
{
case ECS_Corner:
Canvas.SetPos(X, Y);
DrawWhiteBox(Edge, Edge);
X = X + Edge;
Y = Y;
return;
case ECS_BeveledCorner:
Canvas.SetPos(X, Y);
DrawCornerTex(Edge, 2);
X = X + Edge;
Y = Y;
return;
case ECS_VerticalCorner:
Canvas.SetPos(X, Y);
DrawCornerTex(Edge, 3);
X = X + Edge;
Y = Y;
return;
case ECS_HorisontalCorner:
Canvas.SetPos(X - Edge, Y);
DrawCornerTex(Edge, 0);
X = X;
Y = Y;
return;
}
case ECP_BottomRight:
NeedFill = int(false);
switch (CornerShape)
{
case ECS_Corner:
Canvas.SetPos(X, Y);
DrawWhiteBox(Edge, Edge);
X = X + Edge;
Y = Y + Edge;
return;
case ECS_BeveledCorner:
Canvas.SetPos(X, Y);
DrawCornerTex(Edge, 3);
X = X + Edge;
Y = Y + Edge;
return;
case ECS_VerticalCorner:
Canvas.SetPos(X - Edge, Y);
DrawCornerTex(Edge, 2);
X = X + Edge;
Y = Y + Edge;
return;
case ECS_HorisontalCorner:
Canvas.SetPos(X, Y);
DrawCornerTex(Edge, 1);
X = X + Edge;
Y = Y + Edge;
return;
}
}
}
final function FillSmart(out float X, out float Y, float W, float H, bool NeedFill)
{
if (NeedFill)
{
Canvas.SetPos(X, Y);
DrawWhiteBox(W, H);
}
X = X + W;
}
final function DrawRectBox(float X, float Y, float Width, float Height, int Edge, optional byte Extrav) final function DrawRectBox(float X, float Y, float Width, float Height, int Edge, optional byte Extrav)
{ {
local float XPos, YPos;
local int NeedFill;
YPos = Y;
if (Extrav == 2) if (Extrav == 2)
Edge=Min(FMin(Edge, (Width)*0.5), Height);// Verify size. Edge=Min(FMin(Edge, (Width)*0.5), Height);// Verify size.
else else
@ -510,27 +664,22 @@ final function DrawRectBox(float X, float Y, float Width, float Height, int Edge
// | | // | |
// \______\ // \______\
// Top left // Top
Canvas.SetPos(X, Y); XPos = X;
DrawCornerTex(Edge, 0); DrawCornerSmart(ECP_TopLeft, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill);
FillSmart(XPos, YPos, Width - Edge, Edge, bool(NeedFill));
// Top right DrawCornerSmart(ECP_TopRight, ECS_HorisontalCorner, Edge, XPos, YPos, NeedFill);
Canvas.SetPos(X+Width, Y);
DrawCornerTex(Edge, 3); // Mid
XPos = X;
// Bottom right FillSmart(XPos, YPos, Width, Height - Edge * 2, True);
Canvas.SetPos(X+Width, Y+Height-Edge); YPos = YPos + Height - Edge * 2;
DrawCornerTex(Edge, 1);
// Bottom
// Fill XPos = X;
Canvas.SetPos(X+Edge, Y); DrawCornerSmart(ECP_BottomLeft, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill);
DrawWhiteBox(Width-Edge, Height); FillSmart(XPos, YPos, Width - Edge, Edge, bool(NeedFill));
Canvas.SetPos(X, Y+Edge); DrawCornerSmart(ECP_BottomRight, ECS_HorisontalCorner, Edge, XPos, YPos, NeedFill);
DrawWhiteBox(Edge, Height-Edge*2);
// Bottom left
Canvas.SetPos(X, Y+Height-Edge);
DrawCornerTex(Edge, 2);
break; break;
case 2: case 2:
@ -539,29 +688,22 @@ final function DrawRectBox(float X, float Y, float Width, float Height, int Edge
// | ____ | // | ____ |
// |/ \| // |/ \|
// Top left // Top
Canvas.SetPos(X, Y); XPos = X;
DrawCornerTex(Edge, 0); DrawCornerSmart(ECP_TopLeft, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill);
FillSmart(XPos, YPos, Width - Edge * 2, Edge, bool(NeedFill));
DrawCornerSmart(ECP_TopRight, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill);
// Top right // Mid
Canvas.SetPos(X+Width-Edge, Y); XPos = X;
DrawCornerTex(Edge, 1); FillSmart(XPos, YPos, Width, Height - Edge, True);
YPos = YPos + Height - Edge;
// Bottom right
Canvas.SetPos(X+Width-Edge, Y+Height);
DrawCornerTex(Edge, 2);
// Bottom left
Canvas.SetPos(X, Y+Height);
DrawCornerTex(Edge, 3);
// Mid Fill
Canvas.SetPos(X, Y+Edge);
DrawWhiteBox(Width, Height-Edge);
// Top Fill // Bottom
Canvas.SetPos(X+Edge, Y); XPos = X;
DrawWhiteBox(Width-Edge*2, Edge); DrawCornerSmart(ECP_BottomLeft, ECS_VerticalCorner, Edge, XPos, YPos, NeedFill);
FillSmart(XPos, YPos, Width - Edge, Edge, bool(NeedFill));
DrawCornerSmart(ECP_BottomRight, ECS_VerticalCorner, Edge, XPos, YPos, NeedFill);
break; break;
case 3: case 3:
@ -570,33 +712,22 @@ final function DrawRectBox(float X, float Y, float Width, float Height, int Edge
// | | // | |
// /______/ // /______/
// Top left // Top
Canvas.SetPos(X - Edge, Y); XPos = X;
DrawCornerTex(Edge, 2); DrawCornerSmart(ECP_TopLeft, ECS_HorisontalCorner, Edge, XPos, YPos, NeedFill);
FillSmart(XPos, YPos, Width - Edge, Edge, bool(NeedFill));
DrawCornerSmart(ECP_TopRight, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill);
// Top right // Mid
Canvas.SetPos(X+Width-Edge, Y); XPos = X;
DrawCornerTex(Edge, 1); FillSmart(XPos, YPos, Width, Height - Edge * 2, True);
YPos = YPos + Height - Edge * 2;
// Bottom right
Canvas.SetPos(X+Width-Edge, Y+Height-Edge);
DrawCornerTex(Edge, 3);
// Top Fill
Canvas.SetPos(X, Y);
DrawWhiteBox(Width-Edge, Edge);
// Mid Fill // Bottom
Canvas.SetPos(X, Y+Edge); XPos = X;
DrawWhiteBox(Width, Height-Edge*2); DrawCornerSmart(ECP_BottomLeft, ECS_HorisontalCorner, Edge, XPos, YPos, NeedFill);
FillSmart(XPos, YPos, Width - Edge, Edge, bool(NeedFill));
// Bottom Fill DrawCornerSmart(ECP_BottomRight, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill);
Canvas.SetPos(X, Y+Height-Edge);
DrawWhiteBox(Width-Edge, Edge);
// Bottom left
Canvas.SetPos(X - Edge, Y+Height-Edge);
DrawCornerTex(Edge, 0);
break; break;
case 4: case 4:
@ -605,29 +736,22 @@ final function DrawRectBox(float X, float Y, float Width, float Height, int Edge
// | | // | |
// \______/ // \______/
// Top left // Top
Canvas.SetPos(X, Y-Edge); XPos = X;
DrawCornerTex(Edge, 1); DrawCornerSmart(ECP_TopLeft, ECS_VerticalCorner, Edge, XPos, YPos, NeedFill);
FillSmart(XPos, YPos, Width - Edge * 2, Edge, bool(NeedFill));
DrawCornerSmart(ECP_TopRight, ECS_VerticalCorner, Edge, XPos, YPos, NeedFill);
// Top right // Mid
Canvas.SetPos(X+Width-Edge, Y-Edge); XPos = X;
DrawCornerTex(Edge, 0); FillSmart(XPos, YPos, Width, Height - Edge, True);
YPos = YPos + Height - Edge;
// Bottom right
Canvas.SetPos(X+Width-Edge, Y+Height-Edge);
DrawCornerTex(Edge, 3);
// Mid Fill
Canvas.SetPos(X, Y);
DrawWhiteBox(Width, Height-Edge);
// Bottom Fill // Bottom
Canvas.SetPos(X+Edge, Y+Height-Edge); XPos = X;
DrawWhiteBox(Width-Edge*2, Edge); DrawCornerSmart(ECP_BottomLeft, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill);
FillSmart(XPos, YPos, Width - Edge * 2, Edge, bool(NeedFill));
// Bottom left DrawCornerSmart(ECP_BottomRight, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill);
Canvas.SetPos(X, Y+Height-Edge);
DrawCornerTex(Edge, 2);
break; break;
case 5: case 5:
@ -635,12 +759,23 @@ final function DrawRectBox(float X, float Y, float Width, float Height, int Edge
// | | // | |
// | | // | |
// |______| // |______|
// Top left
Canvas.SetPos(X, Y);
// Fill // Top
Canvas.SetPos(X, Y); XPos = X;
DrawWhiteBox(Width, Height); DrawCornerSmart(ECP_TopLeft, ECS_Corner, Edge, XPos, YPos, NeedFill);
FillSmart(XPos, YPos, Width, Edge, bool(NeedFill));
DrawCornerSmart(ECP_TopRight, ECS_Corner, Edge, XPos, YPos, NeedFill);
// Mid
XPos = X;
FillSmart(XPos, YPos, Width, Height - Edge * 2, True);
YPos = YPos + Height - Edge * 2;
// Bottom
XPos = X;
DrawCornerSmart(ECP_BottomLeft, ECS_Corner, Edge, XPos, YPos, NeedFill);
FillSmart(XPos, YPos, Width, Edge, bool(NeedFill));
DrawCornerSmart(ECP_BottomRight, ECS_Corner, Edge, XPos, YPos, NeedFill);
default: // 0 default: // 0
// ______ // ______
@ -648,29 +783,22 @@ final function DrawRectBox(float X, float Y, float Width, float Height, int Edge
// | | // | |
// \______/ // \______/
// Top left // Top
Canvas.SetPos(X, Y); XPos = X;
DrawCornerTex(Edge, 0); DrawCornerSmart(ECP_TopLeft, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill);
FillSmart(XPos, YPos, Width - Edge * 2, Edge, bool(NeedFill));
DrawCornerSmart(ECP_TopRight, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill);
// Top right // Mid
Canvas.SetPos(X+Width-Edge, Y); XPos = X;
DrawCornerTex(Edge, 1); FillSmart(XPos, YPos, Width, Height - Edge * 2, True);
YPos = YPos + Height - Edge * 2;
// Bottom right
Canvas.SetPos(X+Width-Edge, Y+Height-Edge); // Bottom
DrawCornerTex(Edge, 3); XPos = X;
DrawCornerSmart(ECP_BottomLeft, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill);
// Fill FillSmart(XPos, YPos, Width - Edge * 2, Edge, bool(NeedFill));
Canvas.SetPos(X+Edge, Y); DrawCornerSmart(ECP_BottomRight, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill);
DrawWhiteBox(Width-Edge*2, Height);
Canvas.SetPos(X, Y+Edge);
DrawWhiteBox(Edge, Height-Edge*2);
Canvas.SetPos(X+Width-Edge, Y+Edge);
DrawWhiteBox(Edge, Height-Edge*2);
// Bottom left
Canvas.SetPos(X, Y+Height-Edge);
DrawCornerTex(Edge, 2);
break; break;
} }
} }