void PaintCanvas::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { clickedToEndPath=false; //For mask drawing if (backgroundmaskpen){ if(maskpathnewpath){ maskpath.moveTo(event->pos()); maskpathnewpath=false; lastPoint = event->pos(); } maskpath.lineTo(event->pos()); drawLineTo(event->pos()); update(); } //For head and Tail marking if(markHead){ scribbling = true; lastPoint = event->pos(); //THEN SWITCH TO OTHER PEN } if(markTail){ scribbling = true; lastPoint = event->pos(); //THEN SWITCH TO OTHER PEN } //Default other drawing if(targetpen||backgroundpen) scribbling = true; lastPoint = event->pos(); } if (event->button()==Qt::RightButton&&backgroundmaskpen){ //Close off current path closepath(); } }
/* Finally the main colour smooth box drawing routine */ void draw_color_smooth_box(int plot_mode) { double tmp; FILE *out = gppsfile; /* either gpoutfile or PSLATEX_auxfile */ if (color_box.where == SMCOLOR_BOX_NO) return; if (!term->filled_polygon) return; /* firstly, choose some good position of the color box user's position like that (?): else { x_from = color_box.xlow; x_to = color_box.xhigh; } */ if (color_box.where == SMCOLOR_BOX_USER) { if (!is_3d_plot) { double xtemp, ytemp; map_position(&color_box.origin, &color_box.bounds.xleft, &color_box.bounds.ybot, "cbox"); map_position_r(&color_box.size, &xtemp, &ytemp, "cbox"); color_box.bounds.xright = xtemp; color_box.bounds.ytop = ytemp; } else if (splot_map && is_3d_plot) { /* In map view mode we allow any coordinate system for placement */ double xtemp, ytemp; map3d_position_double(&color_box.origin, &xtemp, &ytemp, "cbox"); color_box.bounds.xleft = xtemp; color_box.bounds.ybot = ytemp; map3d_position_r(&color_box.size, &color_box.bounds.xright, &color_box.bounds.ytop, "cbox"); } else { /* But in full 3D mode we only allow screen coordinates */ color_box.bounds.xleft = color_box.origin.x * (term->xmax) + 0.5; color_box.bounds.ybot = color_box.origin.y * (term->ymax) + 0.5; color_box.bounds.xright = color_box.size.x * (term->xmax-1) + 0.5; color_box.bounds.ytop = color_box.size.y * (term->ymax-1) + 0.5; } color_box.bounds.xright += color_box.bounds.xleft; color_box.bounds.ytop += color_box.bounds.ybot; } else { /* color_box.where == SMCOLOR_BOX_DEFAULT */ if (plot_mode == MODE_SPLOT && !splot_map) { /* HBB 20031215: new code. Constants fixed to what the result * of the old code in default view (set view 60,30,1,1) * happened to be. Somebody fix them if they're not right! */ color_box.bounds.xleft = xmiddle + 0.709 * xscaler; color_box.bounds.xright = xmiddle + 0.778 * xscaler; color_box.bounds.ybot = ymiddle - 0.147 * yscaler; color_box.bounds.ytop = ymiddle + 0.497 * yscaler; } else if (is_3d_plot) { /* MWS 09-Dec-05, make color box full size for splot maps. */ double dx = (X_AXIS.max - X_AXIS.min); map3d_xy(X_AXIS.max + dx * 0.025, Y_AXIS.min, base_z, &color_box.bounds.xleft, &color_box.bounds.ybot); map3d_xy(X_AXIS.max + dx * 0.075, Y_AXIS.max, ceiling_z, &color_box.bounds.xright, &color_box.bounds.ytop); } else { /* 2D plot */ struct position default_origin = {graph,graph,graph, 1.025, 0, 0}; struct position default_size = {graph,graph,graph, 0.05, 1.0, 0}; double xtemp, ytemp; map_position(&default_origin, &color_box.bounds.xleft, &color_box.bounds.ybot, "cbox"); color_box.bounds.xleft += color_box.xoffset; map_position_r(&default_size, &xtemp, &ytemp, "cbox"); color_box.bounds.xright = xtemp + color_box.bounds.xleft; color_box.bounds.ytop = ytemp + color_box.bounds.ybot; } /* now corrections for outer tics */ if (color_box.rotation == 'v') { int cblen = (CB_AXIS.tic_in ? -1 : 1) * CB_AXIS.ticscale * (term->h_tic); /* positive for outer tics */ int ylen = (Y_AXIS.tic_in ? -1 : 1) * Y_AXIS.ticscale * (term->h_tic); /* positive for outer tics */ if ((cblen > 0) && (CB_AXIS.ticmode & TICS_MIRROR)) { color_box.bounds.xleft += cblen; color_box.bounds.xright += cblen; } if ((ylen > 0) && (axis_array[FIRST_Y_AXIS].ticmode & TICS_MIRROR)) { color_box.bounds.xleft += ylen; color_box.bounds.xright += ylen; } } } if (color_box.bounds.ybot > color_box.bounds.ytop) { /* switch them */ tmp = color_box.bounds.ytop; color_box.bounds.ytop = color_box.bounds.ybot; color_box.bounds.ybot = tmp; } /* Optimized version of the smooth colour box in postscript. Advantage: only few lines of code is written into the output file. */ if (gppsfile) draw_inside_color_smooth_box_postscript(out); else draw_inside_color_smooth_box_bitmap(out); if (color_box.border) { /* now make boundary around the colour box */ if (color_box.border_lt_tag >= 0) { /* user specified line type */ struct lp_style_type lp = border_lp; lp_use_properties(&lp, color_box.border_lt_tag); term_apply_lp_properties(&lp); } else { /* black solid colour should be chosen, so it's border linetype */ term_apply_lp_properties(&border_lp); } newpath(); (term->move) (color_box.bounds.xleft, color_box.bounds.ybot); (term->vector) (color_box.bounds.xright, color_box.bounds.ybot); (term->vector) (color_box.bounds.xright, color_box.bounds.ytop); (term->vector) (color_box.bounds.xleft, color_box.bounds.ytop); (term->vector) (color_box.bounds.xleft, color_box.bounds.ybot); closepath(); /* Set line properties to some value, this also draws lines in postscript terminals. */ term_apply_lp_properties(&border_lp); } /* draw tics */ if (axis_array[COLOR_AXIS].ticmode) { term_apply_lp_properties(&border_lp); /* border linetype */ gen_tics(COLOR_AXIS, cbtick_callback ); } /* write the colour box label */ if (CB_AXIS.label.text) { int x, y; apply_pm3dcolor(&(CB_AXIS.label.textcolor),term); if (color_box.rotation == 'h') { int len = CB_AXIS.ticscale * (CB_AXIS.tic_in ? 1 : -1) * (term->v_tic); map3d_position_r(&(CB_AXIS.label.offset), &x, &y, "smooth_box"); x += (color_box.bounds.xleft + color_box.bounds.xright) / 2; #define DEFAULT_Y_DISTANCE 1.0 y += color_box.bounds.ybot + (- DEFAULT_Y_DISTANCE - 1.7) * term->v_char; #undef DEFAULT_Y_DISTANCE if (len < 0) y += len; if (x<0) x = 0; if (y<0) y = 0; write_multiline(x, y, CB_AXIS.label.text, CENTRE, JUST_CENTRE, 0, CB_AXIS.label.font); } else { int len = CB_AXIS.ticscale * (CB_AXIS.tic_in ? -1 : 1) * (term->h_tic); /* calculate max length of cb-tics labels */ widest_tic_strlen = 0; if (CB_AXIS.ticmode & TICS_ON_BORDER) { widest_tic_strlen = 0; /* reset the global variable */ gen_tics(COLOR_AXIS, /* 0, */ widest_tic_callback); } map3d_position_r(&(CB_AXIS.label.offset), &x, &y, "smooth_box"); #define DEFAULT_X_DISTANCE 0.0 x += color_box.bounds.xright + (widest_tic_strlen + DEFAULT_X_DISTANCE + 1.5) * term->h_char; #undef DEFAULT_X_DISTANCE if (len > 0) x += len; y += (color_box.bounds.ybot + color_box.bounds.ytop) / 2; if (x<0) x = 0; if (y<0) y = 0; if ((*term->text_angle)(CB_AXIS.label.rotate)) { write_multiline(x, y, CB_AXIS.label.text, CENTRE, JUST_TOP, CB_AXIS.label.rotate, CB_AXIS.label.font); (*term->text_angle)(0); } else { write_multiline(x, y, CB_AXIS.label.text, LEFT, JUST_TOP, 0, CB_AXIS.label.font); } } reset_textcolor(&(CB_AXIS.label.textcolor),term); } }
int main (int argc, char **argv) { char **text,**font,*textcolor,*boxcolor; float size,labelCD=0.0,labelCA,labelCW=0.0,labelCH,bigx,bigy,eps,eps2; float *x; int n,j,nsub; size_t nchar; /* Hook up getpars */ initargs(argc,argv); requestdoc(0); /* Get parameters */ if(!getparint("nsub",&nsub))nsub=0; if(!getparfloat("size",&size))size=30; if(!getparstring("tcolor",&textcolor))textcolor="black"; if(!getparstring("bcolor",&boxcolor))boxcolor="white"; checkpars(); eps=0.25*size; eps2=0.1*size; n=countparname("t"); if(n==0) err("must enter at least one PSTEXT text stream as parameter t"); if(n!=countparname("f")) warn("suggest specify same number of values for t and f"); text =(char **)malloc( (n+1)*sizeof(char *) ); font =(char **)malloc( (n+1)*sizeof(char *) ); x = (float *)malloc( (n+1)*sizeof(float) ); for(bigx=eps,bigy=0.,j=0;j<n;j++){ x[j]=bigx; if(!getnparstring(j+1,"t",&text[j]))text[j]="hello"; if(!getnparstring(j+1,"f",&font[j]))font[j]="Times-Bold"; labelCH = fontheight(font[j],size); labelCW = fontwidth(font[j],size); labelCA = fontascender(font[j],size); labelCD = MIN(labelCD,fontdescender(font[j],size)); nchar = strlen(text[j]); bigx+=0.5*(((double) nchar)*labelCW); bigy=MAX(bigy,labelCH+eps+0.0*labelCA); } bigx+=eps; bigx-=0.5*nsub*labelCW; /* open output eps file */ boundingbox(-eps2,-eps2,bigx+eps2,bigy+eps2); begineps(); gsave(); rectclip(0.,0.,bigx,bigy); /* fill background box with background color */ newpath(); moveto(0.,0.); lineto(bigx,0.); lineto(bigx,bigy); lineto(0.,bigy); closepath(); setcolor(boxcolor); fill(); /* write out text strings */ setcolor(textcolor); moveto(eps,eps-labelCD); for(j=0;j<n;j++) { setfont(font[j],size); show(text[j]); } /* close output stream */ grestore(); showpage(); endeps(); return EXIT_SUCCESS; }