From 5274baaf008948fa1726b2aaee2059d3fff06692 Mon Sep 17 00:00:00 2001 From: Giovanni Mascellani Date: Wed, 13 Nov 2024 16:38:19 +0100 Subject: [PATCH] Support panning with the mouse wheel. The movement scheme is based on common browsers, like Firefox and Chromium, assumed to be a good approximation of what users find intuitive. --- src/gpuvis.cpp | 4 +++- src/gpuvis_graph.cpp | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/gpuvis.cpp b/src/gpuvis.cpp index 68ce7048..e9838d25 100644 --- a/src/gpuvis.cpp +++ b/src/gpuvis.cpp @@ -1383,7 +1383,9 @@ void MainApp::render() { { "Ctrl+click drag", "Graph: Select area" }, { "Shift+click drag", "Graph: Zoom selected area" }, - { "Mousewheel", "Graph: Zoom in / out" }, + { "Mousewheel", "Graph: Pan up / down" }, + { "Shift+mousewheel", "Graph: Pan left / right" }, + { "Ctrl+mousewheel", "Graph: Zoom in / out" }, { "Alt down", "Graph: Hide labels" }, }; int graph_entry_count = 0; diff --git a/src/gpuvis_graph.cpp b/src/gpuvis_graph.cpp index 3b64bd64..4477f3e0 100644 --- a/src/gpuvis_graph.cpp +++ b/src/gpuvis_graph.cpp @@ -4714,9 +4714,26 @@ void TraceWin::graph_handle_mouse_over( graph_info_t &gi ) } else if ( io.MouseWheel ) { - bool zoomin = ( io.MouseWheel > 0.0f ); + // wheel: move vertically + // shift + wheel: move horizontally + // alt + wheel: zoom + uint32_t mask = ( io.KeyCtrl << 0 ) | ( io.KeyAlt << 1 ) | ( io.KeyShift << 2 ); + + if ( mask == ( 1 << 0 ) ) + { + bool zoomin = ( io.MouseWheel > 0.0f ); - graph_zoom( mouse_ts, gi.ts0, zoomin ); + graph_zoom( mouse_ts, gi.ts0, zoomin ); + } + else if ( mask == ( 1 << 2 )) + { + m_graph.start_ts += (int64_t)(io.MouseWheel * m_graph.length_ts / 10); + m_graph.recalc_timebufs = true; + } + else if ( mask == 0 ) + { + m_graph.start_y += io.MouseWheel * ImGui::GetTextLineHeightWithSpacing() * 4; + } } }