From: Michal MalĂ˝ Date: Fri, 10 Oct 2014 00:59:37 +0000 (+0200) Subject: Do not draw graph below time axis (has a few glitches) X-Git-Tag: 0.3e~4 X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=8f940b4c05c7d4ddb61f7371bca9d77453707f80;p=anyanka.git Do not draw graph below time axis (has a few glitches) --- 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; }