changeset 1091:ac10a087e045 spectrogram-minor-refactor

Time-constrained rendering
author Chris Cannam
date Thu, 07 Jul 2016 11:24:28 +0100
parents c8c747783110
children 9b826dd23c84
files layer/SpectrogramLayer.cpp
diffstat 1 files changed, 47 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp	Tue Jul 05 17:48:26 2016 +0100
+++ b/layer/SpectrogramLayer.cpp	Thu Jul 07 11:24:28 2016 +0100
@@ -1536,11 +1536,53 @@
 {
     Colour3DPlotRenderer *renderer = getRenderer(v);
 
-    //!!! not time-constrained for now
-    Colour3DPlotRenderer::RenderResult result = renderer->render(v, paint, rect);
-
-    //!!! do
-    (void)result;
+    if (m_synchronous) {
+        (void)renderer->render(v, paint, rect);
+        return;
+    }
+    
+    Colour3DPlotRenderer::RenderResult result =
+        renderer->renderTimeConstrained(v, paint, rect);
+
+    //!!! + mag range
+
+    QRect rendered = result.rendered;
+    if (rendered == rect) return;
+
+    int rLeft = rendered.x();
+    int rRight = rendered.x() + rendered.width();
+
+    if (rLeft < rect.x()) {
+        rLeft = rect.x();
+    }
+    if (rRight > rect.x() + rect.width()) {
+        rRight = rect.x() + rect.width();
+    }
+    
+    QRect areaLeft(rect.x(), rect.y(),
+                   rLeft - rect.x(), rect.height());
+
+    QRect areaRight(rRight, rect.y(),
+                    rect.x() + rect.width() - rRight, rect.height());
+    
+    bool updateLeft = (areaLeft.width() > 0);
+    bool updateRight = (areaRight.width() > 0);
+            
+    if (updateLeft) {
+        if (updateRight) {
+            if (areaLeft.width() > areaRight.width()) {
+                v->updatePaintRect(areaLeft);
+                v->updatePaintRect(areaRight);
+            } else {
+                v->updatePaintRect(areaRight);
+                v->updatePaintRect(areaLeft);
+            }
+        } else {
+            v->updatePaintRect(areaLeft);
+        }
+    } else {
+        v->updatePaintRect(areaRight);
+    }        
 }
 
 Colour3DPlotRenderer *