From 1a81538eb447116993b1519a0d5a40d514c29351 Mon Sep 17 00:00:00 2001 From: "Andrew D. Zonenberg" Date: Wed, 4 Sep 2024 22:45:29 -0700 Subject: [PATCH] Added a dimmed highlight that follows the timestamp of the mouse cursor when mousing over a protocol analyzer view --- src/ngscopeclient/MainWindow.cpp | 1 + src/ngscopeclient/Marker.h | 8 ++++++++ src/ngscopeclient/PreferenceSchema.cpp | 4 ++++ src/ngscopeclient/ProtocolAnalyzerDialog.cpp | 3 +++ src/ngscopeclient/Session.cpp | 1 + src/ngscopeclient/Session.h | 9 +++++++++ src/ngscopeclient/WaveformGroup.cpp | 21 ++++++++++++++++++-- 7 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/ngscopeclient/MainWindow.cpp b/src/ngscopeclient/MainWindow.cpp index 09b08f7ec..331cdedd5 100644 --- a/src/ngscopeclient/MainWindow.cpp +++ b/src/ngscopeclient/MainWindow.cpp @@ -737,6 +737,7 @@ void MainWindow::RenderUI() } //Dialog boxes + m_session.SetHoveredPacketTimestamp({}); set< shared_ptr > dlgsToClose; for(auto& dlg : m_dialogs) { diff --git a/src/ngscopeclient/Marker.h b/src/ngscopeclient/Marker.h index a66035533..5bb102c97 100644 --- a/src/ngscopeclient/Marker.h +++ b/src/ngscopeclient/Marker.h @@ -58,6 +58,14 @@ class TimePoint : public std::pair { 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; + } }; /** diff --git a/src/ngscopeclient/PreferenceSchema.cpp b/src/ngscopeclient/PreferenceSchema.cpp index 9d0f2c161..693467f4f 100644 --- a/src/ngscopeclient/PreferenceSchema.cpp +++ b/src/ngscopeclient/PreferenceSchema.cpp @@ -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( diff --git a/src/ngscopeclient/ProtocolAnalyzerDialog.cpp b/src/ngscopeclient/ProtocolAnalyzerDialog.cpp index f4f0fa86e..e24029eee 100644 --- a/src/ngscopeclient/ProtocolAnalyzerDialog.cpp +++ b/src/ngscopeclient/ProtocolAnalyzerDialog.cpp @@ -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 diff --git a/src/ngscopeclient/Session.cpp b/src/ngscopeclient/Session.cpp index c4f22ab30..0970f2826 100644 --- a/src/ngscopeclient/Session.cpp +++ b/src/ngscopeclient/Session.cpp @@ -235,6 +235,7 @@ void Session::Clear() //Reset state m_triggerOneShot = false; m_multiScope = false; + m_hoverTime = {}; } vector Session::GetMarkerTimes() diff --git a/src/ngscopeclient/Session.h b/src/ngscopeclient/Session.h index 428d46768..cc778c19f 100644 --- a/src/ngscopeclient/Session.h +++ b/src/ngscopeclient/Session.h @@ -502,7 +502,16 @@ class Session void RemovePackets(TimePoint t); std::set GetAllGraphNodes(); + + ///@brief Returns the timestamp of the protocol analyzer event that the mouse is over, if any + std::optional GetHoveredPacketTimestamp() + { return m_hoverTime; } + + void SetHoveredPacketTimestamp(std::optional t) + { m_hoverTime = t; } + protected: + std::optional m_hoverTime; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // End user preferences (persistent across sessions) diff --git a/src/ngscopeclient/WaveformGroup.cpp b/src/ngscopeclient/WaveformGroup.cpp index 88f77a8ea..b755077db 100644 --- a/src/ngscopeclient/WaveformGroup.cpp +++ b/src/ngscopeclient/WaveformGroup.cpp @@ -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) { @@ -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) @@ -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) { @@ -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();