diff --git a/src/actions.c b/src/actions.c index 40a121d8..1baa9bd3 100644 --- a/src/actions.c +++ b/src/actions.c @@ -194,7 +194,7 @@ const char *add_ext(const char *f, const char *ext) return ff; } -void resetwin(void) +void resetwin(int create_pixmap, int clear_pixmap) { int i; XWindowAttributes wattr; @@ -209,10 +209,10 @@ void resetwin(void) xschem_w=wattr.width; xschem_h=wattr.height; - areax2 = xschem_w+2*lw; - areay2 = xschem_h+2*lw; - areax1 = -2*lw; - areay1 = -2*lw; + areax2 = xschem_w+2*INT_WIDTH(xctx->lw); + areay2 = xschem_h+2*INT_WIDTH(xctx->lw); + areax1 = -2*INT_WIDTH(xctx->lw); + areay1 = -2*INT_WIDTH(xctx->lw); areaw = areax2-areax1; areah = areay2-areay1; @@ -225,7 +225,7 @@ void resetwin(void) xrect[0].width = xschem_w; xrect[0].height = xschem_h; - XFreePixmap(display,save_pixmap); + if(clear_pixmap) XFreePixmap(display,save_pixmap); /* { @@ -236,7 +236,9 @@ void resetwin(void) } */ - save_pixmap = XCreatePixmap(display, window, xschem_w, xschem_h, depth); + if(create_pixmap) { + save_pixmap = XCreatePixmap(display, window, xschem_w, xschem_h, depth); + } XSetTile(display,gctiled, save_pixmap); #else Tk_Window mainwindow = Tk_MainWindow(interp); @@ -248,10 +250,10 @@ void resetwin(void) unsigned int height = rct.bottom - rct.top; xschem_w = width; xschem_h = height; - areax2 = xschem_w + 2 * lw; - areay2 = xschem_h + 2 * lw; - areax1 = -2 * lw; - areay1 = -2 * lw; + areax2 = xschem_w + 2 * INT_WIDTH(xctx->lw); + areay2 = xschem_h + 2 * INT_WIDTH(xctx->lw); + areax1 = -2 * INT_WIDTH(xctx->lw); + areay1 = -2 * INT_WIDTH(xctx->lw); areaw = areax2 - areax1; areah = areay2 - areay1; if (xschem_w != xrect[0].width || xschem_h != xrect[0].height) { /* avoid unnecessary work if no resize */ @@ -262,8 +264,10 @@ void resetwin(void) xrect[0].y = 0; xrect[0].width = xschem_w; xrect[0].height = xschem_h; - Tk_FreePixmap(display, save_pixmap); - save_pixmap = Tk_GetPixmap(display, window, xschem_w, xschem_h, depth); + if(clear_pixmap) Tk_FreePixmap(display, save_pixmap); + if(create_pixmap) { + save_pixmap = Tk_GetPixmap(display, window, xschem_w, xschem_h, depth); + } XSetTile(display, gctiled, save_pixmap); } #endif @@ -315,10 +319,10 @@ void toggle_only_probes() { static double save_lw; if(!only_probes) { - save_lw = lw_double; - lw_double=3.0; + save_lw = xctx->lw; + xctx->lw=3.0; } else { - lw_double= save_lw; + xctx->lw= save_lw; } only_probes =!only_probes; if(only_probes) { @@ -327,7 +331,7 @@ void toggle_only_probes() else { tclsetvar("only_probes","0"); } - change_linewidth(lw_double); + change_linewidth(xctx->lw); draw(); } @@ -1262,31 +1266,26 @@ void change_linewidth(double w) /* choose line width automatically based on zoom */ if(w<0.) { if(change_lw) { - lw_double=xctx->mooz * 0.09 * cadsnap; - bus_width = BUS_WIDTH * xctx->mooz * 0.09 * cadsnap; + xctx->lw=xctx->mooz * 0.09 * cadsnap; cadhalfdotsize = CADHALFDOTSIZE + 0.04 * (cadsnap-10); changed=1; } /* explicitly set line width */ } else { - lw_double=w; - bus_width = BUS_WIDTH * w; + xctx->lw=w; changed=1; } if(!changed) return; - lw=lw_double; - if(lw==0) lw=1; /* on some servers zero width */ - /* draws fast but not good... */ if(has_x) { for(i=0;ilw), LineSolid, CapRound , JoinRound); } - XSetLineAttributes (display, gctiled, lw, LineSolid, CapRound , JoinRound); + XSetLineAttributes (display, gctiled, INT_WIDTH(xctx->lw), LineSolid, CapRound , JoinRound); } - areax1 = -2*lw; - areay1 = -2*lw; - areax2 = xrect[0].width+2*lw; - areay2 = xrect[0].height+2*lw; + areax1 = -2*INT_WIDTH(xctx->lw); + areay1 = -2*INT_WIDTH(xctx->lw); + areax2 = xrect[0].width+2*INT_WIDTH(xctx->lw); + areay2 = xrect[0].height+2*INT_WIDTH(xctx->lw); areaw = areax2-areax1; areah = areay2 - areay1; } @@ -1369,7 +1368,7 @@ void calc_drawing_bbox(xRect *boundbox, int selected) if(!str[0] || !bus_hilight_lookup(str, 0,XLOOKUP)) continue; } if(xctx->wire[i].bus){ - ov = bus_width> cadhalfdotsize ? bus_width : CADHALFDOTSIZE; + ov = INT_BUS_WIDTH(xctx->lw)> cadhalfdotsize ? INT_BUS_WIDTH(xctx->lw) : CADHALFDOTSIZE; if(xctx->wire[i].y1 < xctx->wire[i].y2) { y1 = xctx->wire[i].y1-ov; y2 = xctx->wire[i].y2+ov; } else { y1 = xctx->wire[i].y1+ov; y2 = xctx->wire[i].y2-ov; } } else { @@ -1459,24 +1458,23 @@ void zoom_full(int dr, int sel) double yy1; if(change_lw) { - lw = lw_double=1.; - bus_width = BUS_WIDTH * lw_double; + xctx->lw = 1.; } - areax1 = -2*lw; - areay1 = -2*lw; - areax2 = xrect[0].width+2*lw; - areay2 = xrect[0].height+2*lw; + areax1 = -2*INT_WIDTH(xctx->lw); + areay1 = -2*INT_WIDTH(xctx->lw); + areax2 = xrect[0].width+2*INT_WIDTH(xctx->lw); + areay2 = xrect[0].height+2*INT_WIDTH(xctx->lw); areaw = areax2-areax1; areah = areay2 - areay1; calc_drawing_bbox(&boundbox, sel); - xctx->zoom=(boundbox.x2-boundbox.x1)/(areaw-4*lw); - yy1=(boundbox.y2-boundbox.y1)/(areah-4*lw); + xctx->zoom=(boundbox.x2-boundbox.x1)/(areaw-4*INT_WIDTH(xctx->lw)); + yy1=(boundbox.y2-boundbox.y1)/(areah-4*INT_WIDTH(xctx->lw)); if(yy1>xctx->zoom) xctx->zoom=yy1; xctx->zoom*=1.05; xctx->mooz=1/xctx->zoom; - xctx->xorigin=-boundbox.x1+(areaw-4*lw)/40*xctx->zoom; - xctx->yorigin=(areah-4*lw)*xctx->zoom-boundbox.y2 - (areah-4*lw)/40*xctx->zoom; + xctx->xorigin=-boundbox.x1+(areaw-4*INT_WIDTH(xctx->lw))/40*xctx->zoom; + xctx->yorigin=(areah-4*INT_WIDTH(xctx->lw))*xctx->zoom-boundbox.y2 - (areah-4*INT_WIDTH(xctx->lw))/40*xctx->zoom; dbg(1, "zoom_full(): areaw=%d, areah=%d\n", areaw, areah); change_linewidth(-1.); @@ -1539,8 +1537,8 @@ void zoom_box(int what) RECTORDER(x1,y1,x2,y2); drawtemprect(gctiled, NOW, xx1,yy1,xx2,yy2); xctx->xorigin=-x1;xctx->yorigin=-y1; - xctx->zoom=(x2-x1)/(areaw-4*lw); - yy1=(y2-y1)/(areah-4*lw); + xctx->zoom=(x2-x1)/(areaw-4*INT_WIDTH(xctx->lw)); + yy1=(y2-y1)/(areah-4*INT_WIDTH(xctx->lw)); if(yy1>xctx->zoom) xctx->zoom=yy1; xctx->mooz=1/xctx->zoom; change_linewidth(-1.); diff --git a/src/callback.c b/src/callback.c index 7a1a6ca5..a04059d0 100644 --- a/src/callback.c +++ b/src/callback.c @@ -183,7 +183,7 @@ int callback(int event, int mx, int my, KeySym key, dbg(1, "callback(): Expose\n"); break; case ConfigureNotify: - resetwin(); + resetwin(1, 1); draw(); break; @@ -491,16 +491,16 @@ int callback(int event, int mx, int my, KeySym key, } if(key == '+' && state&ControlMask) /* change line width */ { - lw_double+=0.1; - change_linewidth(lw_double); + xctx->lw+=0.1; + change_linewidth(xctx->lw); draw(); break; } if(key == '-' && state&ControlMask) /* change line width */ { - lw_double-=0.1;if(lw_double<0.0) lw_double=0.0; - change_linewidth(lw_double); + xctx->lw-=0.1;if(xctx->lw<0.0) xctx->lw=0.0; + change_linewidth(xctx->lw); draw(); break; } diff --git a/src/draw.c b/src/draw.c index 9e0f575e..2d21dada 100644 --- a/src/draw.c +++ b/src/draw.c @@ -87,10 +87,10 @@ void print_image() xrect[0].y = 0; xschem_w = xrect[0].width = w; xschem_h = xrect[0].height = h; - areax2 = w+2*lw; - areay2 = h+2*lw; - areax1 = -2*lw; - areay1 = -2*lw; + areax2 = w+2*INT_WIDTH(xctx->lw); + areay2 = h+2*INT_WIDTH(xctx->lw); + areax1 = -2*INT_WIDTH(xctx->lw); + areay1 = -2*INT_WIDTH(xctx->lw); areaw = areax2-areax1; areah = areay2-areay1; saveorx = xctx->xorigin; @@ -163,10 +163,10 @@ void print_image() xrect[0].y = 0; xschem_w = xrect[0].width = w; xschem_h = xrect[0].height = h; - areax2 = w+2*lw; - areay2 = h+2*lw; - areax1 = -2*lw; - areay1 = -2*lw; + areax2 = w+2*INT_WIDTH(xctx->lw); + areay2 = h+2*INT_WIDTH(xctx->lw); + areax1 = -2*INT_WIDTH(xctx->lw); + areay1 = -2*INT_WIDTH(xctx->lw); areaw = areax2-areax1; areah = areay2-areay1; xctx->zoom = savezoom; @@ -858,13 +858,13 @@ void drawline(int c, int what, double linex1, double liney1, double linex2, doub if(dash) { dash_arr[0] = dash_arr[1] = dash; XSetDashes(display, gc[c], 0, dash_arr, 2); - XSetLineAttributes (display, gc[c], lw, xDashType, CapButt, JoinBevel); + XSetLineAttributes (display, gc[c], INT_WIDTH(xctx->lw), xDashType, CapButt, JoinBevel); } if(draw_window) XDrawLine(display, window, gc[c], x1, y1, x2, y2); if(draw_pixmap) XDrawLine(display, save_pixmap, gc[c], x1, y1, x2, y2); if(dash) { - XSetLineAttributes (display, gc[c], lw, LineSolid, CapRound, JoinRound); + XSetLineAttributes (display, gc[c], INT_WIDTH(xctx->lw), LineSolid, CapRound, JoinRound); } } } @@ -881,13 +881,13 @@ void drawline(int c, int what, double linex1, double liney1, double linex2, doub if(dash) { dash_arr[0] = dash_arr[1] = dash; XSetDashes(display, gc[c], 0, dash_arr, 2); - XSetLineAttributes (display, gc[c], bus_width, xDashType, CapButt, JoinBevel); + XSetLineAttributes (display, gc[c], INT_BUS_WIDTH(xctx->lw), xDashType, CapButt, JoinBevel); } else { - XSetLineAttributes (display, gc[c], bus_width, LineSolid, CapRound, JoinRound); + XSetLineAttributes (display, gc[c], INT_BUS_WIDTH(xctx->lw), LineSolid, CapRound, JoinRound); } if(draw_window) XDrawLine(display, window, gc[c], x1, y1, x2, y2); if(draw_pixmap) XDrawLine(display, save_pixmap, gc[c], x1, y1, x2, y2); - XSetLineAttributes (display, gc[c], lw, LineSolid, CapRound , JoinRound); + XSetLineAttributes (display, gc[c], INT_WIDTH(xctx->lw), LineSolid, CapRound , JoinRound); } } else if(what & BEGIN) i=0; @@ -963,10 +963,10 @@ void drawtempline(GC gc, int what, double linex1,double liney1,double linex2,dou y2=Y_TO_SCREEN(liney2); if( clip(&x1,&y1,&x2,&y2) ) { - XSetLineAttributes (display, gc, bus_width, LineSolid, CapRound , JoinRound); + XSetLineAttributes (display, gc, INT_BUS_WIDTH(xctx->lw), LineSolid, CapRound , JoinRound); XDrawLine(display, window, gc, x1, y1, x2, y2); - XSetLineAttributes (display, gc, lw, LineSolid, CapRound , JoinRound); + XSetLineAttributes (display, gc, INT_WIDTH(xctx->lw), LineSolid, CapRound , JoinRound); } } @@ -1199,7 +1199,7 @@ void drawarc(int c, int what, double x, double y, double r, double a, double b, char dash_arr[2]; dash_arr[0] = dash_arr[1] = dash; XSetDashes(display, gc[c], 0, dash_arr, 2); - XSetLineAttributes (display, gc[c], lw, xDashType, CapButt, JoinBevel); + XSetLineAttributes (display, gc[c], INT_WIDTH(xctx->lw), xDashType, CapButt, JoinBevel); } if(draw_window) { @@ -1218,7 +1218,7 @@ void drawarc(int c, int what, double x, double y, double r, double a, double b, } } if(dash) { - XSetLineAttributes (display, gc[c], lw ,LineSolid, CapRound , JoinRound); + XSetLineAttributes (display, gc[c], INT_WIDTH(xctx->lw) ,LineSolid, CapRound , JoinRound); } } } @@ -1386,7 +1386,7 @@ void drawpolygon(int c, int what, double *x, double *y, int points, int poly_fil char dash_arr[2]; dash_arr[0] = dash_arr[1] = dash; XSetDashes(display, gc[c], 0, dash_arr, 2); - XSetLineAttributes (display, gc[c], lw, xDashType, CapButt, JoinBevel); + XSetLineAttributes (display, gc[c], INT_WIDTH(xctx->lw), xDashType, CapButt, JoinBevel); } if(draw_window) XDrawLines(display, window, gc[c], p, points, CoordModeOrigin); if(draw_pixmap) @@ -1399,7 +1399,7 @@ void drawpolygon(int c, int what, double *x, double *y, int points, int poly_fil } } if(dash) { - XSetLineAttributes (display, gc[c], lw ,LineSolid, CapRound , JoinRound); + XSetLineAttributes (display, gc[c], INT_WIDTH(xctx->lw) ,LineSolid, CapRound , JoinRound); } my_free(722, &p); @@ -1448,7 +1448,7 @@ void drawrect(int c, int what, double rectx1,double recty1,double rectx2,double if(dash) { dash_arr[0] = dash_arr[1] = dash; XSetDashes(display, gc[c], 0, dash_arr, 2); - XSetLineAttributes (display, gc[c], lw, xDashType, CapButt, JoinBevel); + XSetLineAttributes (display, gc[c], INT_WIDTH(xctx->lw), xDashType, CapButt, JoinBevel); } if(draw_window) XDrawRectangle(display, window, gc[c], (int)x1, (int)y1, (unsigned int)x2 - (unsigned int)x1, @@ -1460,7 +1460,7 @@ void drawrect(int c, int what, double rectx1,double recty1,double rectx2,double (unsigned int)y2 - (unsigned int)y1); } if(dash) { - XSetLineAttributes (display, gc[c], lw ,LineSolid, CapRound , JoinRound); + XSetLineAttributes (display, gc[c], INT_WIDTH(xctx->lw) ,LineSolid, CapRound , JoinRound); } } } @@ -1763,7 +1763,7 @@ void draw(void) } draw_selection(gc[SELLAYER], 0); /* 20181009 moved outside of cadlayers loop */ - dbg(1, "draw(): lw=%d\n",lw); + dbg(1, "draw(): INT_WIDTH(xctx->lw)=%d\n",INT_WIDTH(xctx->lw)); } /* if(has_x) */ } diff --git a/src/editprop.c b/src/editprop.c index e2188a24..d5a371ee 100644 --- a/src/editprop.c +++ b/src/editprop.c @@ -489,11 +489,11 @@ void edit_line_property(void) } else xctx->line[c][n].dash = 0; if(xctx->line[c][n].y1 < xctx->line[c][n].y2) { - y1 = xctx->line[c][n].y1-bus_width; y2 = xctx->line[c][n].y2+bus_width; + y1 = xctx->line[c][n].y1-INT_BUS_WIDTH(xctx->lw); y2 = xctx->line[c][n].y2+INT_BUS_WIDTH(xctx->lw); } else { - y1 = xctx->line[c][n].y1+bus_width; y2 = xctx->line[c][n].y2-bus_width; + y1 = xctx->line[c][n].y1+INT_BUS_WIDTH(xctx->lw); y2 = xctx->line[c][n].y2-INT_BUS_WIDTH(xctx->lw); } - bbox(ADD, xctx->line[c][n].x1-bus_width, y1 , xctx->line[c][n].x2+bus_width , y2 ); + bbox(ADD, xctx->line[c][n].x1-INT_BUS_WIDTH(xctx->lw), y1 , xctx->line[c][n].x2+INT_BUS_WIDTH(xctx->lw) , y2 ); } bbox(SET , 0.0 , 0.0 , 0.0 , 0.0); draw(); @@ -541,7 +541,7 @@ void edit_wire_property(void) bus_ptr = get_tok_value(xctx->wire[k].prop_ptr,"bus",0); if(!strcmp(bus_ptr, "true")) { int ov, y1, y2; - ov = bus_width > cadhalfdotsize ? bus_width : CADHALFDOTSIZE; + ov = INT_BUS_WIDTH(xctx->lw) > cadhalfdotsize ? INT_BUS_WIDTH(xctx->lw) : CADHALFDOTSIZE; if(xctx->wire[k].y1 < xctx->wire[k].y2) { y1 = xctx->wire[k].y1-ov; y2 = xctx->wire[k].y2+ov; } else { y1 = xctx->wire[k].y1+ov; y2 = xctx->wire[k].y2-ov; } bbox(ADD, xctx->wire[k].x1-ov, y1 , xctx->wire[k].x2+ov , y2 ); @@ -549,7 +549,7 @@ void edit_wire_property(void) } else { if(oldbus){ int ov, y1, y2; - ov = bus_width> cadhalfdotsize ? bus_width : CADHALFDOTSIZE; + ov = INT_BUS_WIDTH(xctx->lw)> cadhalfdotsize ? INT_BUS_WIDTH(xctx->lw) : CADHALFDOTSIZE; if(xctx->wire[k].y1 < xctx->wire[k].y2) { y1 = xctx->wire[k].y1-ov; y2 = xctx->wire[k].y2+ov; } else { y1 = xctx->wire[k].y1+ov; y2 = xctx->wire[k].y2-ov; } bbox(ADD, xctx->wire[k].x1-ov, y1 , xctx->wire[k].x2+ov , y2 ); diff --git a/src/globals.c b/src/globals.c index baa11136..6c2f91ec 100644 --- a/src/globals.c +++ b/src/globals.c @@ -152,16 +152,13 @@ int debug_var=-10; /* will be set to 0 in xinit.c */ int tcp_port = 0; int do_print=0; int no_readline=0; -int lw=0; /* line width */ -int bus_width = BUS_WIDTH; -double lw_double=0.0; /* line width */ int fill=1; /* filled rectangles */ int draw_pixmap=1; /* use pixmap for double buffer */ int draw_window=0; int draw_grid=1; double cadgrid = CADGRID; double cadhalfdotsize = CADHALFDOTSIZE; -int change_lw=0; /* allow change linewidth */ +int change_lw=0; /* allow change xctx->lw */ int incr_hilight=1; int auto_hilight=0; unsigned int color_index[256]; /* layer color lookup table */ diff --git a/src/move.c b/src/move.c index 6c466043..bd71bbb0 100644 --- a/src/move.c +++ b/src/move.c @@ -475,7 +475,7 @@ void find_inst_to_be_redrawn(const char *node) if(node && xctx->wire[i].node && !strcmp(xctx->wire[i].node, node )) { if(xctx->wire[i].bus){ int ov, y1, y2; - ov = bus_width> cadhalfdotsize ? bus_width : CADHALFDOTSIZE; + ov = INT_BUS_WIDTH(xctx->lw)> cadhalfdotsize ? INT_BUS_WIDTH(xctx->lw) : CADHALFDOTSIZE; if(xctx->wire[i].y1 < xctx->wire[i].y2) { y1 = xctx->wire[i].y1-ov; y2 = xctx->wire[i].y2+ov; } else { y1 = xctx->wire[i].y1+ov; y2 = xctx->wire[i].y2-ov; } bbox(ADD, xctx->wire[i].x1-ov, y1 , xctx->wire[i].x2+ov , y2 ); @@ -579,7 +579,7 @@ void copy_objects(int what) /* if(wire[n].bus){ int ov, y1, y2; - ov = bus_width> cadhalfdotsize ? bus_width : CADHALFDOTSIZE; + ov = INT_BUS_WIDTH(xctx->lw)> cadhalfdotsize ? INT_BUS_WIDTH(xctx->lw) : CADHALFDOTSIZE; if(wire[n].y1 < wire[n].y2) { y1 = wire[n].y1-ov; y2 = wire[n].y2+ov; } else { y1 = wire[n].y1+ov; y2 = wire[n].y2-ov; } bbox(ADD, wire[n].x1-ov, y1 , wire[n].x2+ov , y2 ); @@ -1077,7 +1077,7 @@ void move_objects(int what, int merge, double dx, double dy) if(k == 0) { if(wire[n].bus){ int ov, y1, y2; - ov = bus_width> cadhalfdotsize ? bus_width : CADHALFDOTSIZE; + ov = INT_BUS_WIDTH(xctx->lw)> cadhalfdotsize ? INT_BUS_WIDTH(xctx->lw) : CADHALFDOTSIZE; if(wire[n].y1 < wire[n].y2) { y1 = wire[n].y1-ov; y2 = wire[n].y2+ov; } else { y1 = wire[n].y1+ov; y2 = wire[n].y2-ov; } bbox(ADD, wire[n].x1-ov, y1 , wire[n].x2+ov , y2 ); diff --git a/src/psprint.c b/src/psprint.c index 544324b6..d807c16d 100644 --- a/src/psprint.c +++ b/src/psprint.c @@ -36,11 +36,11 @@ static Ps_color *ps_colors; static void restore_lw(void) { - if(lw_double==0.0) + if(xctx->lw==0.0) fprintf(fd, "%.16g setlinewidth\n",0.5); else - if(a3page) fprintf(fd, "%.16g setlinewidth\n",lw_double/1.2/sqrt(2)); - else fprintf(fd, "%.16g setlinewidth\n",lw_double/1.2); + if(a3page) fprintf(fd, "%.16g setlinewidth\n",xctx->lw/1.2/sqrt(2)); + else fprintf(fd, "%.16g setlinewidth\n",xctx->lw/1.2); } static void set_ps_colors(unsigned int pixel) @@ -582,7 +582,7 @@ void ps_draw(void) - dbg(1, "ps_draw(): lw=%d plotfile=%s\n",lw, plotfile); + dbg(1, "ps_draw(): INT_WIDTH(xctx->lw)=%d plotfile=%s\n",INT_WIDTH(xctx->lw), plotfile); fprintf(fd, "showpage\n\n"); fprintf(fd, "%%%%EOF\n"); fclose(fd); diff --git a/src/scheduler.c b/src/scheduler.c index 1b1458f8..e19bb065 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -274,8 +274,8 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg if(factor == 0.) factor = 1.; RECTORDER(x1,y1,x2,y2); xctx->xorigin=-x1;xctx->yorigin=-y1; - xctx->zoom=(x2-x1)/(areaw-4*lw); - yy1=(y2-y1)/(areah-4*lw); + xctx->zoom=(x2-x1)/(areaw-4*INT_WIDTH(xctx->lw)); + yy1=(y2-y1)/(areah-4*INT_WIDTH(xctx->lw)); if(yy1>xctx->zoom) xctx->zoom=yy1; xctx->mooz=1/xctx->zoom; xctx->xorigin=xctx->xorigin+areaw*xctx->zoom*(1-1/factor)/2; @@ -939,7 +939,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg } else if(!strcmp(argv[1],"globals")) { printf("*******global variables:*******\n"); printf("netlist_dir=%s\n", netlist_dir? netlist_dir: ""); - printf("lw=%d\n", lw); + printf("INT_WIDTH(xctx->lw)=%d\n", INT_WIDTH(xctx->lw)); printf("wires=%d\n", xctx->wires); printf("instances=%d\n", xctx->instances); printf("symbols=%d\n", xctx->symbols); diff --git a/src/select.c b/src/select.c index 6f8c20f0..76f003f8 100644 --- a/src/select.c +++ b/src/select.c @@ -126,7 +126,7 @@ static void del_rect_line_arc_poly(void) j++; if(xctx->line[c][i].bus){ int ov, y1, y2; - ov = bus_width; + ov = INT_BUS_WIDTH(xctx->lw); if(xctx->line[c][i].y1 < xctx->line[c][i].y2) { y1 = xctx->line[c][i].y1-ov; y2 = xctx->line[c][i].y2+ov; } else { y1 = xctx->line[c][i].y1+ov; y2 = xctx->line[c][i].y2-ov; } bbox(ADD, xctx->line[c][i].x1-ov, y1 , xctx->line[c][i].x2+ov , y2 ); @@ -331,7 +331,7 @@ void delete(void) j++; if(xctx->wire[i].bus){ int ov, y1, y2; - ov = bus_width> cadhalfdotsize ? bus_width : CADHALFDOTSIZE; + ov = INT_BUS_WIDTH(xctx->lw)> cadhalfdotsize ? INT_BUS_WIDTH(xctx->lw) : CADHALFDOTSIZE; if(xctx->wire[i].y1 < xctx->wire[i].y2) { y1 = xctx->wire[i].y1-ov; y2 = xctx->wire[i].y2+ov; } else { y1 = xctx->wire[i].y1+ov; y2 = xctx->wire[i].y2-ov; } bbox(ADD, xctx->wire[i].x1-ov, y1 , xctx->wire[i].x2+ov , y2 ); @@ -442,8 +442,8 @@ void bbox(int what,double x1,double y1, double x2, double y2) areah = saveh; xrect[0].x = 0; xrect[0].y = 0; - xrect[0].width = areaw-4*lw; - xrect[0].height = areah-4*lw; + xrect[0].width = areaw-4*INT_WIDTH(xctx->lw); + xrect[0].height = areah-4*INT_WIDTH(xctx->lw); XSetClipMask(display, gctiled, None); /* 20171110 optimization, clipping already done in software */ @@ -463,17 +463,17 @@ void bbox(int what,double x1,double y1, double x2, double y2) fprintf(errfp, "ERROR: bbox(SET) call before bbox(BEGIN)\n"); tcleval("alert_ {ERROR: bbox(SET) call before bbox(BEGIN)} {}"); } - areax1 = bbx1-2*lw; - areax2 = bbx2+2*lw; - areay1 = bby1-2*lw; - areay2 = bby2+2*lw; + areax1 = bbx1-2*INT_WIDTH(xctx->lw); + areax2 = bbx2+2*INT_WIDTH(xctx->lw); + areay1 = bby1-2*INT_WIDTH(xctx->lw); + areay2 = bby2+2*INT_WIDTH(xctx->lw); areaw = (areax2-areax1); areah = (areay2-areay1); - xrect[0].x = bbx1-lw; - xrect[0].y = bby1-lw; - xrect[0].width = bbx2-bbx1+2*lw; - xrect[0].height = bby2-bby1+2*lw; + xrect[0].x = bbx1-INT_WIDTH(xctx->lw); + xrect[0].y = bby1-INT_WIDTH(xctx->lw); + xrect[0].width = bbx2-bbx1+2*INT_WIDTH(xctx->lw); + xrect[0].height = bby2-bby1+2*INT_WIDTH(xctx->lw); for(i=0;ilw*0.7; } static void set_svg_colors(unsigned int pixel) @@ -590,7 +590,7 @@ void svg_draw(void) } } - dbg(1, "svg_draw(): lw=%d\n",lw); + dbg(1, "svg_draw(): INT_WIDTH(xctx->lw)=%d\n",INT_WIDTH(xctx->lw)); fprintf(fd, "\n"); fclose(fd); draw_grid=old_grid; diff --git a/src/xinit.c b/src/xinit.c index 9c8ce2a1..d17b5253 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -26,7 +26,6 @@ #endif static int init_done=0; /* 20150409 to avoid double call by Xwindows close and TclExitHandler */ -static Window save_window; static XSetWindowAttributes winattr; static int screen_number; static Tk_Window tkwindow, mainwindow, tkpre_window; @@ -788,6 +787,8 @@ void preview_window(const char *what, const char *tk_win_path, const char *filen Xschem_ctx *save_xctx = NULL; /* save pointer to current schematic context structure */ char *saveptr = NULL; int save_mod, save_ev, save_show_pin; + Pixmap save_save_pixmap; + Window save_window; save_xctx = xctx; /* save current schematic */ @@ -796,6 +797,7 @@ void preview_window(const char *what, const char *tk_win_path, const char *filen /* save some relevant global context */ save_window = window; + save_save_pixmap = save_pixmap; save_mod = modified; save_ev = event_reporting; event_reporting = 0; @@ -803,15 +805,13 @@ void preview_window(const char *what, const char *tk_win_path, const char *filen show_pin_net_names = 0; my_strdup(117, &saveptr, tclgetvar("current_dirname")); - /* dbg(0, "preview_window(): %d %d %d %d\n", areax1, areay1, areaw, areah); */ /* preview */ check_version = 0; /* if set refuse to load and preview anything if not a rel 1.1+ xschem file */ /* if not set heuristics is done in xschem.tcl to ensure it is an xschem file */ load_schematic(1,filename, 0); window = pre_window; - resetwin(); + resetwin(1, 0); zoom_full(1, 0); /* draw */ - /* dbg(0, "preview_window(): %d %d %d %d\n", areax1, areay1, areaw, areah); */ check_version = 0; /* restore context */ @@ -826,12 +826,22 @@ void preview_window(const char *what, const char *tk_win_path, const char *filen xctx = save_xctx; /* restore schematic */ modified = save_mod; set_modify(modified); - + /* free the pixmap used for preview */ +#ifdef __unix__ + XFreePixmap(display,save_pixmap); +#else + Tk_FreePixmap(display, save_pixmap); +#endif window = save_window; - resetwin(); - /* dbg(0, "preview_window(): %d %d %d %d\n", areax1, areay1, areaw, areah); */ + save_pixmap = save_save_pixmap; + /* reset window, but don't delete and create a pixmap since we + have preserved the main window pixmap and already erased the preview pixmap + the goal of this complicated pixmap saving is to avoid a draw() call in the main window + to regenerate the save_pixmap every time user browses a new symbol */ + resetwin(0, 0); change_linewidth(-1.); - /* draw(); */ /* not needed: event loop takes care of this. */ + /* not needed: event loop takes care of this and don't need to regenerate save_pixmap. */ + /* draw(); */ event_reporting = save_ev; } else if(!strcmp(what, "destroy")) { @@ -1164,15 +1174,14 @@ int Tcl_AppInit(Tcl_Interp *inter) tclsetvar("menu_tcl_debug",debug_var ? "1" : "0" ); if(flat_netlist) tclsetvar("flat_netlist","1"); - lw=1; xschem_w = CADWIDTH; xschem_h = CADHEIGHT; - areaw = CADWIDTH+4*lw; /* clip area extends 1 pixel beyond physical window area */ - areah = CADHEIGHT+4*lw; /* to avoid drawing clipped rectangle borders at window edges */ - areax1 = -2*lw; - areay1 = -2*lw; - areax2 = areaw-2*lw; - areay2 = areah-2*lw; + areaw = CADWIDTH+4*INT_WIDTH(xctx->lw); /* clip area extends 1 pixel beyond physical window area */ + areah = CADHEIGHT+4*INT_WIDTH(xctx->lw); /* to avoid drawing clipped rectangle borders at window edges */ + areax1 = -2*INT_WIDTH(xctx->lw); + areay1 = -2*INT_WIDTH(xctx->lw); + areax2 = areaw-2*INT_WIDTH(xctx->lw); + areay2 = areah-2*INT_WIDTH(xctx->lw); xrect[0].x = 0; xrect[0].y = 0; xrect[0].width = CADWIDTH; diff --git a/src/xschem.h b/src/xschem.h index 42f02f1b..269139e1 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -318,6 +318,9 @@ do { \ } \ } while(0) \ +#define INT_WIDTH(x) ( (int)(x) == 0 ? 1 : (int)(x) ) +#define INT_BUS_WIDTH(x) ( (int)( (BUS_WIDTH) * (x) ) == 0 ? 1 : (int)( (BUS_WIDTH) * (x) ) ) + typedef struct { unsigned short type; @@ -503,6 +506,7 @@ typedef struct { double xorigin,yorigin; double zoom; double mooz; + double lw; } Xschem_ctx; struct Lcc { /* used for symbols containing schematics as instances (LCC, Local Custom Cell) */ @@ -616,9 +620,6 @@ extern int tcp_port; extern int debug_var; extern char **color_array; extern unsigned int color_index[]; -extern int lw; /* line width */ -extern int bus_width; /* line width */ -extern double lw_double; /* line width */ extern int change_lw; /* allow change line width */ extern int thin_text; extern int incr_hilight; @@ -814,7 +815,7 @@ extern int Tcl_AppInit(Tcl_Interp *interp); extern int source_tcl_file(char *s); extern int callback(int event, int mx, int my, KeySym key, int button, int aux, int state); -extern void resetwin(void); +extern void resetwin(int create_pixmap, int clear_pixmap); extern void find_closest_net(double mx,double my); extern void find_closest_box(double mx,double my); extern void find_closest_arc(double mx,double my);