changeset 950:43888f891733 osx-retina

Some scaling & zoom bits
author Chris Cannam
date Mon, 20 Apr 2015 14:01:39 +0100
parents e3c7da3d896e
children 53e039d99b5d
files view/View.cpp view/ViewProxy.h
diffstat 2 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/view/View.cpp	Mon Apr 20 11:00:48 2015 +0100
+++ b/view/View.cpp	Mon Apr 20 14:01:39 2015 +0100
@@ -452,6 +452,8 @@
 void
 View::setZoomLevel(int z)
 {
+    int dpratio = devicePixelRatio();
+    if (z < dpratio) return;
     if (z < 1) z = 1;
     if (m_zoomLevel != int(z)) {
 	m_zoomLevel = z;
--- a/view/ViewProxy.h	Mon Apr 20 11:00:48 2015 +0100
+++ b/view/ViewProxy.h	Mon Apr 20 14:01:39 2015 +0100
@@ -33,11 +33,14 @@
 	return m_view->getEndFrame();
     }
     virtual int getXForFrame(sv_frame_t frame) const {
+        //!!! not actually correct, if frame lies between view's pixels
 	return m_scaleFactor * m_view->getXForFrame(frame);
     }
     virtual sv_frame_t getFrameForX(int x) const {
-	//!!! todo: interpolate
-	return m_view->getFrameForX(x / m_scaleFactor);
+        sv_frame_t f0 = m_view->getFrameForX(x / m_scaleFactor);
+        if (m_scaleFactor == 1) return f0;
+        sv_frame_t f1 = m_view->getFrameForX((x / m_scaleFactor) + 1);
+        return f0 + ((f1 - f0) * (x % m_scaleFactor)) / m_scaleFactor;
     }
     virtual sv_frame_t getModelsStartFrame() const {
 	return m_view->getModelsStartFrame();
@@ -53,8 +56,12 @@
     }
     virtual double getFrequencyForY(int y, double minFreq, double maxFreq,
 				    bool logarithmic) const {
-	//!!! todo: interpolate
-	return m_view->getFrequencyForY(y / m_scaleFactor, minFreq, maxFreq, logarithmic);
+        double f0 = m_view->getFrequencyForY
+            (y / m_scaleFactor, minFreq, maxFreq, logarithmic);
+        if (m_scaleFactor == 1) return f0;
+        double f1 = m_view->getFrequencyForY
+            ((y / m_scaleFactor) + 1, minFreq, maxFreq, logarithmic);
+        return f0 + ((f1 - f0) * (y % m_scaleFactor)) / m_scaleFactor;
     }
     virtual int getTextLabelHeight(const Layer *layer, QPainter &paint) const {
 	return m_scaleFactor * m_view->getTextLabelHeight(layer, paint);