diff layer/SpectrogramLayer.cpp @ 1040:25b035362c44 spectrogram-minor-refactor

Truncate edges when about to paint beyond limits of cache
author Chris Cannam
date Wed, 03 Feb 2016 16:51:37 +0000
parents bfce7940c017
children fccee028a522
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp	Tue Feb 02 16:00:31 2016 +0000
+++ b/layer/SpectrogramLayer.cpp	Wed Feb 03 16:51:37 2016 +0000
@@ -2063,14 +2063,31 @@
                  << scaledLeftCrop << " from " << scaledLeftCrop - scaledLeft << endl;
 #endif
 
-            //!!! Update this for failedToRepaint logic
+            int targetLeft = scaledLeftCrop;
+            if (targetLeft < 0) {
+                targetLeft = 0;
+            }
+
+            int targetWidth = scaledRightCrop - targetLeft;
+            if (targetLeft + targetWidth > cache.getSize().width()) {
+                targetWidth = cache.getSize().width() - targetLeft;
+            }
             
-            cache.drawImage
-                (scaledLeftCrop,
-                 scaledRightCrop - scaledLeftCrop,
-                 scaled,
-                 scaledLeftCrop - scaledLeft,
-                 scaledRightCrop - scaledLeftCrop);
+            int sourceLeft = targetLeft - scaledLeft;
+            if (sourceLeft < 0) {
+                sourceLeft = 0;
+            }
+            
+            int sourceWidth = targetWidth;
+
+            if (targetWidth > 0) {
+                cache.drawImage
+                    (targetLeft,
+                     targetWidth,
+                     scaled,
+                     sourceLeft,
+                     sourceWidth);
+            }
 
         } else {