changeset 1373:cca66ce390e0

Scaling tweaks
author Chris Cannam
date Mon, 05 Nov 2018 13:30:21 +0000
parents 2c01be836570
children 631897ba9fca 5a051ca3170e
files layer/PaintAssistant.cpp layer/PaintAssistant.h layer/WaveformLayer.cpp
diffstat 3 files changed, 31 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/layer/PaintAssistant.cpp	Fri Nov 02 15:23:53 2018 +0000
+++ b/layer/PaintAssistant.cpp	Mon Nov 05 13:30:21 2018 +0000
@@ -242,7 +242,7 @@
 }
 
 double
-PaintAssistant::scalePenWidth(double width)
+PaintAssistant::scaleSize(double size)
 {
     static double ratio = 0.0;
     if (ratio == 0.0) {
@@ -255,21 +255,28 @@
         double em = QFontMetrics(QFont()).height();
         ratio = em / baseEm;
 
-        SVDEBUG << "PaintAssistant::scalePenWidth: ratio is " << ratio
+        SVDEBUG << "PaintAssistant::scaleSize: ratio is " << ratio
                 << " (em = " << em << ")" << endl;
+
+        if (ratio < 1.0) {
+            SVDEBUG << "PaintAssistant::scaleSize: rounding ratio up to 1.0"
+                    << endl;
+            ratio = 1.0;
+        }
     }
 
-    if (ratio <= 1.0) {
-        // we only ever scale up in this method
-        return width;
+    return size * ratio;
+}
+
+double
+PaintAssistant::scalePenWidth(double width)
+{
+    if (width <= 0) {
+        // zero-width pen, produce a scaled one-pixel pen
+        width = 1;
     }
 
-    if (width <= 0) {
-        // zero-width pen, produce a scaled one-pixel pen
-        return ratio;
-    }
-
-    return width * ratio;
+    return scaleSize(width);
 }
 
 QPen
--- a/layer/PaintAssistant.h	Fri Nov 02 15:23:53 2018 +0000
+++ b/layer/PaintAssistant.h	Mon Nov 05 13:30:21 2018 +0000
@@ -49,9 +49,18 @@
                                 QString text, TextStyle style);
 
     /**
+     * Scale up a size in pixels for a hi-dpi display without pixel
+     * doubling. This is like ViewManager::scalePixelSize, but taking
+     * and returning floating-point values rather than integer
+     * pixels. It is also a little more conservative - it never
+     * shrinks the size, it can only increase or leave it unchanged.
+     */
+    static double scaleSize(double size);
+
+    /**
      * Scale up pen width for a hi-dpi display without pixel doubling.
-     * Very similar to ViewManager::scalePixelSize, but a bit more
-     * conservative.
+     * This is like scaleSize except that it also scales the
+     * zero-width case.
      */
     static double scalePenWidth(double width);
 
--- a/layer/WaveformLayer.cpp	Fri Nov 02 15:23:53 2018 +0000
+++ b/layer/WaveformLayer.cpp	Mon Nov 05 13:30:21 2018 +0000
@@ -1052,10 +1052,10 @@
     }
     
     if (!individualSamplePoints.empty()) {
-        double sz = ViewManager::scalePixelSize(2.0);
+        double sz = PaintAssistant::scaleSize(2.0);
         if (v->getZoomLevel().zone == ZoomLevel::PixelsPerFrame) {
             if (v->getZoomLevel().level < 10) {
-                sz = 1.5;
+                sz = PaintAssistant::scaleSize(1.2);
             }
         }
         paint->save();