Prevent range-zoom when range has zero length.

This commit is contained in:
Bartosz Taudul 2018-08-05 01:19:08 +02:00
parent b92087bd95
commit 1b44b31eff

View File

@ -828,23 +828,30 @@ void View::HandleZoneViewMouse( int64_t timespan, const ImVec2& wpos, float w, d
} }
else if( m_highlightZoom.active ) else if( m_highlightZoom.active )
{ {
const auto s = std::min( m_highlightZoom.start, m_highlightZoom.end ); if( m_highlightZoom.start != m_highlightZoom.end )
const auto e = std::max( m_highlightZoom.start, m_highlightZoom.end );
// ZoomToRange disables m_highlightZoom.active
if( io.KeyCtrl )
{ {
const auto tsOld = m_zvEnd - m_zvStart; const auto s = std::min( m_highlightZoom.start, m_highlightZoom.end );
const auto tsNew = e - s; const auto e = std::max( m_highlightZoom.start, m_highlightZoom.end );
const auto mul = double( tsOld ) / tsNew;
const auto left = s - m_zvStart;
const auto right = m_zvEnd - e;
ZoomToRange( m_zvStart - left * mul, m_zvEnd + right * mul ); // ZoomToRange disables m_highlightZoom.active
if( io.KeyCtrl )
{
const auto tsOld = m_zvEnd - m_zvStart;
const auto tsNew = e - s;
const auto mul = double( tsOld ) / tsNew;
const auto left = s - m_zvStart;
const auto right = m_zvEnd - e;
ZoomToRange( m_zvStart - left * mul, m_zvEnd + right * mul );
}
else
{
ZoomToRange( s, e );
}
} }
else else
{ {
ZoomToRange( s, e ); m_highlightZoom.active = false;
} }
} }