]> Devoid-pointer.net GitWeb - anyanka.git/commitdiff
Do not draw graph below time axis (has a few glitches)
authorMichal Malý <madcatxster@devoid-pointer.net>
Fri, 10 Oct 2014 00:59:37 +0000 (02:59 +0200)
committerMichal Malý <madcatxster@devoid-pointer.net>
Fri, 10 Oct 2014 00:59:37 +0000 (02:59 +0200)
signaldrawer.cpp

index afb4dd5b07326ad57d1becd1ff91a8e5673af35c..9b2124bddd75fcb3d9fe2fca44b62a758b7e2ca3 100644 (file)
@@ -504,7 +504,32 @@ bool SignalDrawer::renderGraph(QPixmap* const target)
   for (size_t i = 1; i < m_gdData->ddataLen; i++) {
     int toXPix = relToXPix(m_gdData->ddata[i].first);
     int toYPix = relToYPix(m_gdData->ddata[i].second);
-    p.drawLine(fromXPix, fromYPix, toXPix, toYPix);
+
+    if (fromYPix > m_gHeight && toYPix > m_gHeight) {
+      /* Draw nothing */
+    } else if (toXPix == fromXPix)
+      p.drawLine(fromXPix, (fromYPix >= m_gHeight) ? m_gHeight : fromYPix, toXPix, (toYPix >= m_gHeight) ? m_gHeight : toYPix);
+    else if (toYPix >= m_gHeight) {
+      double k = static_cast<double>(toYPix - fromYPix) / static_cast<double>(toXPix - fromXPix);
+      double cToYPix = m_gHeight;
+      double cToXPix = (cToYPix - fromYPix + k * fromXPix) / k;
+      if (isnan(cToXPix))
+        cToXPix = fromXPix;
+      else
+        cToXPix = floor(cToXPix + 0.5);
+      p.drawLine(fromXPix, fromYPix, cToXPix, m_gHeight);
+    } else if (fromYPix >= m_gHeight) {
+      double k = static_cast<double>(toYPix - fromYPix) / static_cast<double>(toXPix - fromXPix);
+      double cFromYPix = m_gHeight;
+      double cFromXPix = (cFromYPix - fromYPix + k * fromXPix) / k;
+      if (isnan(cFromXPix))
+        cFromXPix = fromXPix;
+      else
+        cFromXPix = floor(cFromXPix + 0.5);
+      p.drawLine(cFromXPix, m_gHeight, toXPix, toYPix);
+    } else
+      p.drawLine(fromXPix, fromYPix, toXPix, toYPix);
+
     fromXPix = toXPix;
     fromYPix = toYPix;
   }