⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xreticle.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
    return((((double)q)*den) - num);  }}/******************************************************************//*   here is the code to draw into pixwins (of canvases) *//******************************************************************/#ifdef PW_PLOTstatic void do_x_numbers(x,r,xp,pw)     Pixwin *pw;     double x;     Reticle *r;     register int xp;{  int	xloc, yloc,	font_height = def_font_height,    	font_width = def_font_width;  char	temp[100], *p;  sprintf(temp,r->abscissa.precision,x);  p = temp;  while(*p == ' ') p++;  xloc = xp - ((strlen(p) * font_width)/2);  if(r->abscissa.num_loc & NUM_LB) {    yloc = r->bounds.bottom + font_height;    pw_text(pw, xloc, yloc,	    PIX_COLOR(r->color)|(PIX_SRC /*^PIX_DST*/ ), def_font, p);  }  if(r->abscissa.num_loc & NUM_RT) {    yloc = r->bounds.top - (font_height/4);    pw_ttext(pw, xloc, yloc,	     PIX_COLOR(r->color)|(PIX_SRC /*^PIX_DST*/ ), def_font, p);  }}/******************************************************************/static void do_x_label(r,pw)     Pixwin *pw;     Reticle *r;{  int	xloc, yloc;  int	font_height = def_font_height,    	font_width = def_font_width;  char	temp[100];  if(r->abs_label) {    sprintf(temp,"%s",r->abs_label);    xloc = (r->bounds.right + r->bounds.left  - (strlen(temp) * font_width))/2;    yloc = r->bounds.bottom + font_height;    if(r->abscissa.num_loc & NUM_LB) yloc += (font_height + 1);    pw_text(pw, xloc, yloc,	    PIX_COLOR(r->color)|(PIX_SRC /*^PIX_DST*/ ), def_font, temp);  }} /******************************************************************/static void do_y_numbers(y,r,yp,pw)     Pixwin *pw;     double y;     Reticle *r;     register int yp;{  int	xloc, yloc;  int	font_height = def_font_height,    	font_width = def_font_width, pop;  extern major_lines;  char	temp[100], *p;  sprintf(temp,r->ordinate.precision,y);  p = temp;  while(*p == ' ') p++;  yloc = yp + (font_height/4);  if(r->ordinate.num_loc & NUM_LB) {    xloc = r->bounds.left - (strlen(p) * font_width) - (font_width/2);    pw_text(pw, xloc, yloc,	    PIX_COLOR(r->color)|(PIX_SRC /*^PIX_DST*/ ), def_font, p);    if (major_lines) {    	pop = PIX_COLOR(r->color)|(PIX_SRC /*^PIX_DST*/ );    	pw_vector(pw, r->bounds.left, yp, r->bounds.right, yp, pop, 1);    }  }  if(r->ordinate.num_loc & NUM_RT) {    xloc = r->bounds.right + (font_width/2);    pw_text(pw, xloc, yloc,	    PIX_COLOR(r->color)|(PIX_SRC /*^PIX_DST*/ ), def_font, p);  }}/******************************************************************/reticle_set_absc_precision(r,form)     Reticle *r;     char *form;{  if(r) {    if(!(form && *form)) {      if(r->abscissa.precision)	free(r->abscissa.precision);      r->abscissa.precision = NULL;      return;    }    if(! r->abscissa.precision)      r->abscissa.precision = savestring(form);    else {      if(strlen(form) > strlen(r->abscissa.precision)) {	free(r->abscissa.precision);	r->abscissa.precision = savestring(form);      } else	strcpy(r->abscissa.precision, form);    }  }}/******************************************************************/reticle_set_ord_precision(r,form)     Reticle *r;     char *form;{  if(r) {    if(!(form && *form)) {      if(r->ordinate.precision)	free(r->ordinate.precision);      r->ordinate.precision = NULL;      return;    }    if(! r->ordinate.precision)      r->ordinate.precision = savestring(form);    else {      if(strlen(form) > strlen(r->ordinate.precision)) {	free(r->ordinate.precision);	r->ordinate.precision = savestring(form);      } else	strcpy(r->ordinate.precision, form);    }  }}/******************************************************************/draw_reticle(canvas, r)    Canvas canvas;    Reticle *r;{  double	pix_x, pix_y, x, y, dx, dy, xmint, ymint, xe, xb, ye, yb,		xdel, ydel;  register int	i, j, k, nx, ny;  int		*ed, *ma, *mi1, *mi2, *maa, *mi2a, *mi1a, maxl, mi1xl, mi2xl,		mayl, mi1yl, mi2yl,		*get_absc_marklist(), *get_ord_marklist(), xp, yp, pop, *im[3];  Pixwin	*pw;  extern int	reticle_grid;  LocVal	*list;  int		num;  if(! (canvas && r)) return(FALSE);  xdel = (r->absc.end - r->absc.start);  ydel = (r->ordi.end - r->ordi.start);  if(xdel == 0.0) xdel = 1.0;  if(ydel == 0.0) ydel = 1.0;  pix_x = ((double)(r->bounds.right - r->bounds.left))/xdel;  pix_y = ((double)(r->bounds.bottom - r->bounds.top))/ydel;  maxl = oneormore(.5 + r->abscissa.maj.length * pix_y);  mi1xl = oneormore(.5 + r->abscissa.min1.length * pix_y);  mi2xl = oneormore(.5 + r->abscissa.min2.length * pix_y);  xb = r->absc.start;  xe = r->absc.end;  yb = r->ordi.start;  ye = r->ordi.end;    pw = canvas_pixwin(canvas);  pop = PIX_COLOR(r->color)|(PIX_SRC /*^PIX_DST*/ );    /* draw a box around the exterior of the data display area */  pw_vector(pw, r->bounds.left - 1, r->bounds.bottom + 1,	    r->bounds.right + 1, r->bounds.bottom + 1, pop,1);  pw_vector(pw, r->bounds.right + 1, r->bounds.bottom,	    r->bounds.right + 1, r->bounds.top - 1, pop,1);  pw_vector(pw, r->bounds.right, r->bounds.top - 1,	    r->bounds.left, r->bounds.top - 1, pop,1);  pw_vector(pw, r->bounds.left - 1, r->bounds.top,	    r->bounds.left - 1, r->bounds.bottom, pop,1);  /* ordinate numbering */  if ((ymint = r->ordinate.num_inter) > 0.0)  {      ydel =  myfmod(yb, ymint);      y = yb;      if(ydel > (ymint * .0001)) {        if(yb >= 0.0) y += (ymint - ydel);        else y += ydel;      }      while(y <= ye) {        yp = r->bounds.bottom - (int) (((y - yb) * pix_y) + .5);        do_y_numbers(y, r, yp, pw);        y += ymint;      }  }  else if (list = r->ordinate.maj.list)  {      num = r->ordinate.maj.num;      for (i = 0; i < num; i++)	  do_y_numbers(list[i].val, r, list[i].loc, pw);  }  /* abscissa numbering */  if (((xmint = r->abscissa.num_inter) > 0.0) &&      (r->abscissa.num_loc & NUM_BOTH))  {    xdel = myfmod(xb, xmint);    x = xb;    if(xdel > (xmint * .0001)) {      if(xb >= 0.0) x += (xmint - xdel);      else x += xdel;    }    while(x < xe) {      xp = r->bounds.left + (int) (((x - xb) * pix_x) + .5);      do_x_numbers(x,r,xp,pw);      x += xmint;    }  }  do_x_label(r,pw);		/* apply abscissa label */      if((ed = get_ord_marklist(r,EDGES))) { /* ordinate marks at ends of plot */    for(i = 0, j = 1; i < *ed; i++, j += 3) {      yp = ed[j+2];      pw_vector(pw, r->bounds.left, yp,		r->bounds.left + ed[j+1], yp, pop, 1);      pw_vector(pw, r->bounds.right - ed[j+1], yp,		r->bounds.right, yp, pop, 1);    }  }  /* get ordinate marks to place on interior of plot */  ma = get_ord_marklist(r,MAJOR);  mi1 = get_ord_marklist(r,MINOR1);  mi2 = get_ord_marklist(r,MINOR2);  maa = get_absc_marklist(r,MAJOR);  mi1a = get_absc_marklist(r,MINOR1);  mi2a = get_absc_marklist(r,MINOR2);    pw = canvas_pixwin(canvas);  pop = PIX_COLOR(r->color)|(PIX_SRC /*^PIX_DST*/ );  if ((xmint = r->abscissa.min2.inter) > 0.0      || (xmint = r->abscissa.min1.inter) > 0.0      || (xmint = r->abscissa.maj.inter) > 0.0)  {    if(xb >= 0.0) x = r->absc.start + xmint - myfmod(r->absc.start,xmint);    else x = r->absc.start + myfmod(r->absc.start,xmint);    xdel =  .9999 * xmint;    while(x < xe) {      if(myfmod(x,r->abscissa.maj.inter) < xdel) {	xp = r->bounds.left + (int) (((x - xb) * pix_x) + .5);	if((r->abscissa.maj.style & EDGES)) {	  pw_vector(pw, xp, r->bounds.bottom,		    xp, (int)r->bounds.bottom - maxl, pop, 1);	  pw_vector(pw, xp, r->bounds.top,		    xp, (int)r->bounds.top + maxl, pop, 1);	}	central_marks( ma, maa, xp, pop, pw);      } else {	if(myfmod(x,r->abscissa.min1.inter) < xdel) {	  xp = r->bounds.left + (int) (((x - xb) * pix_x) + .5);	  if((r->abscissa.min1.style & EDGES)) {	    pw_vector(pw, xp, r->bounds.bottom,		      xp, (int)r->bounds.bottom - mi1xl, pop, 1);	    pw_vector(pw, xp, r->bounds.top,		      xp, (int)r->bounds.top + mi1xl, pop, 1);	  }	  central_marks( mi1, mi1a, xp, pop, pw);	} else {	  xp = r->bounds.left + (int) (((x - xb) * pix_x) + .5);	  if((r->abscissa.min2.style & EDGES)) {	    pw_vector(pw, xp, r->bounds.bottom,		      xp, (int)r->bounds.bottom - mi2xl, pop, 1);	    pw_vector(pw, xp, r->bounds.top,		      xp, (int)r->bounds.top + mi2xl, pop, 1);	  }	  central_marks( mi2, mi2a, xp, pop, pw);	}      }      x += xmint;    }  }  if(mi1)free(mi1);		/* free up scratch arrays */  if(mi2)free(mi2);  if(ma)free(ma);  if(mi1a)free(mi1a);  if(mi2a)free(mi2a);  if(maa)free(maa);  if(ed)free(ed);  return(TRUE);}/******************************************************************/static void central_marks( yloco, yloca, xp, pop, pw)     Pixwin *pw;     register int *yloco, *yloca, xp, pop;{  register int yp, i, j, k, *p;  extern int do_central_marks;	    if(do_central_marks) {   if(yloco) {			/* draw ordinate marks at this x-position */    for(i = 0, j = 1; i < *yloco; i++, j += 3) {      yp = yloco[j+2];      pw_vector(pw, xp + yloco[j], yp,		xp + yloco[j+1], yp, pop, 1);    }   }   if(yloca) {			/* draw abscissa marks for this position */    for(i = 0, j = 1; i < *yloca; i++, j += 2) {      pw_vector(pw, xp, yloca[j], xp, yloca[j+1], pop, 1);    }   }  }}#endif/******************************************************************/static int *get_ord_marklist(r, where)    Reticle *r;    int	    where;{    double  pix_x, pix_y, y, ydel, ymint, yb, ye;    int	    mayhl, mi1yhl, mi2yhl, *p, *q, nmarks, i, length;    LocVal  *list;    pix_x = ((double)(r->bounds.right - r->bounds.left))/		(r->absc.end - r->absc.start);    pix_x *= 0.5;    mi2yhl = (r->ordinate.min2.style & where)	     ? oneormore(.5 + (r->ordinate.min2.length * pix_x))	     : 0;    mi1yhl = (r->ordinate.min1.style & where)	     ? oneormore(.5 + (r->ordinate.min1.length * pix_x))	     : mi2yhl;    mayhl = (r->ordinate.maj.style & where)	    ? oneormore(.5 + (r->ordinate.maj.length * pix_x))	    : mi1yhl;    if (mayhl == 0) return NULL;    if (list = r->ordinate.maj.list)    {/*!*//* Elaborate when we do variably spaced minor ticks. */	nmarks = r->ordinate.maj.num;	if (nmarks <= 0) return NULL;	p = (int *) malloc(sizeof(int) * ((nmarks+1) * 3 + 1));	*p = 0;	q = p + 1;	length = mayhl;	for (i = 0; i < nmarks; i++)	{	    *q++ = -length;	    *q++ = length;	    *q++ = list[i].loc;	    *p += 1;	}	return p;    }    else    if ((ymint = r->ordinate.min2.inter) > 0.0	|| (ymint = r->ordinate.min1.inter) > 0.0	|| (ymint = r->ordinate.maj.inter) > 0.0)    {	nmarks = (r->ordi.end - r->ordi.start)/ymint;	if (nmarks <= 0) return (NULL);          pix_y = ((double)(r->bounds.bottom - r->bounds.top))/		    (r->ordi.end - r->ordi.start);        yb = r->ordi.start;        ye = r->ordi.end;	p = (int *) malloc(sizeof(int) * ((nmarks+1) * 3 + 1));	*p = 0;	q = p + 1;	ydel =  .9999 * ymint;	for (y = (yb >= 0.0) ? yb + (ymint - myfmod(yb, ymint))			     : yb + myfmod(yb, ymint);	     y < ye; y += ymint)	{	    length = (myfmod(y, r->ordinate.maj.inter) < ydel) ? mayhl		     : (myfmod(y,r->ordinate.min1.inter) < ydel) ? mi1yhl		     : mi2yhl;	    if (length)	    {		*q++ = -length;		*q++ = length;		*q++ = r->bounds.bottom - (int) ((y - yb) * pix_y + .5);		*p += 1;	    }	}	return p;    }    return NULL;}/******************************************************************/static int *get_absc_marklist(r, where)    Reticle *r;    int	    where;{    double  pix_y, y, dy, ymint, yb, ye;    int	    maxhl, mi1xhl, mi2xhl, majl, min1l, min2l;    int	    *p, *q, nmarks, i, length, yp;    LocVal  *list;    if (r->ordi.end - r->ordi.start == 0)	pix_y = DBL_MAX;    else        pix_y = ((double)(r->bounds.bottom - r->bounds.top))/    		(r->ordi.end - r->ordi.start);    maxhl = oneormore(.5 + (r->abscissa.maj.length * pix_y * .5));    mi1xhl = oneormore(.5 + (r->abscissa.min1.length * pix_y * .5));    mi2xhl = oneormore(.5 + (r->abscissa.min2.length * pix_y * .5));    majl = (r->abscissa.maj.style & MAJOR & where) ? maxhl	   : ((r->abscissa.min1.style & MAJOR)	      && ((MAJOR | MINOR1) & where)) ? mi1xhl	   : (r->abscissa.min2.style & MAJOR) ? mi2xhl	   : 0;    min1l = ((r->abscissa.maj.style & MINOR1) && (MAJOR & where)) ? maxhl	    : ((r->abscissa.min1.style & MINOR1)	       && ((MAJOR | MINOR1) & where)) ? mi1xhl	    : (r->abscissa.min2.style & MINOR1) ? mi2xhl	    : 0;    min2l = ((r->abscissa.maj.style & MINOR2) && (MAJOR & where)) ? maxhl	    : ((r->abscissa.min1.style & MINOR2)	       && ((MAJOR | MINOR1) & where)) ? mi1xhl	    : (r->abscissa.min2.style & MINOR2) ? mi2xhl	    : 0;    if (list = r->ordinate.maj.list)    {/*!*//* Elaborate when we do variably spaced minor ticks. */	nmarks = r->ordinate.maj.num;	if (nmarks <= 0) return NULL;	p = (int *) malloc(sizeof(int) * ((nmarks+1) * 2 + 1));	*p = 0;	q = p + 1;	length = majl;	if (length)	    for (i = 0; i < nmarks; i++)	    {		yp = list[i].loc;		*q++ = yp - length;		*q++ = yp + length;		*p += 1;	    }	return p;    }    else    if ((ymint = r->ordinate.min2.inter) > 0.0	|| (ymint = r->ordinate.min1.inter) > 0.0	|| (ymint = r->ordinate.maj.inter) > 0.0)    {      nmarks = (r->ordi.end - r->ordi.start)/ymint;	if (nmarks <= 0) return (NULL);  	yb = r->ordi.start;	ye = r->ordi.end;	p = (int *) malloc(sizeof(int) * ((nmarks+1) * 2 + 1));	*p = 0;	q = p + 1;	for (y = (yb >= 0.0) ? yb + (ymint - myfmod(yb, ymint))			    : yb + myfmod(yb, ymint);	     y < ye;	     y += ymint)	{	    length = (myfmod(y, r->ordinate.maj.inter) < ymint) ? majl		     : (myfmod(y, r->ordinate.min1.inter) < ymint) ? min1l		     : min2l;	    if (length)	    {		yp = r->bounds.bottom - (int) ((y - yb) * pix_y + .5);		*q++ = yp - length;		*q++ = yp + length;		*p += 1;	    }	  }	return p;    }    return NULL;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -