266void QSGBasicInternalRectangleNode::updateGeometry()
268 float width =
float(m_rect.width());
269 float height =
float(m_rect.height());
270 float penWidth = qMin(qMin(width, height) * 0.5f,
float(m_pen_width));
273 penWidth = qRound(penWidth);
275 QSGGeometry *g = geometry();
276 g->setDrawingMode(QSGGeometry::DrawTriangleStrip);
277 int vertexStride = g->sizeOfVertex();
281 SmoothVertex *smoothVertices;
284 Color4ub fillColor = colorToColor4ub(m_color);
285 Color4ub borderColor = colorToColor4ub(m_border_color);
286 Color4ub transparent = { 0, 0, 0, 0 };
287 const QGradientStops &stops = m_gradient_stops;
289 float gradientStart = (m_gradient_is_vertical ? m_rect.top() : m_rect.left());
290 float gradientLength = (m_gradient_is_vertical ? height : width);
291 float secondaryLength = (m_gradient_is_vertical ? width : height);
293 int nextGradientStop = 0;
294 float gradientPos = penWidth / gradientLength;
295 while (nextGradientStop < stops.size() && stops.at(nextGradientStop).first <= gradientPos)
297 int lastGradientStop = stops.size() - 1;
298 float lastGradientPos = 1.0f - penWidth / gradientLength;
299 while (lastGradientStop >= nextGradientStop && stops.at(lastGradientStop).first >= lastGradientPos)
301 int gradientIntersections = (lastGradientStop - nextGradientStop + 1);
304 || m_isTopLeftRadiusSet
305 || m_isTopRightRadiusSet
306 || m_isBottomLeftRadiusSet
307 || m_isBottomRightRadiusSet) {
311 float radiusTL = qMin(qMin(width, height) * 0.4999f,
312 float(m_isTopLeftRadiusSet ? m_topLeftRadius : m_radius));
313 float radiusTR = qMin(qMin(width, height) * 0.4999f,
314 float(m_isTopRightRadiusSet ? m_topRightRadius : m_radius));
315 float radiusBL = qMin(qMin(width, height) * 0.4999f,
316 float(m_isBottomLeftRadiusSet ? m_bottomLeftRadius : m_radius));
317 float radiusBR = qMin(qMin(width, height) * 0.4999f,
318 float(m_isBottomRightRadiusSet ? m_bottomRightRadius : m_radius));
333 const float innerRadiusTL = qMax(radiusTL - penWidth * 1.0f, 0.01);
334 const float innerRadiusTR = qMax(radiusTR - penWidth * 1.0f, 0.01);
335 const float innerRadiusBL = qMax(radiusBL - penWidth * 1.0f, 0.01);
336 const float innerRadiusBR = qMax(radiusBR - penWidth * 1.0f, 0.01);
337 const float outerRadiusTL = radiusTL;
338 const float outerRadiusTR = radiusTR;
339 const float outerRadiusBL = radiusBL;
340 const float outerRadiusBR = radiusBR;
341 const float delta = qMin(width, height) * 0.5f;
343 int segmentsTL = radiusTL == 0 ? 0 : qBound(3, qCeil(radiusTL * (M_PI / 6)), 18);
344 int segmentsTR = radiusTR == 0 ? 0 : qBound(3, qCeil(radiusTR * (M_PI / 6)), 18);
345 int segmentsBL = radiusBL == 0 ? 0 : qBound(3, qCeil(radiusBL * (M_PI / 6)), 18);
346 int segmentsBR = radiusBR == 0 ? 0 : qBound(3, qCeil(radiusBR * (M_PI / 6)), 18);
351 if (m_gradient_is_vertical) {
352 if (innerRadiusTL == innerRadiusTR) {
353 if (segmentsTL <= segmentsTR)
358 if (innerRadiusBL == innerRadiusBR){
359 if (segmentsBL <= segmentsBR)
365 if (innerRadiusTL == innerRadiusBL) {
366 if (segmentsTL <= segmentsBL)
371 if (innerRadiusTR == innerRadiusBR) {
372 if (segmentsTR <= segmentsBR)
379 const int sumSegments = segmentsTL + segmentsTR + segmentsBL + segmentsBR;
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
401 const int innerVertexCount = (sumSegments + 4) * 2 + gradientIntersections * 2;
402 const int outerVertexCount = (sumSegments + 4) * 2;
403 int vertexCount = innerVertexCount;
404 if (m_antialiasing || penWidth)
405 vertexCount += innerVertexCount;
407 vertexCount += outerVertexCount;
408 if (m_antialiasing && penWidth)
409 vertexCount += outerVertexCount;
412 const int fillIndexCount = innerVertexCount;
413 const int innerAAIndexCount = innerVertexCount * 2 + 2;
414 const int borderIndexCount = innerVertexCount * 2 + 2;
415 const int outerAAIndexCount = outerVertexCount * 2 + 2;
424 bool hasFill = m_color.alpha() > 0 || !stops.isEmpty();
426 indexCount += fillIndexCount;
427 if (m_antialiasing) {
428 innerAATail = innerAAHead = indexCount + (innerAAIndexCount >> 1) + 1;
429 indexCount += innerAAIndexCount;
432 borderTail = borderHead = indexCount + (borderIndexCount >> 1) + 1;
433 indexCount += borderIndexCount;
435 if (m_antialiasing && penWidth) {
436 outerAATail = outerAAHead = indexCount + (outerAAIndexCount >> 1) + 1;
437 indexCount += outerAAIndexCount;
440 g->allocate(vertexCount, indexCount);
441 vertices =
reinterpret_cast<Vertex *>(g->vertexData());
442 memset(vertices, 0, vertexCount * vertexStride);
443 quint16 *indices = g->indexDataAsUShort();
447 float innerXPrev = 0.;
448 float innerYLeftPrev = 0.;
449 float innerYRightPrev = 0.;
451 const float angleTL = 0.5f *
float(M_PI) / segmentsTL;
452 const float cosStepTL = qFastCos(angleTL);
453 const float sinStepTL = qFastSin(angleTL);
454 const float angleTR = 0.5f *
float(M_PI) / segmentsTR;
455 const float cosStepTR = qFastCos(angleTR);
456 const float sinStepTR = qFastSin(angleTR);
457 const float angleBL = 0.5f *
float(M_PI) / segmentsBL;
458 const float cosStepBL = qFastCos(angleBL);
459 const float sinStepBL = qFastSin(angleBL);
460 const float angleBR = 0.5f *
float(M_PI) / segmentsBR;
461 const float cosStepBR = qFastCos(angleBR);
462 const float sinStepBR = qFastSin(angleBR);
494 const float outerXCenter[][2] = {{
495 float(m_gradient_is_vertical ? m_rect.top() + radiusTL : m_rect.left() + radiusTL),
496 float(m_gradient_is_vertical ? m_rect.top() + radiusTR : m_rect.left() + radiusBL)
498 float(m_gradient_is_vertical ? m_rect.bottom() - radiusBL : m_rect.right() - radiusTR),
499 float(m_gradient_is_vertical ? m_rect.bottom() - radiusBR : m_rect.right() - radiusBR)
502 const float outerYCenter[][2] = {{
503 float(!m_gradient_is_vertical ? m_rect.top() + outerRadiusTL : m_rect.left() + outerRadiusTL),
504 float(!m_gradient_is_vertical ? m_rect.bottom() - outerRadiusBL : m_rect.right() - outerRadiusTR)
506 float(!m_gradient_is_vertical ? m_rect.top() + outerRadiusTR : m_rect.left() + outerRadiusBL),
507 float(!m_gradient_is_vertical ? m_rect.bottom() - outerRadiusBR : m_rect.right() - outerRadiusBR)
510 const float innerXCenter[][2] = { {
511 float(m_gradient_is_vertical ? m_rect.top() + innerRadiusTL + penWidth : m_rect.left() + innerRadiusTL + penWidth),
512 float(m_gradient_is_vertical ? m_rect.top() + innerRadiusTR + penWidth: m_rect.left() + innerRadiusBL + penWidth)
514 float(m_gradient_is_vertical ? m_rect.bottom() - innerRadiusBL - penWidth: m_rect.right() - innerRadiusTR - penWidth),
515 float(m_gradient_is_vertical ? m_rect.bottom() - innerRadiusBR - penWidth: m_rect.right() - innerRadiusBR - penWidth)
518 const float innerYCenter[][2] = { {
519 float(!m_gradient_is_vertical ? m_rect.top() + innerRadiusTL + penWidth : m_rect.left() + innerRadiusTL + penWidth),
520 float(!m_gradient_is_vertical ? m_rect.bottom() - innerRadiusBL - penWidth : m_rect.right() - innerRadiusTR - penWidth)
522 float(!m_gradient_is_vertical ? m_rect.top() + innerRadiusTR + penWidth : m_rect.left() + innerRadiusBL + penWidth),
523 float(!m_gradient_is_vertical ? m_rect.bottom() - innerRadiusBR - penWidth : m_rect.right() - innerRadiusBR - penWidth)
526 const float innerRadius[][2] = {{
528 !m_gradient_is_vertical ? innerRadiusBL : innerRadiusTR
530 !m_gradient_is_vertical ? innerRadiusTR : innerRadiusBL,
534 const float outerRadius[][2] = {{
536 !m_gradient_is_vertical ? outerRadiusBL : outerRadiusTR
538 !m_gradient_is_vertical ? outerRadiusTR : outerRadiusBL,
542 const int segments[][2] = {{
544 !m_gradient_is_vertical ? segmentsBL : segmentsTR
546 !m_gradient_is_vertical ? segmentsTR : segmentsBL,
550 const float cosStep[][2] = {{
552 !m_gradient_is_vertical ? cosStepBL : cosStepTR
554 !m_gradient_is_vertical ? cosStepTR : cosStepBL,
558 const float sinStep[][2] = {{
560 !m_gradient_is_vertical ? sinStepBL : sinStepTR
562 !m_gradient_is_vertical ? sinStepTR : sinStepBL,
566 auto fillColorFromX = [&](
float x) {
568 float t = (x - gradientStart) / gradientLength;
569 t = qBound(0.0, t, 1.0);
572 if (t < stops.first().first)
573 return colorToColor4ub(stops.first().second);
574 while (i < stops.size()) {
575 const QGradientStop &prev = stops.at(i - 1);
576 const QGradientStop &next = stops.at(i);
577 if (prev.first <= t && next.first > t) {
578 t = (t - prev.first) / (next.first - prev.first);
579 return colorToColor4ub(prev.second) * (1. - t) + colorToColor4ub(next.second) * t; }
582 return colorToColor4ub(stops.last().second);
585 for (
int part = 0; part < 2; ++part) {
587 float cosSegmentAngleLeft = 1. - part;
589 float sinSegmentAngleLeft = part;
591 float cosSegmentAngleRight = 1. - part;
592 float sinSegmentAngleRight = part;
594 bool advanceLeft =
true;
599 for (
int iLeft = 0, iRight = 0; iLeft <= segments[part][0] || iRight <= segments[part][1]; ) {
604 float outerXLeft, outerYLeft,
605 outerXRight, outerYRight;
607 float sinAngleLeft, cosAngleLeft,
608 sinAngleRight, cosAngleRight;
611 xLeft = innerXCenter[part][0] - innerRadius[part][0] * cosSegmentAngleLeft;
612 xRight = innerXCenter[part][1] - innerRadius[part][1] * cosSegmentAngleRight;
615 yLeft = innerYCenter[part][0] - innerRadius[part][0] * sinSegmentAngleLeft;
616 yRight = innerYCenter[part][1] + innerRadius[part][1] * sinSegmentAngleRight;
622 if ((iLeft <= segments[part][0] && xLeft <= xRight) || iRight > segments[part][1]) {
632 const bool lastVertex = part == 1
633 && (advanceLeft ? iLeft >= segments[part][0] && iRight > segments[part][1]
634 : iRight >= segments[part][1] && iLeft > segments[part][0]);
639 if (innerRadius[part][0] == innerRadius[part][1]) {
644 if (outerRadius[part][0] == 0) {
646 cosAngleLeft = part ? -1. : 1.;
648 sinAngleLeft = sinSegmentAngleLeft;
649 cosAngleLeft = cosSegmentAngleLeft;
651 if (outerRadius[part][1] == 0) {
653 cosAngleRight = part ? -1. : 1.;
655 sinAngleRight = sinSegmentAngleLeft;
656 cosAngleRight = cosSegmentAngleLeft;
659 yRight = innerYCenter[part][1] + innerRadius[part][1] * sinAngleRight;
661 if (outerRadius[part][0] == 0) {
663 cosAngleLeft = part ? -1. : 1.;
665 sinAngleLeft = sinSegmentAngleRight;
666 cosAngleLeft = cosSegmentAngleRight;
668 if (outerRadius[part][1] == 0) {
670 cosAngleRight = part ? -1. : 1.;
672 sinAngleRight = sinSegmentAngleRight;
673 cosAngleRight = cosSegmentAngleRight;
676 yLeft = innerYCenter[part][0] - innerRadius[part][0] * sinAngleLeft;
678 }
else if (advanceLeft) {
679 if (outerRadius[part][0] == 0) {
681 cosAngleLeft = part ? -1. : 1.;
683 sinAngleLeft = sinSegmentAngleLeft;
684 cosAngleLeft = cosSegmentAngleLeft;
686 if (outerRadius[part][1] == 0) {
691 cosAngleRight = part ? -1. : 1.;
693 yRight = innerYCenter[part][1] + innerRadius[part][1] * sinAngleRight;
694 }
else if (xLeft >= innerXCenter[0][1] && xLeft <= innerXCenter[1][1]) {
701 yRight = innerYCenter[part][1] + innerRadius[part][1] * sinAngleRight;
708 if (xRight != innerXPrev) {
709 float t = (xLeft - innerXPrev) / (xRight - innerXPrev);
710 yRight = innerYRightPrev * (1. - t) + yRight * t;
715 sinAngleRight = (yRight - innerYCenter[part][1]) / innerRadius[part][1];
716 cosAngleRight = -(xRight - innerXCenter[part][1]) / innerRadius[part][1];
720 if (outerRadius[part][1] == 0) {
722 cosAngleRight = part ? -1. : 1.;
724 sinAngleRight = sinSegmentAngleRight;
725 cosAngleRight = cosSegmentAngleRight;
727 if (outerRadius[part][0] == 0) {
729 cosAngleLeft = part ? -1. : 1.;
731 yLeft = innerYCenter[part][0] - innerRadius[part][0] * sinAngleLeft;
732 }
else if (xRight >= innerXCenter[0][0] && xRight <= innerXCenter[1][0]) {
736 yLeft = innerYCenter[part][0] - innerRadius[part][0] * sinAngleLeft;
738 if (xLeft != innerXPrev) {
739 float t = (xRight - innerXPrev) / (xLeft - innerXPrev);
740 yLeft = innerYLeftPrev * (1. - t) + yLeft * t;
743 sinAngleLeft = -(yLeft - innerYCenter[part][0]) / innerRadius[part][0];
744 cosAngleLeft = -(xLeft - innerXCenter[part][0]) / innerRadius[part][0];
748 gradientPos = (xLeft - gradientStart) / gradientLength;
751 outerXLeft = outerXCenter[part][0] - outerRadius[part][0] * cosAngleLeft;
752 outerYLeft = outerYCenter[part][0] - outerRadius[part][0] * sinAngleLeft;
753 outerXRight = outerXCenter[part][1] - outerRadius[part][1] * cosAngleRight;
754 outerYRight = outerYCenter[part][1] + outerRadius[part][1] * sinAngleRight;
757 while (nextGradientStop <= lastGradientStop
758 && (lastVertex || stops.at(nextGradientStop).first <= gradientPos)) {
761 float gradientYRight;
764 gradientX = qMin(gradientStart + stops.at(nextGradientStop).first * gradientLength, xLeft);
767 float t = !qFuzzyIsNull(xLeft - innerXPrev)
768 ? qBound(0.0f, (gradientX - innerXPrev) / (xLeft - innerXPrev), 1.0f)
770 gradientYLeft = innerYLeftPrev * (1. - t) + t * yLeft;
771 gradientYRight = innerYRightPrev * (1. - t) + t * yRight;
773 fillColor = fillColorFromX(gradientX);
776 indices[fillHead++] = index;
777 indices[fillHead++] = index + 1;
782 indices[borderHead] = indices[borderHead + 2];
783 indices[--borderHead] = index + 2;
784 indices[borderTail++] = index + 3;
785 indices[borderTail] = indices[borderTail - 2];
789 if (m_antialiasing) {
790 indices[--innerAAHead] = index + 2;
791 indices[--innerAAHead] = index;
792 indices[innerAATail++] = index + 1;
793 indices[innerAATail++] = index + 3;
795 bool lower = stops.at(nextGradientStop).first > 0.5f;
796 float dp = lower ? qMin(0.0f, gradientLength - gradientX - delta) : qMax(0.0f, delta - gradientX);
797 smoothVertices[index++].set(gradientX, gradientYRight, fillColor, dp, secondaryLength - gradientYRight - delta, m_gradient_is_vertical);
798 smoothVertices[index++].set(gradientX, gradientYLeft, fillColor, dp, delta - gradientYLeft, m_gradient_is_vertical);
800 smoothVertices[index++].set(gradientX, gradientYRight, borderColor, -0.49f * penWidth * cosAngleRight, 0.49f * penWidth * sinAngleRight, m_gradient_is_vertical);
801 smoothVertices[index++].set(gradientX, gradientYLeft, borderColor, -0.49f * penWidth * cosAngleLeft, -0.49f * penWidth * sinAngleLeft, m_gradient_is_vertical);
803 dp = lower ? delta : -delta;
804 smoothVertices[index++].set(gradientX, gradientYRight, transparent, dp, delta, m_gradient_is_vertical);
805 smoothVertices[index++].set(gradientX, gradientYLeft, transparent, dp, -delta, m_gradient_is_vertical);
808 vertices[index++].set(gradientX, gradientYRight, fillColor, m_gradient_is_vertical);
809 vertices[index++].set(gradientX, gradientYLeft, fillColor, m_gradient_is_vertical);
811 vertices[index++].set(gradientX, gradientYRight, borderColor, m_gradient_is_vertical);
812 vertices[index++].set(gradientX, gradientYLeft, borderColor, m_gradient_is_vertical);
816 innerXPrev = gradientX;
817 innerYLeftPrev = gradientYLeft;
818 innerYRightPrev = gradientYRight;
823 if (!stops.isEmpty()) {
824 fillColor = fillColorFromX(xLeft);
828 indices[fillHead++] = index;
829 indices[fillHead++] = index + 1;
833 indices[--borderHead] = index + 4;
834 indices[--borderHead] = index + 2;
835 indices[borderTail++] = index + 3;
836 indices[borderTail++] = index + 5;
839 if (m_antialiasing) {
840 indices[--innerAAHead] = index + 2;
841 indices[--innerAAHead] = index;
842 indices[innerAATail++] = index + 1;
843 indices[innerAATail++] = index + 3;
845 float dp = part ? qMin(0.0f, gradientLength - xRight - delta) : qMax(0.0f, delta - xRight);
846 smoothVertices[index++].set(xRight, yRight, fillColor, dp, secondaryLength - yRight - delta, m_gradient_is_vertical);
847 smoothVertices[index++].set(xLeft, yLeft, fillColor, dp, delta - yLeft, m_gradient_is_vertical);
849 dp = part ? delta : -delta;
851 smoothVertices[index++].set(xRight, yRight, borderColor, -0.49f * penWidth * cosAngleRight, 0.49f * penWidth * sinAngleRight, m_gradient_is_vertical);
852 smoothVertices[index++].set(xLeft, yLeft, borderColor, -0.49f * penWidth * cosAngleLeft, -0.49f * penWidth * sinAngleLeft, m_gradient_is_vertical);
853 smoothVertices[index++].set(outerXRight, outerYRight, borderColor, 0.49f * penWidth * cosAngleRight, -0.49f * penWidth * sinAngleRight, m_gradient_is_vertical);
854 smoothVertices[index++].set(outerXLeft, outerYLeft, borderColor, 0.49f * penWidth * cosAngleLeft, 0.49f * penWidth * sinAngleLeft, m_gradient_is_vertical);
855 smoothVertices[index++].set(outerXRight, outerYRight, transparent, dp, delta, m_gradient_is_vertical);
856 smoothVertices[index++].set(outerXLeft, outerYLeft, transparent, dp, -delta, m_gradient_is_vertical);
858 indices[--outerAAHead] = index - 2;
859 indices[--outerAAHead] = index - 4;
860 indices[outerAATail++] = index - 3;
861 indices[outerAATail++] = index - 1;
863 smoothVertices[index++].set(xRight, yRight, transparent, dp, delta, m_gradient_is_vertical);
864 smoothVertices[index++].set(xLeft, yLeft, transparent, dp, -delta, m_gradient_is_vertical);
867 vertices[index++].set(xRight, yRight, fillColor, m_gradient_is_vertical);
868 vertices[index++].set(xLeft, yLeft, fillColor, m_gradient_is_vertical);
870 vertices[index++].set(xRight, yRight, borderColor, m_gradient_is_vertical);
871 vertices[index++].set(xLeft, yLeft, borderColor, m_gradient_is_vertical);
872 vertices[index++].set(outerXRight, outerYRight, borderColor, m_gradient_is_vertical);
873 vertices[index++].set(outerXLeft, outerYLeft, borderColor, m_gradient_is_vertical);
878 innerYLeftPrev = yLeft;
879 innerYRightPrev = yRight;
884 qreal tmp = cosSegmentAngleLeft;
885 cosSegmentAngleLeft = cosSegmentAngleLeft * cosStep[part][0] - sinSegmentAngleLeft * sinStep[part][0];
886 sinSegmentAngleLeft = sinSegmentAngleLeft * cosStep[part][0] + tmp * sinStep[part][0];
889 qreal tmp = cosSegmentAngleRight;
890 cosSegmentAngleRight = cosSegmentAngleRight * cosStep[part][1] - sinSegmentAngleRight * sinStep[part][1];
891 sinSegmentAngleRight = sinSegmentAngleRight * cosStep[part][1] + tmp * sinStep[part][1];
896 Q_ASSERT(index == vertexCount);
899 if (m_antialiasing) {
900 indices[--innerAAHead] = indices[innerAATail - 1];
901 indices[--innerAAHead] = indices[innerAATail - 2];
902 Q_ASSERT(innerAATail <= indexCount);
905 indices[--borderHead] = indices[borderTail - 1];
906 indices[--borderHead] = indices[borderTail - 2];
907 Q_ASSERT(borderTail <= indexCount);
909 if (m_antialiasing && penWidth) {
910 indices[--outerAAHead] = indices[outerAATail - 1];
911 indices[--outerAAHead] = indices[outerAATail - 2];
912 Q_ASSERT(outerAATail == indexCount);
916 QRectF innerRect = m_rect;
917 QRectF outerRect = m_rect;
920 innerRect.adjust(1.0f * penWidth, 1.0f * penWidth, -1.0f * penWidth, -1.0f * penWidth);
922 float delta = qMin(width, height) * 0.5f;
923 int innerVertexCount = 4 + gradientIntersections * 2;
924 int outerVertexCount = 4;
925 int vertexCount = innerVertexCount;
926 if (m_antialiasing || penWidth)
927 vertexCount += innerVertexCount;
929 vertexCount += outerVertexCount;
930 if (m_antialiasing && penWidth)
931 vertexCount += outerVertexCount;
933 int fillIndexCount = innerVertexCount;
934 int innerAAIndexCount = innerVertexCount * 2 + 2;
935 int borderIndexCount = innerVertexCount * 2 + 2;
936 int outerAAIndexCount = outerVertexCount * 2 + 2;
945 bool hasFill = m_color.alpha() > 0 || !stops.isEmpty();
947 indexCount += fillIndexCount;
948 if (m_antialiasing) {
949 innerAATail = innerAAHead = indexCount + (innerAAIndexCount >> 1) + 1;
950 indexCount += innerAAIndexCount;
953 borderTail = borderHead = indexCount + (borderIndexCount >> 1) + 1;
954 indexCount += borderIndexCount;
956 if (m_antialiasing && penWidth) {
957 outerAATail = outerAAHead = indexCount + (outerAAIndexCount >> 1) + 1;
958 indexCount += outerAAIndexCount;
961 g->allocate(vertexCount, indexCount);
962 vertices =
reinterpret_cast<Vertex *>(g->vertexData());
963 memset(vertices, 0, vertexCount * vertexStride);
964 quint16 *indices = g->indexDataAsUShort();
967 float innerStart = (m_gradient_is_vertical ? innerRect.top() : innerRect.left());
968 float innerEnd = (m_gradient_is_vertical ? innerRect.bottom() : innerRect.right());
969 float outerStart = (m_gradient_is_vertical ? outerRect.top() : outerRect.left());
970 float outerEnd = (m_gradient_is_vertical ? outerRect.bottom() : outerRect.right());
972 float innerSecondaryStart = (m_gradient_is_vertical ? innerRect.left() : innerRect.top());
973 float innerSecondaryEnd = (m_gradient_is_vertical ? innerRect.right() : innerRect.bottom());
974 float outerSecondaryStart = (m_gradient_is_vertical ? outerRect.left() : outerRect.top());
975 float outerSecondaryEnd = (m_gradient_is_vertical ? outerRect.right() : outerRect.bottom());
977 for (
int part = -1; part <= 1; part += 2) {
978 float innerEdge = (part == 1 ? innerEnd : innerStart);
979 float outerEdge = (part == 1 ? outerEnd : outerStart);
980 gradientPos = (innerEdge - innerStart + penWidth) / gradientLength;
982 while (nextGradientStop <= lastGradientStop && stops.at(nextGradientStop).first <= gradientPos) {
984 float gp = (innerStart - penWidth) + stops.at(nextGradientStop).first * gradientLength;
986 fillColor = colorToColor4ub(stops.at(nextGradientStop).second);
989 indices[fillHead++] = index;
990 indices[fillHead++] = index + 1;
995 indices[borderHead] = indices[borderHead + 2];
996 indices[--borderHead] = index + 2;
997 indices[borderTail++] = index + 3;
998 indices[borderTail] = indices[borderTail - 2];
1002 if (m_antialiasing) {
1003 indices[--innerAAHead] = index + 2;
1004 indices[--innerAAHead] = index;
1005 indices[innerAATail++] = index + 1;
1006 indices[innerAATail++] = index + 3;
1008 bool lower = stops.at(nextGradientStop).first > 0.5f;
1009 float dp = lower ? qMin(0.0f, gradientLength - gp - delta) : qMax(0.0f, delta - gp);
1010 smoothVertices[index++].set(gp, innerSecondaryEnd, fillColor, dp, secondaryLength - innerSecondaryEnd - delta, m_gradient_is_vertical);
1011 smoothVertices[index++].set(gp, innerSecondaryStart, fillColor, dp, delta - innerSecondaryStart, m_gradient_is_vertical);
1013 smoothVertices[index++].set(gp, innerSecondaryEnd, borderColor, (lower ? 0.49f : -0.49f) * penWidth, 0.49f * penWidth, m_gradient_is_vertical);
1014 smoothVertices[index++].set(gp, innerSecondaryStart, borderColor, (lower ? 0.49f : -0.49f) * penWidth, -0.49f * penWidth, m_gradient_is_vertical);
1016 smoothVertices[index++].set(gp, innerSecondaryEnd, transparent, lower ? delta : -delta, delta, m_gradient_is_vertical);
1017 smoothVertices[index++].set(gp, innerSecondaryStart, transparent, lower ? delta : -delta, -delta, m_gradient_is_vertical);
1020 vertices[index++].set(gp, innerSecondaryEnd, fillColor, m_gradient_is_vertical);
1021 vertices[index++].set(gp, innerSecondaryStart, fillColor, m_gradient_is_vertical);
1023 vertices[index++].set(gp, innerSecondaryEnd, borderColor, m_gradient_is_vertical);
1024 vertices[index++].set(gp, innerSecondaryStart, borderColor, m_gradient_is_vertical);
1030 if (!stops.isEmpty()) {
1031 if (nextGradientStop == 0) {
1032 fillColor = colorToColor4ub(stops.at(0).second);
1033 }
else if (nextGradientStop == stops.size()) {
1034 fillColor = colorToColor4ub(stops.last().second);
1036 const QGradientStop &prev = stops.at(nextGradientStop - 1);
1037 const QGradientStop &next = stops.at(nextGradientStop);
1038 float t = (gradientPos - prev.first) / (next.first - prev.first);
1039 fillColor = colorToColor4ub(prev.second) * (1 - t) + colorToColor4ub(next.second) * t;
1044 indices[fillHead++] = index;
1045 indices[fillHead++] = index + 1;
1049 indices[--borderHead] = index + 4;
1050 indices[--borderHead] = index + 2;
1051 indices[borderTail++] = index + 3;
1052 indices[borderTail++] = index + 5;
1055 if (m_antialiasing) {
1056 indices[--innerAAHead] = index + 2;
1057 indices[--innerAAHead] = index;
1058 indices[innerAATail++] = index + 1;
1059 indices[innerAATail++] = index + 3;
1061 float dp = part == 1 ? qMin(0.0f, gradientLength - innerEdge - delta) : qMax(0.0f, delta - innerEdge);
1062 smoothVertices[index++].set(innerEdge, innerSecondaryEnd, fillColor, dp, secondaryLength - innerSecondaryEnd - delta, m_gradient_is_vertical);
1063 smoothVertices[index++].set(innerEdge, innerSecondaryStart, fillColor, dp, delta - innerSecondaryStart, m_gradient_is_vertical);
1066 smoothVertices[index++].set(innerEdge, innerSecondaryEnd, borderColor, 0.49f * penWidth * part, 0.49f * penWidth, m_gradient_is_vertical);
1067 smoothVertices[index++].set(innerEdge, innerSecondaryStart, borderColor, 0.49f * penWidth * part, -0.49f * penWidth, m_gradient_is_vertical);
1068 smoothVertices[index++].set(outerEdge, outerSecondaryEnd, borderColor, -0.49f * penWidth * part, -0.49f * penWidth, m_gradient_is_vertical);
1069 smoothVertices[index++].set(outerEdge, outerSecondaryStart, borderColor, -0.49f * penWidth * part, 0.49f * penWidth, m_gradient_is_vertical);
1070 smoothVertices[index++].set(outerEdge, outerSecondaryEnd, transparent, delta * part, delta, m_gradient_is_vertical);
1071 smoothVertices[index++].set(outerEdge, outerSecondaryStart, transparent, delta * part, -delta, m_gradient_is_vertical);
1073 indices[--outerAAHead] = index - 2;
1074 indices[--outerAAHead] = index - 4;
1075 indices[outerAATail++] = index - 3;
1076 indices[outerAATail++] = index - 1;
1078 smoothVertices[index++].set(innerEdge, innerSecondaryEnd, transparent, delta * part, delta, m_gradient_is_vertical);
1079 smoothVertices[index++].set(innerEdge, innerSecondaryStart, transparent, delta * part, -delta, m_gradient_is_vertical);
1082 vertices[index++].set(innerEdge, innerSecondaryEnd, fillColor, m_gradient_is_vertical);
1083 vertices[index++].set(innerEdge, innerSecondaryStart, fillColor, m_gradient_is_vertical);
1085 vertices[index++].set(innerEdge, innerSecondaryEnd, borderColor, m_gradient_is_vertical);
1086 vertices[index++].set(innerEdge, innerSecondaryStart, borderColor, m_gradient_is_vertical);
1087 vertices[index++].set(outerEdge, outerSecondaryEnd, borderColor, m_gradient_is_vertical);
1088 vertices[index++].set(outerEdge, outerSecondaryStart, borderColor, m_gradient_is_vertical);
1092 Q_ASSERT(index == vertexCount);
1095 if (m_antialiasing) {
1096 indices[--innerAAHead] = indices[innerAATail - 1];
1097 indices[--innerAAHead] = indices[innerAATail - 2];
1098 Q_ASSERT(innerAATail <= indexCount);
1101 indices[--borderHead] = indices[borderTail - 1];
1102 indices[--borderHead] = indices[borderTail - 2];
1103 Q_ASSERT(borderTail <= indexCount);
1105 if (m_antialiasing && penWidth) {
1106 indices[--outerAAHead] = indices[outerAATail - 1];
1107 indices[--outerAAHead] = indices[outerAATail - 2];
1108 Q_ASSERT(outerAATail == indexCount);