add one more DrawRect abstraction for easy draw rects with variable shapes

This commit is contained in:
GenZmeY 2021-06-13 23:09:34 +03:00
parent 5c702007bd
commit 6219d151d6

View File

@ -509,146 +509,151 @@ 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) final function DrawCornerSmart(out float X, float Y, int Edge, int CornerPosition, int CornerShape)
{ {
switch (CornerPosition) switch (CornerPosition)
{ {
case ECP_TopLeft: case ECP_TopLeft:
NeedFill = int(CornerShape != ECS_VerticalCorner);
switch (CornerShape) switch (CornerShape)
{ {
case ECS_Corner: case ECS_Corner:
Canvas.SetPos(X, Y);
DrawWhiteBox(Edge, Edge);
X = X + Edge;
Y = Y;
return; return;
case ECS_BeveledCorner: case ECS_BeveledCorner:
Canvas.SetPos(X, Y); Canvas.SetPos(X, Y);
DrawCornerTex(Edge, 0); DrawCornerTex(Edge, 0);
X = X + Edge; X += Edge;
Y = Y;
return; return;
case ECS_VerticalCorner: case ECS_VerticalCorner:
Canvas.SetPos(X, Y - Edge); Canvas.SetPos(X, Y - Edge);
DrawCornerTex(Edge, 1); DrawCornerTex(Edge, 1);
X = X + Edge; X += Edge;
Y = Y;
return; return;
case ECS_HorisontalCorner: case ECS_HorisontalCorner:
Canvas.SetPos(X - Edge, Y); Canvas.SetPos(X - Edge, Y);
DrawCornerTex(Edge, 2); DrawCornerTex(Edge, 2);
X = X;
Y = Y;
return; return;
} }
case ECP_TopRight: case ECP_TopRight:
NeedFill = int(false);
switch (CornerShape) switch (CornerShape)
{ {
case ECS_Corner: case ECS_Corner:
Canvas.SetPos(X, Y);
DrawWhiteBox(Edge, Edge);
X = X + Edge;
Y = Y;
return; return;
case ECS_BeveledCorner: case ECS_BeveledCorner:
Canvas.SetPos(X, Y); Canvas.SetPos(X, Y);
DrawCornerTex(Edge, 1); DrawCornerTex(Edge, 1);
X = X + Edge; X += Edge;
Y = Y + Edge;
return; return;
case ECS_VerticalCorner: case ECS_VerticalCorner:
Canvas.SetPos(X, Y - Edge); Canvas.SetPos(X, Y - Edge);
DrawCornerTex(Edge, 0); DrawCornerTex(Edge, 0);
X = X + Edge; X += Edge;
Y = Y;
return; return;
case ECS_HorisontalCorner: case ECS_HorisontalCorner:
Canvas.SetPos(X, Y); Canvas.SetPos(X, Y);
DrawCornerTex(Edge, 3); DrawCornerTex(Edge, 3);
X = X + Edge; X += Edge;
Y = Y + Edge;
return; return;
} }
case ECP_BottomLeft: case ECP_BottomLeft:
NeedFill = int(CornerShape != ECS_VerticalCorner);
switch (CornerShape) switch (CornerShape)
{ {
case ECS_Corner: case ECS_Corner:
Canvas.SetPos(X, Y);
DrawWhiteBox(Edge, Edge);
X = X + Edge;
Y = Y;
return; return;
case ECS_BeveledCorner: case ECS_BeveledCorner:
Canvas.SetPos(X, Y); Canvas.SetPos(X, Y);
DrawCornerTex(Edge, 2); DrawCornerTex(Edge, 2);
X = X + Edge; X += Edge;
Y = Y;
return; return;
case ECS_VerticalCorner: case ECS_VerticalCorner:
Canvas.SetPos(X, Y); Canvas.SetPos(X, Y);
DrawCornerTex(Edge, 3); DrawCornerTex(Edge, 3);
X = X + Edge; X += Edge;
Y = Y;
return; return;
case ECS_HorisontalCorner: case ECS_HorisontalCorner:
Canvas.SetPos(X - Edge, Y); Canvas.SetPos(X - Edge, Y);
DrawCornerTex(Edge, 0); DrawCornerTex(Edge, 0);
X = X;
Y = Y;
return; return;
} }
case ECP_BottomRight: case ECP_BottomRight:
NeedFill = int(false);
switch (CornerShape) switch (CornerShape)
{ {
case ECS_Corner: case ECS_Corner:
Canvas.SetPos(X, Y);
DrawWhiteBox(Edge, Edge);
X = X + Edge;
Y = Y + Edge;
return; return;
case ECS_BeveledCorner: case ECS_BeveledCorner:
Canvas.SetPos(X, Y); Canvas.SetPos(X, Y);
DrawCornerTex(Edge, 3); DrawCornerTex(Edge, 3);
X = X + Edge; X += Edge;
Y = Y + Edge;
return; return;
case ECS_VerticalCorner: case ECS_VerticalCorner:
Canvas.SetPos(X - Edge, Y); Canvas.SetPos(X, Y); // X - Edge ?
DrawCornerTex(Edge, 2); DrawCornerTex(Edge, 2);
X = X + Edge; X += Edge;
Y = Y + Edge;
return; return;
case ECS_HorisontalCorner: case ECS_HorisontalCorner:
Canvas.SetPos(X, Y); Canvas.SetPos(X, Y);
DrawCornerTex(Edge, 1); DrawCornerTex(Edge, 1);
X = X + Edge; X += Edge;
Y = Y + Edge;
return; return;
} }
} }
} }
final function FillSmart(out float X, out float Y, float W, float H, bool NeedFill) final function FillSmart(out float X, float Y, float W, float H, int Edge, int LeftShape, int RightShape)
{ {
if (NeedFill) if (LeftShape != ECS_HorisontalCorner && LeftShape != ECS_Corner)
{
W -= Edge;
}
if (RightShape != ECS_HorisontalCorner && RightShape != ECS_Corner)
{
W -= Edge;
}
if (LeftShape != ECS_VerticalCorner)
{ {
Canvas.SetPos(X, Y); Canvas.SetPos(X, Y);
DrawWhiteBox(W, H); DrawWhiteBox(W, H);
} }
X = X + W;
X += W;
}
final function DrawRectBoxSmart(float X, float Y, float W, float H, int Edge, int TopLeftShape, int TopRightShape, int BottomLeftShape, int BottomRightShape)
{
local float TopY, MidY, BottomY, XPos;
local int FillCount;
local float MidRectHeight;
FillCount = 0;
if (TopLeftShape != ECS_VerticalCorner)
FillCount++;
if (BottomLeftShape != ECS_VerticalCorner)
FillCount++;
MidRectHeight = H - Edge * FillCount;
TopY = Y; MidY = TopY + (TopLeftShape == ECS_VerticalCorner ? 0 : Edge); BottomY = MidY + MidRectHeight;
// Top Line
XPos = X;
DrawCornerSmart(XPos, TopY, Edge, ECP_TopLeft, TopLeftShape);
FillSmart(XPos, TopY, W, Edge, Edge, TopLeftShape, TopRightShape);
DrawCornerSmart(XPos, TopY, Edge, ECP_TopRight, TopRightShape);
// Mid Line
XPos = X;
FillSmart(XPos, MidY, W, MidRectHeight, Edge, ECS_Corner, ECS_Corner);
// Bottom Line
XPos = X;
DrawCornerSmart(XPos, BottomY, Edge, ECP_BottomLeft, BottomLeftShape);
FillSmart(XPos, BottomY, W, Edge, Edge, BottomLeftShape, BottomRightShape);
DrawCornerSmart(XPos, BottomY, Edge, ECP_BottomRight, BottomRightShape);
} }
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
@ -664,22 +669,12 @@ final function DrawRectBox(float X, float Y, float Width, float Height, int Edge
// | | // | |
// \______\ // \______\
// Top DrawRectBoxSmart(X, Y, Width, Height, Edge,
XPos = X; ECS_BeveledCorner, // TopLeft
DrawCornerSmart(ECP_TopLeft, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill); ECS_HorisontalCorner, // TopRight
FillSmart(XPos, YPos, Width - Edge, Edge, bool(NeedFill)); ECS_BeveledCorner, // BottomLeft
DrawCornerSmart(ECP_TopRight, ECS_HorisontalCorner, Edge, XPos, YPos, NeedFill); ECS_HorisontalCorner // BottomRight
);
// Mid
XPos = X;
FillSmart(XPos, YPos, Width, Height - Edge * 2, True);
YPos = YPos + Height - Edge * 2;
// Bottom
XPos = X;
DrawCornerSmart(ECP_BottomLeft, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill);
FillSmart(XPos, YPos, Width - Edge, Edge, bool(NeedFill));
DrawCornerSmart(ECP_BottomRight, ECS_HorisontalCorner, Edge, XPos, YPos, NeedFill);
break; break;
case 2: case 2:
@ -688,22 +683,12 @@ final function DrawRectBox(float X, float Y, float Width, float Height, int Edge
// | ____ | // | ____ |
// |/ \| // |/ \|
// Top DrawRectBoxSmart(X, Y, Width, Height, Edge,
XPos = X; ECS_BeveledCorner, // TopLeft
DrawCornerSmart(ECP_TopLeft, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill); ECS_BeveledCorner, // TopRight
FillSmart(XPos, YPos, Width - Edge * 2, Edge, bool(NeedFill)); ECS_VerticalCorner, // BottomLeft
DrawCornerSmart(ECP_TopRight, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill); ECS_VerticalCorner // BottomRight
);
// Mid
XPos = X;
FillSmart(XPos, YPos, Width, Height - Edge, True);
YPos = YPos + Height - Edge;
// Bottom
XPos = X;
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:
@ -712,22 +697,12 @@ final function DrawRectBox(float X, float Y, float Width, float Height, int Edge
// | | // | |
// /______/ // /______/
// Top DrawRectBoxSmart(X, Y, Width, Height, Edge,
XPos = X; ECS_HorisontalCorner, // TopLeft
DrawCornerSmart(ECP_TopLeft, ECS_HorisontalCorner, Edge, XPos, YPos, NeedFill); ECS_BeveledCorner, // TopRight
FillSmart(XPos, YPos, Width - Edge, Edge, bool(NeedFill)); ECS_HorisontalCorner, // BottomLeft
DrawCornerSmart(ECP_TopRight, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill); ECS_BeveledCorner // BottomRight
);
// Mid
XPos = X;
FillSmart(XPos, YPos, Width, Height - Edge * 2, True);
YPos = YPos + Height - Edge * 2;
// Bottom
XPos = X;
DrawCornerSmart(ECP_BottomLeft, ECS_HorisontalCorner, Edge, XPos, YPos, NeedFill);
FillSmart(XPos, YPos, Width - Edge, Edge, bool(NeedFill));
DrawCornerSmart(ECP_BottomRight, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill);
break; break;
case 4: case 4:
@ -736,22 +711,12 @@ final function DrawRectBox(float X, float Y, float Width, float Height, int Edge
// | | // | |
// \______/ // \______/
// Top DrawRectBoxSmart(X, Y, Width, Height, Edge,
XPos = X; ECS_VerticalCorner, // TopLeft
DrawCornerSmart(ECP_TopLeft, ECS_VerticalCorner, Edge, XPos, YPos, NeedFill); ECS_VerticalCorner, // TopRight
FillSmart(XPos, YPos, Width - Edge * 2, Edge, bool(NeedFill)); ECS_BeveledCorner, // BottomLeft
DrawCornerSmart(ECP_TopRight, ECS_VerticalCorner, Edge, XPos, YPos, NeedFill); ECS_BeveledCorner // BottomRight
);
// Mid
XPos = X;
FillSmart(XPos, YPos, Width, Height - Edge, True);
YPos = YPos + Height - Edge;
// Bottom
XPos = X;
DrawCornerSmart(ECP_BottomLeft, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill);
FillSmart(XPos, YPos, Width - Edge * 2, Edge, bool(NeedFill));
DrawCornerSmart(ECP_BottomRight, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill);
break; break;
case 5: case 5:
@ -760,45 +725,24 @@ final function DrawRectBox(float X, float Y, float Width, float Height, int Edge
// | | // | |
// |______| // |______|
// Top DrawRectBoxSmart(X, Y, Width, Height, Edge,
XPos = X; ECS_Corner, // TopLeft
DrawCornerSmart(ECP_TopLeft, ECS_Corner, Edge, XPos, YPos, NeedFill); ECS_Corner, // TopRight
FillSmart(XPos, YPos, Width, Edge, bool(NeedFill)); ECS_Corner, // BottomLeft
DrawCornerSmart(ECP_TopRight, ECS_Corner, Edge, XPos, YPos, NeedFill); ECS_Corner // BottomRight
);
// 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
// ______ // ______
// / \ // / \
// | | // | |
// \______/ // \______/
// Top DrawRectBoxSmart(X, Y, Width, Height, Edge,
XPos = X; ECS_BeveledCorner, // TopLeft
DrawCornerSmart(ECP_TopLeft, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill); ECS_BeveledCorner, // TopRight
FillSmart(XPos, YPos, Width - Edge * 2, Edge, bool(NeedFill)); ECS_BeveledCorner, // BottomLeft
DrawCornerSmart(ECP_TopRight, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill); ECS_BeveledCorner // BottomRight
);
// Mid
XPos = X;
FillSmart(XPos, YPos, Width, Height - Edge * 2, True);
YPos = YPos + Height - Edge * 2;
// Bottom
XPos = X;
DrawCornerSmart(ECP_BottomLeft, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill);
FillSmart(XPos, YPos, Width - Edge * 2, Edge, bool(NeedFill));
DrawCornerSmart(ECP_BottomRight, ECS_BeveledCorner, Edge, XPos, YPos, NeedFill);
break; break;
} }
} }