100 static QList<int> g_warnedColors; |
100 static QList<int> g_warnedColors; |
101 |
101 |
102 // ============================================================================= |
102 // ============================================================================= |
103 // ----------------------------------------------------------------------------- |
103 // ----------------------------------------------------------------------------- |
104 GLRenderer::GLRenderer (QWidget* parent) : QGLWidget (parent) |
104 GLRenderer::GLRenderer (QWidget* parent) : QGLWidget (parent) |
105 { m_picking = m_rangepick = false; |
105 { m_Picking = m_rangepick = false; |
106 m_camera = (GL::Camera) gl_camera.value; |
106 m_camera = (GL::Camera) gl_camera.value; |
107 m_drawToolTip = false; |
107 m_drawToolTip = false; |
108 m_editMode = Select; |
108 m_EditMode = Select; |
109 m_rectdraw = false; |
109 m_rectdraw = false; |
110 m_panning = false; |
110 m_panning = false; |
111 setFile (null); |
111 setFile (null); |
112 setDrawOnly (false); |
112 setDrawOnly (false); |
113 setMessageLog (null); |
113 setMessageLog (null); |
270 if (list == GL::PickList) |
270 if (list == GL::PickList) |
271 { // Make the color by the object's ID if we're picking, so we can make the |
271 { // Make the color by the object's ID if we're picking, so we can make the |
272 // ID again from the color we get from the picking results. Be sure to use |
272 // ID again from the color we get from the picking results. Be sure to use |
273 // the top level parent's index since we want a subfile's children point |
273 // the top level parent's index since we want a subfile's children point |
274 // to the subfile itself. |
274 // to the subfile itself. |
275 long i = obj->topLevelParent()->id(); |
275 long i = obj->topLevelParent()->getID(); |
276 |
276 |
277 // Calculate a color based from this index. This method caters for |
277 // Calculate a color based from this index. This method caters for |
278 // 16777216 objects. I don't think that'll be exceeded anytime soon. :) |
278 // 16777216 objects. I don't think that'll be exceeded anytime soon. :) |
279 // ATM biggest is 53588.dat with 12600 lines. |
279 // ATM biggest is 53588.dat with 12600 lines. |
280 double r = (i / (256 * 256)) % 256, |
280 double r = (i / (256 * 256)) % 256, |
283 |
283 |
284 qglColor (QColor (r, g, b)); |
284 qglColor (QColor (r, g, b)); |
285 return; |
285 return; |
286 } |
286 } |
287 |
287 |
288 if ( (list == BFCFrontList || list == BFCBackList) && |
288 if ((list == BFCFrontList || list == BFCBackList) && |
289 obj->getType() != LDObject::Line && |
289 obj->getType() != LDObject::Line && |
290 obj->getType() != LDObject::CndLine) |
290 obj->getType() != LDObject::CndLine) |
291 { |
291 { if (list == GL::BFCFrontList) |
292 |
|
293 if (list == GL::BFCFrontList) |
|
294 qcol = QColor (40, 192, 0); |
292 qcol = QColor (40, 192, 0); |
295 else |
293 else |
296 qcol = QColor (224, 0, 0); |
294 qcol = QColor (224, 0, 0); |
297 } |
295 } |
298 else |
296 else |
299 { if (obj->color() == maincolor) |
297 { if (obj->getColor() == maincolor) |
300 qcol = getMainColor(); |
298 qcol = getMainColor(); |
301 else |
299 else |
302 { LDColor* col = getColor (obj->color()); |
300 { LDColor* col = getColor (obj->getColor()); |
303 |
301 |
304 if (col) |
302 if (col) |
305 qcol = col->faceColor; |
303 qcol = col->faceColor; |
306 } |
304 } |
307 |
305 |
308 if (obj->color() == edgecolor) |
306 if (obj->getColor() == edgecolor) |
309 { qcol = luma (m_bgcolor) < 40 ? QColor (64, 64, 64) : Qt::black; |
307 { qcol = luma (m_bgcolor) < 40 ? QColor (64, 64, 64) : Qt::black; |
310 LDColor* col; |
308 LDColor* col; |
311 |
309 |
312 if (!gl_blackedges && obj->parent() && (col = getColor (obj->parent()->color()))) |
310 if (!gl_blackedges && obj->getParent() && (col = getColor (obj->getParent()->getColor()))) |
313 qcol = col->edgeColor; |
311 qcol = col->edgeColor; |
314 } |
312 } |
315 |
313 |
316 if (qcol.isValid() == false) |
314 if (qcol.isValid() == false) |
317 { // The color was unknown. Use main color to make the object at least |
315 { // The color was unknown. Use main color to make the object at least |
318 // not appear pitch-black. |
316 // not appear pitch-black. |
319 if (obj->color() != edgecolor) |
317 if (obj->getColor() != edgecolor) |
320 qcol = getMainColor(); |
318 qcol = getMainColor(); |
321 |
319 |
322 // Warn about the unknown colors, but only once. |
320 // Warn about the unknown colors, but only once. |
323 for (int i : g_warnedColors) |
321 for (int i : g_warnedColors) |
324 if (obj->color() == i) |
322 if (obj->getColor() == i) |
325 return; |
323 return; |
326 |
324 |
327 log ("%1: Unknown color %2!\n", __func__, obj->color()); |
325 log ("%1: Unknown color %2!\n", __func__, obj->getColor()); |
328 g_warnedColors << obj->color(); |
326 g_warnedColors << obj->getColor(); |
329 return; |
327 return; |
330 } |
328 } |
331 } |
329 } |
332 |
330 |
333 long r = qcol.red(), |
331 long r = qcol.red(), |
334 g = qcol.green(), |
332 g = qcol.green(), |
335 b = qcol.blue(), |
333 b = qcol.blue(), |
336 a = qcol.alpha(); |
334 a = qcol.alpha(); |
337 |
335 |
338 if (obj->topLevelParent()->selected()) |
336 if (obj->topLevelParent()->isSelected()) |
339 { // Brighten it up for the select list. |
337 { // Brighten it up for the select list. |
340 const uchar add = 51; |
338 const uchar add = 51; |
341 |
339 |
342 r = min (r + add, 255l); |
340 r = min (r + add, 255l); |
343 g = min (g + add, 255l); |
341 g = min (g + add, 255l); |
383 } |
381 } |
384 |
382 |
385 // ============================================================================= |
383 // ============================================================================= |
386 // ----------------------------------------------------------------------------- |
384 // ----------------------------------------------------------------------------- |
387 void GLRenderer::drawGLScene() |
385 void GLRenderer::drawGLScene() |
388 { if (file() == null) |
386 { if (getFile() == null) |
389 return; |
387 return; |
390 |
388 |
391 if (gl_wireframe && !picking()) |
389 if (gl_wireframe && !isPicking()) |
392 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); |
390 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); |
393 |
391 |
394 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
392 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
395 glEnable (GL_DEPTH_TEST); |
393 glEnable (GL_DEPTH_TEST); |
396 |
394 |
424 glRotatef (rot (X), 1.0f, 0.0f, 0.0f); |
422 glRotatef (rot (X), 1.0f, 0.0f, 0.0f); |
425 glRotatef (rot (Y), 0.0f, 1.0f, 0.0f); |
423 glRotatef (rot (Y), 0.0f, 1.0f, 0.0f); |
426 glRotatef (rot (Z), 0.0f, 0.0f, 1.0f); |
424 glRotatef (rot (Z), 0.0f, 0.0f, 1.0f); |
427 } |
425 } |
428 |
426 |
429 const GL::ListType list = (!drawOnly() && m_picking) ? PickList : NormalList; |
427 const GL::ListType list = (!isDrawOnly() && isPicking()) ? PickList : NormalList; |
430 |
428 |
431 if (gl_colorbfc && !m_picking && !drawOnly()) |
429 if (gl_colorbfc && !isPicking() && !isDrawOnly()) |
432 { glEnable (GL_CULL_FACE); |
430 { glEnable (GL_CULL_FACE); |
433 |
431 |
434 for (LDObject* obj : file()->objects()) |
432 for (LDObject* obj : getFile()->getObjects()) |
435 { if (obj->hidden()) |
433 { if (obj->isHidden()) |
436 continue; |
434 continue; |
437 |
435 |
438 glCullFace (GL_BACK); |
436 glCullFace (GL_BACK); |
439 glCallList (obj->glLists[BFCFrontList]); |
437 glCallList (obj->glLists[BFCFrontList]); |
440 |
438 |
443 } |
441 } |
444 |
442 |
445 glDisable (GL_CULL_FACE); |
443 glDisable (GL_CULL_FACE); |
446 } |
444 } |
447 else |
445 else |
448 { for (LDObject* obj : file()->objects()) |
446 { for (LDObject* obj : getFile()->getObjects()) |
449 { if (obj->hidden()) |
447 { if (obj->isHidden()) |
450 continue; |
448 continue; |
451 |
449 |
452 glCallList (obj->glLists[list]); |
450 glCallList (obj->glLists[list]); |
453 } |
451 } |
454 } |
452 } |
455 |
453 |
456 if (gl_axes && !m_picking && !drawOnly()) |
454 if (gl_axes && !isPicking() && !isDrawOnly()) |
457 glCallList (m_axeslist); |
455 glCallList (m_axeslist); |
458 |
456 |
459 glPopMatrix(); |
457 glPopMatrix(); |
460 glMatrixMode (GL_MODELVIEW); |
458 glMatrixMode (GL_MODELVIEW); |
461 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); |
459 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); |
543 QPainter paint (this); |
541 QPainter paint (this); |
544 QFontMetrics metrics = QFontMetrics (QFont()); |
542 QFontMetrics metrics = QFontMetrics (QFont()); |
545 paint.setRenderHint (QPainter::HighQualityAntialiasing); |
543 paint.setRenderHint (QPainter::HighQualityAntialiasing); |
546 |
544 |
547 // If we wish to only draw the brick, stop here |
545 // If we wish to only draw the brick, stop here |
548 if (drawOnly()) |
546 if (isDrawOnly()) |
549 return; |
547 return; |
550 |
548 |
551 if (m_camera != Free && !picking()) |
549 if (m_camera != Free && !isPicking()) |
552 { // Paint the overlay image if we have one |
550 { // Paint the overlay image if we have one |
553 const LDGLOverlay& overlay = m_overlays[m_camera]; |
551 const LDGLOverlay& overlay = m_overlays[m_camera]; |
554 |
552 |
555 if (overlay.img != null) |
553 if (overlay.img != null) |
556 { QPoint v0 = coordconv3_2 (m_overlays[m_camera].v0), |
554 { QPoint v0 = coordconv3_2 (m_overlays[m_camera].v0), |
631 // Draw their coordinates |
629 // Draw their coordinates |
632 paint.drawText (blip.x(), blip.y() - 8, polyverts[i].stringRep (true)); |
630 paint.drawText (blip.x(), blip.y() - 8, polyverts[i].stringRep (true)); |
633 } |
631 } |
634 } |
632 } |
635 } |
633 } |
636 elif (editMode() == CircleMode) |
634 elif (getEditMode() == CircleMode) |
637 { // If we have not specified the center point of the circle yet, preview it on the screen. |
635 { // If we have not specified the center point of the circle yet, preview it on the screen. |
638 if (m_drawedVerts.isEmpty()) |
636 if (m_drawedVerts.isEmpty()) |
639 drawBlip (paint, coordconv3_2 (m_hoverpos)); |
637 drawBlip (paint, coordconv3_2 (m_hoverpos)); |
640 else |
638 else |
641 { QVector<vertex> verts, verts2; |
639 { QVector<vertex> verts, verts2; |
717 } |
715 } |
718 } |
716 } |
719 } |
717 } |
720 |
718 |
721 // Camera icons |
719 // Camera icons |
722 if (!m_picking) |
720 if (!isPicking()) |
723 { // Draw a background for the selected camera |
721 { // Draw a background for the selected camera |
724 paint.setPen (m_thinBorderPen); |
722 paint.setPen (m_thinBorderPen); |
725 paint.setBrush (QBrush (QColor (0, 128, 160, 128))); |
723 paint.setBrush (QBrush (QColor (0, 128, 160, 128))); |
726 paint.drawRect (m_cameraIcons[camera()].selRect); |
724 paint.drawRect (m_cameraIcons[camera()].selRect); |
727 |
725 |
728 // Draw the actual icons |
726 // Draw the actual icons |
729 for (CameraIcon& info : m_cameraIcons) |
727 for (CameraIcon& info : m_cameraIcons) |
730 { // Don't draw the free camera icon when in draw mode |
728 { // Don't draw the free camera icon when in draw mode |
731 if (&info == &m_cameraIcons[GL::Free] && editMode() != Select) |
729 if (&info == &m_cameraIcons[GL::Free] && getEditMode() != Select) |
732 continue; |
730 continue; |
733 |
731 |
734 paint.drawPixmap (info.destRect, *info.img, info.srcRect); |
732 paint.drawPixmap (info.destRect, *info.img, info.srcRect); |
735 } |
733 } |
736 |
734 |
755 } |
753 } |
756 } |
754 } |
757 } |
755 } |
758 |
756 |
759 // Message log |
757 // Message log |
760 if (msglog()) |
758 if (getMessageLog()) |
761 { int y = 0; |
759 { int y = 0; |
762 const int margin = 2; |
760 const int margin = 2; |
763 QColor penColor = getTextPen(); |
761 QColor penColor = getTextPen(); |
764 |
762 |
765 for (const MessageManager::Line& line : msglog()->getLines()) |
763 for (const MessageManager::Line& line : getMessageLog()->getLines()) |
766 { penColor.setAlphaF (line.alpha); |
764 { penColor.setAlphaF (line.alpha); |
767 paint.setPen (penColor); |
765 paint.setPen (penColor); |
768 paint.drawText (QPoint (margin, y + margin + metrics.ascent()), line.text); |
766 paint.drawText (QPoint (margin, y + margin + metrics.ascent()), line.text); |
769 y += metrics.height(); |
767 y += metrics.height(); |
770 } |
768 } |
771 } |
769 } |
772 |
770 |
773 // If we're range-picking, draw a rectangle encompassing the selection area. |
771 // If we're range-picking, draw a rectangle encompassing the selection area. |
774 if (m_rangepick && !m_picking && m_totalmove >= 10) |
772 if (m_rangepick && !isPicking() && m_totalmove >= 10) |
775 { int x0 = m_rangeStart.x(), |
773 { int x0 = m_rangeStart.x(), |
776 y0 = m_rangeStart.y(), |
774 y0 = m_rangeStart.y(), |
777 x1 = m_pos.x(), |
775 x1 = m_pos.x(), |
778 y1 = m_pos.y(); |
776 y1 = m_pos.y(); |
779 |
777 |
805 } |
803 } |
806 |
804 |
807 // ============================================================================= |
805 // ============================================================================= |
808 // ----------------------------------------------------------------------------- |
806 // ----------------------------------------------------------------------------- |
809 void GLRenderer::compileAllObjects() |
807 void GLRenderer::compileAllObjects() |
810 { if (!file()) |
808 { if (!getFile()) |
811 return; |
809 return; |
812 |
810 |
813 // Compiling all is a big job, use a busy cursor |
811 // Compiling all is a big job, use a busy cursor |
814 setCursor (Qt::BusyCursor); |
812 setCursor (Qt::BusyCursor); |
815 |
813 |
816 m_knownVerts.clear(); |
814 m_knownVerts.clear(); |
817 |
815 |
818 for (LDObject* obj : file()->objects()) |
816 for (LDObject* obj : getFile()->getObjects()) |
819 compileObject (obj); |
817 compileObject (obj); |
820 |
818 |
821 // Compile axes |
819 // Compile axes |
822 glDeleteLists (m_axeslist, 1); |
820 glDeleteLists (m_axeslist, 1); |
823 m_axeslist = glGenLists (1); |
821 m_axeslist = glGenLists (1); |
893 LDSubfile::DeepInline | |
891 LDSubfile::DeepInline | |
894 LDSubfile::CacheInline | |
892 LDSubfile::CacheInline | |
895 LDSubfile::RendererInline); |
893 LDSubfile::RendererInline); |
896 bool oldinvert = g_glInvert; |
894 bool oldinvert = g_glInvert; |
897 |
895 |
898 if (ref->transform().getDeterminant() < 0) |
896 if (ref->getTransform().getDeterminant() < 0) |
899 g_glInvert = !g_glInvert; |
897 g_glInvert = !g_glInvert; |
900 |
898 |
901 LDObject* prev = ref->prev(); |
899 LDObject* prev = ref->prev(); |
902 |
900 |
903 if (prev && prev->getType() == LDObject::BFC && static_cast<LDBFC*> (prev)->type == LDBFC::InvertNext) |
901 if (prev && prev->getType() == LDObject::BFC && static_cast<LDBFC*> (prev)->type == LDBFC::InvertNext) |
935 |
933 |
936 // ============================================================================= |
934 // ============================================================================= |
937 // ----------------------------------------------------------------------------- |
935 // ----------------------------------------------------------------------------- |
938 void GLRenderer::addDrawnVertex (vertex pos) |
936 void GLRenderer::addDrawnVertex (vertex pos) |
939 { // If we picked an already-existing vertex, stop drawing |
937 { // If we picked an already-existing vertex, stop drawing |
940 if (editMode() != CircleMode) |
938 if (getEditMode() != CircleMode) |
941 { for (vertex& vert : m_drawedVerts) |
939 { for (vertex& vert : m_drawedVerts) |
942 { if (vert == pos) |
940 { if (vert == pos) |
943 { endDraw (true); |
941 { endDraw (true); |
944 return; |
942 return; |
945 } |
943 } |
1282 compileObject (removedObj); |
1278 compileObject (removedObj); |
1283 |
1279 |
1284 // Restore line thickness |
1280 // Restore line thickness |
1285 glLineWidth (gl_linethickness); |
1281 glLineWidth (gl_linethickness); |
1286 |
1282 |
1287 m_picking = false; |
1283 setPicking (false); |
1288 m_rangepick = false; |
1284 m_rangepick = false; |
1289 glEnable (GL_DITHER); |
1285 glEnable (GL_DITHER); |
1290 |
1286 |
1291 setBackground(); |
1287 setBackground(); |
1292 repaint(); |
1288 repaint(); |
1293 } |
1289 } |
1294 |
1290 |
1295 // ============================================================================= |
1291 // ============================================================================= |
1296 // ----------------------------------------------------------------------------- |
1292 // ----------------------------------------------------------------------------- |
1297 READ_ACCESSOR (EditMode, GLRenderer::editMode) |
1293 void GLRenderer::EditModeChanged() |
1298 { return m_editMode; |
1294 { switch (getEditMode()) |
1299 } |
|
1300 |
|
1301 // ============================================================================= |
|
1302 // ----------------------------------------------------------------------------- |
|
1303 SET_ACCESSOR (EditMode, GLRenderer::setEditMode) |
|
1304 { m_editMode = val; |
|
1305 |
|
1306 switch (editMode()) |
|
1307 { case Select: |
1295 { case Select: |
1308 { unsetCursor(); |
1296 { unsetCursor(); |
1309 setContextMenuPolicy (Qt::DefaultContextMenu); |
1297 setContextMenuPolicy (Qt::DefaultContextMenu); |
1310 } break; |
1298 } break; |
1311 |
1299 |
1336 |
1324 |
1337 g_win->updateEditModeActions(); |
1325 g_win->updateEditModeActions(); |
1338 update(); |
1326 update(); |
1339 } |
1327 } |
1340 |
1328 |
1341 // ============================================================================= |
1329 void GLRenderer::FileChanged() |
1342 // ----------------------------------------------------------------------------- |
1330 { if (getFile() != null) |
1343 READ_ACCESSOR (LDFile*, GLRenderer::file) |
|
1344 { return m_file; |
|
1345 } |
|
1346 |
|
1347 // ============================================================================= |
|
1348 // ----------------------------------------------------------------------------- |
|
1349 SET_ACCESSOR (LDFile*, GLRenderer::setFile) |
|
1350 { m_file = val; |
|
1351 |
|
1352 if (val != null) |
|
1353 initOverlaysFromObjects(); |
1331 initOverlaysFromObjects(); |
1354 } |
1332 } |
1355 |
1333 |
1356 // ============================================================================= |
1334 // ============================================================================= |
1357 // ----------------------------------------------------------------------------- |
1335 // ----------------------------------------------------------------------------- |
1436 if (dist1 < dist0) |
1414 if (dist1 < dist0) |
1437 std::swap<double> (dist0, dist1); |
1415 std::swap<double> (dist0, dist1); |
1438 |
1416 |
1439 if (dist0 == dist1) |
1417 if (dist0 == dist1) |
1440 { // If the radii are the same, there's no ring space to fill. Use a circle. |
1418 { // If the radii are the same, there's no ring space to fill. Use a circle. |
1441 refFile = getFile ("4-4edge.dat"); |
1419 refFile = ::getFile ("4-4edge.dat"); |
1442 transform = getCircleDrawMatrix (dist0); |
1420 transform = getCircleDrawMatrix (dist0); |
1443 circleOrDisc = true; |
1421 circleOrDisc = true; |
1444 } |
1422 } |
1445 elif (dist0 == 0 || dist1 == 0) |
1423 elif (dist0 == 0 || dist1 == 0) |
1446 { // If either radii is 0, use a disc. |
1424 { // If either radii is 0, use a disc. |
1447 refFile = getFile ("4-4disc.dat"); |
1425 refFile = ::getFile ("4-4disc.dat"); |
1448 transform = getCircleDrawMatrix ((dist0 != 0) ? dist0 : dist1); |
1426 transform = getCircleDrawMatrix ((dist0 != 0) ? dist0 : dist1); |
1449 circleOrDisc = true; |
1427 circleOrDisc = true; |
1450 } |
1428 } |
1451 elif (g_RingFinder (dist0, dist1)) |
1429 elif (g_RingFinder (dist0, dist1)) |
1452 { // The ring finder found a solution, use that. Add the component rings to the file. |
1430 { // The ring finder found a solution, use that. Add the component rings to the file. |
1453 for (const RingFinder::Component& cmp : g_RingFinder.bestSolution()->getComponents()) |
1431 for (const RingFinder::Component& cmp : g_RingFinder.bestSolution()->getComponents()) |
1454 { if ((refFile = getFile (radialFileName (::Ring, lores, lores, cmp.num))) == null) |
1432 { if ((refFile = ::getFile (radialFileName (::Ring, lores, lores, cmp.num))) == null) |
1455 { refFile = generatePrimitive (::Ring, lores, lores, cmp.num); |
1433 { refFile = generatePrimitive (::Ring, lores, lores, cmp.num); |
1456 refFile->setImplicit (false); |
1434 refFile->setImplicit (false); |
1457 } |
1435 } |
1458 |
1436 |
1459 LDSubfile* ref = new LDSubfile; |
1437 LDSubfile* ref = new LDSubfile; |
1582 // ============================================================================= |
1560 // ============================================================================= |
1583 // ----------------------------------------------------------------------------- |
1561 // ----------------------------------------------------------------------------- |
1584 void GLRenderer::compileObject (LDObject* obj) |
1562 void GLRenderer::compileObject (LDObject* obj) |
1585 { deleteLists (obj); |
1563 { deleteLists (obj); |
1586 |
1564 |
1587 for (const GL::ListType listType : g_glListTypes) |
1565 for (const GL::ListType listType : g_glListTypes) |
1588 { if (drawOnly() && listType != GL::NormalList) |
1566 { if (isDrawOnly() && listType != GL::NormalList) |
1589 continue; |
1567 continue; |
1590 |
1568 |
1591 GLuint list = glGenLists (1); |
1569 GLuint list = glGenLists (1); |
1592 glNewList (list, GL_COMPILE); |
1570 glNewList (list, GL_COMPILE); |
1593 |
1571 |
1774 glClearColor (1.0, 1.0, 1.0, 1.0); |
1752 glClearColor (1.0, 1.0, 1.0, 1.0); |
1775 glDisable (GL_DITHER); |
1753 glDisable (GL_DITHER); |
1776 |
1754 |
1777 // Use the pick list while drawing the scene, this way we can tell whether borders |
1755 // Use the pick list while drawing the scene, this way we can tell whether borders |
1778 // are background or not. |
1756 // are background or not. |
1779 m_picking = true; |
1757 setPicking (true); |
1780 |
1758 |
1781 for (;;) |
1759 for (;;) |
1782 { if (zoom() > 10000.0 || zoom() < 0.0) |
1760 { if (zoom() > 10000.0 || zoom() < 0.0) |
1783 { // Obviously, there's nothing to draw if we get here. |
1761 { // Obviously, there's nothing to draw if we get here. |
1784 // Default to 30.0f and break out. |
1762 // Default to 30.0f and break out. |
1903 // ============================================================================= |
1881 // ============================================================================= |
1904 // ----------------------------------------------------------------------------- |
1882 // ----------------------------------------------------------------------------- |
1905 LDOverlay* GLRenderer::findOverlayObject (GLRenderer::Camera cam) |
1883 LDOverlay* GLRenderer::findOverlayObject (GLRenderer::Camera cam) |
1906 { LDOverlay* ovlobj = null; |
1884 { LDOverlay* ovlobj = null; |
1907 |
1885 |
1908 for (LDObject * obj : file()->objects()) |
1886 for (LDObject * obj : getFile()->getObjects()) |
1909 { if (obj->getType() == LDObject::Overlay && static_cast<LDOverlay*> (obj)->camera() == cam) |
1887 { if (obj->getType() == LDObject::Overlay && static_cast<LDOverlay*> (obj)->getCamera() == cam) |
1910 { ovlobj = static_cast<LDOverlay*> (obj); |
1888 { ovlobj = static_cast<LDOverlay*> (obj); |
1911 break; |
1889 break; |
1912 } |
1890 } |
1913 } |
1891 } |
1914 |
1892 |
1928 LDOverlay* ovlobj = findOverlayObject (cam); |
1906 LDOverlay* ovlobj = findOverlayObject (cam); |
1929 |
1907 |
1930 if (!ovlobj && meta.img) |
1908 if (!ovlobj && meta.img) |
1931 { delete meta.img; |
1909 { delete meta.img; |
1932 meta.img = null; |
1910 meta.img = null; |
1933 } elif (ovlobj && (!meta.img || meta.fname != ovlobj->filename())) |
1911 } elif (ovlobj && (!meta.img || meta.fname != ovlobj->getFileName())) |
1934 setupOverlay (cam, ovlobj->filename(), ovlobj->x(), ovlobj->y(), ovlobj->width(), ovlobj->height()); |
1912 setupOverlay (cam, ovlobj->getFileName(), ovlobj->getX(), |
|
1913 ovlobj->getY(), ovlobj->getWidth(), ovlobj->getHeight()); |
1935 } |
1914 } |
1936 } |
1915 } |
1937 |
1916 |
1938 // ============================================================================= |
1917 // ============================================================================= |
1939 // ----------------------------------------------------------------------------- |
1918 // ----------------------------------------------------------------------------- |
1948 if (!meta.img && ovlobj) |
1927 if (!meta.img && ovlobj) |
1949 { // If this is the last overlay image, we need to remove the empty space after it as well. |
1928 { // If this is the last overlay image, we need to remove the empty space after it as well. |
1950 LDObject* nextobj = ovlobj->next(); |
1929 LDObject* nextobj = ovlobj->next(); |
1951 |
1930 |
1952 if (nextobj && nextobj->getType() == LDObject::Empty) |
1931 if (nextobj && nextobj->getType() == LDObject::Empty) |
1953 { m_file->forgetObject (nextobj); |
1932 { getFile()->forgetObject (nextobj); |
1954 delete nextobj; |
1933 delete nextobj; |
1955 } |
1934 } |
1956 |
1935 |
1957 // If the overlay object was there and the overlay itself is |
1936 // If the overlay object was there and the overlay itself is |
1958 // not, remove the object. |
1937 // not, remove the object. |
1959 m_file->forgetObject (ovlobj); |
1938 getFile()->forgetObject (ovlobj); |
1960 delete ovlobj; |
1939 delete ovlobj; |
1961 } elif (meta.img && !ovlobj) |
1940 } elif (meta.img && !ovlobj) |
1962 { // Inverse case: image is there but the overlay object is |
1941 { // Inverse case: image is there but the overlay object is |
1963 // not, thus create the object. |
1942 // not, thus create the object. |
1964 ovlobj = new LDOverlay; |
1943 ovlobj = new LDOverlay; |
1983 if (obj->getType() == LDObject::Overlay) |
1962 if (obj->getType() == LDObject::Overlay) |
1984 lastOverlay = i; |
1963 lastOverlay = i; |
1985 } |
1964 } |
1986 |
1965 |
1987 if (lastOverlay != -1) |
1966 if (lastOverlay != -1) |
1988 file()->insertObj (lastOverlay + 1, ovlobj); |
1967 getFile()->insertObj (lastOverlay + 1, ovlobj); |
1989 else |
1968 else |
1990 { file()->insertObj (i, ovlobj); |
1969 { getFile()->insertObj (i, ovlobj); |
1991 |
1970 |
1992 if (found) |
1971 if (found) |
1993 file()->insertObj (i + 1, new LDEmpty); |
1972 getFile()->insertObj (i + 1, new LDEmpty); |
1994 } |
1973 } |
1995 } |
1974 } |
1996 |
1975 |
1997 if (meta.img && ovlobj) |
1976 if (meta.img && ovlobj) |
1998 { ovlobj->setCamera (cam); |
1977 { ovlobj->setCamera (cam); |
1999 ovlobj->setFilename (meta.fname); |
1978 ovlobj->setFileName (meta.fname); |
2000 ovlobj->setX (meta.ox); |
1979 ovlobj->setX (meta.ox); |
2001 ovlobj->setY (meta.oy); |
1980 ovlobj->setY (meta.oy); |
2002 ovlobj->setWidth (meta.lw); |
1981 ovlobj->setWidth (meta.lw); |
2003 ovlobj->setHeight (meta.lh); |
1982 ovlobj->setHeight (meta.lh); |
2004 } |
1983 } |