Proper handling of mouse over timeline view.

This fixes:
- Dead zones between header, frame sets and the rest of timeline
  display.
- One-frame frame set position lag when panning the view with mouse over
  zones region of timeline.
This commit is contained in:
Bartosz Taudul 2020-07-29 17:52:51 +02:00
parent f37a324a9e
commit ff5daf9df7
2 changed files with 15 additions and 22 deletions

View File

@ -1876,7 +1876,7 @@ const char* View::GetFrameText( const FrameData& fd, int i, uint64_t ftime, uint
return buf; return buf;
} }
bool View::DrawZoneFramesHeader() void View::DrawZoneFramesHeader()
{ {
const auto wpos = ImGui::GetCursorScreenPos(); const auto wpos = ImGui::GetCursorScreenPos();
const auto w = ImGui::GetWindowContentRegionWidth() - ImGui::GetStyle().ScrollbarSize; const auto w = ImGui::GetWindowContentRegionWidth() - ImGui::GetStyle().ScrollbarSize;
@ -1887,13 +1887,10 @@ bool View::DrawZoneFramesHeader()
const auto ty05 = round( ty * 0.5f ); const auto ty05 = round( ty * 0.5f );
ImGui::InvisibleButton( "##zoneFrames", ImVec2( w, ty * 1.5f ) ); ImGui::InvisibleButton( "##zoneFrames", ImVec2( w, ty * 1.5f ) );
bool hover = ImGui::IsItemHovered();
auto timespan = m_vd.zvEnd - m_vd.zvStart; auto timespan = m_vd.zvEnd - m_vd.zvStart;
auto pxns = w / double( timespan ); auto pxns = w / double( timespan );
if( hover ) HandleZoneViewMouse( timespan, wpos, w, pxns );
{ {
const auto nspx = 1.0 / pxns; const auto nspx = 1.0 / pxns;
const auto scale = std::max( 0.0, round( log10( nspx ) + 2 ) ); const auto scale = std::max( 0.0, round( log10( nspx ) + 2 ) );
@ -1944,8 +1941,6 @@ bool View::DrawZoneFramesHeader()
tt += step; tt += step;
} }
} }
return hover;
} }
static uint32_t DarkenColor( uint32_t color ) static uint32_t DarkenColor( uint32_t color )
@ -2016,7 +2011,7 @@ static uint32_t GetColorMuted( uint32_t color, bool active )
} }
} }
bool View::DrawZoneFrames( const FrameData& frames ) void View::DrawZoneFrames( const FrameData& frames )
{ {
const auto wpos = ImGui::GetCursorScreenPos(); const auto wpos = ImGui::GetCursorScreenPos();
const auto w = ImGui::GetWindowContentRegionWidth() - ImGui::GetStyle().ScrollbarSize; const auto w = ImGui::GetWindowContentRegionWidth() - ImGui::GetStyle().ScrollbarSize;
@ -2032,12 +2027,10 @@ bool View::DrawZoneFrames( const FrameData& frames )
auto timespan = m_vd.zvEnd - m_vd.zvStart; auto timespan = m_vd.zvEnd - m_vd.zvStart;
auto pxns = w / double( timespan ); auto pxns = w / double( timespan );
if( hover ) HandleZoneViewMouse( timespan, wpos, w, pxns );
const auto nspx = 1.0 / pxns; const auto nspx = 1.0 / pxns;
const std::pair <int, int> zrange = m_worker.GetFrameRange( frames, m_vd.zvStart, m_vd.zvEnd ); const std::pair <int, int> zrange = m_worker.GetFrameRange( frames, m_vd.zvStart, m_vd.zvEnd );
if( zrange.first < 0 ) return hover; if( zrange.first < 0 ) return;
int64_t prev = -1; int64_t prev = -1;
int64_t prevEnd = -1; int64_t prevEnd = -1;
@ -2248,8 +2241,6 @@ bool View::DrawZoneFrames( const FrameData& frames )
m_frames = &frames; m_frames = &frames;
} }
} }
return hover;
} }
static float AdjustThreadPosition( View::VisData& vis, float wy, int& offset ) static float AdjustThreadPosition( View::VisData& vis, float wy, int& offset )
@ -2333,13 +2324,21 @@ void View::DrawZones()
} }
} }
bool drawMouseLine = DrawZoneFramesHeader(); const auto winpos = ImGui::GetWindowPos();
const auto winsize = ImGui::GetWindowSize();
const bool drawMouseLine = ImGui::IsMouseHoveringRect( winpos, winpos + winsize, false );
if( drawMouseLine )
{
HandleZoneViewMouse( timespan, ImGui::GetCursorScreenPos(), w, pxns );
}
DrawZoneFramesHeader();
auto& frames = m_worker.GetFrames(); auto& frames = m_worker.GetFrames();
for( auto fd : frames ) for( auto fd : frames )
{ {
if( Vis( fd ).visible ) if( Vis( fd ).visible )
{ {
drawMouseLine |= DrawZoneFrames( *fd ); DrawZoneFrames( *fd );
} }
} }
@ -2355,12 +2354,6 @@ void View::DrawZones()
bool hover = ImGui::IsItemHovered(); bool hover = ImGui::IsItemHovered();
draw = ImGui::GetWindowDrawList(); draw = ImGui::GetWindowDrawList();
if( hover )
{
drawMouseLine = true;
HandleZoneViewMouse( timespan, wpos, w, pxns );
}
const auto nspx = 1.0 / pxns; const auto nspx = 1.0 / pxns;
const auto ty = ImGui::GetFontSize(); const auto ty = ImGui::GetFontSize();

View File

@ -133,8 +133,8 @@ private:
void DrawNotificationArea(); void DrawNotificationArea();
bool DrawConnection(); bool DrawConnection();
void DrawFrames(); void DrawFrames();
bool DrawZoneFramesHeader(); void DrawZoneFramesHeader();
bool DrawZoneFrames( const FrameData& frames ); void DrawZoneFrames( const FrameData& frames );
void DrawZones(); void DrawZones();
void DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int endOffset ); void DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int endOffset );
void DrawSamples( const Vector<SampleData>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset ); void DrawSamples( const Vector<SampleData>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset );