1237 // ============================================================================= |
1232 // ============================================================================= |
1238 // |
1233 // |
1239 void GLRenderer::zoomToFit() |
1234 void GLRenderer::zoomToFit() |
1240 { |
1235 { |
1241 zoom() = 30.0f; |
1236 zoom() = 30.0f; |
1242 |
|
1243 if (model() == nullptr or m_width == -1 or m_height == -1) |
|
1244 return; |
|
1245 |
|
1246 bool lastfilled = false; |
1237 bool lastfilled = false; |
1247 bool firstrun = true; |
1238 bool firstrun = true; |
1248 enum { black = 0xFF000000 }; |
1239 enum { black = 0xFF000000 }; |
1249 bool inward = true; |
1240 bool inward = true; |
1250 int runaway = 50; |
1241 int runaway = 50; |
1341 |
1332 |
1342 // ============================================================================= |
1333 // ============================================================================= |
1343 // |
1334 // |
1344 LDOverlay* GLRenderer::findOverlayObject (Camera cam) |
1335 LDOverlay* GLRenderer::findOverlayObject (Camera cam) |
1345 { |
1336 { |
1346 for (LDObject* obj : model()->objects()) |
1337 for (LDObject* obj : m_model->objects()) |
1347 { |
1338 { |
1348 LDOverlay* overlay = dynamic_cast<LDOverlay*> (obj); |
1339 LDOverlay* overlay = dynamic_cast<LDOverlay*> (obj); |
1349 |
1340 |
1350 if (overlay and overlay->camera() == cam) |
1341 if (overlay and overlay->camera() == cam) |
1351 return overlay; |
1342 return overlay; |
1401 { |
1392 { |
1402 // If this is the last overlay image, we need to remove the empty space after it as well. |
1393 // If this is the last overlay image, we need to remove the empty space after it as well. |
1403 LDObject* nextobj = overlayObject->next(); |
1394 LDObject* nextobj = overlayObject->next(); |
1404 |
1395 |
1405 if (nextobj and nextobj->type() == OBJ_Empty) |
1396 if (nextobj and nextobj->type() == OBJ_Empty) |
1406 model()->remove(nextobj); |
1397 m_model->remove(nextobj); |
1407 |
1398 |
1408 // If the overlay object was there and the overlay itself is |
1399 // If the overlay object was there and the overlay itself is |
1409 // not, remove the object. |
1400 // not, remove the object. |
1410 model()->remove(overlayObject); |
1401 m_model->remove(overlayObject); |
1411 overlayObject = nullptr; |
1402 overlayObject = nullptr; |
1412 } |
1403 } |
1413 else if (meta.image and overlayObject == nullptr) |
1404 else if (meta.image and overlayObject == nullptr) |
1414 { |
1405 { |
1415 // Inverse case: image is there but the overlay object is |
1406 // Inverse case: image is there but the overlay object is |
1439 lastOverlayPosition = i; |
1430 lastOverlayPosition = i; |
1440 } |
1431 } |
1441 |
1432 |
1442 if (lastOverlayPosition != -1) |
1433 if (lastOverlayPosition != -1) |
1443 { |
1434 { |
1444 overlayObject = model()->emplaceAt<LDOverlay>(lastOverlayPosition + 1); |
1435 overlayObject = m_model->emplaceAt<LDOverlay>(lastOverlayPosition + 1); |
1445 } |
1436 } |
1446 else |
1437 else |
1447 { |
1438 { |
1448 overlayObject = model()->emplaceAt<LDOverlay>(i); |
1439 overlayObject = m_model->emplaceAt<LDOverlay>(i); |
1449 |
1440 |
1450 if (found) |
1441 if (found) |
1451 model()->emplaceAt<LDEmpty>(i + 1); |
1442 m_model->emplaceAt<LDEmpty>(i + 1); |
1452 } |
1443 } |
1453 } |
1444 } |
1454 |
1445 |
1455 if (meta.image and overlayObject) |
1446 if (meta.image and overlayObject) |
1456 { |
1447 { |