diff view/View.cpp @ 1330:c1f719094c25 zoom

Ensure getFrameForX returns value on zoom blocksize boundary; take advantage of that (this is essentially reverting to the same behaviour as in the default branch, which we should probably have done all along)
author Chris Cannam
date Fri, 21 Sep 2018 11:50:05 +0100
parents 344f29e46258
children 9758dfc12555
line wrap: on
line diff
--- a/view/View.cpp	Thu Sep 20 15:42:12 2018 +0100
+++ b/view/View.cpp	Fri Sep 21 11:50:05 2018 +0100
@@ -395,16 +395,33 @@
 sv_frame_t
 View::getFrameForX(int x) const
 {
+    // Note, this must always return a value that is on a zoom-level
+    // boundary - regardless of whether the nominal centre frame is on
+    // such a boundary or not
+
     int diff = x - (width()/2);
-    sv_frame_t fdiff = diff;
-
+    sv_frame_t level = m_zoomLevel.level;
+    sv_frame_t fdiff, result;
+    
     if (m_zoomLevel.zone == ZoomLevel::FramesPerPixel) {
-        fdiff *= m_zoomLevel.level;
+        fdiff = diff * level;
+        result = ((fdiff + m_centreFrame) / level) * level;
     } else {
-        fdiff /= m_zoomLevel.level;
+        fdiff = diff / level;
+        result = fdiff + m_centreFrame;
     }
-
-    return fdiff + m_centreFrame;
+/*    
+    if (x == 0) {
+        SVCERR << "getFrameForX(" << x << "): diff = " << diff << ", fdiff = "
+               << fdiff << ", m_centreFrame = " << m_centreFrame
+               << ", level = " << m_zoomLevel.level
+               << ", diff % level = " << (diff % m_zoomLevel.level)
+               << ", nominal " << fdiff + m_centreFrame
+               << ", will return " << result
+               << endl;
+    }
+*/        
+    return result;
 }
 
 double