- zoom-to-fit now works.. better than before

Wed, 22 Oct 2014 20:53:15 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Wed, 22 Oct 2014 20:53:15 +0300
changeset 901
6e89eaa1df70
parent 898
4dea33733251
child 902
3a69c2e0532c

- zoom-to-fit now works.. better than before
- zooming no longer jumps to absurd values when zooming in enough

src/glRenderer.cc file | annotate | diff | comparison | revisions
--- a/src/glRenderer.cc	Tue Oct 21 20:36:03 2014 +0300
+++ b/src/glRenderer.cc	Wed Oct 22 20:53:15 2014 +0300
@@ -1296,10 +1296,7 @@
 //
 void GLRenderer::zoomNotch (bool inward)
 {
-	if (zoom() > 15)
-		zoom() *= inward ? 0.833f : 1.2f;
-	else
-		zoom() += inward ? -1.2f : 1.2f;
+	zoom() *= inward ? 0.833f : 1.2f;
 }
 
 // =============================================================================
@@ -1313,14 +1310,10 @@
 
 	bool lastfilled = false;
 	bool firstrun = true;
-	const uint32 white = 0xFFFFFFFF;
+	enum { black = 0xFF000000 };
 	bool inward = true;
-	const int w = m_width, h = m_height;
 	int runaway = 50;
 
-	glClearColor (1.0, 1.0, 1.0, 1.0);
-	glDisable (GL_DITHER);
-
 	// Use the pick list while drawing the scene, this way we can tell whether borders
 	// are background or not.
 	setPicking (true);
@@ -1329,24 +1322,22 @@
 	{
 		if (zoom() > 10000.0 or zoom() < 0.0)
 		{
-			// Obviously, there's nothing to draw if we get here.
-			// Default to 30.0f and break out.
+			// Nothing to draw if we get here.
 			zoom() = 30.0;
 			break;
 		}
 
 		zoomNotch (inward);
-
-		uchar* cap = new uchar[4 * w * h];
+		QVector<unsigned char> capture (4 * m_width * m_height);
 		drawGLScene();
-		glReadPixels (0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, cap);
-		uint32* imgdata = reinterpret_cast<uint32*> (cap);
+		glReadPixels (0, 0, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, capture.data());
+		QImage image (capture.constData(), m_width, m_height, QImage::Format_ARGB32);
 		bool filled = false;
 
 		// Check the top and bottom rows
-		for (int i = 0; i < w; ++i)
+		for (int i = 0; i < image.width(); ++i)
 		{
-			if (imgdata[i] != white or imgdata[((h - 1) * w) + i] != white)
+			if (image.pixel (i, 0) != black or image.pixel (i, m_height - 1) != black)
 			{
 				filled = true;
 				break;
@@ -1356,9 +1347,9 @@
 		// Left and right edges
 		if (filled == false)
 		{
-			for (int i = 0; i < h; ++i)
+			for (int i = 0; i < image.height(); ++i)
 			{
-				if (imgdata[i * w] != white or imgdata[(i * w) + w - 1] != white)
+				if (image.pixel (0, i) != black or image.pixel (m_width - 1, i) != black)
 				{
 					filled = true;
 					break;
@@ -1366,8 +1357,6 @@
 			}
 		}
 
-		delete[] cap;
-
 		if (firstrun)
 		{
 			// If this is the first run, we don't know enough to determine
@@ -1397,7 +1386,6 @@
 		lastfilled = filled;
 	}
 
-	setBackground();
 	setPicking (false);
 }
 
@@ -1405,15 +1393,7 @@
 //
 void GLRenderer::zoomAllToFit()
 {
-	ECamera oldcam = camera();
-
-	for (ECamera cam = EFirstCamera; cam < ENumCameras; ++cam)
-	{
-		setCamera (cam);
-		zoomToFit();
-	}
-
-	setCamera (oldcam);
+	zoomToFit();
 }
 
 // =============================================================================

mercurial