265void QSGBasicInternalRectangleNode::updateGeometry()
267 float width =
float(m_rect.width());
268 float height =
float(m_rect.height());
269 float penWidth = qMin(qMin(width, height) * 0.5f,
float(m_pen_width));
272 penWidth = qRound(penWidth);
274 QSGGeometry *g = geometry();
275 g->setDrawingMode(QSGGeometry::DrawTriangleStrip);
276 int vertexStride = g->sizeOfVertex();
280 SmoothVertex *smoothVertices;
283 Color4ub fillColor = colorToColor4ub(m_color);
284 Color4ub borderColor = colorToColor4ub(m_border_color);
285 Color4ub transparent = { 0, 0, 0, 0 };
286 const QGradientStops &stops = m_gradient_stops;
288 float gradientStart = (m_gradient_is_vertical ? m_rect.top() : m_rect.left());
289 float gradientLength = (m_gradient_is_vertical ? height : width);
290 float secondaryLength = (m_gradient_is_vertical ? width : height);
292 int nextGradientStop = 0;
293 float gradientPos = penWidth / gradientLength;
294 while (nextGradientStop < stops.size() && stops.at(nextGradientStop).first <= gradientPos)
296 int lastGradientStop = stops.size() - 1;
297 float lastGradientPos = 1.0f - penWidth / gradientLength;
298 while (lastGradientStop >= nextGradientStop && stops.at(lastGradientStop).first >= lastGradientPos)
300 int gradientIntersections = (lastGradientStop - nextGradientStop + 1);
303 || m_isTopLeftRadiusSet
304 || m_isTopRightRadiusSet
305 || m_isBottomLeftRadiusSet
306 || m_isBottomRightRadiusSet) {
310 float radiusTL = qMin(qMin(width, height) * 0.4999f,
311 float(m_isTopLeftRadiusSet ? m_topLeftRadius : m_radius));
312 float radiusTR = qMin(qMin(width, height) * 0.4999f,
313 float(m_isTopRightRadiusSet ? m_topRightRadius : m_radius));
314 float radiusBL = qMin(qMin(width, height) * 0.4999f,
315 float(m_isBottomLeftRadiusSet ? m_bottomLeftRadius : m_radius));
316 float radiusBR = qMin(qMin(width, height) * 0.4999f,
317 float(m_isBottomRightRadiusSet ? m_bottomRightRadius : m_radius));
332 const float innerRadiusTL = qMax(radiusTL - penWidth * 1.0f, 0.01);
333 const float innerRadiusTR = qMax(radiusTR - penWidth * 1.0f, 0.01);
334 const float innerRadiusBL = qMax(radiusBL - penWidth * 1.0f, 0.01);
335 const float innerRadiusBR = qMax(radiusBR - penWidth * 1.0f, 0.01);
336 const float outerRadiusTL = radiusTL;
337 const float outerRadiusTR = radiusTR;
338 const float outerRadiusBL = radiusBL;
339 const float outerRadiusBR = radiusBR;
340 const float delta = qMin(width, height) * 0.5f;
342 int segmentsTL = radiusTL == 0 ? 0 : qBound(3, qCeil(radiusTL * (M_PI / 6)), 18);
343 int segmentsTR = radiusTR == 0 ? 0 : qBound(3, qCeil(radiusTR * (M_PI / 6)), 18);
344 int segmentsBL = radiusBL == 0 ? 0 : qBound(3, qCeil(radiusBL * (M_PI / 6)), 18);
345 int segmentsBR = radiusBR == 0 ? 0 : qBound(3, qCeil(radiusBR * (M_PI / 6)), 18);
350 if (m_gradient_is_vertical) {
351 if (innerRadiusTL == innerRadiusTR) {
352 if (segmentsTL <= segmentsTR)
357 if (innerRadiusBL == innerRadiusBR){
358 if (segmentsBL <= segmentsBR)
364 if (innerRadiusTL == innerRadiusBL) {
365 if (segmentsTL <= segmentsBL)
370 if (innerRadiusTR == innerRadiusBR) {
371 if (segmentsTR <= segmentsBR)
378 const int sumSegments = segmentsTL + segmentsTR + segmentsBL + segmentsBR;
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
400 const int innerVertexCount = (sumSegments + 4) * 2 + gradientIntersections * 2;
401 const int outerVertexCount = (sumSegments + 4) * 2;
402 int vertexCount = innerVertexCount;
403 if (m_antialiasing || penWidth)
404 vertexCount += innerVertexCount;
406 vertexCount += outerVertexCount;
407 if (m_antialiasing && penWidth)
408 vertexCount += outerVertexCount;
411 const int fillIndexCount = innerVertexCount;
412 const int innerAAIndexCount = innerVertexCount * 2 + 2;
413 const int borderIndexCount = innerVertexCount * 2 + 2;
414 const int outerAAIndexCount = outerVertexCount * 2 + 2;
423 bool hasFill = m_color.alpha() > 0 || !stops.isEmpty();
425 indexCount += fillIndexCount;
426 if (m_antialiasing) {
427 innerAATail = innerAAHead = indexCount + (innerAAIndexCount >> 1) + 1;
428 indexCount += innerAAIndexCount;
431 borderTail = borderHead = indexCount + (borderIndexCount >> 1) + 1;
432 indexCount += borderIndexCount;
434 if (m_antialiasing && penWidth) {
435 outerAATail = outerAAHead = indexCount + (outerAAIndexCount >> 1) + 1;
436 indexCount += outerAAIndexCount;
439 g->allocate(vertexCount, indexCount);
440 vertices =
reinterpret_cast<Vertex *>(g->vertexData());
441 memset(vertices, 0, vertexCount * vertexStride);
442 quint16 *indices = g->indexDataAsUShort();
446 float innerXPrev = 0.;
447 float innerYLeftPrev = 0.;
448 float innerYRightPrev = 0.;
450 const float angleTL = 0.5f *
float(M_PI) / segmentsTL;
451 const float cosStepTL = qFastCos(angleTL);
452 const float sinStepTL = qFastSin(angleTL);
453 const float angleTR = 0.5f *
float(M_PI) / segmentsTR;
454 const float cosStepTR = qFastCos(angleTR);
455 const float sinStepTR = qFastSin(angleTR);
456 const float angleBL = 0.5f *
float(M_PI) / segmentsBL;
457 const float cosStepBL = qFastCos(angleBL);
458 const float sinStepBL = qFastSin(angleBL);
459 const float angleBR = 0.5f *
float(M_PI) / segmentsBR;
460 const float cosStepBR = qFastCos(angleBR);
461 const float sinStepBR = qFastSin(angleBR);
493 const float outerXCenter[][2] = {{
494 float(m_gradient_is_vertical ? m_rect.top() + radiusTL : m_rect.left() + radiusTL),
495 float(m_gradient_is_vertical ? m_rect.top() + radiusTR : m_rect.left() + radiusBL)
497 float(m_gradient_is_vertical ? m_rect.bottom() - radiusBL : m_rect.right() - radiusTR),
498 float(m_gradient_is_vertical ? m_rect.bottom() - radiusBR : m_rect.right() - radiusBR)
501 const float outerYCenter[][2] = {{
502 float(!m_gradient_is_vertical ? m_rect.top() + outerRadiusTL : m_rect.left() + outerRadiusTL),
503 float(!m_gradient_is_vertical ? m_rect.bottom() - outerRadiusBL : m_rect.right() - outerRadiusTR)
505 float(!m_gradient_is_vertical ? m_rect.top() + outerRadiusTR : m_rect.left() + outerRadiusBL),
506 float(!m_gradient_is_vertical ? m_rect.bottom() - outerRadiusBR : m_rect.right() - outerRadiusBR)
509 const float innerXCenter[][2] = { {
510 float(m_gradient_is_vertical ? m_rect.top() + innerRadiusTL + penWidth : m_rect.left() + innerRadiusTL + penWidth),
511 float(m_gradient_is_vertical ? m_rect.top() + innerRadiusTR + penWidth: m_rect.left() + innerRadiusBL + penWidth)
513 float(m_gradient_is_vertical ? m_rect.bottom() - innerRadiusBL - penWidth: m_rect.right() - innerRadiusTR - penWidth),
514 float(m_gradient_is_vertical ? m_rect.bottom() - innerRadiusBR - penWidth: m_rect.right() - innerRadiusBR - penWidth)
517 const float innerYCenter[][2] = { {
518 float(!m_gradient_is_vertical ? m_rect.top() + innerRadiusTL + penWidth : m_rect.left() + innerRadiusTL + penWidth),
519 float(!m_gradient_is_vertical ? m_rect.bottom() - innerRadiusBL - penWidth : m_rect.right() - innerRadiusTR - penWidth)
521 float(!m_gradient_is_vertical ? m_rect.top() + innerRadiusTR + penWidth : m_rect.left() + innerRadiusBL + penWidth),
522 float(!m_gradient_is_vertical ? m_rect.bottom() - innerRadiusBR - penWidth : m_rect.right() - innerRadiusBR - penWidth)
525 const float innerRadius[][2] = {{
527 !m_gradient_is_vertical ? innerRadiusBL : innerRadiusTR
529 !m_gradient_is_vertical ? innerRadiusTR : innerRadiusBL,
533 const float outerRadius[][2] = {{
535 !m_gradient_is_vertical ? outerRadiusBL : outerRadiusTR
537 !m_gradient_is_vertical ? outerRadiusTR : outerRadiusBL,
541 const int segments[][2] = {{
543 !m_gradient_is_vertical ? segmentsBL : segmentsTR
545 !m_gradient_is_vertical ? segmentsTR : segmentsBL,
549 const float cosStep[][2] = {{
551 !m_gradient_is_vertical ? cosStepBL : cosStepTR
553 !m_gradient_is_vertical ? cosStepTR : cosStepBL,
557 const float sinStep[][2] = {{
559 !m_gradient_is_vertical ? sinStepBL : sinStepTR
561 !m_gradient_is_vertical ? sinStepTR : sinStepBL,
565 auto fillColorFromX = [&](
float x) {
567 float t = (x - gradientStart) / gradientLength;
568 t = qBound(0.0, t, 1.0);
571 if (t < stops.first().first)
572 return colorToColor4ub(stops.first().second);
573 while (i < stops.size()) {
574 const QGradientStop &prev = stops.at(i - 1);
575 const QGradientStop &next = stops.at(i);
576 if (prev.first <= t && next.first > t) {
577 t = (t - prev.first) / (next.first - prev.first);
578 return colorToColor4ub(prev.second) * (1. - t) + colorToColor4ub(next.second) * t; }
581 return colorToColor4ub(stops.last().second);
584 for (
int part = 0; part < 2; ++part) {
586 float cosSegmentAngleLeft = 1. - part;
588 float sinSegmentAngleLeft = part;
590 float cosSegmentAngleRight = 1. - part;
591 float sinSegmentAngleRight = part;
593 bool advanceLeft =
true;
598 for (
int iLeft = 0, iRight = 0; iLeft <= segments[part][0] || iRight <= segments[part][1]; ) {
603 float outerXLeft, outerYLeft,
604 outerXRight, outerYRight;
606 float sinAngleLeft, cosAngleLeft,
607 sinAngleRight, cosAngleRight;
610 xLeft = innerXCenter[part][0] - innerRadius[part][0] * cosSegmentAngleLeft;
611 xRight = innerXCenter[part][1] - innerRadius[part][1] * cosSegmentAngleRight;
614 yLeft = innerYCenter[part][0] - innerRadius[part][0] * sinSegmentAngleLeft;
615 yRight = innerYCenter[part][1] + innerRadius[part][1] * sinSegmentAngleRight;
621 if ((iLeft <= segments[part][0] && xLeft <= xRight) || iRight > segments[part][1]) {
630 if (innerRadius[part][0] == innerRadius[part][1]) {
635 if (outerRadius[part][0] == 0) {
637 cosAngleLeft = part ? -1. : 1.;
639 sinAngleLeft = sinSegmentAngleLeft;
640 cosAngleLeft = cosSegmentAngleLeft;
642 if (outerRadius[part][1] == 0) {
644 cosAngleRight = part ? -1. : 1.;
646 sinAngleRight = sinSegmentAngleLeft;
647 cosAngleRight = cosSegmentAngleLeft;
650 yRight = innerYCenter[part][1] + innerRadius[part][1] * sinAngleRight;
652 if (outerRadius[part][0] == 0) {
654 cosAngleLeft = part ? -1. : 1.;
656 sinAngleLeft = sinSegmentAngleRight;
657 cosAngleLeft = cosSegmentAngleRight;
659 if (outerRadius[part][1] == 0) {
661 cosAngleRight = part ? -1. : 1.;
663 sinAngleRight = sinSegmentAngleRight;
664 cosAngleRight = cosSegmentAngleRight;
667 yLeft = innerYCenter[part][0] - innerRadius[part][0] * sinAngleLeft;
669 }
else if (advanceLeft) {
670 if (outerRadius[part][0] == 0) {
672 cosAngleLeft = part ? -1. : 1.;
674 sinAngleLeft = sinSegmentAngleLeft;
675 cosAngleLeft = cosSegmentAngleLeft;
677 if (outerRadius[part][1] == 0) {
682 cosAngleRight = part ? -1. : 1.;
684 yRight = innerYCenter[part][1] + innerRadius[part][1] * sinAngleRight;
685 }
else if (xLeft >= innerXCenter[0][1] && xLeft <= innerXCenter[1][1]) {
692 yRight = innerYCenter[part][1] + innerRadius[part][1] * sinAngleRight;
699 if (xRight != innerXPrev) {
700 float t = (xLeft - innerXPrev) / (xRight - innerXPrev);
701 yRight = innerYRightPrev * (1. - t) + yRight * t;
706 sinAngleRight = (yRight - innerYCenter[part][1]) / innerRadius[part][1];
707 cosAngleRight = -(xRight - innerXCenter[part][1]) / innerRadius[part][1];
711 if (outerRadius[part][1] == 0) {
713 cosAngleRight = part ? -1. : 1.;
715 sinAngleRight = sinSegmentAngleRight;
716 cosAngleRight = cosSegmentAngleRight;
718 if (outerRadius[part][0] == 0) {
720 cosAngleLeft = part ? -1. : 1.;
722 yLeft = innerYCenter[part][0] - innerRadius[part][0] * sinAngleLeft;
723 }
else if (xRight >= innerXCenter[0][0] && xRight <= innerXCenter[1][0]) {
727 yLeft = innerYCenter[part][0] - innerRadius[part][0] * sinAngleLeft;
729 if (xLeft != innerXPrev) {
730 float t = (xRight - innerXPrev) / (xLeft - innerXPrev);
731 yLeft = innerYLeftPrev * (1. - t) + yLeft * t;
734 sinAngleLeft = -(yLeft - innerYCenter[part][0]) / innerRadius[part][0];
735 cosAngleLeft = -(xLeft - innerXCenter[part][0]) / innerRadius[part][0];
739 gradientPos = (xLeft - gradientStart) / gradientLength;
742 outerXLeft = outerXCenter[part][0] - outerRadius[part][0] * cosAngleLeft;
743 outerYLeft = outerYCenter[part][0] - outerRadius[part][0] * sinAngleLeft;
744 outerXRight = outerXCenter[part][1] - outerRadius[part][1] * cosAngleRight;
745 outerYRight = outerYCenter[part][1] + outerRadius[part][1] * sinAngleRight;
748 while (nextGradientStop <= lastGradientStop && stops.at(nextGradientStop).first <= gradientPos) {
751 float gradientYRight;
754 gradientX = gradientStart + stops.at(nextGradientStop).first * gradientLength;
756 float t = (gradientX - innerXPrev) / (xLeft - innerXPrev);
757 gradientYLeft = innerYLeftPrev * (1. - t) + t * yLeft;
758 gradientYRight = innerYRightPrev * (1. - t) + t * yRight;
760 fillColor = fillColorFromX(gradientX);
763 indices[fillHead++] = index;
764 indices[fillHead++] = index + 1;
769 indices[borderHead] = indices[borderHead + 2];
770 indices[--borderHead] = index + 2;
771 indices[borderTail++] = index + 3;
772 indices[borderTail] = indices[borderTail - 2];
776 if (m_antialiasing) {
777 indices[--innerAAHead] = index + 2;
778 indices[--innerAAHead] = index;
779 indices[innerAATail++] = index + 1;
780 indices[innerAATail++] = index + 3;
782 bool lower = stops.at(nextGradientStop).first > 0.5f;
783 float dp = lower ? qMin(0.0f, gradientLength - gradientX - delta) : qMax(0.0f, delta - gradientX);
784 smoothVertices[index++].set(gradientX, gradientYRight, fillColor, dp, secondaryLength - gradientYRight - delta, m_gradient_is_vertical);
785 smoothVertices[index++].set(gradientX, gradientYLeft, fillColor, dp, delta - gradientYLeft, m_gradient_is_vertical);
787 smoothVertices[index++].set(gradientX, gradientYRight, borderColor, -0.49f * penWidth * cosAngleRight, 0.49f * penWidth * sinAngleRight, m_gradient_is_vertical);
788 smoothVertices[index++].set(gradientX, gradientYLeft, borderColor, -0.49f * penWidth * cosAngleLeft, -0.49f * penWidth * sinAngleLeft, m_gradient_is_vertical);
790 dp = lower ? delta : -delta;
791 smoothVertices[index++].set(gradientX, gradientYRight, transparent, dp, delta, m_gradient_is_vertical);
792 smoothVertices[index++].set(gradientX, gradientYLeft, transparent, dp, -delta, m_gradient_is_vertical);
795 vertices[index++].set(gradientX, gradientYRight, fillColor, m_gradient_is_vertical);
796 vertices[index++].set(gradientX, gradientYLeft, fillColor, m_gradient_is_vertical);
798 vertices[index++].set(gradientX, gradientYRight, borderColor, m_gradient_is_vertical);
799 vertices[index++].set(gradientX, gradientYLeft, borderColor, m_gradient_is_vertical);
803 innerXPrev = gradientX;
804 innerYLeftPrev = gradientYLeft;
805 innerYRightPrev = gradientYRight;
810 if (!stops.isEmpty()) {
811 fillColor = fillColorFromX(xLeft);
815 indices[fillHead++] = index;
816 indices[fillHead++] = index + 1;
820 indices[--borderHead] = index + 4;
821 indices[--borderHead] = index + 2;
822 indices[borderTail++] = index + 3;
823 indices[borderTail++] = index + 5;
826 if (m_antialiasing) {
827 indices[--innerAAHead] = index + 2;
828 indices[--innerAAHead] = index;
829 indices[innerAATail++] = index + 1;
830 indices[innerAATail++] = index + 3;
832 float dp = part ? qMin(0.0f, gradientLength - xRight - delta) : qMax(0.0f, delta - xRight);
833 smoothVertices[index++].set(xRight, yRight, fillColor, dp, secondaryLength - yRight - delta, m_gradient_is_vertical);
834 smoothVertices[index++].set(xLeft, yLeft, fillColor, dp, delta - yLeft, m_gradient_is_vertical);
836 dp = part ? delta : -delta;
838 smoothVertices[index++].set(xRight, yRight, borderColor, -0.49f * penWidth * cosAngleRight, 0.49f * penWidth * sinAngleRight, m_gradient_is_vertical);
839 smoothVertices[index++].set(xLeft, yLeft, borderColor, -0.49f * penWidth * cosAngleLeft, -0.49f * penWidth * sinAngleLeft, m_gradient_is_vertical);
840 smoothVertices[index++].set(outerXRight, outerYRight, borderColor, 0.49f * penWidth * cosAngleRight, -0.49f * penWidth * sinAngleRight, m_gradient_is_vertical);
841 smoothVertices[index++].set(outerXLeft, outerYLeft, borderColor, 0.49f * penWidth * cosAngleLeft, 0.49f * penWidth * sinAngleLeft, m_gradient_is_vertical);
842 smoothVertices[index++].set(outerXRight, outerYRight, transparent, dp, delta, m_gradient_is_vertical);
843 smoothVertices[index++].set(outerXLeft, outerYLeft, transparent, dp, -delta, m_gradient_is_vertical);
845 indices[--outerAAHead] = index - 2;
846 indices[--outerAAHead] = index - 4;
847 indices[outerAATail++] = index - 3;
848 indices[outerAATail++] = index - 1;
850 smoothVertices[index++].set(xRight, yRight, transparent, dp, delta, m_gradient_is_vertical);
851 smoothVertices[index++].set(xLeft, yLeft, transparent, dp, -delta, m_gradient_is_vertical);
854 vertices[index++].set(xRight, yRight, fillColor, m_gradient_is_vertical);
855 vertices[index++].set(xLeft, yLeft, fillColor, m_gradient_is_vertical);
857 vertices[index++].set(xRight, yRight, borderColor, m_gradient_is_vertical);
858 vertices[index++].set(xLeft, yLeft, borderColor, m_gradient_is_vertical);
859 vertices[index++].set(outerXRight, outerYRight, borderColor, m_gradient_is_vertical);
860 vertices[index++].set(outerXLeft, outerYLeft, borderColor, m_gradient_is_vertical);
865 innerYLeftPrev = yLeft;
866 innerYRightPrev = yRight;
871 qreal tmp = cosSegmentAngleLeft;
872 cosSegmentAngleLeft = cosSegmentAngleLeft * cosStep[part][0] - sinSegmentAngleLeft * sinStep[part][0];
873 sinSegmentAngleLeft = sinSegmentAngleLeft * cosStep[part][0] + tmp * sinStep[part][0];
876 qreal tmp = cosSegmentAngleRight;
877 cosSegmentAngleRight = cosSegmentAngleRight * cosStep[part][1] - sinSegmentAngleRight * sinStep[part][1];
878 sinSegmentAngleRight = sinSegmentAngleRight * cosStep[part][1] + tmp * sinStep[part][1];
883 Q_ASSERT(index == vertexCount);
886 if (m_antialiasing) {
887 indices[--innerAAHead] = indices[innerAATail - 1];
888 indices[--innerAAHead] = indices[innerAATail - 2];
889 Q_ASSERT(innerAATail <= indexCount);
892 indices[--borderHead] = indices[borderTail - 1];
893 indices[--borderHead] = indices[borderTail - 2];
894 Q_ASSERT(borderTail <= indexCount);
896 if (m_antialiasing && penWidth) {
897 indices[--outerAAHead] = indices[outerAATail - 1];
898 indices[--outerAAHead] = indices[outerAATail - 2];
899 Q_ASSERT(outerAATail == indexCount);
903 QRectF innerRect = m_rect;
904 QRectF outerRect = m_rect;
907 innerRect.adjust(1.0f * penWidth, 1.0f * penWidth, -1.0f * penWidth, -1.0f * penWidth);
909 float delta = qMin(width, height) * 0.5f;
910 int innerVertexCount = 4 + gradientIntersections * 2;
911 int outerVertexCount = 4;
912 int vertexCount = innerVertexCount;
913 if (m_antialiasing || penWidth)
914 vertexCount += innerVertexCount;
916 vertexCount += outerVertexCount;
917 if (m_antialiasing && penWidth)
918 vertexCount += outerVertexCount;
920 int fillIndexCount = innerVertexCount;
921 int innerAAIndexCount = innerVertexCount * 2 + 2;
922 int borderIndexCount = innerVertexCount * 2 + 2;
923 int outerAAIndexCount = outerVertexCount * 2 + 2;
932 bool hasFill = m_color.alpha() > 0 || !stops.isEmpty();
934 indexCount += fillIndexCount;
935 if (m_antialiasing) {
936 innerAATail = innerAAHead = indexCount + (innerAAIndexCount >> 1) + 1;
937 indexCount += innerAAIndexCount;
940 borderTail = borderHead = indexCount + (borderIndexCount >> 1) + 1;
941 indexCount += borderIndexCount;
943 if (m_antialiasing && penWidth) {
944 outerAATail = outerAAHead = indexCount + (outerAAIndexCount >> 1) + 1;
945 indexCount += outerAAIndexCount;
948 g->allocate(vertexCount, indexCount);
949 vertices =
reinterpret_cast<Vertex *>(g->vertexData());
950 memset(vertices, 0, vertexCount * vertexStride);
951 quint16 *indices = g->indexDataAsUShort();
954 float innerStart = (m_gradient_is_vertical ? innerRect.top() : innerRect.left());
955 float innerEnd = (m_gradient_is_vertical ? innerRect.bottom() : innerRect.right());
956 float outerStart = (m_gradient_is_vertical ? outerRect.top() : outerRect.left());
957 float outerEnd = (m_gradient_is_vertical ? outerRect.bottom() : outerRect.right());
959 float innerSecondaryStart = (m_gradient_is_vertical ? innerRect.left() : innerRect.top());
960 float innerSecondaryEnd = (m_gradient_is_vertical ? innerRect.right() : innerRect.bottom());
961 float outerSecondaryStart = (m_gradient_is_vertical ? outerRect.left() : outerRect.top());
962 float outerSecondaryEnd = (m_gradient_is_vertical ? outerRect.right() : outerRect.bottom());
964 for (
int part = -1; part <= 1; part += 2) {
965 float innerEdge = (part == 1 ? innerEnd : innerStart);
966 float outerEdge = (part == 1 ? outerEnd : outerStart);
967 gradientPos = (innerEdge - innerStart + penWidth) / gradientLength;
969 while (nextGradientStop <= lastGradientStop && stops.at(nextGradientStop).first <= gradientPos) {
971 float gp = (innerStart - penWidth) + stops.at(nextGradientStop).first * gradientLength;
973 fillColor = colorToColor4ub(stops.at(nextGradientStop).second);
976 indices[fillHead++] = index;
977 indices[fillHead++] = index + 1;
982 indices[borderHead] = indices[borderHead + 2];
983 indices[--borderHead] = index + 2;
984 indices[borderTail++] = index + 3;
985 indices[borderTail] = indices[borderTail - 2];
989 if (m_antialiasing) {
990 indices[--innerAAHead] = index + 2;
991 indices[--innerAAHead] = index;
992 indices[innerAATail++] = index + 1;
993 indices[innerAATail++] = index + 3;
995 bool lower = stops.at(nextGradientStop).first > 0.5f;
996 float dp = lower ? qMin(0.0f, gradientLength - gp - delta) : qMax(0.0f, delta - gp);
997 smoothVertices[index++].set(gp, innerSecondaryEnd, fillColor, dp, secondaryLength - innerSecondaryEnd - delta, m_gradient_is_vertical);
998 smoothVertices[index++].set(gp, innerSecondaryStart, fillColor, dp, delta - innerSecondaryStart, m_gradient_is_vertical);
1000 smoothVertices[index++].set(gp, innerSecondaryEnd, borderColor, (lower ? 0.49f : -0.49f) * penWidth, 0.49f * penWidth, m_gradient_is_vertical);
1001 smoothVertices[index++].set(gp, innerSecondaryStart, borderColor, (lower ? 0.49f : -0.49f) * penWidth, -0.49f * penWidth, m_gradient_is_vertical);
1003 smoothVertices[index++].set(gp, innerSecondaryEnd, transparent, lower ? delta : -delta, delta, m_gradient_is_vertical);
1004 smoothVertices[index++].set(gp, innerSecondaryStart, transparent, lower ? delta : -delta, -delta, m_gradient_is_vertical);
1007 vertices[index++].set(gp, innerSecondaryEnd, fillColor, m_gradient_is_vertical);
1008 vertices[index++].set(gp, innerSecondaryStart, fillColor, m_gradient_is_vertical);
1010 vertices[index++].set(gp, innerSecondaryEnd, borderColor, m_gradient_is_vertical);
1011 vertices[index++].set(gp, innerSecondaryStart, borderColor, m_gradient_is_vertical);
1017 if (!stops.isEmpty()) {
1018 if (nextGradientStop == 0) {
1019 fillColor = colorToColor4ub(stops.at(0).second);
1020 }
else if (nextGradientStop == stops.size()) {
1021 fillColor = colorToColor4ub(stops.last().second);
1023 const QGradientStop &prev = stops.at(nextGradientStop - 1);
1024 const QGradientStop &next = stops.at(nextGradientStop);
1025 float t = (gradientPos - prev.first) / (next.first - prev.first);
1026 fillColor = colorToColor4ub(prev.second) * (1 - t) + colorToColor4ub(next.second) * t;
1031 indices[fillHead++] = index;
1032 indices[fillHead++] = index + 1;
1036 indices[--borderHead] = index + 4;
1037 indices[--borderHead] = index + 2;
1038 indices[borderTail++] = index + 3;
1039 indices[borderTail++] = index + 5;
1042 if (m_antialiasing) {
1043 indices[--innerAAHead] = index + 2;
1044 indices[--innerAAHead] = index;
1045 indices[innerAATail++] = index + 1;
1046 indices[innerAATail++] = index + 3;
1048 float dp = part == 1 ? qMin(0.0f, gradientLength - innerEdge - delta) : qMax(0.0f, delta - innerEdge);
1049 smoothVertices[index++].set(innerEdge, innerSecondaryEnd, fillColor, dp, secondaryLength - innerSecondaryEnd - delta, m_gradient_is_vertical);
1050 smoothVertices[index++].set(innerEdge, innerSecondaryStart, fillColor, dp, delta - innerSecondaryStart, m_gradient_is_vertical);
1053 smoothVertices[index++].set(innerEdge, innerSecondaryEnd, borderColor, 0.49f * penWidth * part, 0.49f * penWidth, m_gradient_is_vertical);
1054 smoothVertices[index++].set(innerEdge, innerSecondaryStart, borderColor, 0.49f * penWidth * part, -0.49f * penWidth, m_gradient_is_vertical);
1055 smoothVertices[index++].set(outerEdge, outerSecondaryEnd, borderColor, -0.49f * penWidth * part, -0.49f * penWidth, m_gradient_is_vertical);
1056 smoothVertices[index++].set(outerEdge, outerSecondaryStart, borderColor, -0.49f * penWidth * part, 0.49f * penWidth, m_gradient_is_vertical);
1057 smoothVertices[index++].set(outerEdge, outerSecondaryEnd, transparent, delta * part, delta, m_gradient_is_vertical);
1058 smoothVertices[index++].set(outerEdge, outerSecondaryStart, transparent, delta * part, -delta, m_gradient_is_vertical);
1060 indices[--outerAAHead] = index - 2;
1061 indices[--outerAAHead] = index - 4;
1062 indices[outerAATail++] = index - 3;
1063 indices[outerAATail++] = index - 1;
1065 smoothVertices[index++].set(innerEdge, innerSecondaryEnd, transparent, delta * part, delta, m_gradient_is_vertical);
1066 smoothVertices[index++].set(innerEdge, innerSecondaryStart, transparent, delta * part, -delta, m_gradient_is_vertical);
1069 vertices[index++].set(innerEdge, innerSecondaryEnd, fillColor, m_gradient_is_vertical);
1070 vertices[index++].set(innerEdge, innerSecondaryStart, fillColor, m_gradient_is_vertical);
1072 vertices[index++].set(innerEdge, innerSecondaryEnd, borderColor, m_gradient_is_vertical);
1073 vertices[index++].set(innerEdge, innerSecondaryStart, borderColor, m_gradient_is_vertical);
1074 vertices[index++].set(outerEdge, outerSecondaryEnd, borderColor, m_gradient_is_vertical);
1075 vertices[index++].set(outerEdge, outerSecondaryStart, borderColor, m_gradient_is_vertical);
1079 Q_ASSERT(index == vertexCount);
1082 if (m_antialiasing) {
1083 indices[--innerAAHead] = indices[innerAATail - 1];
1084 indices[--innerAAHead] = indices[innerAATail - 2];
1085 Q_ASSERT(innerAATail <= indexCount);
1088 indices[--borderHead] = indices[borderTail - 1];
1089 indices[--borderHead] = indices[borderTail - 2];
1090 Q_ASSERT(borderTail <= indexCount);
1092 if (m_antialiasing && penWidth) {
1093 indices[--outerAAHead] = indices[outerAATail - 1];
1094 indices[--outerAAHead] = indices[outerAATail - 2];
1095 Q_ASSERT(outerAATail == indexCount);