Exemple #1
0
void
x11_cplot(const XDpy * dpy, XAnim * anim,
	int x, int y, uint w, uint h,
	double *adata, double *rdata, int l,
	const char *atitle, const char *rtitle)
{
  int j;
  int wm1, hm1;			/* actual dimensions of plot area */
  int lm1;			/* actual span of x-data is(l-1 - 0) */
  double amin, amax, aspan;
  double rmin, rmax, rspan;
  vec2s p[l];
  double gstep, gfirsti, glasti;	/* r grid step, first and last */
  /* use integer indexing to prevent arithmetic roundoff in loop */
  uint gi;		/* r grid line index */
  uint gn;		/* number of r grid lines */
  uint pad;
  color_t grid;

  /* looks cool with a black background */
  x11_setFG(dpy, &anim->win, COLOR_BLACK);
  x11_fRect(dpy, anim, x, y, w, h);

  pad = 48;

  /* draw titles */
  x11_setFG(dpy, &anim->win, COLOR_WHITE);
  x11_setFont(dpy, &anim->win, dpy->hdr_fnt);
/*      x11_fTextA(dpy, anim, x+w/2, y+h-pad/2, atitle, 'c', 'c', 0); */
/*      x11_fTextA(dpy, anim, x+pad/2, y+pad/2, rtitle, 'l', 'c', 0); */

  x += pad;
  y += pad;
  if (w < 2 * pad) {
    w = 0;
  } else {
    w -= 2 * pad;
  }
  if (h < 2 * pad) {
    h = 0;
  } else {
    h -= 2 * pad;
  }

  wm1 = w - 1;
  hm1 = h - 1;
  lm1 = l - 1;

  /* draw plotarea frame */
  grid = COLOR_GRAY(128);
  x11_setFG(dpy, &anim->win, grid);
  x11_setDefaultLn(dpy, &anim->win);
  x11_dRect(dpy, anim, x, y, wm1, hm1);

  if (l < 2) {
    return;
  }

  /* get extremes and spans */
  darray_extremes(adata, l, &amin, &amax);
  aspan = amax - amin;
  darray_extremes(rdata, l, &rmin, &rmax);
  rspan = rmax - rmin;

  /* grid settings */
  x11_setFont(dpy, &anim->win, dpy->nrm_fnt);

  /* calculate and draw a grid */
  gstep = M_2PI / 16;
  gfirsti = 0.0;
  glasti = 0.0;
  gn = 16;
  for (gi = 0; gi < gn; gi++) {
    char buf[32];
    /* rounding is needed because of round-off error in expression */
    double val = (double) gi * gstep;
    int xi, yi;
    int x1, y1;
    int x2, y2;

    xi = (int) ROUND((double) wm1 * cos(val));
    yi = -(int) ROUND((double) hm1 * sin(val));
    x1 = x + (wm1 + 0) / 2;
    y1 = y + (hm1 + 0) / 2;
    x2 = x + (wm1 + xi) / 2;
    y2 = y + (hm1 + yi) / 2;

    x11_setFG(dpy, &anim->win, grid);
    x11_dLine(dpy, anim, x1, y1, x2, y2);

    xi = (int) ROUND((double) (23 + wm1) * cos(val));
    yi = -(int) ROUND((double) (23 + hm1) * sin(val));
    x2 = x + (wm1 + xi) / 2;
    y2 = y + (hm1 + yi) / 2;

    snprintf(buf, sizeof(buf), "%.1f", val * 360 / M_2PI);
    x11_setFG(dpy, &anim->win, COLOR_WHITE);
    x11_fTextA(dpy, anim, x2, y2,
	     buf, strlen(buf), 'c', 'c', 0);
  }

  /* calculate and draw r grid */
  gen_axticksd(&gstep, &gfirsti, &glasti, &gn, rmin, rmax);
  for (gi = 0; gi < gn; gi++) {
    char buf[32];
    /* rounding is needed because of round-off error in expression */
    double val = ((double) gi + gfirsti) * gstep;
    int wi = (int) ROUND((double) wm1 * ((val - rmin) / rspan));
    int hi = (int) ROUND((double) hm1 * ((val - rmin) / rspan));

    x11_setFG(dpy, &anim->win, grid);
    x11_dEll(dpy, anim, x + (wm1 - wi) / 2, y + (hm1 - hi) / 2, wi, hi);

    snprintf(buf, sizeof(buf), "%g", val);
    x11_setFG(dpy, &anim->win, COLOR_WHITE);
    x11_fTextA(dpy, anim, x + (wm1 + wi) / 2, y + hm1 / 2,
	     buf, strlen(buf), 'c', 'c', 0);
  }

  /* calculate plot */
  for (j = 0; j < l; j++) {
    /* round is needed because of roundoff-errors operations */
    int xpos, ypos;

    xpos = (int) ROUND((double) wm1 * (rdata[j] - rmin) / rspan *
		       cos(adata[j]));
    p[j].x = x + 0 + (wm1 + xpos) / 2;

    ypos = (int) ROUND((double) hm1 * (rdata[j] - rmin) / rspan *
		       sin(adata[j]));
    p[j].y = y + hm1 - (hm1 + ypos) / 2;
  }

  /* draw plot */
  x11_setFG(dpy, &anim->win, COLOR_GREEN);
  x11_setDefaultLn(dpy, &anim->win);
  x11_dLines(dpy, anim, p, l);

}
Exemple #2
0
void
x11_plot(const XDpy * dpy, XAnim * anim,
	 int x, int y, uint w, uint h,
	 double *xdat, double *ydat, int l,
	 double xmin, double xmax,
	 double ymin, double ymax,
	 const char *xtitle, const char *ytitle)
{
  int j;
  int wm1, hm1;			/* actual dimensions of plot area */
  int lm1;			/* actual span of x-data is(l-1 - 0) */
  vec2s p[l];
  double gstep, gfirsti, glasti;	/* y grid step, first and last */
  /* use integer indexing to prevent arithmetic roundoff in loop */
  uint gi;		/* y grid line index */
  uint gn;		/* number of y grid lines */
  uint pad;
  int use_tmpx;
  color_t grid;

  /* looks cool with a black background */
  x11_setFG(dpy, &anim->win, COLOR_BLACK);
  x11_fRect(dpy, anim, x, y, w, h);

  pad = 48;

  /* draw titles */
  x11_setFG(dpy, &anim->win, COLOR_WHITE);
  x11_setFont(dpy, &anim->win, dpy->hdr_fnt);
  x11_fTextA(dpy, anim, x + w / 2, y + h - pad / 2,
	   xtitle, strlen(xtitle), 'c', 'c', 0);
  x11_fTextA(dpy, anim, x + pad / 2, y + pad / 2,
	   ytitle, strlen(ytitle), 'l', 'c', 0);

  x += pad;
  y += pad;
  if (w < 2 * pad) {
    w = 0;
  } else {
    w -= 2 * pad;
  }
  if (h < 2 * pad) {
    h = 0;
  } else {
    h -= 2 * pad;
  }

  wm1 = w - 1;
  hm1 = h - 1;
  lm1 = l - 1;

  /* draw plotarea frame */
  grid = COLOR_GRAY(128);
  x11_setFG(dpy, &anim->win, grid);
  x11_setDefaultLn(dpy, &anim->win);
  x11_dRect(dpy, anim, x, y, wm1, hm1);

  if (l < 2) {
    return;
  }

  /* if necessary, create temporary x buffer */
  if (xdat == NULL) {
    use_tmpx = TRUE;
    xdat = (double*)malloc(l * sizeof(double));
    darray_ramp(xdat, l, 0.0, 1.0);	/* default data to [0, 1, ..., l-1] */
  } else {
    use_tmpx = FALSE;
  }

  /* grid settings */
  x11_setFont(dpy, &anim->win, dpy->nrm_fnt);

  double xspan = xmax - xmin;
  double yspan = ymax - ymin;

  /* calculate and draw x grid */
  gen_axticksd(&gstep, &gfirsti, &glasti, &gn, xmin, xmax);
  for (gi = 0; gi < gn; gi++) {
    char buf[32];
    /* rounding is needed because of round-off error in expression */
    double val = ((double) gi + gfirsti) * gstep;
    int pos = x + (int) ROUND((double) wm1 * ((val - xmin) / xspan));

    snprintf(buf, sizeof(buf), "%g", val);
    x11_setFG(dpy, &anim->win, COLOR_WHITE);
    x11_fTextA(dpy, anim, pos, y + hm1 + 4,
	     buf, strlen(buf), 'c', 't', 0);

    x11_setFG(dpy, &anim->win, grid);
    x11_dLine(dpy, anim, pos, y, pos, y + hm1);
  }

  /* calculate and draw y grid */
  gen_axticksd(&gstep, &gfirsti, &glasti, &gn, ymin, ymax);
  for (gi = 0; gi < gn; gi++) {
    char buf[32];
    /* rounding is needed because of round-off error in expression */
    double val = ((double) gi + gfirsti) * gstep;
    int pos = y + hm1 - (int) ROUND((double) hm1 * ((val - ymin) / yspan));

    snprintf(buf, sizeof(buf), "%g", val);
    x11_setFG(dpy, &anim->win, COLOR_WHITE);
    x11_fTextA(dpy, anim, x - 3, pos,
	     buf, strlen(buf), 'r', 'c', 0);

    x11_setFG(dpy, &anim->win, grid);
    x11_dLine(dpy, anim, x, pos, x + wm1, pos);
  }

  /* calculate plot */
  for (j = 0; j < l; j++) {
    /* round is needed because of roundoff-errors operations */
    int xpos, ypos;

    xpos = (int) ROUND((double) wm1 * (xdat[j] - xmin) / xspan);
    p[j].x = x + xpos;

    /*  p[j].x = x + j * wm1 / lm1; */
    ypos = (int) ROUND((double) hm1 * (ydat[j] - ymin) / yspan);
    p[j].y = y + hm1 - ypos;
  }

  if (use_tmpx) {
    free(xdat);
  }

  /* draw plot */
  x11_setFG(dpy, &anim->win, COLOR_GREEN);
  x11_setDefaultLn(dpy, &anim->win);
  x11_dLines(dpy, anim, p, l);

}
static MENU_UPDATE_FUNC(mrc_dump_update_all)
{
    if (!info->can_custom_draw) return;
    info->custom_drawing = CUSTOM_DRAW_THIS_MENU;
    bmp_fill(COLOR_BLACK, 0, 0, 720, 480);

    int skip = (mrc_dump_page - 1) * (450 / font_large.height);
    int k = 0;
    int y = 0;
    int printed = 0;

    for(int pos = 0; pos < COUNT(cp_regs); pos++)
    {
        char *str = cp_regs[pos].desc;

        if(!str)
        {
            break;
        }

        k++;
        if (k <= skip)
        {
            continue;
        }

        mrc_cp = cp_regs[pos].cp;
        mrc_crn = cp_regs[pos].crn;
        mrc_op1 = cp_regs[pos].op1;
        mrc_crm = cp_regs[pos].crm;
        mrc_op2 = cp_regs[pos].op2;
        mrc_dump_process();

        printed = 1;

        if(k%2)
        {
            bmp_fill(COLOR_GRAY(10), 0, y, 720, font_large.height);
        }

        int yasm = y + font_small.height;
        bmp_printf(
            SHADOW_FONT(FONT_SMALL), 10, y,
            "%s", str
        );

        bmp_printf(
            SHADOW_FONT(FONT_MED), 10, yasm,
            "MRC p%d, %d, Rd, c%d, c%d, %d",
            mrc_cp, mrc_op1, mrc_crn, mrc_crm, mrc_op2
        );

        bmp_printf(
            SHADOW_FONT(FONT(FONT_LARGE, COLOR_YELLOW, COLOR_BLACK)),
            720 - 8*font_large.width, y,
            "%8x",
            mrc_value
        );

        y += font_large.height;

        if (y > 440)
        {
            bmp_printf(FONT(FONT_MED, COLOR_CYAN, COLOR_BLACK), 710 - 7*font_med.width, y, "more...");
            break;
        }
    }
    if (!printed)
    {
        mrc_dump_page = 1;
    }
}