src/glRenderer.cpp

changeset 985
ed7b31b9f904
parent 984
a7b6f987d269
child 986
525921eae58c
equal deleted inserted replaced
984:a7b6f987d269 985:ed7b31b9f904
210 210
211 // ============================================================================= 211 // =============================================================================
212 // 212 //
213 void GLRenderer::needZoomToFit() 213 void GLRenderer::needZoomToFit()
214 { 214 {
215 if (document() != nullptr) 215 if (document())
216 currentDocumentData().needZoomToFit = true; 216 currentDocumentData().needZoomToFit = true;
217 } 217 }
218 218
219 // ============================================================================= 219 // =============================================================================
220 // 220 //
623 if (camera() != EFreeCamera and not isPicking()) 623 if (camera() != EFreeCamera and not isPicking())
624 { 624 {
625 // Paint the overlay image if we have one 625 // Paint the overlay image if we have one
626 const LDGLOverlay& overlay = currentDocumentData().overlays[camera()]; 626 const LDGLOverlay& overlay = currentDocumentData().overlays[camera()];
627 627
628 if (overlay.img != nullptr) 628 if (overlay.img)
629 { 629 {
630 QPoint v0 = coordconv3_2 (currentDocumentData().overlays[camera()].v0), 630 QPoint v0 = coordconv3_2 (currentDocumentData().overlays[camera()].v0),
631 v1 = coordconv3_2 (currentDocumentData().overlays[camera()].v1); 631 v1 = coordconv3_2 (currentDocumentData().overlays[camera()].v1);
632 632
633 QRect targRect (v0.x(), v0.y(), qAbs (v1.x() - v0.x()), qAbs (v1.y() - v0.y())), 633 QRect targRect (v0.x(), v0.y(), qAbs (v1.x() - v0.x()), qAbs (v1.y() - v0.y())),
1021 1021
1022 // ============================================================================= 1022 // =============================================================================
1023 // 1023 //
1024 void GLRenderer::setEditMode (EditModeType a) 1024 void GLRenderer::setEditMode (EditModeType a)
1025 { 1025 {
1026 if (m_editmode != nullptr and m_editmode->type() == a) 1026 if (m_editmode and m_editmode->type() == a)
1027 return; 1027 return;
1028 1028
1029 delete m_editmode; 1029 delete m_editmode;
1030 m_editmode = AbstractEditMode::createByType (this, a); 1030 m_editmode = AbstractEditMode::createByType (this, a);
1031 1031
1048 // 1048 //
1049 void GLRenderer::setDocument (LDDocument* const& a) 1049 void GLRenderer::setDocument (LDDocument* const& a)
1050 { 1050 {
1051 m_document = a; 1051 m_document = a;
1052 1052
1053 if (a != nullptr) 1053 if (a)
1054 { 1054 {
1055 initOverlaysFromObjects(); 1055 initOverlaysFromObjects();
1056 1056
1057 if (not currentDocumentData().init) 1057 if (not currentDocumentData().init)
1058 { 1058 {
1431 continue; 1431 continue;
1432 1432
1433 LDGLOverlay& meta = currentDocumentData().overlays[cam]; 1433 LDGLOverlay& meta = currentDocumentData().overlays[cam];
1434 LDOverlay* ovlobj = findOverlayObject (cam); 1434 LDOverlay* ovlobj = findOverlayObject (cam);
1435 1435
1436 if (ovlobj == nullptr and meta.img != nullptr) 1436 if (ovlobj == nullptr and meta.img)
1437 { 1437 {
1438 delete meta.img; 1438 delete meta.img;
1439 meta.img = nullptr; 1439 meta.img = nullptr;
1440 } 1440 }
1441 else if (ovlobj != nullptr and 1441 else if (ovlobj and
1442 (meta.img == nullptr or meta.fname != ovlobj->fileName()) and 1442 (meta.img == nullptr or meta.fname != ovlobj->fileName()) and
1443 not meta.invalid) 1443 not meta.invalid)
1444 { 1444 {
1445 setupOverlay (cam, ovlobj->fileName(), ovlobj->x(), 1445 setupOverlay (cam, ovlobj->fileName(), ovlobj->x(),
1446 ovlobj->y(), ovlobj->width(), ovlobj->height()); 1446 ovlobj->y(), ovlobj->width(), ovlobj->height());
1458 continue; 1458 continue;
1459 1459
1460 LDGLOverlay& meta = currentDocumentData().overlays[cam]; 1460 LDGLOverlay& meta = currentDocumentData().overlays[cam];
1461 LDOverlay* ovlobj = findOverlayObject (cam); 1461 LDOverlay* ovlobj = findOverlayObject (cam);
1462 1462
1463 if (meta.img == nullptr and ovlobj != nullptr) 1463 if (meta.img == nullptr and ovlobj)
1464 { 1464 {
1465 // If this is the last overlay image, we need to remove the empty space after it as well. 1465 // If this is the last overlay image, we need to remove the empty space after it as well.
1466 LDObject* nextobj = ovlobj->next(); 1466 LDObject* nextobj = ovlobj->next();
1467 1467
1468 if (nextobj and nextobj->type() == OBJ_Empty) 1468 if (nextobj and nextobj->type() == OBJ_Empty)
1470 1470
1471 // If the overlay object was there and the overlay itself is 1471 // If the overlay object was there and the overlay itself is
1472 // not, remove the object. 1472 // not, remove the object.
1473 ovlobj->destroy(); 1473 ovlobj->destroy();
1474 } 1474 }
1475 else if (meta.img != nullptr and ovlobj == nullptr) 1475 else if (meta.img and ovlobj == nullptr)
1476 { 1476 {
1477 // Inverse case: image is there but the overlay object is 1477 // Inverse case: image is there but the overlay object is
1478 // not, thus create the object. 1478 // not, thus create the object.
1479 ovlobj = LDSpawn<LDOverlay>(); 1479 ovlobj = LDSpawn<LDOverlay>();
1480 1480
1510 if (found) 1510 if (found)
1511 document()->insertObj (i + 1, LDSpawn<LDEmpty>()); 1511 document()->insertObj (i + 1, LDSpawn<LDEmpty>());
1512 } 1512 }
1513 } 1513 }
1514 1514
1515 if (meta.img != nullptr and ovlobj != nullptr) 1515 if (meta.img and ovlobj)
1516 { 1516 {
1517 ovlobj->setCamera (cam); 1517 ovlobj->setCamera (cam);
1518 ovlobj->setFileName (meta.fname); 1518 ovlobj->setFileName (meta.fname);
1519 ovlobj->setX (meta.ox); 1519 ovlobj->setX (meta.ox);
1520 ovlobj->setY (meta.oy); 1520 ovlobj->setY (meta.oy);
1551 unsigned char pixel[4]; 1551 unsigned char pixel[4];
1552 glReadPixels (m_mousePosition.x(), m_height - m_mousePosition.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel[0]); 1552 glReadPixels (m_mousePosition.x(), m_height - m_mousePosition.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel[0]);
1553 newIndex = pixel[0] * 0x10000 | pixel[1] * 0x100 | pixel[2]; 1553 newIndex = pixel[0] * 0x10000 | pixel[1] * 0x100 | pixel[2];
1554 } 1554 }
1555 1555
1556 if (newIndex != (oldObject != nullptr ? oldObject->id() : 0)) 1556 if (newIndex != (oldObject ? oldObject->id() : 0))
1557 { 1557 {
1558 if (newIndex != 0) 1558 if (newIndex != 0)
1559 newObject = LDObject::fromID (newIndex); 1559 newObject = LDObject::fromID (newIndex);
1560 1560
1561 setObjectAtCursor (newObject); 1561 setObjectAtCursor (newObject);
1562 1562
1563 if (oldObject != nullptr) 1563 if (oldObject)
1564 compileObject (oldObject); 1564 compileObject (oldObject);
1565 1565
1566 if (newObject != nullptr) 1566 if (newObject)
1567 compileObject (newObject); 1567 compileObject (newObject);
1568 } 1568 }
1569 1569
1570 update(); 1570 update();
1571 } 1571 }
1572 1572
1573 void GLRenderer::dragEnterEvent (QDragEnterEvent* ev) 1573 void GLRenderer::dragEnterEvent (QDragEnterEvent* ev)
1574 { 1574 {
1575 if (m_window != nullptr and ev->source() == m_window->getPrimitivesTree() and m_window->getPrimitivesTree()->currentItem() != nullptr) 1575 if (m_window and ev->source() == m_window->getPrimitivesTree() and m_window->getPrimitivesTree()->currentItem())
1576 ev->acceptProposedAction(); 1576 ev->acceptProposedAction();
1577 } 1577 }
1578 1578
1579 void GLRenderer::dropEvent (QDropEvent* ev) 1579 void GLRenderer::dropEvent (QDropEvent* ev)
1580 { 1580 {
1581 if (m_window != nullptr and ev->source() == m_window->getPrimitivesTree()) 1581 if (m_window and ev->source() == m_window->getPrimitivesTree())
1582 { 1582 {
1583 QString primName = static_cast<SubfileListItem*> (m_window->getPrimitivesTree()->currentItem())->primitive()->name; 1583 QString primName = static_cast<SubfileListItem*> (m_window->getPrimitivesTree()->currentItem())->primitive()->name;
1584 LDSubfile* ref = LDSpawn<LDSubfile>(); 1584 LDSubfile* ref = LDSpawn<LDSubfile>();
1585 ref->setColor (MainColor); 1585 ref->setColor (MainColor);
1586 ref->setFileInfo (GetDocument (primName)); 1586 ref->setFileInfo (GetDocument (primName));

mercurial