Skip to content

Commit

Permalink
Added a dimmed highlight that follows the timestamp of the mouse curs…
Browse files Browse the repository at this point in the history
…or when mousing over a protocol analyzer view
  • Loading branch information
azonenberg committed Sep 5, 2024
1 parent f9f5775 commit 1a81538
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/ngscopeclient/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ void MainWindow::RenderUI()
}

//Dialog boxes
m_session.SetHoveredPacketTimestamp({});
set< shared_ptr<Dialog> > dlgsToClose;
for(auto& dlg : m_dialogs)
{
Expand Down
8 changes: 8 additions & 0 deletions src/ngscopeclient/Marker.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ class TimePoint : public std::pair<time_t, int64_t>
{ second = fs; }

std::string PrettyPrint() const;

int64_t operator-(const TimePoint& rhs)
{
int64_t dsec = first - rhs.first;
int64_t dfs = second - rhs.second;

return dsec*FS_PER_SECOND + dfs;
}
};

/**
Expand Down
4 changes: 4 additions & 0 deletions src/ngscopeclient/PreferenceSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ void PreferenceManager::InitializeDefaults()
Preference::Color("marker_color", ColorFromString("#ff00a0"))
.Label("Marker color")
.Description("Color for markers"));
cursors.AddPreference(
Preference::Color("hover_color", ColorFromString("#ffffff80"))
.Label("Hover color")
.Description("Color for the hovered-packet indicator"));

auto& decodes = appearance.AddCategory("Decodes");
decodes.AddPreference(
Expand Down
3 changes: 3 additions & 0 deletions src/ngscopeclient/ProtocolAnalyzerDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ bool ProtocolAnalyzerDialog::DoRender()
m_parent.NavigateToTimestamp(offset, len, StreamDescriptor(m_filter, 0));
}

if(ImGui::IsItemHovered())
m_session.SetHoveredPacketTimestamp(packtime);

if(pack)
{
//Headers
Expand Down
1 change: 1 addition & 0 deletions src/ngscopeclient/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ void Session::Clear()
//Reset state
m_triggerOneShot = false;
m_multiScope = false;
m_hoverTime = {};
}

vector<TimePoint> Session::GetMarkerTimes()
Expand Down
9 changes: 9 additions & 0 deletions src/ngscopeclient/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,16 @@ class Session
void RemovePackets(TimePoint t);

std::set<FlowGraphNode*> GetAllGraphNodes();

///@brief Returns the timestamp of the protocol analyzer event that the mouse is over, if any
std::optional<TimePoint> GetHoveredPacketTimestamp()
{ return m_hoverTime; }

void SetHoveredPacketTimestamp(std::optional<TimePoint> t)
{ m_hoverTime = t; }

protected:
std::optional<TimePoint> m_hoverTime;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// End user preferences (persistent across sessions)
Expand Down
21 changes: 19 additions & 2 deletions src/ngscopeclient/WaveformGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ float WaveformGroup::GetInBandPower(WaveformBase* wfm, Unit yunit, int64_t t1, i
}

/**
@brief Render our markers
@brief Render our markers (and the hovered-packet indicator if any)
*/
void WaveformGroup::RenderMarkers(ImVec2 pos, ImVec2 size)
{
Expand All @@ -496,7 +496,11 @@ void WaveformGroup::RenderMarkers(ImVec2 pos, ImVec2 size)
if(m_areas.empty())
return;

auto& markers = m_parent->GetSession().GetMarkers(m_areas[0]->GetWaveformTimestamp());
auto& session = m_parent->GetSession();
auto wavetime = m_areas[0]->GetWaveformTimestamp();
auto& markers = session.GetMarkers(wavetime);

auto packetHover = session.GetHoveredPacketTimestamp();

//Create a child window for all of our drawing
//(this is needed so we're above the WaveformArea's in z order, but behind popup windows)
Expand All @@ -507,8 +511,10 @@ void WaveformGroup::RenderMarkers(ImVec2 pos, ImVec2 size)

auto& prefs = m_parent->GetSession().GetPreferences();
auto color = prefs.GetColor("Appearance.Cursors.marker_color");
auto hcolor = prefs.GetColor("Appearance.Cursors.hover_color");
auto font = m_parent->GetFontPref("Appearance.Cursors.label_font");
auto fontSize = font->FontSize * ImGui::GetIO().FontGlobalScale;

//Draw the markers
for(auto& m : markers)
{
Expand All @@ -535,6 +541,17 @@ void WaveformGroup::RenderMarkers(ImVec2 pos, ImVec2 size)
color,
str.c_str());
}

//Draw the hovered packet, if any
if(packetHover)
{
//Calculate the delta between the times
auto offset = packetHover.value() - wavetime;

//Lines
auto xpos = round(XAxisUnitsToXPosition(offset));
list->AddLine(ImVec2(xpos, pos.y), ImVec2(xpos, pos.y + size.y), hcolor);
}
}
ImGui::EndChild();

Expand Down

0 comments on commit 1a81538

Please sign in to comment.