Example #1
0
int Text(char *text, int top, int bottom, int left, int right, int edge)
{
    R_set_window(top, bottom, left, right);
    R_move_abs(left + edge, bottom - edge);
    R_text(text);
    R_set_window(SCREEN_TOP, SCREEN_BOTTOM, SCREEN_LEFT, SCREEN_RIGHT);

    return 0;
}
Example #2
0
int do_text(char *buff)
{
    char *ptr;

    ptr = buff;
    /* skip to beginning of actual text */
    for (; *ptr != ' '; ptr++) ;
    for (; *ptr == ' '; ptr++) ;
    R_text(ptr);

    return 0;
}
Example #3
0
static int dotext(char *text, int top, int bottom, int left, int right,
		  int centered)
{
    R_text_size(text_size, text_size);
    R_move_abs(left + 1 + edge, bottom - 1 - edge);
    if (centered)
	R_move_rel((right - left - strlen(text) * size) / 2, 0);
    R_set_window(top, bottom, left, right);	/* for text clipping */
    R_text(text);
    R_set_window(SCREEN_TOP, SCREEN_BOTTOM, SCREEN_LEFT, SCREEN_RIGHT);

    return 0;
}
Example #4
0
int draw_scale(char *save, int toptext, int size)
{
    double meters;
    double line_len;
    int incr;
    int x_pos, y_pos;
    int t, b, l, r;
    int pt, pb, pl, pr;
    int i;
    int xarr[5], yarr[5];
    double seg_len;
    const struct scale *scales = all_scales[use_feet];

    /* Establish text size */
    D_get_screen_window(&t, &b, &l, &r);
    R_set_window(t, b, l, r);
    R_text_size(size, size);

    x_pos = (int)(east * (r - l) / 100.);
    y_pos = (int)(north * (b - t) / 100.);

    if (draw == 1) {
	int w, h;

	w = 30;
	h = 17 + 2 * w;

	pl = x_pos;
	pt = y_pos;
	pr = x_pos + w + 2;	/* 1 pixel margin for both sides */
	pb = y_pos + h + 2;	/* 1 pixel margin for both sides */

	if (save)
	    R_panel_save(save, pt, pb, pl, pr);

	if (do_background) {
	    D_raster_use_color(color1);

	    R_box_abs(pl, pt, pr, pb);
	}
	/* Draw legend */
	D_raster_use_color(color2);

	R_move_abs(pl + w / 2 + 1, pt + 17 + 1);
	xarr[0] = 0;
	yarr[0] = 0;
	xarr[1] = -w / 2;
	yarr[1] = 2 * w;
	xarr[2] = w / 2;
	yarr[2] = -w / 2;
	xarr[3] = 0;
	yarr[3] = -1.5 * w;
	R_polyline_rel(xarr, yarr, 4);

	xarr[1] = -xarr[1];
	xarr[2] = -xarr[2];
	R_polygon_rel(xarr, yarr, 4);

	/* actual text width is 81% of size? from d.legend */
	R_move_abs((int)(pl + w / 2 - 7 * .81), pt + 14);
	R_text("N");

	R_stabilize();

	return 0;
    }

    meters = D_get_u_east() - D_get_u_west();
    meters *= G_database_units_to_meters_factor();

    /* find the right scale */
    for (incr = 0; incr < NUMSCALES; incr++) {
	if (meters <= scales[incr].limit)
	    break;
    }

    if (!incr)
	return (-1);

    /* beyond the maximum just make the longest scale narrower */
    if (incr >= NUMSCALES)
	incr = NUMSCALES - 1;

    line_len = D_get_u_to_d_xconv() * scales[incr].size
	/ G_database_units_to_meters_factor();
    seg_len = line_len / scales[incr].seg;
    /* work around round off */
    line_len = ((int)seg_len) * scales[incr].seg;

    /* Blank out area with background color */
    if (toptext) {
	pr = x_pos + 35 + (int)line_len;
	pt = y_pos - 15;
	if (pt < t)
	    pt = t;
    }
    else {
	pr = x_pos + 35 + (int)line_len + size * strlen(scales[incr].name);
	pt = y_pos + 0;
	if (pt < t)
	    pt = t;
    }
    pb = y_pos + 30;
    if (pb > b)
	pb = b;
    pl = x_pos + 0;
    if (pl < l)
	pl = l;
    pr = pr;
    if (pr > r)
	pr = r;

    if (save)
	R_panel_save(save, pt, pb, pl, pr);

    if (do_background) {
	D_raster_use_color(color1);

	R_box_abs(pl, pt, pr, pb);
    }

    /* Draw legend */
    D_raster_use_color(color2);

    if (draw != 2) {
	R_move_abs(x_pos + 5, y_pos + 20);
	R_cont_rel(0, -10);
	R_cont_rel(10, 10);
	R_cont_rel(0, -10);
	R_move_rel(-5, 14);
	R_cont_rel(0, -17);
	R_cont_rel(-2, -0);
	R_cont_rel(2, -2);
	R_cont_rel(2, 2);
	R_cont_rel(-2, -0);
    }

    if (draw == 2) {
	R_move_abs(x_pos + 25 - draw * 10, y_pos + 17);
	/* actual width is line_len-1+1=line_len and height is 7+1=8 */
	R_cont_rel((int)line_len - 1, 0);
	R_cont_rel(0, -7);
	R_cont_rel((int)(line_len * -1 + 1), 0);
	R_cont_rel(0, 7);
	R_move_rel(0, 1 - 4);
	for (i = 1; i <= scales[incr].seg; i++) {
	    xarr[0] = 0;
	    yarr[0] = 0;
	    xarr[1] = (int)seg_len;
	    yarr[1] = 0;
	    xarr[2] = 0;
	    yarr[2] = (i % 2 ? -4 : 4);
	    xarr[3] = (int)-seg_len;
	    yarr[3] = 0;
	    xarr[4] = 0;
	    yarr[4] = (i % 2 ? 4 : -4);
	    /* width is seg_len and height is 4 */
	    R_polygon_rel(xarr, yarr, 4);
	    R_move_rel((int)seg_len, 0);
	}
    }
    else if (do_bar) {
	R_move_abs(x_pos + 25, y_pos + 17);
	/* actual width is line_len-1+1=line_len and height is 4+1=5 */
	R_cont_rel((int)line_len - 1, 0);
	R_cont_rel(0, -4);
	R_cont_rel((int)(line_len * -1 + 1), 0);
	R_cont_rel(0, 4);
	R_move_rel(0, 1);
	for (i = 1; i <= scales[incr].seg; i += 2) {
	    /* width is seg_len and height is 5 */
	    R_box_rel((int)seg_len, -5);
	    R_move_rel((int)(seg_len * 2), 0);
	}
    }
    else {			/* draw simple line scale */
	R_move_abs(x_pos + 25, y_pos + 5);
	R_cont_abs(x_pos + 25, y_pos + 25);
	R_move_abs(x_pos + 25, y_pos + 15);
	R_cont_abs(x_pos + 25 + (int)line_len, y_pos + 15);
	R_move_abs(x_pos + 25 + (int)line_len, y_pos + 5);
	R_cont_abs(x_pos + 25 + (int)line_len, y_pos + 25);
    }

    if (toptext) {
	R_move_abs(x_pos + 25 - draw * 10 +
		   (int)(line_len / 2. -
			 strlen(scales[incr].name) * size * 0.81 / 2), y_pos);
	R_text(scales[incr].name);
    }
    else {
	R_move_abs(x_pos + 35 - draw * 10 + (int)line_len, y_pos + 20);
	R_text(scales[incr].name);
    }

    R_stabilize();

    return (0);
}
Example #5
0
int draw_slice(struct Colors *colors, int fill_flag, DCELL fill_color1, DCELL fill_color2, int txt_color, double cx, double cy, double r,	/* in normalized coords. */
	       double a1, double a2	/* in degrees */
    )
{
    int tt, tb, tr, tl;
    int height, width;
    int yoffset, xoffset;
    int x[1000], y[1000];
    int lx, ly;
    int i = 1;
    char txt[512];
    double arc, arc_incr = 0.01;
    DCELL fill_color;

    D_get_screen_window(&tt, &tb, &tl, &tr);

    height = tb - tt;
    width = tr - tl;
    yoffset = tb;
    xoffset = tl;

    while (a2 / arc_incr > 998)
	arc_incr *= 2;

    x[0] = (int)((double)xoffset + cx * (double)width);
    y[0] = (int)((double)yoffset - cy * (double)height);

    arc = a1;
    if (fill_flag && fill_color1 != fill_color2) {
	i = 1;
	while (arc <= (a1 + a2)) {
	    fill_color = fill_color1 + (arc - a1) *
		(fill_color2 - fill_color1) / a2;
	    x[i] = x[0] + r * (width) * cos(arc / 57.296);
	    y[i] = y[0] - r * (height) * sin(arc / 57.296);
	    if (i == 2) {
		D_d_color(fill_color, colors);
		R_polygon_abs(x + i - 2, y + i - 2, 3);
		x[i - 1] = x[i];
		y[i - 1] = y[i];
	    }
	    else
		i++;
	    arc = arc + arc_incr;
	}
    }
    else {
	i = 1;
	while (arc <= (a1 + a2)) {
	    x[i] = x[0] + r * (width) * cos(arc / 57.296);
	    y[i] = y[0] - r * (height) * sin(arc / 57.296);
	    i++;
	    arc = arc + arc_incr;
	}

	if (!fill_flag) {
	    R_standard_color(txt_color);
	    R_polyline_abs(x, y, i);
	}
	else {
	    D_d_color(fill_color1, colors);
	    R_polygon_abs(x, y, i);
	}
    }

    if (a2 > 15.0) {
	/* draw a label */
	arc = a1 + a2 / 2;
	sprintf(txt, "%2.0f%s", (double)(a2 / (double)360.0) * (double)100.0,
		percent);
	R_get_text_box(txt, &tt, &tb, &tl, &tr);
	lx = x[0] + (r + 0.03) * (width) * cos(arc / 57.296) - (tr - tl) / 2;
	ly = y[0] - (r + 0.03) * (height) * sin(arc / 57.296) + (tb - tt) / 2;
	R_move_abs(lx, ly);
	R_standard_color(txt_color);
	R_text(txt);
    }

    return 0;
}