Exemplo n.º 1
0
int do_color(char *buff)
{
    char in_color[64];
    int R, G, B, color = 0;

    if (1 != sscanf(buff, "%*s %s", in_color)) {
	G_warning(_("Unable to read color"));
	return (-1);
    }

    /* Parse and select color */
    color = G_str_to_color(in_color, &R, &G, &B);
    if (color == 0) {
	G_warning(_("[%s]: No such color"), in_color);
	/* store for backup */
	last_color.a = RGBA_COLOR_NONE;
	return (-1);
    }
    if (color == 1) {
	R_RGB_color(R, G, B);
	/* store for backup */
	set_last_color(R, G, B, RGBA_COLOR_OPAQUE);
    }
    if (color == 2) {		/* color == 'none' */
	R = D_translate_color(DEFAULT_BG_COLOR);
	R_standard_color(R);
	/* store for backup */
	set_last_color(0, 0, 0, RGBA_COLOR_NONE);
    }
    return (0);
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
    struct GModule *module;
    struct Option *opt1, *opt2;
    struct Flag *mapcoords;
    int R, G, B, color = 0;

    /* Initialize the GIS calls */
    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("display"));
    G_add_keyword(_("cartography"));
    module->description =
	_("Program for generating and displaying simple graphics on the "
	  "display monitor.");

    opt1 = G_define_option();
    opt1->key = "input";
    opt1->type = TYPE_STRING;
    opt1->required = NO;
    opt1->description = _("Name of file containing graphics commands, "
			  "if not given reads from standard input");
    opt1->gisprompt = "old_file,file,input";

    opt2 = G_define_option();
    opt2->key = "color";
    opt2->type = TYPE_STRING;
    opt2->required = NO;
    opt2->description = _("Color to draw with, either a standard GRASS color "
			  "or R:G:B triplet");
    opt2->answer = DEFAULT_FG_COLOR;
    opt2->gisprompt = "old_color,color,color";

    mapcoords = G_define_flag();
    mapcoords->key = 'm';
    mapcoords->description = _("Coordinates are given in map units");

    /* Check command line */
    if (G_parser(argc, argv))
	exit(EXIT_FAILURE);

    /* default font scaling: 5% of active frame */
    hsize = vsize = 5.;

    if (opt1->answer != NULL) {
	if ((infile = fopen(opt1->answer, "r")) == NULL)
	    G_fatal_error(_("Graph file <%s> not found"), opt1->answer);
    }
    else
	infile = stdin;

    /* open graphics window */
    if (D_open_driver() != 0)
	G_fatal_error(_("No graphics device selected. "
			"Use d.mon to select graphics device."));
    
    /* Parse and select color */
    if (opt2->answer != NULL) {
	color = G_str_to_color(opt2->answer, &R, &G, &B);

	if (color == 0)
	    G_fatal_error(_("[%s]: No such color"), opt2->answer);

	if (color == 1) {
	    D_RGB_color(R, G, B);
	    set_last_color(R, G, B, RGBA_COLOR_OPAQUE);
	}
	else			/* (color==2) is "none" */
	    set_last_color(0, 0, 0, RGBA_COLOR_NONE);
    }

    if (mapcoords->answer) {
	mapunits = TRUE;
	D_setup(0);
    }
    else {
	D_setup2(0, 0, 100, 0, 0, 100);
	mapunits = FALSE;
    }

    /* Do the graphics */
    set_graph_stuff();
    set_text_size();
    graphics(infile);

    D_save_command(G_recreate_command());
    D_close_driver();

    exit(EXIT_SUCCESS);
}