513 m_virtHeight = (m_height * m_virtWidth) / m_width; |
513 m_virtHeight = (m_height * m_virtWidth) / m_width; |
514 |
514 |
515 initGLData(); |
515 initGLData(); |
516 drawGLScene(); |
516 drawGLScene(); |
517 |
517 |
518 QPen textpen = getTextPen(); |
518 const QPen textpen = getTextPen(); |
|
519 const QBrush polybrush (QColor (64, 192, 0, 128)); |
519 QPainter paint (this); |
520 QPainter paint (this); |
520 QFontMetrics metrics = QFontMetrics (QFont()); |
521 QFontMetrics metrics = QFontMetrics (QFont()); |
521 paint.setRenderHint (QPainter::HighQualityAntialiasing); |
522 paint.setRenderHint (QPainter::HighQualityAntialiasing); |
522 |
523 |
523 // If we wish to only draw the brick, stop here |
524 // If we wish to only draw the brick, stop here |
612 elif (editMode() == CircleMode) |
613 elif (editMode() == CircleMode) |
613 { // If we have not specified the center point of the circle yet, preview it on the screen. |
614 { // If we have not specified the center point of the circle yet, preview it on the screen. |
614 if (m_drawedVerts.size() == 0) |
615 if (m_drawedVerts.size() == 0) |
615 drawBlip (paint, coordconv3_2 (m_hoverpos)); |
616 drawBlip (paint, coordconv3_2 (m_hoverpos)); |
616 else |
617 else |
617 { QVector<vertex> verts; |
618 { QVector<vertex> verts, verts2; |
618 const double dist = circleDrawDist(); |
619 const double dist0 = circleDrawDist(0), |
|
620 dist1 = (m_drawedVerts.size() >= 2) ? circleDrawDist (1) : -1; |
619 const int segs = lores; |
621 const int segs = lores; |
620 const double angleUnit = (2 * pi) / segs; |
622 const double angleUnit = (2 * pi) / segs; |
621 Axis relX, relY; |
623 Axis relX, relY; |
622 QVector<QPoint> points; |
624 QVector<QPoint> points, |
|
625 points2; |
623 |
626 |
624 getRelativeAxes (relX, relY); |
627 getRelativeAxes (relX, relY); |
625 |
628 |
626 for (int i = 0; i < segs; ++i) |
629 for (int i = 0; i < segs; ++i) |
627 { vertex v = g_origin; |
630 { vertex v = g_origin; |
628 v[relX] = m_drawedVerts[0][relX] + (cos (i * angleUnit) * dist); |
631 v[relX] = m_drawedVerts[0][relX] + (cos (i * angleUnit) * dist0); |
629 v[relY] = m_drawedVerts[0][relY] + (sin (i * angleUnit) * dist); |
632 v[relY] = m_drawedVerts[0][relY] + (sin (i * angleUnit) * dist0); |
630 verts << v; |
633 verts << v; |
|
634 |
|
635 if (dist1 != -1) |
|
636 { v[relX] = m_drawedVerts[0][relX] + (cos (i * angleUnit) * dist1); |
|
637 v[relY] = m_drawedVerts[0][relY] + (sin (i * angleUnit) * dist1); |
|
638 verts2 << v; |
|
639 } |
631 } |
640 } |
632 |
641 |
633 for (const vertex& v : verts) |
642 for (const vertex& v : verts + verts2) |
634 { QPoint point = coordconv3_2 (v); |
643 { QPoint point = coordconv3_2 (v); |
635 drawBlip (paint, point); |
644 drawBlip (paint, point); |
636 points << point; |
645 points << point; |
637 } |
646 } |
638 |
647 |
639 paint.setPen (linepen); |
648 // Insert the first point as the seventeenth one so that |
640 paint.setBrush (Qt::NoBrush); |
649 // the ring polygon is closed properly. |
641 paint.drawPolygon (QPolygon (points)); |
650 if (points.size() >= 16) |
|
651 points.insert (16, points[0]); |
|
652 |
|
653 // Same for the outer ring. Note that the indices are offset by 1 |
|
654 // because of the insertion done above bumps the values. |
|
655 if (points.size() >= 33) |
|
656 points.insert (33, points[17]); |
642 |
657 |
643 { // Draw the current radius in the middle of the circle. |
658 { // Draw the current radius in the middle of the circle. |
644 QPoint origin = coordconv3_2 (m_drawedVerts[0]); |
659 QPoint origin = coordconv3_2 (m_drawedVerts[0]); |
645 str label = str::number (dist); |
660 str label = str::number (dist0); |
646 paint.setPen (textpen); |
661 paint.setPen (textpen); |
647 paint.drawText (origin.x() - (metrics.width (label) / 2), origin.y(), label); |
662 paint.drawText (origin.x() - (metrics.width (label) / 2), origin.y(), label); |
|
663 |
|
664 if (m_drawedVerts.size() >= 2) |
|
665 { label = str::number (dist1); |
|
666 paint.drawText (origin.x() - (metrics.width (label) / 2), origin.y() + metrics.height(), label); |
|
667 } |
648 } |
668 } |
|
669 |
|
670 // Draw the circle/ring |
|
671 paint.setPen (linepen); |
|
672 paint.setBrush ((m_drawedVerts.size() >= 2) ? polybrush : Qt::NoBrush); |
|
673 paint.drawPolygon (QPolygon (points)); |
649 } |
674 } |
650 } |
675 } |
651 } |
676 } |
652 |
677 |
653 // Camera icons |
678 // Camera icons |
1388 m_rectdraw = false; |
1413 m_rectdraw = false; |
1389 } |
1414 } |
1390 |
1415 |
1391 // ============================================================================= |
1416 // ============================================================================= |
1392 // ----------------------------------------------------------------------------- |
1417 // ----------------------------------------------------------------------------- |
1393 double GLRenderer::circleDrawDist() const |
1418 double GLRenderer::circleDrawDist (int pos) const |
1394 { assert (m_drawedVerts.size() >= 1); |
1419 { assert (m_drawedVerts.size() >= pos + 1); |
1395 const vertex& v1 = (m_drawedVerts.size() == 2) ? m_drawedVerts[1] : m_hoverpos; |
1420 const vertex& v1 = (m_drawedVerts.size() >= pos + 2) ? m_drawedVerts[pos + 1] : m_hoverpos; |
1396 Axis relX, relY; |
1421 Axis relX, relY; |
1397 getRelativeAxes (relX, relY); |
1422 getRelativeAxes (relX, relY); |
1398 |
1423 |
1399 const double dx = m_drawedVerts[0][relX] - v1[relX]; |
1424 const double dx = m_drawedVerts[0][relX] - v1[relX]; |
1400 const double dy = m_drawedVerts[0][relY] - v1[relY]; |
1425 const double dy = m_drawedVerts[0][relY] - v1[relY]; |
1401 return sqrt ( (dx * dx) + (dy * dy)); |
1426 return sqrt ((dx * dx) + (dy * dy)); |
1402 } |
1427 } |
1403 |
1428 |
1404 // ============================================================================= |
1429 // ============================================================================= |
1405 // ----------------------------------------------------------------------------- |
1430 // ----------------------------------------------------------------------------- |
1406 void GLRenderer::getRelativeAxes (Axis& relX, Axis& relY) const |
1431 void GLRenderer::getRelativeAxes (Axis& relX, Axis& relY) const |