Beispiel #1
0
/*
**	Open graphics
*/
static PSD
DJGR_open(PSD psd)
{
	int		x;
	int		y;
	int		c;
        GrVideoMode	*md_info;

	x = 640;
	y = 480;
	c = 256;

        GrSetMode(GR_width_height_color_graphics,x,y,c);

        md_info = (GrVideoMode *) GrCurrentVideoMode();

	psd->xres = psd->xvirtres = GrScreenX();
	psd->yres = psd->yvirtres = GrScreenY();
	psd->linelen = md_info->lineoffset;
	psd->planes = 1;
	psd->bpp = md_info->bpp;
	psd->ncolors = GrNumColors();
	psd->flags = PSF_SCREEN;
	psd->addr = 0;		/* FIXME */

	/* note: must change psd->pixtype here for truecolor systems*/
	psd->pixtype = MWPF_PALETTE;

	return psd;
}
Beispiel #2
0
void init_gnugraph()
{ int k;
  int c;    /* color, 0-15 */
  int g;    /* gray level, 0-15 */

  GrSetMode(GR_default_graphics);
  numcolors = GrNumColors();
  if ( (numcolors < 256) && color_flag )
      shading_flag = 0;  /* not enough for shading */
  
  /* first index background color */
  for ( c = 0 ; c < 16 ; c++ ) color_perm[c] = c;
  color_perm[background_color] = 0;
  color_perm[0] = background_color;
  
  if ( shading_flag && color_flag )
  { for ( c = 0 ; c < 16 ; c++ )
      for ( g = 0 ; g <= MAXGRAY ; g++ )
        GrSetColor(CINDEX(c,g),
         (int)(0xff*(g+12.)/(MAXGRAY+12.)*rgb_colors[c][0]), 
         (int)(0xff*(g+12.)/(MAXGRAY+12.)*rgb_colors[c][1]),
         (int)(0xff*(g+12.)/(MAXGRAY+12.)*rgb_colors[c][2]));
    }
    else if ( shading_flag ) /* shading */
    { for ( g = 0 ; g <= MAXGRAY ; g++ )
        GrSetColor(CINDEX(WHITE,g),
         (int)(0xff*(g+12.)/(MAXGRAY+12.)), 
         (int)(0xff*(g+12.)/(MAXGRAY+12.)),
         (int)(0xff*(g+12.)/(MAXGRAY+12.)));
    }
    else if ( color_flag )
    { for ( c = 0 ; c < 16 ; c++ )
        GrSetColor(CINDEX(c,MAXGRAY),
         (int)(0xff*rgb_colors[c][0]), 
         (int)(0xff*rgb_colors[c][1]),
         (int)(0xff*rgb_colors[c][2]));
    }

  if ( numcolors == 32768 )
     GrClearScreen(CINDEX(WHITE,MAXGRAY));
  else
  {  GrFreeColor(0);
      GrSetColor(0,(int)(0xff*rgb_colors[background_color][0]),
        (int)(0xff*rgb_colors[background_color][1]),
        (int)(0xff*rgb_colors[background_color][2]));
  }

  maxx = GrMaxX(); maxy = GrMaxY();
  if ( maxx/3 < maxy/3 )
    { xscale = maxx/3;
      yscale = xscale; /* assume square pixel screen */
    }
  else
    { yscale = maxy/3;
      xscale = yscale; /* assume square pixel screen */
    }
}
Beispiel #3
0
/* Make space for a pallette & make a 332 color map, if possible */
static void
pallette_init()
{
    unsigned i, r, g, b;

#ifdef GRX
    if (GrNumColors() != 256) {
 	GrSetColor(0, 0, 0, 0);
 	GrSetColor(1, 255, 255, 255);
 	return;
    }
#else
    if (pallette == NULL) {
	pallette = malloc(sizeof(pallette_array));
	if (pallette == NULL) {
	    fprintf(stderr, "Failed to allocate pallette array\n");
	    exit(1);
	}
    }
#endif

    i = 0;
    for (r=0;r<8;r++)
	for (g=0;g<8;g++)
	    for (b=0;b<4;b++) {
#ifdef GRX
		GrSetColor(i, r << 5, g << 5, b << 6);
#else
		(*pallette)[i][0] = r << 3;
		(*pallette)[i][1] = g << 3;
		(*pallette)[i][2] = b << 4;
#endif
		i++;
	    }
#ifndef GRX
    setmany(*pallette, 0, 256);
#endif
}
Beispiel #4
0
int main(int argc, char **argv)
{
	int i, n;
	char *s;
	char *bad = NULL;
	int c;

	int width = 0, height = 0, bpp = 8, gray = 192, attributes = 0;

	char *name, *testname;
	GrFontHeader *hdr;
	FILE *f;
	char buffer[210];
	GrEvent ev;
	int key;

	/* unfortunately not all systems support getopt() */
	for(i = 1; i < argc; i++) {
	    s = argv[i];
	    if(*s != '-' || ((c = *++s) == '\0') || *++s != '\0') break;
	    if(c == '-') {
		i++;
		break;
	    }
	    if(++i == argc) {
		fprintf(stderr, "-%c: argument required\n", c);
		return(1);
	    }
	    if(sscanf(argv[i], "%d", &n) != 1 || n < 0) {
		fprintf(stderr, "%s: invalid argument\n", argv[i]);
		exit(1);
	    }
	    switch(c) {
		case 'x' : width = n; break;
		case 'y' : height = n; break;
		case 'b' : if((bpp = n) < 2 || bpp > 32) bad = "bpp"; break;
		case 'g' : if((gray = n) > 255) bad = "gray"; break;
		case 'X' : if((deltax = n) > 31) bad = "deltax"; break;
		case 'Y' : if((deltax = n) > 31) bad = "deltay"; break;
		case 'a' : if((attributes = n) > 3) bad = "attributes"; break;
		default  : {
		    fprintf(stderr, "-%c: invalid option\n", c);
		    return(1);
		}
	    }
	    if(bad) {
		fprintf(stderr, "%d: %s out of range\n", n, bad);
		return(1);
	    }
	}

	if(i == argc) {
	    printf(
		"usage:\tfontdemo [-x WIDTH] [-y HEIGHT] [-b BPP] [-g COMPONENT]\n"
		      "\t[-X DELTAX] [-Y DELTAY] [-a ATTRIBUTES] FONT [FILE...]\n"
	    );
	    return(0);
	}

	name = argv[i++];
	opt.txo_font = GrLoadFont(name);
        if(opt.txo_font == NULL && (testname = malloc(strlen(name) + 10)) != NULL) {
            /* try again, this is a test and the path can not been set yet */
#if defined(__MSDOS__) || defined(__WIN32__)
            sprintf( testname,"..\\fonts\\%s",name );
#else
            sprintf( testname,"../fonts/%s",name );
#endif
            opt.txo_font = GrLoadFont(testname);
	    free(testname);
        }
	if(opt.txo_font == NULL) {
	    fprintf(stderr, "%s: load error\n", name);
	    return(1);
	}
	hdr = &opt.txo_font->h;

	if(height == 0) {
	    if(width == 0) {
		switch(hdr->height) {
		    case 8 :
		    case 14 : height = 400; break;
		    case 16 : height = 480; break;
		    case 20 : height = 600; break;
		    case 24 : height = 768; break;
		    default : height = hdr->height < 20 ? 480 : 768;
		}
	    }
	    else height = width * 3 / 4;
	}
	if(width == 0) width = height == 400 ? 640 : height * 4 / 3;

	GrSetMode(GR_width_height_bpp_graphics, width, height, bpp);
	if(!gray || (opt.txo_fgcolor.v = GrAllocColor(gray, gray, gray)) == GrNOCOLOR) opt.txo_fgcolor.v = GrWhite();
	if(attributes & 0x02) opt.txo_fgcolor.v |= GR_UNDERLINE_TEXT;
	opt.txo_bgcolor.v = GrBlack();
	if(attributes & 0x01) revert();
	opt.txo_chrtype = GR_BYTE_TEXT;
	opt.txo_direct = GR_TEXT_RIGHT;
	opt.txo_xalign = GR_ALIGN_LEFT;
	opt.txo_yalign = GR_ALIGN_TOP;

	sprintf(buffer, "Font name:%s %dx%d", hdr->name, GrCharWidth('A', &opt), GrCharHeight('A', &opt));
        if (hdr->proportional)
	    strcat(buffer, " proportional");
	else
	    strcat(buffer, " fixed");
	gputs(buffer);
	sprintf(buffer, "Font family: %s", hdr->family);
	gputs(buffer);
	sprintf(buffer, "Min char, num chars: %d, %d", hdr->minchar,hdr->numchars);
	gputs(buffer);
	sprintf(buffer, "Screen res: %dx%d@%lu", GrSizeX(), GrSizeY(), (unsigned long) GrNumColors());
	gputs(buffer);
	gnewl();

	gputs("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG");
	gputs("the quick brown fox jumps over the lazy dog");
	gnewl();

//	if(hdr->minchar <= 0xC0 && hdr->minchar + hdr->numchars >= 0x100) {
//	    gputs("������� ��� ���� ���� ��");
//	    gputs("������� ��� ���� ���� ��");
//	    gnewl();
//	}

	/* ascii table, or to be precise, a full table of the current font */
	opt.txo_chrtype = GR_WORD_TEXT;
	for(c = 0; c < hdr->numchars; c++) {
	    gputc(hdr->minchar + c);
	    if(c % 0x20 == 0x1F) gnewl();
	}
	gnewl();
	if(c % 0x20 != 0) gnewl();
	opt.txo_chrtype = GR_BYTE_TEXT;

	while(i < argc) {
	    name = argv[i++];
	    if((f = fopen(name, "r")) == NULL) {
		perror(name);
		return(1);
	    }
	    while((c = getc(f)) != EOF) if(c != '\n') gputc(c); else gnewl();
	    if(ferror(f) != 0 || fclose(f) != 0) {
		perror(name);
		return(1);
	    }
	}

	/* enter and esc are < 0x100 and displayed 1:1 */
	gputs("F1-new line  F5-toggle reverse  F7-toggle underline  F10-exit");
	gnewl();

	GrEventInit();
	while(1) {
	    GrEventWait(&ev);
	    if(ev.type == GREV_KEY) {
		key = ev.p1;
		if( key == GrKey_F10) break;
		if(key == GrKey_F1) gnewl();
		else if(key == GrKey_F5) revert();
		else if(key == GrKey_F7) opt.txo_fgcolor.v ^= GR_UNDERLINE_TEXT;
		else if(key < 0x100) gputc(key);
	    }
	}
	GrEventUnInit();

	GrUnloadFont(opt.txo_font);

	return(0);
}