src/glRenderer.cc

changeset 714
b4a990f59a5e
parent 713
46377d340c23
parent 662
2f1bd9112408
child 715
56f1b77951c8
equal deleted inserted replaced
713:46377d340c23 714:b4a990f59a5e
297 // 297 //
298 QColor GLRenderer::getMainColor() 298 QColor GLRenderer::getMainColor()
299 { 299 {
300 QColor col (gl_maincolor); 300 QColor col (gl_maincolor);
301 301
302 if (!col.isValid()) 302 if (not col.isValid())
303 return QColor (0, 0, 0); 303 return QColor (0, 0, 0);
304 304
305 col.setAlpha (gl_maincolor_alpha * 255.f); 305 col.setAlpha (gl_maincolor_alpha * 255.f);
306 return col; 306 return col;
307 } 307 }
310 // 310 //
311 void GLRenderer::setBackground() 311 void GLRenderer::setBackground()
312 { 312 {
313 QColor col (gl_bgcolor); 313 QColor col (gl_bgcolor);
314 314
315 if (!col.isValid()) 315 if (not col.isValid())
316 return; 316 return;
317 317
318 col.setAlpha (255); 318 col.setAlpha (255);
319 319
320 m_darkbg = luma (col) < 80; 320 m_darkbg = luma (col) < 80;
360 void GLRenderer::drawGLScene() 360 void GLRenderer::drawGLScene()
361 { 361 {
362 if (document() == null) 362 if (document() == null)
363 return; 363 return;
364 364
365 if (gl_wireframe && !isPicking()) 365 if (gl_wireframe && not isPicking())
366 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 366 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
367 367
368 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 368 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
369 glEnable (GL_DEPTH_TEST); 369 glEnable (GL_DEPTH_TEST);
370 370
621 QPoint poly[4]; 621 QPoint poly[4];
622 Vertex poly3d[4]; 622 Vertex poly3d[4];
623 int numverts = 4; 623 int numverts = 4;
624 624
625 // Calculate polygon data 625 // Calculate polygon data
626 if (!m_rectdraw) 626 if (not m_rectdraw)
627 { 627 {
628 numverts = m_drawedVerts.size() + 1; 628 numverts = m_drawedVerts.size() + 1;
629 int i = 0; 629 int i = 0;
630 630
631 for (Vertex& vert : m_drawedVerts) 631 for (Vertex& vert : m_drawedVerts)
797 } 797 }
798 } 798 }
799 } 799 }
800 800
801 // Camera icons 801 // Camera icons
802 if (!isPicking()) 802 if (not isPicking())
803 { 803 {
804 // Draw a background for the selected camera 804 // Draw a background for the selected camera
805 paint.setPen (m_thinBorderPen); 805 paint.setPen (m_thinBorderPen);
806 paint.setBrush (QBrush (QColor (0, 128, 160, 128))); 806 paint.setBrush (QBrush (QColor (0, 128, 160, 128)));
807 paint.drawRect (m_cameraIcons[camera()].selRect); 807 paint.drawRect (m_cameraIcons[camera()].selRect);
829 } 829 }
830 830
831 // Tool tips 831 // Tool tips
832 if (m_drawToolTip) 832 if (m_drawToolTip)
833 { 833 {
834 if (m_cameraIcons[m_toolTipCamera].destRect.contains (m_pos) == false) 834 if (not m_cameraIcons[m_toolTipCamera].destRect.contains (m_pos))
835 m_drawToolTip = false; 835 m_drawToolTip = false;
836 else 836 else
837 { 837 {
838 QString label = format (formatstr, tr (g_CameraNames[m_toolTipCamera])); 838 QString label = format (formatstr, tr (g_CameraNames[m_toolTipCamera]));
839 QToolTip::showText (m_globalpos, label); 839 QToolTip::showText (m_globalpos, label);
856 y += metrics.height(); 856 y += metrics.height();
857 } 857 }
858 } 858 }
859 859
860 // If we're range-picking, draw a rectangle encompassing the selection area. 860 // If we're range-picking, draw a rectangle encompassing the selection area.
861 if (m_rangepick && !isPicking() && m_totalmove >= 10) 861 if (m_rangepick && not isPicking() && m_totalmove >= 10)
862 { 862 {
863 int x0 = m_rangeStart.x(), 863 int x0 = m_rangeStart.x(),
864 y0 = m_rangeStart.y(), 864 y0 = m_rangeStart.y(),
865 x1 = m_pos.x(), 865 x1 = m_pos.x(),
866 y1 = m_pos.y(); 866 y1 = m_pos.y();
920 920
921 // ============================================================================= 921 // =============================================================================
922 // 922 //
923 void GLRenderer::mouseReleaseEvent (QMouseEvent* ev) 923 void GLRenderer::mouseReleaseEvent (QMouseEvent* ev)
924 { 924 {
925 const bool wasLeft = (m_lastButtons & Qt::LeftButton) && ! (ev->buttons() & Qt::LeftButton), 925 const bool wasLeft = (m_lastButtons & Qt::LeftButton) && not (ev->buttons() & Qt::LeftButton),
926 wasRight = (m_lastButtons & Qt::RightButton) && ! (ev->buttons() & Qt::RightButton), 926 wasRight = (m_lastButtons & Qt::RightButton) && not (ev->buttons() & Qt::RightButton),
927 wasMid = (m_lastButtons & Qt::MidButton) && ! (ev->buttons() & Qt::MidButton); 927 wasMid = (m_lastButtons & Qt::MidButton) && not (ev->buttons() & Qt::MidButton);
928 928
929 if (m_panning) 929 if (m_panning)
930 m_panning = false; 930 m_panning = false;
931 931
932 if (wasLeft) 932 if (wasLeft)
933 { 933 {
934 // Check if we selected a camera icon 934 // Check if we selected a camera icon
935 if (!m_rangepick) 935 if (not m_rangepick)
936 { 936 {
937 for (CameraIcon & info : m_cameraIcons) 937 for (CameraIcon & info : m_cameraIcons)
938 { 938 {
939 if (info.destRect.contains (ev->pos())) 939 if (info.destRect.contains (ev->pos()))
940 { 940 {
985 addDrawnVertex (m_hoverpos); 985 addDrawnVertex (m_hoverpos);
986 } break; 986 } break;
987 987
988 case ESelectMode: 988 case ESelectMode:
989 { 989 {
990 if (!isDrawOnly()) 990 if (not isDrawOnly())
991 { 991 {
992 if (m_totalmove < 10) 992 if (m_totalmove < 10)
993 m_rangepick = false; 993 m_rangepick = false;
994 994
995 if (!m_rangepick) 995 if (not m_rangepick)
996 m_addpick = (m_keymods & Qt::ControlModifier); 996 m_addpick = (m_keymods & Qt::ControlModifier);
997 997
998 if (m_totalmove < 10 || m_rangepick) 998 if (m_totalmove < 10 || m_rangepick)
999 pick (ev->x(), ev->y()); 999 pick (ev->x(), ev->y());
1000 } 1000 }
1039 1039
1040 if (valid) 1040 if (valid)
1041 addDrawnVertex (closest); 1041 addDrawnVertex (closest);
1042 } 1042 }
1043 1043
1044 if (wasRight && !m_drawedVerts.isEmpty()) 1044 if (wasRight && not m_drawedVerts.isEmpty())
1045 { 1045 {
1046 // Remove the last vertex 1046 // Remove the last vertex
1047 m_drawedVerts.removeLast(); 1047 m_drawedVerts.removeLast();
1048 1048
1049 if (m_drawedVerts.isEmpty()) 1049 if (m_drawedVerts.isEmpty())
1089 if (mid || (left && shift)) 1089 if (mid || (left && shift))
1090 { 1090 {
1091 pan (X) += 0.03f * dx * (zoom() / 7.5f); 1091 pan (X) += 0.03f * dx * (zoom() / 7.5f);
1092 pan (Y) -= 0.03f * dy * (zoom() / 7.5f); 1092 pan (Y) -= 0.03f * dy * (zoom() / 7.5f);
1093 m_panning = true; 1093 m_panning = true;
1094 } elif (left && !m_rangepick && camera() == EFreeCamera) 1094 }
1095 elif (left && not m_rangepick && camera() == EFreeCamera)
1095 { 1096 {
1096 rot (X) = rot (X) + dy; 1097 rot (X) = rot (X) + dy;
1097 rot (Y) = rot (Y) + dx; 1098 rot (Y) = rot (Y) + dx;
1098 1099
1099 clampAngle (rot (X)); 1100 clampAngle (rot (X));
1100 clampAngle (rot (Y)); 1101 clampAngle (rot (Y));
1101 } 1102 }
1102 1103
1103 // Start the tool tip timer 1104 // Start the tool tip timer
1104 if (!m_drawToolTip) 1105 if (not m_drawToolTip)
1105 m_toolTipTimer->start (500); 1106 m_toolTipTimer->start (500);
1106 1107
1107 // Update 2d position 1108 // Update 2d position
1108 m_pos = ev->pos(); 1109 m_pos = ev->pos();
1109 m_globalpos = ev->globalPos(); 1110 m_globalpos = ev->globalPos();
1178 1179
1179 // Use particularly thick lines while picking ease up selecting lines. 1180 // Use particularly thick lines while picking ease up selecting lines.
1180 glLineWidth (max<double> (gl_linethickness, 6.5f)); 1181 glLineWidth (max<double> (gl_linethickness, 6.5f));
1181 1182
1182 // Clear the selection if we do not wish to add to it. 1183 // Clear the selection if we do not wish to add to it.
1183 if (!m_addpick) 1184 if (not m_addpick)
1184 { 1185 {
1185 LDObjectList oldsel = selection(); 1186 LDObjectList oldsel = selection();
1186 getCurrentDocument()->clearSelection(); 1187 getCurrentDocument()->clearSelection();
1187 1188
1188 for (LDObject* obj : oldsel) 1189 for (LDObject* obj : oldsel)
1261 LDObject* obj = LDObject::fromID (idx); 1262 LDObject* obj = LDObject::fromID (idx);
1262 assert (obj != null); 1263 assert (obj != null);
1263 1264
1264 // If this is an additive single pick and the object is currently selected, 1265 // If this is an additive single pick and the object is currently selected,
1265 // we remove it from selection instead. 1266 // we remove it from selection instead.
1266 if (!m_rangepick && m_addpick) 1267 if (not m_rangepick && m_addpick)
1267 { 1268 {
1268 if (obj->isSelected()) 1269 if (obj->isSelected())
1269 { 1270 {
1270 obj->unselect(); 1271 obj->unselect();
1271 removedObj = obj; 1272 removedObj = obj;
1351 1352
1352 if (a != null) 1353 if (a != null)
1353 { 1354 {
1354 initOverlaysFromObjects(); 1355 initOverlaysFromObjects();
1355 1356
1356 if (currentDocumentData().init == false) 1357 if (not currentDocumentData().init)
1357 { 1358 {
1358 resetAllAngles(); 1359 resetAllAngles();
1359 currentDocumentData().init = true; 1360 currentDocumentData().init = true;
1360 } 1361 }
1361 } 1362 }
1869 if (firstrun) 1870 if (firstrun)
1870 { 1871 {
1871 // If this is the first run, we don't know enough to determine 1872 // If this is the first run, we don't know enough to determine
1872 // whether the zoom was to fit, so we mark in our knowledge so 1873 // whether the zoom was to fit, so we mark in our knowledge so
1873 // far and start over. 1874 // far and start over.
1874 inward = !filled; 1875 inward = not filled;
1875 firstrun = false; 1876 firstrun = false;
1876 } 1877 }
1877 else 1878 else
1878 { 1879 {
1879 // If this run filled the screen and the last one did not, the 1880 // If this run filled the screen and the last one did not, the
1880 // last run had ideal zoom - zoom a bit back and we should reach it. 1881 // last run had ideal zoom - zoom a bit back and we should reach it.
1881 if (filled && !lastfilled) 1882 if (filled && not lastfilled)
1882 { 1883 {
1883 zoomNotch (false); 1884 zoomNotch (false);
1884 break; 1885 break;
1885 } 1886 }
1886 1887
1887 // If this run did not fill the screen and the last one did, we've 1888 // If this run did not fill the screen and the last one did, we've
1888 // now reached ideal zoom so we're done here. 1889 // now reached ideal zoom so we're done here.
1889 if (!filled && lastfilled) 1890 if (not filled && lastfilled)
1890 break; 1891 break;
1891 1892
1892 inward = !filled; 1893 inward = not filled;
1893 } 1894 }
1894 1895
1895 lastfilled = filled; 1896 lastfilled = filled;
1896 } 1897 }
1897 1898
1917 1918
1918 // ============================================================================= 1919 // =============================================================================
1919 // 1920 //
1920 void GLRenderer::updateRectVerts() 1921 void GLRenderer::updateRectVerts()
1921 { 1922 {
1922 if (!m_rectdraw) 1923 if (not m_rectdraw)
1923 return; 1924 return;
1924 1925
1925 if (m_drawedVerts.isEmpty()) 1926 if (m_drawedVerts.isEmpty())
1926 { 1927 {
1927 for (int i = 0; i < 4; ++i) 1928 for (int i = 0; i < 4; ++i)
1952 1953
1953 // ============================================================================= 1954 // =============================================================================
1954 // 1955 //
1955 void GLRenderer::mouseDoubleClickEvent (QMouseEvent* ev) 1956 void GLRenderer::mouseDoubleClickEvent (QMouseEvent* ev)
1956 { 1957 {
1957 if (!(ev->buttons() & Qt::LeftButton) || editMode() != ESelectMode) 1958 if (not (ev->buttons() & Qt::LeftButton) || editMode() != ESelectMode)
1958 return; 1959 return;
1959 1960
1960 pick (ev->x(), ev->y()); 1961 pick (ev->x(), ev->y());
1961 1962
1962 if (selection().isEmpty()) 1963 if (selection().isEmpty())
1998 continue; 1999 continue;
1999 2000
2000 LDGLOverlay& meta = currentDocumentData().overlays[cam]; 2001 LDGLOverlay& meta = currentDocumentData().overlays[cam];
2001 LDOverlay* ovlobj = findOverlayObject (cam); 2002 LDOverlay* ovlobj = findOverlayObject (cam);
2002 2003
2003 if (!ovlobj && meta.img) 2004 if (not ovlobj && meta.img)
2004 { 2005 {
2005 delete meta.img; 2006 delete meta.img;
2006 meta.img = null; 2007 meta.img = null;
2007 } 2008 }
2008 elif (ovlobj && (meta.img == null || meta.fname != ovlobj->fileName()) && meta.invalid == false) 2009 elif (ovlobj && (meta.img == null || meta.fname != ovlobj->fileName()) && meta.invalid == false)
2073 if (found) 2074 if (found)
2074 document()->insertObj (i + 1, new LDEmpty); 2075 document()->insertObj (i + 1, new LDEmpty);
2075 } 2076 }
2076 } 2077 }
2077 2078
2078 if (meta.img && ovlobj) 2079 if (meta.img != null && ovlobj != null)
2079 { 2080 {
2080 ovlobj->setCamera (cam); 2081 ovlobj->setCamera (cam);
2081 ovlobj->setFileName (meta.fname); 2082 ovlobj->setFileName (meta.fname);
2082 ovlobj->setX (meta.ox); 2083 ovlobj->setX (meta.ox);
2083 ovlobj->setY (meta.oy); 2084 ovlobj->setY (meta.oy);

mercurial