From eadd991651c91405bcda5bdc6c51da7f2a1b2039 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Thu, 30 Jan 2025 03:47:13 +0100 Subject: [PATCH] reduce calls to find_closest_net_or_symbol_pin() in draw_crosshair() --- src/callback.c | 27 +++++++++++++++++++++++++-- src/xinit.c | 1 + src/xschem.h | 3 ++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/callback.c b/src/callback.c index 9111d645..b0860efd 100644 --- a/src/callback.c +++ b/src/callback.c @@ -1355,6 +1355,7 @@ void draw_crosshair(int what, int state) int sdw, sdp; int xhair_size = tclgetintvar("crosshair_size"); double mx, my; + int changed = 0; dbg(1, "draw_crosshair(): what=%d\n", what); sdw = xctx->draw_window; sdp = xctx->draw_pixmap; @@ -1364,9 +1365,25 @@ void draw_crosshair(int what, int state) my = xctx->mousey_snap; if( ( (xctx->ui_state & (MENUSTART | STARTWIRE) ) || xctx->ui_state == 0 ) && (state == ShiftMask) ) { - find_closest_net_or_symbol_pin(xctx->mousex, xctx->mousey, &mx, &my); + /* mouse not changed so closest net or symbol pin unchanged too */ + if(mx == xctx->prev_m_crossx && my == xctx->prev_m_crossy) { + mx = xctx->prev_crossx; /* get previous one */ + my = xctx->prev_crossy; + } else { + /* mouse position changed, so find new closest net or pin */ + find_closest_net_or_symbol_pin(xctx->mousex_snap, xctx->mousey_snap, &mx, &my); + changed = 1; /* we force a cursor redraw */ + dbg(1, "find\n"); + } } - if(!(what & 4) && mx == xctx->prev_crossx && my == xctx->prev_crossy) return; + + /* no changed closest pin/net, no force, mx,my is not changed. --> do nothing + | _____________| | + | | _____________________|____________________________ */ + if(!changed && !(what & 4) && mx == xctx->prev_crossx && my == xctx->prev_crossy) { + return; + } + dbg(1, "draw %d\n", what); xctx->draw_pixmap = 0; xctx->draw_window = 1; if(what & 1) { /* delete previous */ @@ -1459,9 +1476,15 @@ void draw_crosshair(int what, int state) } } if(what) draw_selection(xctx->gc[SELLAYER], 0); + if(what & 2) { + /* previous closest pin or net position (if snap wire or Shift pressed) */ xctx->prev_crossx = mx; xctx->prev_crossy = my; + /* previous mouse_snap position */ + xctx->prev_m_crossx = xctx->mousex_snap; + xctx->prev_m_crossy = xctx->mousey_snap; + dbg(0, "update prev\n"); } xctx->draw_window = sdw; diff --git a/src/xinit.c b/src/xinit.c index 68c31fde..46160eb2 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -646,6 +646,7 @@ static void alloc_xschem_data(const char *top_path, const char *win_path) xctx->enable_drill = 0; xctx->prev_set_modify = -1; xctx->prev_crossx = xctx->prev_crossy = 0.0; + xctx->prev_m_crossx = xctx->prev_m_crossy = 0.0; xctx->prev_rubberx = xctx->prev_rubbery = 0.0; xctx->mouse_inside = 0; xctx->pending_fullzoom = 0; diff --git a/src/xschem.h b/src/xschem.h index 6743790a..1ddfb2de 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -1050,7 +1050,8 @@ typedef struct { double xpan,ypan,xpan2,ypan2; double p_xx1,p_xx2,p_yy1,p_yy2; /* draw_crosshair */ - double prev_crossx, prev_crossy; + double prev_crossx, prev_crossy; /* previous closest net/pin found by draw_crosshair() */ + double prev_m_crossx, prev_m_crossy; /* previous snap mouse position processed by draw_crosshair() */ int mouse_inside; /* set_modify */ int prev_set_modify;