45 { { -1, 0, 0 }, X, Z, false, true }, |
45 { { -1, 0, 0 }, X, Z, false, true }, |
46 { { 0, 0, 0 }, X, Y, true, true }, |
46 { { 0, 0, 0 }, X, Y, true, true }, |
47 { { 0, -1, 0 }, Z, Y, false, true }, |
47 { { 0, -1, 0 }, Z, Y, false, true }, |
48 }; |
48 }; |
49 |
49 |
50 overlayMeta g_overlays[6]; |
|
51 double g_depthValues[6]; |
|
52 |
|
53 cfg (str, gl_bgcolor, "#CCCCD9"); |
50 cfg (str, gl_bgcolor, "#CCCCD9"); |
54 cfg (str, gl_maincolor, "#707078"); |
51 cfg (str, gl_maincolor, "#707078"); |
55 cfg (float, gl_maincolor_alpha, 1.0); |
52 cfg (float, gl_maincolor_alpha, 1.0); |
56 cfg (int, gl_linethickness, 2); |
53 cfg (int, gl_linethickness, 2); |
57 cfg (bool, gl_colorbfc, true); |
54 cfg (bool, gl_colorbfc, true); |
131 GLRenderer::~GLRenderer () { |
128 GLRenderer::~GLRenderer () { |
132 for (CameraIcon& info : g_CameraIcons) |
129 for (CameraIcon& info : g_CameraIcons) |
133 delete info.img; |
130 delete info.img; |
134 |
131 |
135 for (int i = 0; i < 6; ++i) |
132 for (int i = 0; i < 6; ++i) |
136 delete g_overlays[i].img; |
133 delete m_overlays[i].img; |
137 } |
134 } |
138 |
135 |
139 // ============================================================================= |
136 // ============================================================================= |
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
141 // ============================================================================= |
138 // ============================================================================= |
489 QFontMetrics metrics = QFontMetrics (QFont ()); |
486 QFontMetrics metrics = QFontMetrics (QFont ()); |
490 paint.setRenderHint (QPainter::HighQualityAntialiasing); |
487 paint.setRenderHint (QPainter::HighQualityAntialiasing); |
491 |
488 |
492 if (m_camera != Free) { |
489 if (m_camera != Free) { |
493 // Paint the overlay image if we have one |
490 // Paint the overlay image if we have one |
494 const overlayMeta& overlay = g_overlays[m_camera]; |
491 const overlayMeta& overlay = m_overlays[m_camera]; |
495 if (overlay.img != null) { |
492 if (overlay.img != null) { |
496 QPoint v0 = coordconv3_2 (g_overlays[m_camera].v0), |
493 QPoint v0 = coordconv3_2 (m_overlays[m_camera].v0), |
497 v1 = coordconv3_2 (g_overlays[m_camera].v1); |
494 v1 = coordconv3_2 (m_overlays[m_camera].v1); |
498 |
495 |
499 QRect targRect (v0.x (), v0.y (), abs (v1.x () - v0.x ()), abs (v1.y () - v0.y ())), |
496 QRect targRect (v0.x (), v0.y (), abs (v1.x () - v0.x ()), abs (v1.y () - v0.y ())), |
500 srcRect (0, 0, overlay.img->width (), overlay.img->height ()); |
497 srcRect (0, 0, overlay.img->width (), overlay.img->height ()); |
501 paint.drawImage (targRect, *overlay.img, srcRect); |
498 paint.drawImage (targRect, *overlay.img, srcRect); |
502 } |
499 } |
514 |
511 |
515 paint.drawText (m_width - textSize.width (), m_height - 16, textSize.width (), |
512 paint.drawText (m_width - textSize.width (), m_height - 16, textSize.width (), |
516 textSize.height (), Qt::AlignCenter, text); |
513 textSize.height (), Qt::AlignCenter, text); |
517 |
514 |
518 // If we're drawing, draw the vertices onto the screen. |
515 // If we're drawing, draw the vertices onto the screen. |
519 if (m_editMode == Draw) { |
516 if (editMode () == Draw) { |
520 ushort numverts; |
517 ushort numverts; |
521 |
518 |
522 if (!m_rectdraw) |
519 if (!m_rectdraw) |
523 numverts = m_drawedVerts.size () + 1; |
520 numverts = m_drawedVerts.size () + 1; |
524 else |
521 else |
759 break; |
756 break; |
760 |
757 |
761 case LDObject::Radial: |
758 case LDObject::Radial: |
762 { |
759 { |
763 LDRadial* rad = static_cast<LDRadial*> (obj); |
760 LDRadial* rad = static_cast<LDRadial*> (obj); |
764 std::vector<LDObject*> objs = rad->decompose (true); |
761 vector<LDObject*> objs = rad->decompose (true); |
765 |
762 |
766 bool oldinvert = g_glInvert; |
763 bool oldinvert = g_glInvert; |
767 if (rad->transform.determinant () < 0) |
764 if (rad->transform.determinant () < 0) |
768 g_glInvert = !g_glInvert; |
765 g_glInvert = !g_glInvert; |
769 |
766 |
1009 // Use particularly thick lines while picking ease up selecting lines. |
1006 // Use particularly thick lines while picking ease up selecting lines. |
1010 glLineWidth (max<double> (gl_linethickness, 6.5f)); |
1007 glLineWidth (max<double> (gl_linethickness, 6.5f)); |
1011 |
1008 |
1012 // Clear the selection if we do not wish to add to it. |
1009 // Clear the selection if we do not wish to add to it. |
1013 if (!m_addpick) { |
1010 if (!m_addpick) { |
1014 std::vector<LDObject*> oldsel = g_win->sel (); |
1011 vector<LDObject*> oldsel = g_win->sel (); |
1015 g_win->sel ().clear (); |
1012 g_win->sel ().clear (); |
1016 |
1013 |
1017 for (LDObject* obj : oldsel) { |
1014 for (LDObject* obj : oldsel) { |
1018 obj->setSelected (false); |
1015 obj->setSelected (false); |
1019 compileObject (obj); |
1016 compileObject (obj); |
1090 if (!m_rangepick && m_addpick) { |
1087 if (!m_rangepick && m_addpick) { |
1091 bool removed = false; |
1088 bool removed = false; |
1092 |
1089 |
1093 for (ulong i = 0; i < g_win->sel ().size(); ++i) { |
1090 for (ulong i = 0; i < g_win->sel ().size(); ++i) { |
1094 if (g_win->sel ()[i] == obj) { |
1091 if (g_win->sel ()[i] == obj) { |
1095 g_win->sel ().erase (g_win->sel ().begin () + i); |
1092 g_win->sel ().erase (i); |
1096 obj->setSelected (false); |
1093 obj->setSelected (false); |
1097 removed = true; |
1094 removed = true; |
1098 removedObj = obj; |
1095 removedObj = obj; |
1099 } |
1096 } |
1100 } |
1097 } |
1108 |
1105 |
1109 delete[] pixeldata; |
1106 delete[] pixeldata; |
1110 |
1107 |
1111 // Remove duplicate entries. For this to be effective, the vector must be |
1108 // Remove duplicate entries. For this to be effective, the vector must be |
1112 // sorted first. |
1109 // sorted first. |
1113 std::vector<LDObject*>& sel = g_win->sel (); |
1110 vector<LDObject*>& sel = g_win->sel (); |
1114 std::sort (sel.begin(), sel.end ()); |
1111 std::sort (sel.begin (), sel.end ()); |
1115 std::vector<LDObject*>::iterator pos = std::unique (sel.begin (), sel.end ()); |
1112 vector<LDObject*>::it pos = std::unique (sel.begin (), sel.end ()); |
1116 sel.resize (std::distance (sel.begin (), pos)); |
1113 sel.resize (std::distance (sel.begin (), pos)); |
1117 |
|
1118 // Update everything now. |
1114 // Update everything now. |
1119 g_win->updateSelection (); |
1115 g_win->updateSelection (); |
1120 |
1116 |
1121 // Recompile the objects now to update their color |
1117 // Recompile the objects now to update their color |
1122 for (LDObject* obj : sel) |
1118 for (LDObject* obj : sel) |
1318 |
1312 |
1319 if (!dlg.exec ()) |
1313 if (!dlg.exec ()) |
1320 return; |
1314 return; |
1321 |
1315 |
1322 QImage* img = new QImage (dlg.fpath ().chars ()); |
1316 QImage* img = new QImage (dlg.fpath ().chars ()); |
1323 overlayMeta& info = g_overlays[camera ()]; |
1317 overlayMeta& info = getOverlay (camera ()); |
1324 |
1318 |
1325 if (img->isNull ()) { |
1319 if (img->isNull ()) { |
1326 critical ("Failed to load overlay image!"); |
1320 critical ("Failed to load overlay image!"); |
1327 delete img; |
1321 delete img; |
1328 return; |
1322 return; |
1329 } |
1323 } |
1330 |
1324 |
1331 delete info.img; // delete the old image |
1325 delete info.img; // delete the old image |
1332 |
1326 |
1333 info.fname = dlg.fpath (); |
1327 info.fname = dlg.fpath (); |
1334 info.lw = dlg.lwidth (); |
1328 info.lw = dlg.lwidth (); |
1335 info.lh = dlg.lheight (); |
1329 info.lh = dlg.lheight (); |
1336 info.ox = dlg.ofsx (); |
1330 info.ox = dlg.ofsx (); |
1337 info.oy = dlg.ofsy (); |
1331 info.oy = dlg.ofsy (); |
1365 |
1359 |
1366 void GLRenderer::clearOverlay () { |
1360 void GLRenderer::clearOverlay () { |
1367 if (camera () == Free) |
1361 if (camera () == Free) |
1368 return; |
1362 return; |
1369 |
1363 |
1370 overlayMeta& info = g_overlays[camera ()]; |
1364 overlayMeta& info = m_overlays[camera ()]; |
1371 delete info.img; |
1365 delete info.img; |
1372 info.img = null; |
1366 info.img = null; |
1373 } |
1367 } |
1374 |
1368 |
1375 void GLRenderer::setDepthValue (double depth) { |
1369 void GLRenderer::setDepthValue (double depth) { |
1376 assert (camera () < Free); |
1370 assert (camera () < Free); |
1377 g_depthValues[camera ()] = depth; |
1371 m_depthValues[camera ()] = depth; |
1378 } |
1372 } |
1379 |
1373 |
1380 double GLRenderer::depthValue () const { |
1374 double GLRenderer::depthValue () const { |
1381 assert (camera () < Free); |
1375 assert (camera () < Free); |
1382 return g_depthValues[camera ()]; |
1376 return m_depthValues[camera ()]; |
1383 } |
1377 } |
1384 |
1378 |
1385 const char* GLRenderer::cameraName () const { |
1379 const char* GLRenderer::cameraName () const { |
1386 return g_CameraNames[camera ()]; |
1380 return g_CameraNames[camera ()]; |
1387 } |
1381 } |
|
1382 |
|
1383 overlayMeta& GLRenderer::getOverlay (int newcam) { |
|
1384 return m_overlays[newcam]; |
|
1385 } |