MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / DrawRectangle

Method DrawRectangle

Source/Engine/Render2D/Render2D.cpp:1461–1624  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1459}
1460
1461void Render2D::DrawRectangle(const Rectangle& rect, const Color& color1, const Color& color2, const Color& color3, const Color& color4, float thickness)
1462{
1463 RENDER2D_CHECK_RENDERING_STATE;
1464
1465 const auto& mask = ClipLayersStack.Peek().Mask;
1466 float thick = thickness;
1467 thickness *= (TransformCached.M11 + TransformCached.M22 + TransformCached.M33) * 0.3333333f;
1468
1469 // When lines thickness is very large, don't use corner caps and place line ends to not overlap
1470 if (thickness > 4.0f)
1471 {
1472 thick *= Math::Lerp(0.6f, 1.0f, Math::Saturate(thick - 4.0f)); // Smooth transition between soft LineAA and harsh FillRect
1473 Float2 totalMin = rect.GetUpperLeft() - Float2(thick * 0.5f);
1474 Float2 totalMax = rect.GetBottomRight() + Float2(thick * 0.5f);
1475 Float2 size = totalMax - totalMin;
1476 Render2DDrawCall& drawCall = DrawCalls.AddOne();
1477 drawCall.Type = NeedAlphaWithTint(color1, color2, color3, color4) ? DrawCallType::FillRect : DrawCallType::FillRectNoAlpha;
1478 drawCall.StartIB = IBIndex;
1479 drawCall.CountIB = 6 * 4;
1480 // TODO: interpolate colors from corners to extended rectangle edges properly
1481 WriteRect(Rectangle(totalMin.X, totalMin.Y, size.X, thick), color1, color2, color2, color1);
1482 WriteRect(Rectangle(totalMin.X, totalMin.Y + rect.Size.Y, size.X, thick), color4, color3, color3, color4);
1483 WriteRect(Rectangle(totalMin.X, totalMin.Y + thick, thick, rect.Size.Y - thick), color1, color1, color4, color4);
1484 WriteRect(Rectangle(totalMax.X - thick, totalMin.Y + thick, thick, rect.Size.Y - thick), color2, color2, color3, color3);
1485 return;
1486 }
1487
1488 Float2 points[5];
1489 ApplyTransform(rect.GetUpperLeft(), points[0]);
1490 ApplyTransform(rect.GetUpperRight(), points[1]);
1491 ApplyTransform(rect.GetBottomRight(), points[2]);
1492 ApplyTransform(rect.GetBottomLeft(), points[3]);
1493 points[4] = points[0];
1494
1495 Color colors[5];
1496 colors[0] = color1;
1497 colors[1] = color2;
1498 colors[2] = color3;
1499 colors[3] = color4;
1500 colors[4] = colors[0];
1501
1502 Render2DVertex v[4];
1503 uint32 indices[6];
1504 Float2 p1t, p2t;
1505 Color c1t, c2t;
1506
1507 p1t = points[0];
1508 c1t = colors[0];
1509
1510#if RENDER2D_USE_LINE_AA
1511 Render2DDrawCall& drawCall = DrawCalls.AddOne();
1512 drawCall.Type = DrawCallType::LineAA;
1513 drawCall.StartIB = IBIndex;
1514 drawCall.CountIB = 4 * (6 + 3);
1515
1516 // This must be the same as in HLSL code
1517 const float filterScale = 1.0f;
1518 const float thicknessHalf = (2.82842712f + thickness) * 0.5f + filterScale;

Callers 15

DrawSelfMethod · 0.80
DrawSelfMethod · 0.80
DrawSelfMethod · 0.80
DrawSelfMethod · 0.80
DrawSelfMethod · 0.80
DrawMethod · 0.80
DrawMethod · 0.80
DrawMethod · 0.80
DrawMethod · 0.80
DrawSelectionMethod · 0.80
DrawLazyConnectMethod · 0.80
DrawMethod · 0.80

Calls 11

SaturateFunction · 0.85
Float2Class · 0.85
NeedAlphaWithTintFunction · 0.85
WriteRectFunction · 0.85
ApplyTransformFunction · 0.85
AddOneMethod · 0.80
LerpFunction · 0.50
RectangleClass · 0.50
NormalizeFunction · 0.50
PeekMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected