From 8f940b4c05c7d4ddb61f7371bca9d77453707f80 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Fri, 10 Oct 2014 02:59:37 +0200 Subject: [PATCH] Do not draw graph below time axis (has a few glitches) --- signaldrawer.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/signaldrawer.cpp b/signaldrawer.cpp index afb4dd5..9b2124b 100644 --- a/signaldrawer.cpp +++ b/signaldrawer.cpp @@ -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(toYPix - fromYPix) / static_cast(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(toYPix - fromYPix) / static_cast(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; } -- 2.43.5