From f2d22075ebd3f5e17628d1cf1ea102c7ce0bbb09 Mon Sep 17 00:00:00 2001 From: pencilpusher <83676301+jakethesnake420@users.noreply.github.com> Date: Sat, 19 Aug 2023 02:07:52 -0500 Subject: [PATCH] ui/map: interactive counter fix (#29470) * use interactive_counter instead of separate zoom and pan counters * use interaction_counter instead of separate zoom and pan counters * same styling --------- Co-authored-by: Shane Smiskol --- selfdrive/ui/qt/maps/map.cc | 20 +++++++------------- selfdrive/ui/qt/maps/map.h | 3 +-- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/selfdrive/ui/qt/maps/map.cc b/selfdrive/ui/qt/maps/map.cc index b596b11260..d756a777c4 100644 --- a/selfdrive/ui/qt/maps/map.cc +++ b/selfdrive/ui/qt/maps/map.cc @@ -10,7 +10,7 @@ #include "selfdrive/ui/ui.h" -const int PAN_TIMEOUT = 100; +const int INTERACTION_TIMEOUT = 100; const float MAX_ZOOM = 17; const float MIN_ZOOM = 14; @@ -193,17 +193,12 @@ void MapWindow::updateState(const UIState &s) { m_map->updateSource("carPosSource", carPosSource); } - if (pan_counter == 0) { + if (interaction_counter == 0) { if (last_position) m_map->setCoordinate(*last_position); if (last_bearing) m_map->setBearing(*last_bearing); - } else { - pan_counter--; - } - - if (zoom_counter == 0) { m_map->setZoom(util::map_val(velocity_filter.x(), 0, 30, MAX_ZOOM, MIN_ZOOM)); } else { - zoom_counter--; + interaction_counter--; } if (sm.updated("navInstruction")) { @@ -307,15 +302,14 @@ void MapWindow::mouseDoubleClickEvent(QMouseEvent *ev) { m_map->setZoom(util::map_val(velocity_filter.x(), 0, 30, MAX_ZOOM, MIN_ZOOM)); update(); - pan_counter = 0; - zoom_counter = 0; + interaction_counter = 0; } void MapWindow::mouseMoveEvent(QMouseEvent *ev) { QPointF delta = ev->localPos() - m_lastPos; if (!delta.isNull()) { - pan_counter = PAN_TIMEOUT; + interaction_counter = INTERACTION_TIMEOUT; m_map->moveBy(delta / MAP_SCALE); update(); } @@ -337,7 +331,7 @@ void MapWindow::wheelEvent(QWheelEvent *ev) { m_map->scaleBy(1 + factor, ev->pos() / MAP_SCALE); update(); - zoom_counter = PAN_TIMEOUT; + interaction_counter = INTERACTION_TIMEOUT; ev->accept(); } @@ -362,7 +356,7 @@ void MapWindow::pinchTriggered(QPinchGesture *gesture) { // TODO: figure out why gesture centerPoint doesn't work m_map->scaleBy(gesture->scaleFactor(), {width() / 2.0 / MAP_SCALE, height() / 2.0 / MAP_SCALE}); update(); - zoom_counter = PAN_TIMEOUT; + interaction_counter = INTERACTION_TIMEOUT; } } diff --git a/selfdrive/ui/qt/maps/map.h b/selfdrive/ui/qt/maps/map.h index 66d10a00a0..5fe79f8b15 100644 --- a/selfdrive/ui/qt/maps/map.h +++ b/selfdrive/ui/qt/maps/map.h @@ -53,8 +53,7 @@ private: // Panning QPointF m_lastPos; - int pan_counter = 0; - int zoom_counter = 0; + int interaction_counter = 0; // Position std::optional last_valid_nav_dest;