Zoom in and out at mouse position.

This commit is contained in:
Bartosz Taudul 2017-09-20 00:08:15 +02:00
parent 9b93fea0f5
commit 1cb19a56eb

View File

@ -451,9 +451,10 @@ void View::DrawFrames()
draw->AddRectFilled( wpos, wpos + ImVec2( w, Height ), 0x33FFFFFF ); draw->AddRectFilled( wpos, wpos + ImVec2( w, Height ), 0x33FFFFFF );
bool hover = ImGui::IsMouseHoveringRect( wpos, wpos + ImVec2( w, 60 ) ); bool hover = ImGui::IsMouseHoveringRect( wpos, wpos + ImVec2( w, 60 ) );
const auto wheel = io.MouseWheel;
const auto prevScale = m_frameScale;
if( hover ) if( hover )
{ {
const auto wheel = io.MouseWheel;
if( wheel > 0 ) if( wheel > 0 )
{ {
if( m_frameScale > -1 ) m_frameScale--; if( m_frameScale > -1 ) m_frameScale--;
@ -470,7 +471,6 @@ void View::DrawFrames()
const int onScreen = ( w - 2 ) / fwidth; const int onScreen = ( w - 2 ) / fwidth;
if( !m_pause ) m_frameStart = ( total < onScreen * group ) ? 0 : total - onScreen * group; if( !m_pause ) m_frameStart = ( total < onScreen * group ) ? 0 : total - onScreen * group;
int sel = -1;
if( hover ) if( hover )
{ {
if( ImGui::IsMouseDragging( 1, 0 ) ) if( ImGui::IsMouseDragging( 1, 0 ) )
@ -490,12 +490,11 @@ void View::DrawFrames()
{ {
const auto mo = mx - ( wpos.x + 1 ); const auto mo = mx - ( wpos.x + 1 );
const auto off = mo * group / fwidth; const auto off = mo * group / fwidth;
if( m_frameStart + off < total )
const int sel = m_frameStart + off;
if( sel < total )
{ {
sel = m_frameStart + off;
ImGui::BeginTooltip(); ImGui::BeginTooltip();
if( group > 1 ) if( group > 1 )
{ {
uint64_t f = GetFrameTime( sel ); uint64_t f = GetFrameTime( sel );
@ -515,6 +514,15 @@ void View::DrawFrames()
} }
ImGui::EndTooltip(); ImGui::EndTooltip();
} }
if( m_pause && wheel != 0 )
{
const int pfwidth = GetFrameWidth( prevScale );
const int pgroup = GetFrameGroup( prevScale );
const auto oldoff = mo * pgroup / pfwidth;
m_frameStart = std::min( total, std::max( 0, m_frameStart - int( off - oldoff ) ) );
}
} }
} }