From 99b0bba5b8292b500f8c461be645a8d554d0c458 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Tue, 21 Jan 2025 12:34:14 +0100 Subject: [PATCH 1/5] if big_grid_points is not set draw always thin axes and mouse crosshairs; dashed axes --- src/callback.c | 10 ++-- src/draw.c | 138 +++++++++++++++++++++++++++++++++++-------------- src/xinit.c | 5 +- src/xschem.h | 1 + 4 files changed, 108 insertions(+), 46 deletions(-) diff --git a/src/callback.c b/src/callback.c index d0abffdb..e2fd6371 100644 --- a/src/callback.c +++ b/src/callback.c @@ -1356,7 +1356,7 @@ void draw_crosshair(int what) (int)X_TO_SCREEN(xctx->prev_crossx) - 2 * INT_WIDTH(xctx->lw), 0, 4 * INT_WIDTH(xctx->lw), xctx->xrect[0].height, (int)X_TO_SCREEN(xctx->prev_crossx) - 2 * INT_WIDTH(xctx->lw), 0); - } else { + } else { drawtempline(xctx->gctiled, NOW, X_TO_XSCHEM(xctx->areax1), xctx->prev_crossy, X_TO_XSCHEM(xctx->areax2), xctx->prev_crossy); drawtempline(xctx->gctiled, NOW, xctx->prev_crossx, Y_TO_XSCHEM(xctx->areay1), @@ -1364,10 +1364,10 @@ void draw_crosshair(int what) } } if(what != 1) { - drawline(xctx->crosshair_layer, NOW,X_TO_XSCHEM( xctx->areax1), xctx->mousey_snap, - X_TO_XSCHEM(xctx->areax2), xctx->mousey_snap, 3, NULL); - drawline(xctx->crosshair_layer, NOW, xctx->mousex_snap, Y_TO_XSCHEM(xctx->areay1), - xctx->mousex_snap, Y_TO_XSCHEM(xctx->areay2), 3, NULL); + draw_xhair_line(xctx->crosshair_layer, X_TO_XSCHEM( xctx->areax1), xctx->mousey_snap, + X_TO_XSCHEM(xctx->areax2), xctx->mousey_snap); + draw_xhair_line(xctx->crosshair_layer, xctx->mousex_snap, Y_TO_XSCHEM(xctx->areay1), + xctx->mousex_snap, Y_TO_XSCHEM(xctx->areay2)); } draw_selection(xctx->gc[SELLAYER], 0); xctx->prev_crossx = xctx->mousex_snap; diff --git a/src/draw.c b/src/draw.c index 6c7bf8b7..80e4b540 100644 --- a/src/draw.c +++ b/src/draw.c @@ -968,14 +968,26 @@ void draw_temp_symbol(int what, GC gc, int n,int layer,short tmp_flip, short rot static void drawgrid() { - double x,y; + double x, y, xax, yax, xx, yy; double delta,tmp; double mult; #if DRAW_ALL_CAIRO==0 int i=0; int big_gr = tclgetboolvar("big_grid_points"); + char dash_arr[2]; int axes = tclgetboolvar("draw_grid_axes"); - + + if(axes) { + dash_arr[0] = dash_arr[1] = (char) 3; + XSetDashes(display, xctx->gc[GRIDLAYER], 0, dash_arr, 1); + if(!big_gr) { + XSetLineAttributes (display, xctx->gc[GRIDLAYER], + 0, xDashType, xCap, xJoin); + } else { + XSetLineAttributes (display, xctx->gc[GRIDLAYER], + XLINEWIDTH(xctx->lw), xDashType, xCap, xJoin); + } + } #endif dbg(1, "drawgrid(): draw grid\n"); if( !tclgetboolvar("draw_grid") || !has_x) return; @@ -994,76 +1006,93 @@ static void drawgrid() #if DRAW_ALL_CAIRO==1 - x =floor(xctx->xorigin*xctx->mooz) + 0.5; y = floor(xctx->yorigin*xctx->mooz) + 0.5; + xax =floor(xctx->xorigin*xctx->mooz) + 0.5; yax = floor(xctx->yorigin*xctx->mooz) + 0.5; #else - x =xctx->xorigin*xctx->mooz; y = xctx->yorigin*xctx->mooz; + xax =xctx->xorigin*xctx->mooz; yax = xctx->yorigin*xctx->mooz; #endif - if(y > xctx->areay1 && y < xctx->areay2) { + if(yax > xctx->areay1 && yax < xctx->areay2) { if(xctx->draw_window) { #if DRAW_ALL_CAIRO==1 - cairo_move_to(xctx->cairo_ctx, xctx->areax1+1, y); - cairo_line_to(xctx->cairo_ctx, xctx->areax2-1, y); + cairo_move_to(xctx->cairo_ctx, xctx->areax1+1, yax); + cairo_line_to(xctx->cairo_ctx, xctx->areax2-1, yax); #else - if(axes) XDrawLine(display, xctx->window, xctx->gc[GRIDLAYER],xctx->areax1+1,(int)y, xctx->areax2-1, (int)y); + if(axes) XDrawLine(display, xctx->window, xctx->gc[GRIDLAYER], xctx->areax1+1, + (int)yax, xctx->areax2-1, (int)yax); #endif } if(xctx->draw_pixmap) { #if DRAW_ALL_CAIRO==1 - cairo_move_to(xctx->cairo_save_ctx, xctx->areax1+1, y); - cairo_line_to(xctx->cairo_save_ctx, xctx->areax2-1, y); + cairo_move_to(xctx->cairo_save_ctx, xctx->areax1+1, yax); + cairo_line_to(xctx->cairo_save_ctx, xctx->areax2-1, yax); #else - if(axes) XDrawLine(display, xctx->save_pixmap, xctx->gc[GRIDLAYER],xctx->areax1+1,(int)y, xctx->areax2-1, (int)y); + if(axes) XDrawLine(display, xctx->save_pixmap, xctx->gc[GRIDLAYER], xctx->areax1+1, (int)yax, + xctx->areax2-1, (int)yax); #endif } } - if(x > xctx->areax1 && x < xctx->areax2) { + if(xax > xctx->areax1 && xax < xctx->areax2) { if(xctx->draw_window) { #if DRAW_ALL_CAIRO==1 - cairo_move_to(xctx->cairo_ctx, x, xctx->areay1+1); - cairo_line_to(xctx->cairo_ctx, x, xctx->areay2-1); + cairo_move_to(xctx->cairo_ctx, xax, xctx->areay1+1); + cairo_line_to(xctx->cairo_ctx, xax, xctx->areay2-1); #else - if(axes) XDrawLine(display, xctx->window, xctx->gc[GRIDLAYER],(int)x,xctx->areay1+1, (int)x, xctx->areay2-1); + if(axes) XDrawLine(display, xctx->window, xctx->gc[GRIDLAYER], (int)xax, xctx->areay1+1, + (int)xax, xctx->areay2-1); #endif } if(xctx->draw_pixmap) { #if DRAW_ALL_CAIRO==1 - cairo_move_to(xctx->cairo_save_ctx, x, xctx->areay1+1); - cairo_line_to(xctx->cairo_save_ctx, x, xctx->areay2-1); + cairo_move_to(xctx->cairo_save_ctx, xax, xctx->areay1+1); + cairo_line_to(xctx->cairo_save_ctx, xax, xctx->areay2-1); #else - if(axes) XDrawLine(display, xctx->save_pixmap, xctx->gc[GRIDLAYER],(int)x,xctx->areay1+1, (int)x, xctx->areay2-1); + if(axes) XDrawLine(display, xctx->save_pixmap, xctx->gc[GRIDLAYER], (int)xax, xctx->areay1+1, + (int)xax, xctx->areay2-1); #endif } } - tmp = floor((xctx->areay1+1)/delta)*delta-fmod(-xctx->yorigin*xctx->mooz,delta); - for(x=floor((xctx->areax1+1)/delta)*delta-fmod(-xctx->xorigin*xctx->mooz,delta); x < xctx->areax2; x += delta) { + #if DRAW_ALL_CAIRO==0 + if(axes) { + XSetLineAttributes (display, xctx->gc[GRIDLAYER], + XLINEWIDTH(xctx->lw), LineSolid, LINECAP, LINEJOIN); + } + #endif + + tmp = floor((xctx->areay1+1)/delta)*delta-fmod(-xctx->yorigin*xctx->mooz, delta); + for(x=floor((xctx->areax1+1)/delta)*delta-fmod(-xctx->xorigin*xctx->mooz, delta); x < xctx->areax2; x += delta) { + xx = x; #if DRAW_ALL_CAIRO==1 - double xx = floor(x) + 0.5; + xx = floor(x) + 0.5; #endif + if((int)xx == (int)xax) continue; for(y=tmp; y < xctx->areay2; y += delta) { + yy = y; #if DRAW_ALL_CAIRO==1 - double yy = floor(y) + 0.5; - if(xctx->draw_window) { - cairo_move_to(xctx->cairo_ctx, xx, yy) ; - cairo_close_path(xctx->cairo_ctx); - } - if(xctx->draw_pixmap) { - cairo_move_to(xctx->cairo_save_ctx, xx, yy); - cairo_close_path(xctx->cairo_save_ctx); - } + yy = floor(y) + 0.5; + #endif + if((int)yy == (int)yax) continue; + #if DRAW_ALL_CAIRO==1 + if(xctx->draw_window) { + cairo_move_to(xctx->cairo_ctx, xx, yy) ; + cairo_close_path(xctx->cairo_ctx); + } + if(xctx->draw_pixmap) { + cairo_move_to(xctx->cairo_save_ctx, xx, yy); + cairo_close_path(xctx->cairo_save_ctx); + } #else if(i>=CADMAXGRIDPOINTS) { if(xctx->draw_window) { if(big_gr) { - XDrawSegments(display,xctx->window,xctx->gc[GRIDLAYER],xctx->biggridpoint,i); + XDrawSegments(display, xctx->window, xctx->gc[GRIDLAYER], xctx->biggridpoint, i); } else { - XDrawPoints(display,xctx->window,xctx->gc[GRIDLAYER],xctx->gridpoint,i,CoordModeOrigin); + XDrawPoints(display, xctx->window, xctx->gc[GRIDLAYER], xctx->gridpoint, i, CoordModeOrigin); } } if(xctx->draw_pixmap) { if(big_gr) { - XDrawSegments(display,xctx->save_pixmap,xctx->gc[GRIDLAYER],xctx->biggridpoint,i); + XDrawSegments(display, xctx->save_pixmap, xctx->gc[GRIDLAYER], xctx->biggridpoint, i); } else { - XDrawPoints(display,xctx->save_pixmap,xctx->gc[GRIDLAYER],xctx->gridpoint,i,CoordModeOrigin); + XDrawPoints(display, xctx->save_pixmap, xctx->gc[GRIDLAYER], xctx->gridpoint, i, CoordModeOrigin); } } i=0; @@ -1083,16 +1112,16 @@ static void drawgrid() #if DRAW_ALL_CAIRO==0 if(xctx->draw_window) { if(big_gr) { - XDrawSegments(display,xctx->window,xctx->gc[GRIDLAYER],xctx->biggridpoint,i); + XDrawSegments(display, xctx->window, xctx->gc[GRIDLAYER], xctx->biggridpoint, i); } else { - XDrawPoints(display,xctx->window,xctx->gc[GRIDLAYER],xctx->gridpoint,i,CoordModeOrigin); + XDrawPoints(display, xctx->window, xctx->gc[GRIDLAYER], xctx->gridpoint, i, CoordModeOrigin); } } if(xctx->draw_pixmap) { if(big_gr) { - XDrawSegments(display,xctx->save_pixmap,xctx->gc[GRIDLAYER],xctx->biggridpoint,i); + XDrawSegments(display, xctx->save_pixmap, xctx->gc[GRIDLAYER], xctx->biggridpoint, i); } else { - XDrawPoints(display,xctx->save_pixmap,xctx->gc[GRIDLAYER],xctx->gridpoint,i,CoordModeOrigin); + XDrawPoints(display, xctx->save_pixmap, xctx->gc[GRIDLAYER], xctx->gridpoint, i, CoordModeOrigin); } } #endif @@ -1148,6 +1177,39 @@ static void check_cairo_drawpoints(void *cr, int layer, XPoint *points, int npoi } #endif + +void draw_xhair_line(int c, double linex1, double liney1, double linex2, double liney2) +{ + int big_gr = tclgetboolvar("big_grid_points"); + char dash_arr[2]; + double x1, y1, x2, y2; + x1=X_TO_SCREEN(linex1); + y1=Y_TO_SCREEN(liney1); + x2=X_TO_SCREEN(linex2); + y2=Y_TO_SCREEN(liney2); + if( clip(&x1,&y1,&x2,&y2) ) + { + dash_arr[0] = dash_arr[1] = (char) 3; + XSetDashes(display, xctx->gc[c], 0, dash_arr, 1); + if(!big_gr) { + XSetLineAttributes (display, xctx->gc[c], + 0, xDashType, xCap, xJoin); + } else { + XSetLineAttributes (display, xctx->gc[c], + XLINEWIDTH(xctx->lw), xDashType, xCap, xJoin); + } + + if(xctx->draw_window) + XDrawLine(display, xctx->window, xctx->gc[c], (int)x1, (int)y1, (int)x2, (int)y2); + if(xctx->draw_pixmap) + XDrawLine(display, xctx->save_pixmap, xctx->gc[c], (int)x1, (int)y1, (int)x2, (int)y2); + if(!big_gr) { + XSetLineAttributes (display, xctx->gc[c], + XLINEWIDTH(xctx->lw), LineSolid, LINECAP, LINEJOIN); + } + } +} + void drawline(int c, int what, double linex1, double liney1, double linex2, double liney2, int dash, void *ct) { static int i = 0; diff --git a/src/xinit.c b/src/xinit.c index e65cbfea..82edc3a3 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -2037,7 +2037,6 @@ int new_schematic(const char *what, const char *win_path, const char *fname, int void change_linewidth(double w) { int i, linew; - /* choose line width automatically based on zoom */ dbg(1, "change_linewidth(): w = %g, win_path=%s lw=%g\n", w, xctx->current_win_path, xctx->lw); if(w<0. || xctx->lw == -1.0) { @@ -2054,8 +2053,8 @@ void change_linewidth(double w) linew = INT_WIDTH(xctx->lw); dbg(1, "Line width = %d\n", linew); for(i=0;igc[i], linew, LineSolid, LINECAP , LINEJOIN); - } + XSetLineAttributes(display, xctx->gc[i], linew, LineSolid, LINECAP , LINEJOIN); + } XSetLineAttributes (display, xctx->gctiled, linew, LineSolid, LINECAP , LINEJOIN); } if(!xctx->only_probes) { diff --git a/src/xschem.h b/src/xschem.h index 3e6a91bc..942cf1a8 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -1404,6 +1404,7 @@ extern Selected find_closest_obj(double mx,double my, int override_lock); extern void find_closest_net_or_symbol_pin(double mx,double my, double *x, double *y); extern void drawline(int c, int what, double x1,double y1,double x2,double y2, int dash, void *ct); +extern void draw_xhair_line(int c, double linex1, double liney1, double linex2, double liney2); extern void draw_string(int layer,int what, const char *str, short rot, short flip, int hcenter, int vcenter, double x1, double y1, double xscale, double yscale); extern void get_sym_text_size(int inst, int text_n, double *xscale, double *yscale); From 72d961aacdc439a72720531e37810c7a330c8b78 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Tue, 21 Jan 2025 15:38:19 +0100 Subject: [PATCH 2/5] fix a regression where a mouse wheel zoom or schematic pan unexpectedly end an ongoing wire placement. Add xschemrc variable crosshair_size; if set to 0 draw full crosshair, if set to a small integer draw a small square around the mouse snapped coordinate --- src/callback.c | 121 +++++++++++++++++++++++++++++++++++++++---------- src/draw.c | 24 +++++----- src/xschem.h | 2 +- src/xschem.tcl | 3 +- src/xschemrc | 3 ++ 5 files changed, 114 insertions(+), 39 deletions(-) diff --git a/src/callback.c b/src/callback.c index e2fd6371..dadf52e1 100644 --- a/src/callback.c +++ b/src/callback.c @@ -82,9 +82,11 @@ static int waves_selected(int event, KeySym key, int state, int button) if(!is_inside) { xctx->graph_master = -1; xctx->ui_state &= ~GRAPHPAN; /* terminate ongoing GRAPHPAN to avoid deadlocks */ - if(draw_xhair) - tclvareval(xctx->top_path, ".drw configure -cursor none" , NULL); - else + if(draw_xhair) { + if(tclgetintvar("crosshair_size") == 0) { + tclvareval(xctx->top_path, ".drw configure -cursor none" , NULL); + } + } else tclvareval(xctx->top_path, ".drw configure -cursor {}" , NULL); if(xctx->graph_flags & 64) { tcleval("graph_show_measure stop"); @@ -1338,36 +1340,103 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int void draw_crosshair(int what) { int sdw, sdp; + int xhair_size = tclgetintvar("crosshair_size");; dbg(1, "draw_crosshair(): what=%d\n", what); sdw = xctx->draw_window; sdp = xctx->draw_pixmap; if(!xctx->mouse_inside) return; + xctx->draw_pixmap = 0; xctx->draw_window = 1; - if(what != 2) { + if(what != 2) { /* delete previous */ if(fix_broken_tiled_fill || !_unix) { - MyXCopyArea(display, xctx->save_pixmap, xctx->window, xctx->gc[0], - 0, (int)Y_TO_SCREEN(xctx->prev_crossy) - 2 * INT_WIDTH(xctx->lw), - xctx->xrect[0].width, 4 * INT_WIDTH(xctx->lw), - 0, (int)Y_TO_SCREEN(xctx->prev_crossy) - 2 * INT_WIDTH(xctx->lw)); + if(xhair_size) { + MyXCopyArea(display, xctx->save_pixmap, xctx->window, xctx->gc[0], + (int)X_TO_SCREEN(xctx->prev_crossx) - 2 * INT_WIDTH(xctx->lw) - xhair_size, + (int)Y_TO_SCREEN(xctx->prev_crossy) - 2 * INT_WIDTH(xctx->lw) - xhair_size, + 4 * INT_WIDTH(xctx->lw) + 4 * xhair_size, + 4 * INT_WIDTH(xctx->lw) + 4 * xhair_size, + (int)X_TO_SCREEN(xctx->prev_crossx) - 2 * INT_WIDTH(xctx->lw) - xhair_size, + (int)Y_TO_SCREEN(xctx->prev_crossy) - 2 * INT_WIDTH(xctx->lw) - xhair_size); + MyXCopyArea(display, xctx->save_pixmap, xctx->window, xctx->gc[0], + (int)X_TO_SCREEN(xctx->prev_crossx) - 2 * INT_WIDTH(xctx->lw) - xhair_size, + (int)Y_TO_SCREEN(xctx->prev_crossy) - 2 * INT_WIDTH(xctx->lw) - xhair_size, + 4 * INT_WIDTH(xctx->lw) + 4 * xhair_size, + 4 * INT_WIDTH(xctx->lw) + 4 * xhair_size, + (int)X_TO_SCREEN(xctx->prev_crossx) - 2 * INT_WIDTH(xctx->lw) - xhair_size, + (int)Y_TO_SCREEN(xctx->prev_crossy) - 2 * INT_WIDTH(xctx->lw) - xhair_size); + } else { /* full screen span xhair */ + MyXCopyArea(display, xctx->save_pixmap, xctx->window, xctx->gc[0], + 0, (int)Y_TO_SCREEN(xctx->prev_crossy) - 2 * INT_WIDTH(xctx->lw), + xctx->xrect[0].width, 4 * INT_WIDTH(xctx->lw), + 0, (int)Y_TO_SCREEN(xctx->prev_crossy) - 2 * INT_WIDTH(xctx->lw)); + MyXCopyArea(display, xctx->save_pixmap, xctx->window, xctx->gc[0], + (int)X_TO_SCREEN(xctx->prev_crossx) - 2 * INT_WIDTH(xctx->lw), 0, + 4 * INT_WIDTH(xctx->lw), xctx->xrect[0].height, + (int)X_TO_SCREEN(xctx->prev_crossx) - 2 * INT_WIDTH(xctx->lw), 0); + } - MyXCopyArea(display, xctx->save_pixmap, xctx->window, xctx->gc[0], - (int)X_TO_SCREEN(xctx->prev_crossx) - 2 * INT_WIDTH(xctx->lw), 0, - 4 * INT_WIDTH(xctx->lw), xctx->xrect[0].height, - (int)X_TO_SCREEN(xctx->prev_crossx) - 2 * INT_WIDTH(xctx->lw), 0); } else { - drawtempline(xctx->gctiled, NOW, X_TO_XSCHEM(xctx->areax1), - xctx->prev_crossy, X_TO_XSCHEM(xctx->areax2), xctx->prev_crossy); - drawtempline(xctx->gctiled, NOW, xctx->prev_crossx, Y_TO_XSCHEM(xctx->areay1), - xctx->prev_crossx, Y_TO_XSCHEM(xctx->areay2)); + if(xhair_size) { + draw_xhair_line(xctx->gctiled, xhair_size, + X_TO_SCREEN(xctx->mousex_snap) - xhair_size, + Y_TO_SCREEN(xctx->mousey_snap) - xhair_size, + X_TO_SCREEN(xctx->mousex_snap) + xhair_size, + Y_TO_SCREEN(xctx->mousey_snap) - xhair_size); + draw_xhair_line(xctx->gctiled, xhair_size, + X_TO_SCREEN(xctx->mousex_snap) - xhair_size, + Y_TO_SCREEN(xctx->mousey_snap) + xhair_size, + X_TO_SCREEN(xctx->mousex_snap) + xhair_size, + Y_TO_SCREEN(xctx->mousey_snap) + xhair_size); + draw_xhair_line(xctx->gctiled, xhair_size, + X_TO_SCREEN(xctx->mousex_snap) - xhair_size, + Y_TO_SCREEN(xctx->mousey_snap) - xhair_size, + X_TO_SCREEN(xctx->mousex_snap) - xhair_size, + Y_TO_SCREEN(xctx->mousey_snap) + xhair_size); + draw_xhair_line(xctx->gctiled, xhair_size, + X_TO_SCREEN(xctx->mousex_snap) + xhair_size, + Y_TO_SCREEN(xctx->mousey_snap) - xhair_size, + X_TO_SCREEN(xctx->mousex_snap) + xhair_size, + Y_TO_SCREEN(xctx->mousey_snap) + xhair_size); + } else { /* full screen span xhair */ + drawtempline(xctx->gctiled, NOW, X_TO_XSCHEM(xctx->areax1), + xctx->prev_crossy, X_TO_XSCHEM(xctx->areax2), xctx->prev_crossy); + drawtempline(xctx->gctiled, NOW, xctx->prev_crossx, Y_TO_XSCHEM(xctx->areay1), + xctx->prev_crossx, Y_TO_XSCHEM(xctx->areay2)); + } } } - if(what != 1) { - draw_xhair_line(xctx->crosshair_layer, X_TO_XSCHEM( xctx->areax1), xctx->mousey_snap, - X_TO_XSCHEM(xctx->areax2), xctx->mousey_snap); - draw_xhair_line(xctx->crosshair_layer, xctx->mousex_snap, Y_TO_XSCHEM(xctx->areay1), - xctx->mousex_snap, Y_TO_XSCHEM(xctx->areay2)); + if(what != 1) { /* draw new */ + if(xhair_size) { + draw_xhair_line(xctx->gc[xctx->crosshair_layer], xhair_size, + X_TO_SCREEN(xctx->mousex_snap) - xhair_size, + Y_TO_SCREEN(xctx->mousey_snap) - xhair_size, + X_TO_SCREEN(xctx->mousex_snap) + xhair_size, + Y_TO_SCREEN(xctx->mousey_snap) - xhair_size); + draw_xhair_line(xctx->gc[xctx->crosshair_layer], xhair_size, + X_TO_SCREEN(xctx->mousex_snap) - xhair_size, + Y_TO_SCREEN(xctx->mousey_snap) + xhair_size, + X_TO_SCREEN(xctx->mousex_snap) + xhair_size, + Y_TO_SCREEN(xctx->mousey_snap) + xhair_size); + draw_xhair_line(xctx->gc[xctx->crosshair_layer], xhair_size, + X_TO_SCREEN(xctx->mousex_snap) - xhair_size, + Y_TO_SCREEN(xctx->mousey_snap) - xhair_size, + X_TO_SCREEN(xctx->mousex_snap) - xhair_size, + Y_TO_SCREEN(xctx->mousey_snap) + xhair_size); + draw_xhair_line(xctx->gc[xctx->crosshair_layer], xhair_size, + X_TO_SCREEN(xctx->mousex_snap) + xhair_size, + Y_TO_SCREEN(xctx->mousey_snap) - xhair_size, + X_TO_SCREEN(xctx->mousex_snap) + xhair_size, + Y_TO_SCREEN(xctx->mousey_snap) + xhair_size); + } else { /* full screen span xhair */ + draw_xhair_line(xctx->gc[xctx->crosshair_layer], xhair_size, + xctx->areax1, Y_TO_SCREEN(xctx->mousey_snap), + xctx->areax2, Y_TO_SCREEN(xctx->mousey_snap)); + draw_xhair_line(xctx->gc[xctx->crosshair_layer], xhair_size, + X_TO_SCREEN(xctx->mousex_snap), xctx->areay1, + X_TO_SCREEN(xctx->mousex_snap), xctx->areay2); + } } draw_selection(xctx->gc[SELLAYER], 0); xctx->prev_crossx = xctx->mousex_snap; @@ -2321,9 +2390,11 @@ int rstate; /* (reduced state, without ShiftMask) */ case EnterNotify: dbg(2, "callback(): Enter event, ui_state=%d\n", xctx->ui_state); xctx->mouse_inside = 1; - if(draw_xhair) - tclvareval(xctx->top_path, ".drw configure -cursor none" , NULL); - else + if(draw_xhair) { + if(tclgetintvar("crosshair_size") == 0) { + tclvareval(xctx->top_path, ".drw configure -cursor none" , NULL); + } + } else tclvareval(xctx->top_path, ".drw configure -cursor {}" , NULL); /* xschem window *sending* selected objects when the pointer comes back in abort copy operation since it has been done @@ -4171,7 +4242,7 @@ int rstate; /* (reduced state, without ShiftMask) */ } /* end wire creation when dragging in intuitive interface from an inst pin ow wire endpoint */ - else if(xctx->intuitive_interface && (xctx->ui_state & STARTWIRE)) { + else if(state == Button1Mask && xctx->intuitive_interface && (xctx->ui_state & STARTWIRE)) { if(end_place_move_copy_zoom()) break; } diff --git a/src/draw.c b/src/draw.c index 80e4b540..2165bd21 100644 --- a/src/draw.c +++ b/src/draw.c @@ -1178,33 +1178,33 @@ static void check_cairo_drawpoints(void *cr, int layer, XPoint *points, int npoi #endif -void draw_xhair_line(int c, double linex1, double liney1, double linex2, double liney2) +void draw_xhair_line(GC gc, int size, double linex1, double liney1, double linex2, double liney2) { int big_gr = tclgetboolvar("big_grid_points"); char dash_arr[2]; double x1, y1, x2, y2; - x1=X_TO_SCREEN(linex1); - y1=Y_TO_SCREEN(liney1); - x2=X_TO_SCREEN(linex2); - y2=Y_TO_SCREEN(liney2); + x1=/* X_TO_SCREEN */ (linex1); + y1=/* Y_TO_SCREEN */ (liney1); + x2=/* X_TO_SCREEN */ (linex2); + y2=/* Y_TO_SCREEN */ (liney2); if( clip(&x1,&y1,&x2,&y2) ) { dash_arr[0] = dash_arr[1] = (char) 3; - XSetDashes(display, xctx->gc[c], 0, dash_arr, 1); + XSetDashes(display, gc, 0, dash_arr, 1); if(!big_gr) { - XSetLineAttributes (display, xctx->gc[c], - 0, xDashType, xCap, xJoin); + XSetLineAttributes (display, gc, + 0, size ? LineSolid : xDashType, xCap, xJoin); } else { - XSetLineAttributes (display, xctx->gc[c], + XSetLineAttributes (display, gc, XLINEWIDTH(xctx->lw), xDashType, xCap, xJoin); } if(xctx->draw_window) - XDrawLine(display, xctx->window, xctx->gc[c], (int)x1, (int)y1, (int)x2, (int)y2); + XDrawLine(display, xctx->window, gc, (int)x1, (int)y1, (int)x2, (int)y2); if(xctx->draw_pixmap) - XDrawLine(display, xctx->save_pixmap, xctx->gc[c], (int)x1, (int)y1, (int)x2, (int)y2); + XDrawLine(display, xctx->save_pixmap, gc, (int)x1, (int)y1, (int)x2, (int)y2); if(!big_gr) { - XSetLineAttributes (display, xctx->gc[c], + XSetLineAttributes (display, gc, XLINEWIDTH(xctx->lw), LineSolid, LINECAP, LINEJOIN); } } diff --git a/src/xschem.h b/src/xschem.h index 942cf1a8..67dfc35d 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -1404,7 +1404,7 @@ extern Selected find_closest_obj(double mx,double my, int override_lock); extern void find_closest_net_or_symbol_pin(double mx,double my, double *x, double *y); extern void drawline(int c, int what, double x1,double y1,double x2,double y2, int dash, void *ct); -extern void draw_xhair_line(int c, double linex1, double liney1, double linex2, double liney2); +extern void draw_xhair_line(GC gc, int size, double linex1, double liney1, double linex2, double liney2); extern void draw_string(int layer,int what, const char *str, short rot, short flip, int hcenter, int vcenter, double x1, double y1, double xscale, double yscale); extern void get_sym_text_size(int inst, int text_n, double *xscale, double *yscale); diff --git a/src/xschem.tcl b/src/xschem.tcl index ef71c0a4..a377c398 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -7656,7 +7656,7 @@ set tctx::global_list { add_all_windows_drives auto_hilight auto_hilight_graph_nodes autofocus_mainwindow autotrim_wires bespice_listen_port big_grid_points bus_replacement_char cadgrid cadlayers cadsnap cairo_font_name cairo_font_scale change_lw color_ps tctx::colors compare_sch constr_mv - copy_cell crosshair_layer custom_label_prefix custom_token dark_colors dark_colorscheme + copy_cell crosshair_layer crosshair_size custom_label_prefix custom_token dark_colors dark_colorscheme dark_gui_colorscheme delay_flag dim_bg dim_value disable_unique_names do_all_inst draw_crosshair draw_grid draw_grid_axes draw_window edit_prop_pos edit_prop_size @@ -9096,6 +9096,7 @@ set_ne netlist_show 0 set_ne color_ps 1 set_ne ps_page_title 1 ;# add a title in the top left page corner set_ne crosshair_layer 3 ;# TEXTLAYER +set_ne crosshair_size 3 set_ne ps_paper_size {a4 842 595} set_ne transparent_svg 0 set_ne only_probes 0 ; # 20110112 diff --git a/src/xschemrc b/src/xschemrc index fdc9b455..f32941cf 100644 --- a/src/xschemrc +++ b/src/xschemrc @@ -270,6 +270,9 @@ #### set crosshair layer; Default 3 (TEXTLAYER) # set crosshair_layer 3 +#### set crosshair size; Default: 0 (full screen spanning crosshair) +# set crosshair_size 5 + #### enable to scale grid point size as done with lines at close zoom, default: 0 # set big_grid_points 0 From 49aab703b4bb92c9ffaf14c2f2b56487af00ca9b Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Tue, 21 Jan 2025 15:40:59 +0100 Subject: [PATCH 3/5] set default value for crosshair_size tcl var to 0 --- src/xschem.tcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xschem.tcl b/src/xschem.tcl index a377c398..a7a88a5a 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -9096,7 +9096,7 @@ set_ne netlist_show 0 set_ne color_ps 1 set_ne ps_page_title 1 ;# add a title in the top left page corner set_ne crosshair_layer 3 ;# TEXTLAYER -set_ne crosshair_size 3 +set_ne crosshair_size 0 set_ne ps_paper_size {a4 842 595} set_ne transparent_svg 0 set_ne only_probes 0 ; # 20110112 From 7ee11e8dbcc74513c79a491232b6da227791df66 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Tue, 21 Jan 2025 16:07:23 +0100 Subject: [PATCH 4/5] various fixes related to crosshair mouse display --- src/callback.c | 32 ++++++++++++++++---------------- src/draw.c | 9 +++------ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/callback.c b/src/callback.c index dadf52e1..07ea4a3e 100644 --- a/src/callback.c +++ b/src/callback.c @@ -1380,25 +1380,25 @@ void draw_crosshair(int what) } else { if(xhair_size) { draw_xhair_line(xctx->gctiled, xhair_size, - X_TO_SCREEN(xctx->mousex_snap) - xhair_size, - Y_TO_SCREEN(xctx->mousey_snap) - xhair_size, - X_TO_SCREEN(xctx->mousex_snap) + xhair_size, - Y_TO_SCREEN(xctx->mousey_snap) - xhair_size); + X_TO_SCREEN(xctx->prev_crossx) - xhair_size, + Y_TO_SCREEN(xctx->prev_crossy) - xhair_size, + X_TO_SCREEN(xctx->prev_crossx) + xhair_size, + Y_TO_SCREEN(xctx->prev_crossy) - xhair_size); draw_xhair_line(xctx->gctiled, xhair_size, - X_TO_SCREEN(xctx->mousex_snap) - xhair_size, - Y_TO_SCREEN(xctx->mousey_snap) + xhair_size, - X_TO_SCREEN(xctx->mousex_snap) + xhair_size, - Y_TO_SCREEN(xctx->mousey_snap) + xhair_size); + X_TO_SCREEN(xctx->prev_crossx) - xhair_size, + Y_TO_SCREEN(xctx->prev_crossy) + xhair_size, + X_TO_SCREEN(xctx->prev_crossx) + xhair_size, + Y_TO_SCREEN(xctx->prev_crossy) + xhair_size); draw_xhair_line(xctx->gctiled, xhair_size, - X_TO_SCREEN(xctx->mousex_snap) - xhair_size, - Y_TO_SCREEN(xctx->mousey_snap) - xhair_size, - X_TO_SCREEN(xctx->mousex_snap) - xhair_size, - Y_TO_SCREEN(xctx->mousey_snap) + xhair_size); + X_TO_SCREEN(xctx->prev_crossx) - xhair_size, + Y_TO_SCREEN(xctx->prev_crossy) - xhair_size, + X_TO_SCREEN(xctx->prev_crossx) - xhair_size, + Y_TO_SCREEN(xctx->prev_crossy) + xhair_size); draw_xhair_line(xctx->gctiled, xhair_size, - X_TO_SCREEN(xctx->mousex_snap) + xhair_size, - Y_TO_SCREEN(xctx->mousey_snap) - xhair_size, - X_TO_SCREEN(xctx->mousex_snap) + xhair_size, - Y_TO_SCREEN(xctx->mousey_snap) + xhair_size); + X_TO_SCREEN(xctx->prev_crossx) + xhair_size, + Y_TO_SCREEN(xctx->prev_crossy) - xhair_size, + X_TO_SCREEN(xctx->prev_crossx) + xhair_size, + Y_TO_SCREEN(xctx->prev_crossy) + xhair_size); } else { /* full screen span xhair */ drawtempline(xctx->gctiled, NOW, X_TO_XSCHEM(xctx->areax1), xctx->prev_crossy, X_TO_XSCHEM(xctx->areax2), xctx->prev_crossy); diff --git a/src/draw.c b/src/draw.c index 2165bd21..9c5f9d6e 100644 --- a/src/draw.c +++ b/src/draw.c @@ -1196,17 +1196,14 @@ void draw_xhair_line(GC gc, int size, double linex1, double liney1, double linex 0, size ? LineSolid : xDashType, xCap, xJoin); } else { XSetLineAttributes (display, gc, - XLINEWIDTH(xctx->lw), xDashType, xCap, xJoin); + size ? 0 : XLINEWIDTH(xctx->lw), size ? LineSolid : xDashType, xCap, xJoin); } - if(xctx->draw_window) XDrawLine(display, xctx->window, gc, (int)x1, (int)y1, (int)x2, (int)y2); if(xctx->draw_pixmap) XDrawLine(display, xctx->save_pixmap, gc, (int)x1, (int)y1, (int)x2, (int)y2); - if(!big_gr) { - XSetLineAttributes (display, gc, - XLINEWIDTH(xctx->lw), LineSolid, LINECAP, LINEJOIN); - } + XSetLineAttributes (display, gc, + XLINEWIDTH(xctx->lw), LineSolid, LINECAP, LINEJOIN); } } From 1015a9d71ec76d57fff0134a678b4d4144c655f1 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Tue, 21 Jan 2025 16:50:31 +0100 Subject: [PATCH 5/5] added command `xschem set crosshair_layer` to change layer used for crosshair drawing --- doc/xschem_man/developer_info.html | 1 + src/scheduler.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/doc/xschem_man/developer_info.html b/doc/xschem_man/developer_info.html index cf43eea3..3d64a8ee 100644 --- a/doc/xschem_man/developer_info.html +++ b/doc/xschem_man/developer_info.html @@ -1438,6 +1438,7 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
  • cadgrid set cad grid (default: 20)
  • cadsnap set mouse snap (default: 10)
  • color_ps set color psoscript (1 or 0)
  • +
  • crosshair_layer set layer for mouse crosshair
  • constr_mv set constrained move (1=horiz, 2=vert, 0=none)
  • cursor1_x set graph cursor1 position
  • cursor2_x set graph cursor2 position
  • diff --git a/src/scheduler.c b/src/scheduler.c index 08d6c033..ffb1ff47 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -5081,8 +5081,16 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg else if(!strcmp(argv[2], "color_ps")) { /* set color psoscript (1 or 0) */ color_ps=atoi(argv[3]); } + else if(!strcmp(argv[2], "crosshair_layer")) { /* set layer for mouse crosshair */ + int c = atoi(argv[3]); + tclsetintvar("crosshair_layer", c); + xctx->crosshair_layer = c; + if(xctx->crosshair_layer < 0 ) xctx->crosshair_layer = 2; + if(xctx->crosshair_layer >= cadlayers ) xctx->crosshair_layer = 2; + } else if(!strcmp(argv[2], "constr_mv")) { /* set constrained move (1=horiz, 2=vert, 0=none) */ xctx->constr_mv = atoi(argv[3]); + if(xctx->constr_mv < 0 || xctx->constr_mv > 2) xctx->constr_mv = 0; } else if(!strcmp(argv[2], "cursor1_x")) { /* set graph cursor1 position */ xctx->graph_cursor1_x = atof_spice(argv[3]);