src/glRenderer.cc

changeset 840
d077dd19bf9a
parent 828
7dd8f19159f7
child 844
11587d419d2f
equal deleted inserted replaced
839:5f822ad61875 840:d077dd19bf9a
358 { 358 {
359 currentDocumentData().needZoomToFit = false; 359 currentDocumentData().needZoomToFit = false;
360 zoomAllToFit(); 360 zoomAllToFit();
361 } 361 }
362 362
363 if (cfg::drawWireframe && not isPicking()) 363 if (cfg::drawWireframe and not isPicking())
364 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 364 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
365 365
366 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 366 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
367 glEnable (GL_DEPTH_TEST); 367 glEnable (GL_DEPTH_TEST);
368 368
373 373
374 glLoadIdentity(); 374 glLoadIdentity();
375 glOrtho (-m_virtWidth, m_virtWidth, -m_virtHeight, m_virtHeight, -100.0f, 100.0f); 375 glOrtho (-m_virtWidth, m_virtWidth, -m_virtHeight, m_virtHeight, -100.0f, 100.0f);
376 glTranslatef (pan (X), pan (Y), 0.0f); 376 glTranslatef (pan (X), pan (Y), 0.0f);
377 377
378 if (camera() != EFrontCamera && camera() != EBackCamera) 378 if (camera() != EFrontCamera and camera() != EBackCamera)
379 { 379 {
380 glRotatef (90.0f, g_FixedCameras[camera()].glrotate[0], 380 glRotatef (90.0f, g_FixedCameras[camera()].glrotate[0],
381 g_FixedCameras[camera()].glrotate[1], 381 g_FixedCameras[camera()].glrotate[1],
382 g_FixedCameras[camera()].glrotate[2]); 382 g_FixedCameras[camera()].glrotate[2]);
383 } 383 }
468 // ============================================================================= 468 // =============================================================================
469 // 469 //
470 void GLRenderer::drawVBOs (EVBOSurface surface, EVBOComplement colors, GLenum type) 470 void GLRenderer::drawVBOs (EVBOSurface surface, EVBOComplement colors, GLenum type)
471 { 471 {
472 // Filter this through some configuration options 472 // Filter this through some configuration options
473 if ((eq (surface, VBOSF_Quads, VBOSF_Triangles) && cfg::drawSurfaces == false) || 473 if ((eq (surface, VBOSF_Quads, VBOSF_Triangles) and cfg::drawSurfaces == false) or
474 (surface == VBOSF_Lines && cfg::drawEdgeLines == false) || 474 (surface == VBOSF_Lines and cfg::drawEdgeLines == false) or
475 (surface == VBOSF_CondLines && cfg::drawConditionalLines == false)) 475 (surface == VBOSF_CondLines and cfg::drawConditionalLines == false))
476 { 476 {
477 return; 477 return;
478 } 478 }
479 479
480 int surfacenum = m_compiler->vboNumber (surface, VBOCM_Surfaces); 480 int surfacenum = m_compiler->vboNumber (surface, VBOCM_Surfaces);
608 paint.drawText ((width() - textSize.width()) / 2, height() - textSize.height(), textSize.width(), 608 paint.drawText ((width() - textSize.width()) / 2, height() - textSize.height(), textSize.width(),
609 textSize.height(), Qt::AlignCenter, text); 609 textSize.height(), Qt::AlignCenter, text);
610 } 610 }
611 #endif 611 #endif
612 612
613 if (camera() != EFreeCamera && not isPicking()) 613 if (camera() != EFreeCamera and not isPicking())
614 { 614 {
615 // Paint the overlay image if we have one 615 // Paint the overlay image if we have one
616 const LDGLOverlay& overlay = currentDocumentData().overlays[camera()]; 616 const LDGLOverlay& overlay = currentDocumentData().overlays[camera()];
617 617
618 if (overlay.img != null) 618 if (overlay.img != null)
646 646
647 // Draw the camera icons 647 // Draw the camera icons
648 for (CameraIcon& info : m_cameraIcons) 648 for (CameraIcon& info : m_cameraIcons)
649 { 649 {
650 // Don't draw the free camera icon when in draw mode 650 // Don't draw the free camera icon when in draw mode
651 if (&info == &m_cameraIcons[EFreeCamera] && not m_editmode->allowFreeCamera()) 651 if (&info == &m_cameraIcons[EFreeCamera] and not m_editmode->allowFreeCamera())
652 continue; 652 continue;
653 653
654 paint.drawPixmap (info.destRect, *info.img, info.srcRect); 654 paint.drawPixmap (info.destRect, *info.img, info.srcRect);
655 } 655 }
656 656
721 721
722 // ============================================================================= 722 // =============================================================================
723 // 723 //
724 void GLRenderer::mouseReleaseEvent (QMouseEvent* ev) 724 void GLRenderer::mouseReleaseEvent (QMouseEvent* ev)
725 { 725 {
726 const bool wasLeft = (m_lastButtons & Qt::LeftButton) && not (ev->buttons() & Qt::LeftButton); 726 const bool wasLeft = (m_lastButtons & Qt::LeftButton) and not (ev->buttons() & Qt::LeftButton);
727 727
728 Qt::MouseButtons releasedbuttons = m_lastButtons & ~ev->buttons(); 728 Qt::MouseButtons releasedbuttons = m_lastButtons & ~ev->buttons();
729 729
730 if (m_panning) 730 if (m_panning)
731 m_panning = false; 731 m_panning = false;
787 { 787 {
788 const bool left = ev->buttons() & Qt::LeftButton, 788 const bool left = ev->buttons() & Qt::LeftButton,
789 mid = ev->buttons() & Qt::MidButton, 789 mid = ev->buttons() & Qt::MidButton,
790 shift = ev->modifiers() & Qt::ShiftModifier; 790 shift = ev->modifiers() & Qt::ShiftModifier;
791 791
792 if (mid || (left && shift)) 792 if (mid or (left and shift))
793 { 793 {
794 pan (X) += 0.03f * dx * (zoom() / 7.5f); 794 pan (X) += 0.03f * dx * (zoom() / 7.5f);
795 pan (Y) -= 0.03f * dy * (zoom() / 7.5f); 795 pan (Y) -= 0.03f * dy * (zoom() / 7.5f);
796 m_panning = true; 796 m_panning = true;
797 setCameraMoving (true); 797 setCameraMoving (true);
798 } 798 }
799 elif (left && camera() == EFreeCamera) 799 elif (left and camera() == EFreeCamera)
800 { 800 {
801 rot (X) = rot (X) + dy; 801 rot (X) = rot (X) + dy;
802 rot (Y) = rot (Y) + dx; 802 rot (Y) = rot (Y) + dx;
803 803
804 clampAngle (rot (X)); 804 clampAngle (rot (X));
870 // ============================================================================= 870 // =============================================================================
871 // 871 //
872 void GLRenderer::setCamera (const ECamera cam) 872 void GLRenderer::setCamera (const ECamera cam)
873 { 873 {
874 // The edit mode may forbid the free camera. 874 // The edit mode may forbid the free camera.
875 if (cam == EFreeCamera && not m_editmode->allowFreeCamera()) 875 if (cam == EFreeCamera and not m_editmode->allowFreeCamera())
876 return; 876 return;
877 877
878 m_camera = cam; 878 m_camera = cam;
879 cfg::camera = (int) cam; 879 cfg::camera = (int) cam;
880 g_win->updateEditModeActions(); 880 g_win->updateEditModeActions();
1001 1001
1002 // ============================================================================= 1002 // =============================================================================
1003 // 1003 //
1004 void GLRenderer::setEditMode (EditModeType a) 1004 void GLRenderer::setEditMode (EditModeType a)
1005 { 1005 {
1006 if (m_editmode != null && m_editmode->type() == a) 1006 if (m_editmode != null and m_editmode->type() == a)
1007 return; 1007 return;
1008 1008
1009 delete m_editmode; 1009 delete m_editmode;
1010 m_editmode = AbstractEditMode::createByType (this, a); 1010 m_editmode = AbstractEditMode::createByType (this, a);
1011 1011
1012 // If we cannot use the free camera, use the top one instead. 1012 // If we cannot use the free camera, use the top one instead.
1013 if (camera() == EFreeCamera && not m_editmode->allowFreeCamera()) 1013 if (camera() == EFreeCamera and not m_editmode->allowFreeCamera())
1014 setCamera (ETopCamera); 1014 setCamera (ETopCamera);
1015 1015
1016 g_win->updateEditModeActions(); 1016 g_win->updateEditModeActions();
1017 update(); 1017 update();
1018 } 1018 }
1283 // 1283 //
1284 void GLRenderer::zoomToFit() 1284 void GLRenderer::zoomToFit()
1285 { 1285 {
1286 zoom() = 30.0f; 1286 zoom() = 30.0f;
1287 1287
1288 if (document() == null || m_width == -1 || m_height == -1) 1288 if (document() == null or m_width == -1 or m_height == -1)
1289 return; 1289 return;
1290 1290
1291 bool lastfilled = false; 1291 bool lastfilled = false;
1292 bool firstrun = true; 1292 bool firstrun = true;
1293 const uint32 white = 0xFFFFFFFF; 1293 const uint32 white = 0xFFFFFFFF;
1302 // are background or not. 1302 // are background or not.
1303 setPicking (true); 1303 setPicking (true);
1304 1304
1305 while (--runaway) 1305 while (--runaway)
1306 { 1306 {
1307 if (zoom() > 10000.0 || zoom() < 0.0) 1307 if (zoom() > 10000.0 or zoom() < 0.0)
1308 { 1308 {
1309 // Obviously, there's nothing to draw if we get here. 1309 // Obviously, there's nothing to draw if we get here.
1310 // Default to 30.0f and break out. 1310 // Default to 30.0f and break out.
1311 zoom() = 30.0; 1311 zoom() = 30.0;
1312 break; 1312 break;
1321 bool filled = false; 1321 bool filled = false;
1322 1322
1323 // Check the top and bottom rows 1323 // Check the top and bottom rows
1324 for (int i = 0; i < w; ++i) 1324 for (int i = 0; i < w; ++i)
1325 { 1325 {
1326 if (imgdata[i] != white || imgdata[((h - 1) * w) + i] != white) 1326 if (imgdata[i] != white or imgdata[((h - 1) * w) + i] != white)
1327 { 1327 {
1328 filled = true; 1328 filled = true;
1329 break; 1329 break;
1330 } 1330 }
1331 } 1331 }
1333 // Left and right edges 1333 // Left and right edges
1334 if (filled == false) 1334 if (filled == false)
1335 { 1335 {
1336 for (int i = 0; i < h; ++i) 1336 for (int i = 0; i < h; ++i)
1337 { 1337 {
1338 if (imgdata[i * w] != white || imgdata[(i * w) + w - 1] != white) 1338 if (imgdata[i * w] != white or imgdata[(i * w) + w - 1] != white)
1339 { 1339 {
1340 filled = true; 1340 filled = true;
1341 break; 1341 break;
1342 } 1342 }
1343 } 1343 }
1355 } 1355 }
1356 else 1356 else
1357 { 1357 {
1358 // If this run filled the screen and the last one did not, the 1358 // If this run filled the screen and the last one did not, the
1359 // last run had ideal zoom - zoom a bit back and we should reach it. 1359 // last run had ideal zoom - zoom a bit back and we should reach it.
1360 if (filled && not lastfilled) 1360 if (filled and not lastfilled)
1361 { 1361 {
1362 zoomNotch (false); 1362 zoomNotch (false);
1363 break; 1363 break;
1364 } 1364 }
1365 1365
1366 // If this run did not fill the screen and the last one did, we've 1366 // If this run did not fill the screen and the last one did, we've
1367 // now reached ideal zoom so we're done here. 1367 // now reached ideal zoom so we're done here.
1368 if (not filled && lastfilled) 1368 if (not filled and lastfilled)
1369 break; 1369 break;
1370 1370
1371 inward = not filled; 1371 inward = not filled;
1372 } 1372 }
1373 1373
1407 { 1407 {
1408 for (LDObjectPtr obj : document()->objects()) 1408 for (LDObjectPtr obj : document()->objects())
1409 { 1409 {
1410 LDOverlayPtr ovlobj = obj.dynamicCast<LDOverlay>(); 1410 LDOverlayPtr ovlobj = obj.dynamicCast<LDOverlay>();
1411 1411
1412 if (ovlobj != null && obj.staticCast<LDOverlay>()->camera() == cam) 1412 if (ovlobj != null and obj.staticCast<LDOverlay>()->camera() == cam)
1413 return ovlobj; 1413 return ovlobj;
1414 } 1414 }
1415 1415
1416 return LDOverlayPtr(); 1416 return LDOverlayPtr();
1417 } 1417 }
1428 continue; 1428 continue;
1429 1429
1430 LDGLOverlay& meta = currentDocumentData().overlays[cam]; 1430 LDGLOverlay& meta = currentDocumentData().overlays[cam];
1431 LDOverlayPtr ovlobj = findOverlayObject (cam); 1431 LDOverlayPtr ovlobj = findOverlayObject (cam);
1432 1432
1433 if (ovlobj == null && meta.img != null) 1433 if (ovlobj == null and meta.img != null)
1434 { 1434 {
1435 delete meta.img; 1435 delete meta.img;
1436 meta.img = null; 1436 meta.img = null;
1437 } 1437 }
1438 elif (ovlobj != null && 1438 elif (ovlobj != null and
1439 (meta.img == null || meta.fname != ovlobj->fileName()) && 1439 (meta.img == null or meta.fname != ovlobj->fileName()) and
1440 not meta.invalid) 1440 not meta.invalid)
1441 { 1441 {
1442 setupOverlay (cam, ovlobj->fileName(), ovlobj->x(), 1442 setupOverlay (cam, ovlobj->fileName(), ovlobj->x(),
1443 ovlobj->y(), ovlobj->width(), ovlobj->height()); 1443 ovlobj->y(), ovlobj->width(), ovlobj->height());
1444 } 1444 }
1455 continue; 1455 continue;
1456 1456
1457 LDGLOverlay& meta = currentDocumentData().overlays[cam]; 1457 LDGLOverlay& meta = currentDocumentData().overlays[cam];
1458 LDOverlayPtr ovlobj = findOverlayObject (cam); 1458 LDOverlayPtr ovlobj = findOverlayObject (cam);
1459 1459
1460 if (meta.img == null && ovlobj != null) 1460 if (meta.img == null and ovlobj != null)
1461 { 1461 {
1462 // If this is the last overlay image, we need to remove the empty space after it as well. 1462 // If this is the last overlay image, we need to remove the empty space after it as well.
1463 LDObjectPtr nextobj = ovlobj->next(); 1463 LDObjectPtr nextobj = ovlobj->next();
1464 1464
1465 if (nextobj && nextobj->type() == OBJ_Empty) 1465 if (nextobj and nextobj->type() == OBJ_Empty)
1466 nextobj->destroy(); 1466 nextobj->destroy();
1467 1467
1468 // If the overlay object was there and the overlay itself is 1468 // If the overlay object was there and the overlay itself is
1469 // not, remove the object. 1469 // not, remove the object.
1470 ovlobj->destroy(); 1470 ovlobj->destroy();
1471 } 1471 }
1472 elif (meta.img != null && ovlobj == null) 1472 elif (meta.img != null and ovlobj == null)
1473 { 1473 {
1474 // Inverse case: image is there but the overlay object is 1474 // Inverse case: image is there but the overlay object is
1475 // not, thus create the object. 1475 // not, thus create the object.
1476 ovlobj = spawn<LDOverlay>(); 1476 ovlobj = spawn<LDOverlay>();
1477 1477
1507 if (found) 1507 if (found)
1508 document()->insertObj (i + 1, spawn<LDEmpty>()); 1508 document()->insertObj (i + 1, spawn<LDEmpty>());
1509 } 1509 }
1510 } 1510 }
1511 1511
1512 if (meta.img != null && ovlobj != null) 1512 if (meta.img != null and ovlobj != null)
1513 { 1513 {
1514 ovlobj->setCamera (cam); 1514 ovlobj->setCamera (cam);
1515 ovlobj->setFileName (meta.fname); 1515 ovlobj->setFileName (meta.fname);
1516 ovlobj->setX (meta.ox); 1516 ovlobj->setX (meta.ox);
1517 ovlobj->setY (meta.oy); 1517 ovlobj->setY (meta.oy);
1526 1526
1527 // ============================================================================= 1527 // =============================================================================
1528 // 1528 //
1529 void GLRenderer::highlightCursorObject() 1529 void GLRenderer::highlightCursorObject()
1530 { 1530 {
1531 if (not cfg::highlightObjectBelowCursor && objectAtCursor() == null) 1531 if (not cfg::highlightObjectBelowCursor and objectAtCursor() == null)
1532 return; 1532 return;
1533 1533
1534 LDObjectWeakPtr newObject; 1534 LDObjectWeakPtr newObject;
1535 LDObjectWeakPtr oldObject = objectAtCursor(); 1535 LDObjectWeakPtr oldObject = objectAtCursor();
1536 qint32 newIndex; 1536 qint32 newIndex;
1537 1537
1538 if (isCameraMoving() || not cfg::highlightObjectBelowCursor) 1538 if (isCameraMoving() or not cfg::highlightObjectBelowCursor)
1539 { 1539 {
1540 newIndex = 0; 1540 newIndex = 0;
1541 } 1541 }
1542 else 1542 else
1543 { 1543 {
1567 update(); 1567 update();
1568 } 1568 }
1569 1569
1570 void GLRenderer::dragEnterEvent (QDragEnterEvent* ev) 1570 void GLRenderer::dragEnterEvent (QDragEnterEvent* ev)
1571 { 1571 {
1572 if (g_win != null && ev->source() == g_win->getPrimitivesTree() && g_win->getPrimitivesTree()->currentItem() != null) 1572 if (g_win != null and ev->source() == g_win->getPrimitivesTree() and g_win->getPrimitivesTree()->currentItem() != null)
1573 ev->acceptProposedAction(); 1573 ev->acceptProposedAction();
1574 } 1574 }
1575 1575
1576 void GLRenderer::dropEvent (QDropEvent* ev) 1576 void GLRenderer::dropEvent (QDropEvent* ev)
1577 { 1577 {
1578 if (g_win != null && ev->source() == g_win->getPrimitivesTree()) 1578 if (g_win != null and ev->source() == g_win->getPrimitivesTree())
1579 { 1579 {
1580 QString primName = static_cast<SubfileListItem*> (g_win->getPrimitivesTree()->currentItem())->primitive()->name; 1580 QString primName = static_cast<SubfileListItem*> (g_win->getPrimitivesTree()->currentItem())->primitive()->name;
1581 LDSubfilePtr ref = spawn<LDSubfile>(); 1581 LDSubfilePtr ref = spawn<LDSubfile>();
1582 ref->setColor (maincolor()); 1582 ref->setColor (maincolor());
1583 ref->setFileInfo (getDocument (primName)); 1583 ref->setFileInfo (getDocument (primName));

mercurial