src/gldraw.cpp

changeset 505
a01482cdf8a7
parent 504
6a1fa662bfc1
child 506
525f6c48db83
equal deleted inserted replaced
504:6a1fa662bfc1 505:a01482cdf8a7
565 vertex polyverts[4]; 565 vertex polyverts[4];
566 566
567 if (!m_rectdraw) 567 if (!m_rectdraw)
568 { uchar i = 0; 568 { uchar i = 0;
569 569
570 for (vertex & vert : m_drawedVerts) 570 for (vertex& vert : m_drawedVerts)
571 { poly[i] = coordconv3_2 (vert); 571 { poly[i] = coordconv3_2 (vert);
572 polyverts[i] = vert; 572 polyverts[i] = vert;
573 ++i; 573 ++i;
574 } 574 }
575 575
620 const double dist0 = circleDrawDist(0), 620 const double dist0 = circleDrawDist(0),
621 dist1 = (m_drawedVerts.size() >= 2) ? circleDrawDist (1) : -1; 621 dist1 = (m_drawedVerts.size() >= 2) ? circleDrawDist (1) : -1;
622 const int segs = lores; 622 const int segs = lores;
623 const double angleUnit = (2 * pi) / segs; 623 const double angleUnit = (2 * pi) / segs;
624 Axis relX, relY; 624 Axis relX, relY;
625 QVector<QPoint> points, 625 QVector<QPoint> ringpoints, circlepoints, circle2points;
626 points2;
627 626
628 getRelativeAxes (relX, relY); 627 getRelativeAxes (relX, relY);
629 628
629 // Calculate the preview positions of vertices
630 for (int i = 0; i < segs; ++i) 630 for (int i = 0; i < segs; ++i)
631 { vertex v = g_origin; 631 { vertex v = g_origin;
632 v[relX] = m_drawedVerts[0][relX] + (cos (i * angleUnit) * dist0); 632 v[relX] = m_drawedVerts[0][relX] + (cos (i * angleUnit) * dist0);
633 v[relY] = m_drawedVerts[0][relY] + (sin (i * angleUnit) * dist0); 633 v[relY] = m_drawedVerts[0][relY] + (sin (i * angleUnit) * dist0);
634 verts << v; 634 verts << v;
638 v[relY] = m_drawedVerts[0][relY] + (sin (i * angleUnit) * dist1); 638 v[relY] = m_drawedVerts[0][relY] + (sin (i * angleUnit) * dist1);
639 verts2 << v; 639 verts2 << v;
640 } 640 }
641 } 641 }
642 642
643 int i = 0;
643 for (const vertex& v : verts + verts2) 644 for (const vertex& v : verts + verts2)
644 { QPoint point = coordconv3_2 (v); 645 { // Calculate the 2D point of the vertex
646 QPoint point = coordconv3_2 (v);
647
648 // Draw a green blip at where it is
645 drawBlip (paint, point); 649 drawBlip (paint, point);
646 points << point; 650
651 // Add it to the list of points for the green ring fill.
652 ringpoints << point;
653
654 // Also add the circle points to separate lists
655 if (i < verts.size())
656 circlepoints << point;
657 else
658 circle2points << point;
659
660 ++i;
647 } 661 }
648 662
649 // Insert the first point as the seventeenth one so that 663 // Insert the first point as the seventeenth one so that
650 // the ring polygon is closed properly. 664 // the ring polygon is closed properly.
651 if (points.size() >= 16) 665 if (ringpoints.size() >= 16)
652 points.insert (16, points[0]); 666 ringpoints.insert (16, ringpoints[0]);
653 667
654 // Same for the outer ring. Note that the indices are offset by 1 668 // Same for the outer ring. Note that the indices are offset by 1
655 // because of the insertion done above bumps the values. 669 // because of the insertion done above bumps the values.
656 if (points.size() >= 33) 670 if (ringpoints.size() >= 33)
657 points.insert (33, points[17]); 671 ringpoints.insert (33, ringpoints[17]);
658 672
659 // Draw the circle/ring 673 // Draw the ring
674 paint.setBrush ((m_drawedVerts.size() >= 2) ? polybrush : Qt::NoBrush);
675 paint.setPen (Qt::NoPen);
676 paint.drawPolygon (QPolygon (ringpoints));
677
678 // Draw the circles
679 paint.setBrush (Qt::NoBrush);
660 paint.setPen (linepen); 680 paint.setPen (linepen);
661 paint.setBrush ((m_drawedVerts.size() >= 2) ? polybrush : Qt::NoBrush); 681 paint.drawPolygon (QPolygon (circlepoints));
662 paint.drawPolygon (QPolygon (points)); 682 paint.drawPolygon (QPolygon (circle2points));
663 683
664 { // Draw the current radius in the middle of the circle. 684 { // Draw the current radius in the middle of the circle.
665 QPoint origin = coordconv3_2 (m_drawedVerts[0]); 685 QPoint origin = coordconv3_2 (m_drawedVerts[0]);
666 str label = str::number (dist0); 686 str label = str::number (dist0);
667 paint.setPen (textpen); 687 paint.setPen (textpen);

mercurial