66 cfg (Bool, gl_axes, false); |
66 cfg (Bool, gl_axes, false); |
67 cfg (Bool, gl_wireframe, false); |
67 cfg (Bool, gl_wireframe, false); |
68 cfg (Bool, gl_logostuds, false); |
68 cfg (Bool, gl_logostuds, false); |
69 cfg (Bool, gl_aa, true); |
69 cfg (Bool, gl_aa, true); |
70 cfg (Bool, gl_linelengths, true); |
70 cfg (Bool, gl_linelengths, true); |
|
71 cfg (Bool, gl_drawangles, false); |
71 |
72 |
72 // argh |
73 // argh |
73 const char* g_CameraNames[7] = |
74 const char* g_CameraNames[7] = |
74 { QT_TRANSLATE_NOOP ("GLRenderer", "Top"), |
75 { QT_TRANSLATE_NOOP ("GLRenderer", "Top"), |
75 QT_TRANSLATE_NOOP ("GLRenderer", "Front"), |
76 QT_TRANSLATE_NOOP ("GLRenderer", "Front"), |
580 |
581 |
581 QPen linepen = m_thinBorderPen; |
582 QPen linepen = m_thinBorderPen; |
582 linepen.setWidth (2); |
583 linepen.setWidth (2); |
583 linepen.setColor (luma (m_bgcolor) < 40 ? Qt::white : Qt::black); |
584 linepen.setColor (luma (m_bgcolor) < 40 ? Qt::white : Qt::black); |
584 |
585 |
585 // If we're drawing, draw the vertices onto the screen. |
586 // Mode-specific rendering |
586 if (getEditMode() == EDrawMode) |
587 if (getEditMode() == EDrawMode) |
587 { int numverts = 4; |
588 { QPoint poly[4]; |
588 |
589 vertex poly3d[4]; |
|
590 int numverts = 4; |
|
591 |
|
592 // Calculate polygon data |
589 if (!m_rectdraw) |
593 if (!m_rectdraw) |
590 numverts = m_drawedVerts.size() + 1; |
594 { numverts = m_drawedVerts.size() + 1; |
|
595 int i = 0; |
|
596 |
|
597 for (vertex& vert : m_drawedVerts) |
|
598 poly3d[i++] = vert; |
|
599 |
|
600 // Draw the cursor vertex as the last one in the list. |
|
601 if (numverts <= 4) |
|
602 poly3d[i] = m_hoverpos; |
|
603 else |
|
604 numverts = 4; |
|
605 } |
|
606 else |
|
607 { // Get vertex information from m_rectverts |
|
608 if (m_drawedVerts.size() > 0) |
|
609 for (int i = 0; i < numverts; ++i) |
|
610 poly3d[i] = m_rectverts[i]; |
|
611 else |
|
612 poly3d[0] = m_hoverpos; |
|
613 } |
|
614 |
|
615 // Convert to 2D |
|
616 for (int i = 0; i < numverts; ++i) |
|
617 poly[i] = coordconv3_2 (poly3d[i]); |
591 |
618 |
592 if (numverts > 0) |
619 if (numverts > 0) |
593 { QPoint poly[4]; |
620 { // Draw the polygon-to-be |
594 vertex poly3d[4]; |
|
595 |
|
596 if (!m_rectdraw) |
|
597 { int i = 0; |
|
598 |
|
599 for (vertex& vert : m_drawedVerts) |
|
600 poly3d[i++] = vert; |
|
601 |
|
602 // Draw the cursor vertex as the last one in the list. |
|
603 if (numverts <= 4) |
|
604 poly3d[i] = m_hoverpos; |
|
605 else |
|
606 numverts = 4; |
|
607 } |
|
608 else |
|
609 { // Get vertex information from m_rectverts |
|
610 if (m_drawedVerts.size() > 0) |
|
611 for (int i = 0; i < numverts; ++i) |
|
612 poly3d[i] = m_rectverts[i]; |
|
613 else |
|
614 poly3d[0] = m_hoverpos; |
|
615 } |
|
616 |
|
617 // convert to 2d |
|
618 for (int i = 0; i < numverts; ++i) |
|
619 poly[i] = coordconv3_2 (poly3d[i]); |
|
620 |
|
621 // Draw the polygon-to-be |
|
622 paint.setPen (linepen); |
621 paint.setPen (linepen); |
623 paint.setBrush (polybrush); |
622 paint.setBrush (polybrush); |
624 paint.drawPolygon (poly, numverts); |
623 paint.drawPolygon (poly, numverts); |
625 |
624 |
626 // Draw vertex blips |
625 // Draw vertex blips |
630 |
629 |
631 // Draw their coordinates |
630 // Draw their coordinates |
632 paint.drawText (blip.x(), blip.y() - 8, poly3d[i].stringRep (true)); |
631 paint.drawText (blip.x(), blip.y() - 8, poly3d[i].stringRep (true)); |
633 } |
632 } |
634 |
633 |
635 // Draw line lengths |
634 // Draw line lenghts and angle info if appropriate |
636 if (numverts >= 2 && gl_linelengths) |
635 if (numverts >= 2) |
637 { int numlines = (m_drawedVerts.size() == 1) ? 1 : m_drawedVerts.size() + 1; |
636 { int numlines = (m_drawedVerts.size() == 1) ? 1 : m_drawedVerts.size() + 1; |
|
637 paint.setPen (textpen); |
638 |
638 |
639 for (int i = 0; i < numlines; ++i) |
639 for (int i = 0; i < numlines; ++i) |
640 { const int j = (i + 1 < numverts) ? i + 1 : 0; |
640 { const int j = (i + 1 < numverts) ? i + 1 : 0; |
641 const str label = str::number (poly3d[i].distanceTo (poly3d[j])); |
641 const int h = (i - 1 >= 0) ? i - 1 : numverts - 1; |
642 paint.setPen (textpen); |
642 |
643 paint.drawText (QLineF (poly[i], poly[j]).pointAt (0.5), label); |
643 if (gl_linelengths) |
|
644 { const str label = str::number (poly3d[i].distanceTo (poly3d[j])); |
|
645 QPoint origin = QLineF (poly[i], poly[j]).pointAt (0.5).toPoint(); |
|
646 paint.drawText (origin, label); |
|
647 } |
|
648 |
|
649 if (gl_drawangles) |
|
650 { QLineF l0 (poly[h], poly[i]), |
|
651 l1 (poly[i], poly[j]); |
|
652 double angle = l0.angleTo (l1); |
|
653 str label = str::number (angle) + str::fromUtf8 (QByteArray ("\302\260")); |
|
654 QPoint pos = poly[i]; |
|
655 pos.setY (pos.y() + metrics.height()); |
|
656 paint.drawText (pos, label); |
|
657 } |
644 } |
658 } |
645 } |
659 } |
646 } |
660 } |
647 } |
661 } |
648 elif (getEditMode() == ECircleMode) |
662 elif (getEditMode() == ECircleMode) |
939 |
953 |
940 // ============================================================================= |
954 // ============================================================================= |
941 // ----------------------------------------------------------------------------- |
955 // ----------------------------------------------------------------------------- |
942 void GLRenderer::addDrawnVertex (vertex pos) |
956 void GLRenderer::addDrawnVertex (vertex pos) |
943 { // If we picked an already-existing vertex, stop drawing |
957 { // If we picked an already-existing vertex, stop drawing |
944 if (getEditMode() != ECircleMode) |
958 if (getEditMode() == EDrawMode) |
945 { for (vertex& vert : m_drawedVerts) |
959 { for (vertex& vert : m_drawedVerts) |
946 { if (vert == pos) |
960 { if (vert == pos) |
947 { endDraw (true); |
961 { endDraw (true); |
948 return; |
962 return; |
949 } |
963 } |
1175 } |
1189 } |
1176 |
1190 |
1177 // ============================================================================= |
1191 // ============================================================================= |
1178 // ----------------------------------------------------------------------------- |
1192 // ----------------------------------------------------------------------------- |
1179 void GLRenderer::pick (int mouseX, int mouseY) |
1193 void GLRenderer::pick (int mouseX, int mouseY) |
1180 { GLint viewport[4]; |
1194 { makeCurrent(); |
1181 makeCurrent(); |
|
1182 |
1195 |
1183 // Use particularly thick lines while picking ease up selecting lines. |
1196 // Use particularly thick lines while picking ease up selecting lines. |
1184 glLineWidth (max<double> (gl_linethickness, 6.5f)); |
1197 glLineWidth (max<double> (gl_linethickness, 6.5f)); |
1185 |
1198 |
1186 // Clear the selection if we do not wish to add to it. |
1199 // Clear the selection if we do not wish to add to it. |
1227 // Clamp the values to ensure they're within bounds |
1237 // Clamp the values to ensure they're within bounds |
1228 x0 = max (0, x0); |
1238 x0 = max (0, x0); |
1229 y0 = max (0, y0); |
1239 y0 = max (0, y0); |
1230 x1 = min (x1, m_width); |
1240 x1 = min (x1, m_width); |
1231 y1 = min (y1, m_height); |
1241 y1 = min (y1, m_height); |
1232 |
|
1233 const int areawidth = (x1 - x0); |
1242 const int areawidth = (x1 - x0); |
1234 const int areaheight = (y1 - y0); |
1243 const int areaheight = (y1 - y0); |
1235 const qint32 numpixels = areawidth * areaheight; |
1244 const qint32 numpixels = areawidth * areaheight; |
1236 |
1245 |
1237 // Allocate space for the pixel data. |
1246 // Allocate space for the pixel data. |
1238 uchar* const pixeldata = new uchar[4 * numpixels]; |
1247 uchar* const pixeldata = new uchar[4 * numpixels]; |
1239 uchar* pixelptr = &pixeldata[0]; |
1248 uchar* pixelptr = &pixeldata[0]; |
1240 |
1249 |
1241 assert (viewport[3] == m_height); |
|
1242 |
|
1243 // Read pixels from the color buffer. |
1250 // Read pixels from the color buffer. |
1244 glReadPixels (x0, viewport[3] - y1, areawidth, areaheight, GL_RGBA, GL_UNSIGNED_BYTE, pixeldata); |
1251 glReadPixels (x0, m_height - y1, areawidth, areaheight, GL_RGBA, GL_UNSIGNED_BYTE, pixeldata); |
1245 |
1252 |
1246 LDObject* removedObj = null; |
1253 LDObject* removedObj = null; |
1247 |
1254 |
1248 // Go through each pixel read and add them to the selection. |
1255 // Go through each pixel read and add them to the selection. |
1249 for (qint32 i = 0; i < numpixels; ++i) |
1256 for (qint32 i = 0; i < numpixels; ++i) |