src/glRenderer.cc

changeset 909
f025ab5e57ac
parent 901
6e89eaa1df70
child 927
409b82a4765e
child 943
af81220741d9
equal deleted inserted replaced
904:f8e1852b91bc 909:f025ab5e57ac
1294 1294
1295 // ============================================================================= 1295 // =============================================================================
1296 // 1296 //
1297 void GLRenderer::zoomNotch (bool inward) 1297 void GLRenderer::zoomNotch (bool inward)
1298 { 1298 {
1299 if (zoom() > 15) 1299 zoom() *= inward ? 0.833f : 1.2f;
1300 zoom() *= inward ? 0.833f : 1.2f;
1301 else
1302 zoom() += inward ? -1.2f : 1.2f;
1303 } 1300 }
1304 1301
1305 // ============================================================================= 1302 // =============================================================================
1306 // 1303 //
1307 void GLRenderer::zoomToFit() 1304 void GLRenderer::zoomToFit()
1311 if (document() == null or m_width == -1 or m_height == -1) 1308 if (document() == null or m_width == -1 or m_height == -1)
1312 return; 1309 return;
1313 1310
1314 bool lastfilled = false; 1311 bool lastfilled = false;
1315 bool firstrun = true; 1312 bool firstrun = true;
1316 const uint32 white = 0xFFFFFFFF; 1313 enum { black = 0xFF000000 };
1317 bool inward = true; 1314 bool inward = true;
1318 const int w = m_width, h = m_height;
1319 int runaway = 50; 1315 int runaway = 50;
1320
1321 glClearColor (1.0, 1.0, 1.0, 1.0);
1322 glDisable (GL_DITHER);
1323 1316
1324 // Use the pick list while drawing the scene, this way we can tell whether borders 1317 // Use the pick list while drawing the scene, this way we can tell whether borders
1325 // are background or not. 1318 // are background or not.
1326 setPicking (true); 1319 setPicking (true);
1327 1320
1328 while (--runaway) 1321 while (--runaway)
1329 { 1322 {
1330 if (zoom() > 10000.0 or zoom() < 0.0) 1323 if (zoom() > 10000.0 or zoom() < 0.0)
1331 { 1324 {
1332 // Obviously, there's nothing to draw if we get here. 1325 // Nothing to draw if we get here.
1333 // Default to 30.0f and break out.
1334 zoom() = 30.0; 1326 zoom() = 30.0;
1335 break; 1327 break;
1336 } 1328 }
1337 1329
1338 zoomNotch (inward); 1330 zoomNotch (inward);
1339 1331 QVector<unsigned char> capture (4 * m_width * m_height);
1340 uchar* cap = new uchar[4 * w * h];
1341 drawGLScene(); 1332 drawGLScene();
1342 glReadPixels (0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, cap); 1333 glReadPixels (0, 0, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, capture.data());
1343 uint32* imgdata = reinterpret_cast<uint32*> (cap); 1334 QImage image (capture.constData(), m_width, m_height, QImage::Format_ARGB32);
1344 bool filled = false; 1335 bool filled = false;
1345 1336
1346 // Check the top and bottom rows 1337 // Check the top and bottom rows
1347 for (int i = 0; i < w; ++i) 1338 for (int i = 0; i < image.width(); ++i)
1348 { 1339 {
1349 if (imgdata[i] != white or imgdata[((h - 1) * w) + i] != white) 1340 if (image.pixel (i, 0) != black or image.pixel (i, m_height - 1) != black)
1350 { 1341 {
1351 filled = true; 1342 filled = true;
1352 break; 1343 break;
1353 } 1344 }
1354 } 1345 }
1355 1346
1356 // Left and right edges 1347 // Left and right edges
1357 if (filled == false) 1348 if (filled == false)
1358 { 1349 {
1359 for (int i = 0; i < h; ++i) 1350 for (int i = 0; i < image.height(); ++i)
1360 { 1351 {
1361 if (imgdata[i * w] != white or imgdata[(i * w) + w - 1] != white) 1352 if (image.pixel (0, i) != black or image.pixel (m_width - 1, i) != black)
1362 { 1353 {
1363 filled = true; 1354 filled = true;
1364 break; 1355 break;
1365 } 1356 }
1366 } 1357 }
1367 } 1358 }
1368
1369 delete[] cap;
1370 1359
1371 if (firstrun) 1360 if (firstrun)
1372 { 1361 {
1373 // If this is the first run, we don't know enough to determine 1362 // If this is the first run, we don't know enough to determine
1374 // whether the zoom was to fit, so we mark in our knowledge so 1363 // whether the zoom was to fit, so we mark in our knowledge so
1395 } 1384 }
1396 1385
1397 lastfilled = filled; 1386 lastfilled = filled;
1398 } 1387 }
1399 1388
1400 setBackground();
1401 setPicking (false); 1389 setPicking (false);
1402 } 1390 }
1403 1391
1404 // ============================================================================= 1392 // =============================================================================
1405 // 1393 //
1406 void GLRenderer::zoomAllToFit() 1394 void GLRenderer::zoomAllToFit()
1407 { 1395 {
1408 ECamera oldcam = camera(); 1396 zoomToFit();
1409
1410 for (ECamera cam = EFirstCamera; cam < ENumCameras; ++cam)
1411 {
1412 setCamera (cam);
1413 zoomToFit();
1414 }
1415
1416 setCamera (oldcam);
1417 } 1397 }
1418 1398
1419 // ============================================================================= 1399 // =============================================================================
1420 // 1400 //
1421 void GLRenderer::mouseDoubleClickEvent (QMouseEvent* ev) 1401 void GLRenderer::mouseDoubleClickEvent (QMouseEvent* ev)
1648 int GLRenderer::depthNegateFactor() const 1628 int GLRenderer::depthNegateFactor() const
1649 { 1629 {
1650 return g_FixedCameras[camera()].negatedDepth ? -1 : 1; 1630 return g_FixedCameras[camera()].negatedDepth ? -1 : 1;
1651 } 1631 }
1652 1632
1633 Qt::KeyboardModifiers GLRenderer::keyboardModifiers() const
1634 {
1635 return m_keymods;
1636 }
1637
1653 LDFixedCamera const& GetFixedCamera (ECamera cam) 1638 LDFixedCamera const& GetFixedCamera (ECamera cam)
1654 { 1639 {
1655 assert (cam != EFreeCamera); 1640 assert (cam != EFreeCamera);
1656 return g_FixedCameras[cam]; 1641 return g_FixedCameras[cam];
1657 } 1642 }

mercurial