src/gldraw.cpp

changeset 499
ebd30d9eb667
parent 498
791c831c8020
child 500
cad8cdc42a64
equal deleted inserted replaced
498:791c831c8020 499:ebd30d9eb667
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
594 } 595 }
595 } 596 }
596 597
597 // Draw the polygon-to-be 598 // Draw the polygon-to-be
598 paint.setPen (linepen); 599 paint.setPen (linepen);
599 paint.setBrush (QColor (64, 192, 0, 128)); 600 paint.setBrush (polybrush);
600 paint.drawPolygon (poly, numverts); 601 paint.drawPolygon (poly, numverts);
601 602
602 // Draw vertex blips 603 // Draw vertex blips
603 for (int i = 0; i < numverts; ++i) 604 for (int i = 0; i < numverts; ++i)
604 { QPoint& blip = poly[i]; 605 { QPoint& blip = poly[i];
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
924 949
925 addDrawnVertex (m_hoverpos); 950 addDrawnVertex (m_hoverpos);
926 } break; 951 } break;
927 952
928 case CircleMode: 953 case CircleMode:
929 { if (m_drawedVerts.size() == 2) 954 { if (m_drawedVerts.size() == 3)
930 { endDraw (true); 955 { endDraw (true);
931 return; 956 return;
932 } 957 }
933 958
934 addDrawnVertex (m_hoverpos); 959 addDrawnVertex (m_hoverpos);
1349 } 1374 }
1350 1375
1351 break; 1376 break;
1352 1377
1353 case CircleMode: 1378 case CircleMode:
1354 { const double dist = circleDrawDist(); 1379 { const double dist = circleDrawDist (0);
1355 1380
1356 matrix transform = g_circleDrawTransforms[camera() % 3]; 1381 matrix transform = g_circleDrawTransforms[camera() % 3];
1357 1382
1358 for (int i = 0; i < 9; ++i) 1383 for (int i = 0; i < 9; ++i)
1359 { if (transform[i] == 2) 1384 { if (transform[i] == 2)
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

mercurial