| 500 QRect targRect (v0.x (), v0.y (), abs (v1.x () - v0.x ()), abs (v1.y () - v0.y ())), |
499 QRect targRect (v0.x (), v0.y (), abs (v1.x () - v0.x ()), abs (v1.y () - v0.y ())), |
| 501 srcRect (0, 0, overlay.img->width (), overlay.img->height ()); |
500 srcRect (0, 0, overlay.img->width (), overlay.img->height ()); |
| 502 paint.drawImage (targRect, *overlay.img, srcRect); |
501 paint.drawImage (targRect, *overlay.img, srcRect); |
| 503 } |
502 } |
| 504 |
503 |
| 505 // Calculate 3d position of the cursor |
|
| 506 m_hoverpos = coordconv2_3 (m_pos, true); |
|
| 507 |
|
| 508 // Paint the coordinates onto the screen. |
504 // Paint the coordinates onto the screen. |
| 509 str text = fmt ("X: %s, Y: %s, Z: %s", ftoa (m_hoverpos[X]).chars (), |
505 str text = fmt ("X: %s, Y: %s, Z: %s", ftoa (m_hoverpos[X]).chars (), |
| 510 ftoa (m_hoverpos[Y]).chars (), ftoa (m_hoverpos[Z]).chars ()); |
506 ftoa (m_hoverpos[Y]).chars (), ftoa (m_hoverpos[Z]).chars ()); |
| 511 |
507 |
| 512 QFontMetrics metrics = QFontMetrics (font ()); |
508 QFontMetrics metrics = QFontMetrics (font ()); |
| 518 |
514 |
| 519 // If we're drawing, draw the vertices onto the screen. |
515 // If we're drawing, draw the vertices onto the screen. |
| 520 if (editMode () == Draw) { |
516 if (editMode () == Draw) { |
| 521 ushort numverts; |
517 ushort numverts; |
| 522 |
518 |
| |
519 numverts = 4; |
| 523 if (!m_rectdraw) |
520 if (!m_rectdraw) |
| 524 numverts = m_drawedVerts.size () + 1; |
521 numverts = m_drawedVerts.size () + 1; |
| 525 else |
|
| 526 numverts = (m_drawedVerts.size () > 0) ? 4 : 1; |
|
| 527 |
522 |
| 528 const short blipsize = 8; |
523 const short blipsize = 8; |
| 529 |
524 |
| 530 if (numverts > 0) { |
525 if (numverts > 0) { |
| 531 QPoint* poly = new QPoint[numverts]; |
526 QPoint poly[4]; |
| |
527 vertex polyverts[4]; |
| 532 |
528 |
| 533 if (!m_rectdraw) { |
529 if (!m_rectdraw) { |
| 534 uchar i = 0; |
530 uchar i = 0; |
| 535 for (vertex& vert : m_drawedVerts) { |
531 for (vertex& vert : m_drawedVerts) { |
| 536 poly[i] = coordconv3_2 (vert); |
532 poly[i] = coordconv3_2 (vert); |
| |
533 polyverts[i] = vert; |
| 537 ++i; |
534 ++i; |
| 538 } |
535 } |
| 539 |
536 |
| 540 // Draw the cursor vertex as the last one in the list. |
537 // Draw the cursor vertex as the last one in the list. |
| 541 if (numverts < 5) |
538 if (numverts <= 4) { |
| 542 poly[i] = coordconv3_2 (m_hoverpos); |
539 poly[i] = coordconv3_2 (m_hoverpos); |
| 543 else |
540 polyverts[i] = m_hoverpos; |
| |
541 } else { |
| 544 numverts = 4; |
542 numverts = 4; |
| |
543 } |
| 545 } else { |
544 } else { |
| 546 if (m_drawedVerts.size () > 0) { |
545 if (m_drawedVerts.size () > 0) { |
| 547 QPoint v0 = coordconv3_2 (m_drawedVerts[0]), |
546 // Get vertex information from m_rectverts |
| 548 v1 = coordconv3_2 ((m_drawedVerts.size () >= 2) ? m_drawedVerts[1] : m_hoverpos); |
547 for (ushort i = 0; i < numverts; ++i) { |
| 549 |
548 polyverts[i] = m_rectverts[i]; |
| 550 poly[0] = QPoint (v0.x (), v0.y ()); |
549 poly[i] = coordconv3_2 (polyverts[i]); |
| 551 poly[1] = QPoint (v0.x (), v1.y ()); |
550 } |
| 552 poly[2] = QPoint (v1.x (), v1.y ()); |
|
| 553 poly[3] = QPoint (v1.x (), v0.y ()); |
|
| 554 } else { |
551 } else { |
| 555 poly[0] = coordconv3_2 (m_hoverpos); |
552 poly[0] = coordconv3_2 (m_hoverpos); |
| |
553 polyverts[0] = m_hoverpos; |
| 556 } |
554 } |
| 557 } |
555 } |
| 558 |
556 |
| |
557 // Draw the polygon-to-be |
| 559 QPen pen = m_thinBorderPen; |
558 QPen pen = m_thinBorderPen; |
| 560 pen.setWidth (1); |
|
| 561 paint.setPen (pen); |
|
| 562 paint.setBrush (QColor (128, 192, 0)); |
|
| 563 |
|
| 564 // Draw vertex blips |
|
| 565 for (ushort i = 0; i < numverts; ++i) { |
|
| 566 QPoint& blip = poly[i]; |
|
| 567 paint.drawEllipse (blip.x () - blipsize / 2, blip.y () - blipsize / 2, |
|
| 568 blipsize, blipsize); |
|
| 569 } |
|
| 570 |
|
| 571 pen.setWidth (2); |
559 pen.setWidth (2); |
| 572 pen.setColor (luma (m_bgcolor) < 40 ? Qt::white : Qt::black); |
560 pen.setColor (luma (m_bgcolor) < 40 ? Qt::white : Qt::black); |
| 573 paint.setPen (pen); |
561 paint.setPen (pen); |
| 574 paint.setBrush (QColor (128, 192, 0, 128)); |
562 paint.setBrush (QColor (128, 192, 0, 128)); |
| 575 paint.drawPolygon (poly, numverts); |
563 paint.drawPolygon (poly, numverts); |
| 576 |
564 |
| 577 delete[] poly; |
565 // Draw vertex blips |
| |
566 pen = m_thinBorderPen; |
| |
567 pen.setWidth (1); |
| |
568 paint.setPen (pen); |
| |
569 paint.setBrush (QColor (128, 192, 0)); |
| |
570 |
| |
571 for (ushort i = 0; i < numverts; ++i) { |
| |
572 QPoint& blip = poly[i]; |
| |
573 paint.drawEllipse (blip.x () - blipsize / 2, blip.y () - blipsize / 2, |
| |
574 blipsize, blipsize); |
| |
575 |
| |
576 // Draw their coordinates |
| |
577 paint.drawText (blip.x (), blip.y () - 8, polyverts[i].stringRep (true)); |
| |
578 } |
| 578 } |
579 } |
| 579 } |
580 } |
| 580 } |
581 } |
| 581 |
582 |
| 582 // Camera icons |
583 // Camera icons |
| 856 // ============================================================================= |
857 // ============================================================================= |
| 857 void GLRenderer::mouseReleaseEvent (QMouseEvent* ev) { |
858 void GLRenderer::mouseReleaseEvent (QMouseEvent* ev) { |
| 858 const bool wasLeft = (m_lastButtons & Qt::LeftButton) && !(ev->buttons() & Qt::LeftButton); |
859 const bool wasLeft = (m_lastButtons & Qt::LeftButton) && !(ev->buttons() & Qt::LeftButton); |
| 859 const bool wasRight = (m_lastButtons & Qt::RightButton) && !(ev->buttons() & Qt::RightButton); |
860 const bool wasRight = (m_lastButtons & Qt::RightButton) && !(ev->buttons() & Qt::RightButton); |
| 860 const bool wasMid = (m_lastButtons & Qt::MidButton) && !(ev->buttons() & Qt::MidButton); |
861 const bool wasMid = (m_lastButtons & Qt::MidButton) && !(ev->buttons() & Qt::MidButton); |
| 861 printf ("totalmove: %lu\n", m_totalmove); |
862 |
| |
863 if (m_panning) |
| |
864 m_panning = false; |
| 862 |
865 |
| 863 if (wasLeft) { |
866 if (wasLeft) { |
| 864 // Check if we selected a camera icon |
867 // Check if we selected a camera icon |
| 865 if (!m_rangepick) { |
868 if (!m_rangepick) { |
| 866 for (CameraIcon& info : g_CameraIcons) { |
869 for (CameraIcon& info : g_CameraIcons) { |
| 867 if (info.destRect.contains (ev->pos ())) { |
870 if (info.destRect.contains (ev->pos ())) { |
| 868 setCamera (info.cam); |
871 setCamera (info.cam); |
| 869 update (); |
872 goto end; |
| 870 return; |
|
| 871 } |
873 } |
| 872 } |
874 } |
| 873 } |
875 } |
| 874 |
876 |
| 875 switch (editMode ()) { |
877 switch (editMode ()) { |
| 984 } |
986 } |
| 985 |
987 |
| 986 if (ev->buttons () & Qt::MidButton) { |
988 if (ev->buttons () & Qt::MidButton) { |
| 987 m_panX += 0.03f * dx * (zoom () / 7.5f); |
989 m_panX += 0.03f * dx * (zoom () / 7.5f); |
| 988 m_panY -= 0.03f * dy * (zoom () / 7.5f); |
990 m_panY -= 0.03f * dy * (zoom () / 7.5f); |
| |
991 m_panning = true; |
| 989 } |
992 } |
| 990 |
993 |
| 991 // Start the tool tip timer |
994 // Start the tool tip timer |
| 992 if (!m_drawToolTip) |
995 if (!m_drawToolTip) |
| 993 m_toolTipTimer->start (1000); |
996 m_toolTipTimer->start (1000); |
| 994 |
997 |
| |
998 // Update 2d position |
| 995 m_pos = ev->pos (); |
999 m_pos = ev->pos (); |
| |
1000 |
| |
1001 // Calculate 3d position of the cursor |
| |
1002 m_hoverpos = (camera () != Free) ? coordconv2_3 (m_pos, true) : g_origin; |
| |
1003 |
| |
1004 // Update rect vertices since m_hoverpos may have changed |
| |
1005 updateRectVerts (); |
| |
1006 |
| 996 update (); |
1007 update (); |
| 997 } |
1008 } |
| 998 |
1009 |
| 999 // ============================================================================= |
1010 // ============================================================================= |
| 1000 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
1011 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 1211 vector<vertex>& verts = m_drawedVerts; |
1222 vector<vertex>& verts = m_drawedVerts; |
| 1212 LDObject* obj = null; |
1223 LDObject* obj = null; |
| 1213 |
1224 |
| 1214 if (m_rectdraw) { |
1225 if (m_rectdraw) { |
| 1215 LDQuad* quad = new LDQuad; |
1226 LDQuad* quad = new LDQuad; |
| 1216 vertex v0 = m_drawedVerts[0], |
1227 |
| 1217 v1 = m_drawedVerts[1]; |
1228 // Copy the vertices from m_rectverts |
| 1218 const Axis axisX = cameraAxis (false), |
1229 updateRectVerts (); |
| 1219 axisY = cameraAxis (true); |
1230 memcpy (quad->coords, m_rectverts, sizeof quad->coords); |
| 1220 |
1231 |
| 1221 memset (quad->coords, 0, sizeof quad->coords); |
|
| 1222 quad->coords[0][axisX] = v0[axisX]; |
|
| 1223 quad->coords[0][axisY] = v0[axisY]; |
|
| 1224 quad->coords[1][axisX] = v1[axisX]; |
|
| 1225 quad->coords[1][axisY] = v0[axisY]; |
|
| 1226 quad->coords[2][axisX] = v1[axisX]; |
|
| 1227 quad->coords[2][axisY] = v1[axisY]; |
|
| 1228 quad->coords[3][axisX] = v0[axisX]; |
|
| 1229 quad->coords[3][axisY] = v1[axisY]; |
|
| 1230 quad->color = maincolor; |
1232 quad->color = maincolor; |
| 1231 obj = quad; |
1233 obj = quad; |
| 1232 } else { |
1234 } else { |
| 1233 switch (verts.size ()) { |
1235 switch (verts.size ()) { |
| 1234 case 1: |
1236 case 1: |
| 1539 } |
1543 } |
| 1540 |
1544 |
| 1541 setBackground (); |
1545 setBackground (); |
| 1542 m_picking = false; |
1546 m_picking = false; |
| 1543 } |
1547 } |
| |
1548 |
| |
1549 // ============================================================================= |
| |
1550 void GLRenderer::updateRectVerts () { |
| |
1551 if (!m_rectdraw) |
| |
1552 return; |
| |
1553 |
| |
1554 if (m_drawedVerts.size () == 0) { |
| |
1555 for (int i = 0; i < 4; ++i) |
| |
1556 m_rectverts[i] = m_hoverpos; |
| |
1557 |
| |
1558 return; |
| |
1559 } |
| |
1560 |
| |
1561 vertex v0 = m_drawedVerts[0], |
| |
1562 v1 = (m_drawedVerts.size () >= 2) ? m_drawedVerts[1] : m_hoverpos; |
| |
1563 |
| |
1564 const Axis ax = cameraAxis (false), |
| |
1565 ay = cameraAxis (true), |
| |
1566 az = (Axis) (3 - ax - ay); |
| |
1567 |
| |
1568 for (int i = 0; i < 4; ++i) |
| |
1569 m_rectverts[i][az] = depthValue (); |
| |
1570 |
| |
1571 m_rectverts[0][ax] = v0[ax]; |
| |
1572 m_rectverts[0][ay] = v0[ay]; |
| |
1573 m_rectverts[1][ax] = v1[ax]; |
| |
1574 m_rectverts[1][ay] = v0[ay]; |
| |
1575 m_rectverts[2][ax] = v1[ax]; |
| |
1576 m_rectverts[2][ay] = v1[ay]; |
| |
1577 m_rectverts[3][ax] = v0[ax]; |
| |
1578 m_rectverts[3][ay] = v1[ay]; |
| |
1579 } |