Пример #1
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 */
    }
}
Пример #2
0
static void revert(void)
{
	GrColor color;

	color = opt.txo_fgcolor.v;
	opt.txo_fgcolor.v = opt.txo_bgcolor.v | (color & GR_UNDERLINE_TEXT);
	opt.txo_bgcolor.v = color & ~GR_UNDERLINE_TEXT;
	GrClearScreen(color);
	curx = cury = 0;
}
Пример #3
0
static void gnewl(void)
{
	cury += GrCharHeight('A', &opt) + deltay;
	curx = 0;
	if(cury + GrCharHeight('A', &opt) > GrSizeY() + deltay) {
//	    if(GrKeyRead() == GrKey_F10) {
//		GrUnloadFont(opt.txo_font);
//		exit(0);
//	    }
	    GrClearScreen(opt.txo_bgcolor.v);
	    cury = 0;
	}
}
Пример #4
0
static void ini_graphics(void)
{
    gfaz_ini(gwidth, gheight, gbpp);
    gwidth = GrScreenX();
    gheight = GrScreenY();
    grcglob = NULL;
    if (gwidth > 640 || gheight > 480) {
	GrClearScreen(GrAllocColor(120, 90, 60));
	worg = (gwidth - 640) / 2;
	horg = (gheight - 480) / 2;
        grcglob = GrCreateSubContext(worg, horg, worg + 639, horg + 479,
                                     NULL, NULL);
	GrSetContext(grcglob);
    }
}
Пример #5
0
void drawellip(int xc,int yc,int xa,int ya,GrColor c1,GrColor c2,GrColor c3)
{
    double ddx = (double)xa;
    double ddy = (double)ya;
    double R2 = ddx*ddx*ddy*ddy;
    double SQ;
    int x1,x2,y1,y2;
    int dx,dy;
    int *wdt, idx;
    GrLineOption *l;
    GrEvent ev;

    for (idx = 0, l = *Patterns; l != NULL; l = Patterns[++idx])
        for (wdt=widths; *wdt != 0; ++wdt) {
            GrClearScreen(GrBlack());

            GrFilledBox(xc-xa,yc-ya,xc+xa,yc+ya,c1);
            dx = xa;
            dy = 0;
            GrPlot(xc-dx,yc,c3);
            GrPlot(xc+dx,yc,c3);
            while(++dy <= ya) {
                SQ = R2 - (double)dy * (double)dy * ddx * ddx;
                dx = (int)(sqrt(SQ)/ddy + 0.5);
                x1 = xc - dx;
                x2 = xc + dx;
                y1 = yc - dy;
                y2 = yc + dy;
                GrPlot(x1,y1,c3);
                GrPlot(x2,y1,c3);
                GrPlot(x1,y2,c3);
                GrPlot(x2,y2,c3);
            }
            GrSleep(100);

            l->lno_color = c2;
            l->lno_width = *wdt;
            GrCustomEllipse(xc,yc,xa,ya,l);
            GrEventRead(&ev);
            if(ev.type == GREV_KEY && ev.p1 == 'q') {
                stop = 1;
                return;
            }
            GrSleep(100);
        }
}
Пример #6
0
/* Initialize Grfx-Mode&Mouse.Try to use xres,yres,colors and font <fontname>.
   If you are successful, return a 1.
   If you can't initialize this mode, return a 0. */
int ws_initgrfx(int xres, int yres, int colors, const char *fontname) {
    static char pixels[2];
/* unsigned char value; 
    Why?  -jgk*/
    GrBitmap pat_bm = {
        0, 2, pixels, 1, 0, 0
    };


    if ( ( ws_private.textopt.txo_font =
              GrLoadFont( (char *)(fontname == NULL ?
                                   DEFAULT_FONT :
                                   fontname) ) ) == NULL ) {
        fprintf(errf, "Can't find font %s\n", fontname);
        return 0;
    }

    if ( !GrSetMode(GR_width_height_color_graphics, xres, yres, colors) ) {
        fprintf(errf, "Can't set grfx-mode. Try to load VESA-driver\n");
        return 0;
    }

    if (GrSizeX() != xres || GrSizeY() != yres) {
        fprintf(errf, "Can't set grfx-mode. Try to load VESA-driver\n");
        return 0;
    }

    GrClearScreen(0);

    if ( !GrMouseDetect() ) {
        fprintf(errf, "Can't find mouse\n");
        return 0;
    }

    GrMouseInit();
    GrMouseSetColors(255, 0);
    GrMouseDisplayCursor();
    pixels[0] = 0x79;   /* Prevent compiler warning for now */
    pixels[1] = 0x55;
    ws_private.pat_box.gp_bitmap = pat_bm;
/* value=_farpeekb(0x40,0x17);
   _farpokeb(0x40,0x17,value^0x20); */
    return 1;
}
Пример #7
0
int main(void)
{
    GrContext *grc;
    int wide, high, maxval;
    char s[81];
    GrEvent ev;

    /*GrSetMode( GR_default_graphics ); */
    GrSetMode(GR_width_height_color_graphics, 640, 480, 32768);
    GrEventInit();
    GrMouseDisplayCursor();
    GrQueryPnm(FIMAGEPPM, &wide, &high, &maxval);
    sprintf(s, "%s %d x %d pixels", FIMAGEPPM, wide, high);
    GrTextXY(10, 20, s, GrBlack(), GrWhite());
    GrBox(10, 40, 10+wide+1, 40+high+1, GrWhite());
    grc = GrCreateSubContext(11, 41, 11+wide-1, 41+high-1, NULL, NULL);
    GrLoadContextFromPnm(grc, FIMAGEPPM);
    GrSaveContextToPgm(grc, FIMAGEPGM, "TestPnm");
    GrDestroyContext(grc);
    GrTextXY(10, 50+high, "Press RETURN to continue", GrBlack(), GrWhite());
    GrEventWaitKeyOrClick(&ev);

    GrClearScreen(GrBlack());
    GrQueryPnm(FIMAGEPGM, &wide, &high, &maxval);
    sprintf(s, "%s %d x %d pixels", FIMAGEPGM, wide, high);
    GrTextXY(10, 20, s, GrBlack(), GrWhite());
    GrBox(10, 40, 10+wide+1, 40+high+1, GrWhite());
    grc = GrCreateSubContext(11, 41, 11+wide-1, 41+high-1, NULL, NULL);
    GrLoadContextFromPnm(grc,FIMAGEPGM);
    GrDestroyContext(grc);
    GrTextXY(10, 50+high, "Press RETURN to continue", GrBlack(), GrWhite());
    GrEventWaitKeyOrClick(&ev);

    GrClearScreen(GrBlack());
    GrQueryPnm(FIMAGEPBM, &wide, &high, &maxval);
    sprintf(s, "%s %d x %d pixels", FIMAGEPBM, wide, high);
    GrTextXY(10, 20, s, GrBlack(), GrWhite());
    GrBox(10, 40, 10+wide+1, 40+high+1, GrWhite());
    grc = GrCreateSubContext(11, 41, 11+wide-1, 41+high-1, NULL, NULL);
    GrLoadContextFromPnm(grc,FIMAGEPBM);
    GrSaveContextToPbm(grc, FIMAGEPBM2, "TestPnm");
    GrDestroyContext(grc);
    GrTextXY(10, 50+high, "Press RETURN to continue", GrBlack(), GrWhite());
    GrEventWaitKeyOrClick(&ev);

    GrClearScreen(GrBlack());
    GrQueryPnm(FIMAGEPPM, &wide, &high, &maxval);
    GrBox(10, 40, 10+wide+1, 40+high+1, GrWhite());
    grc = GrCreateSubContext(11, 41, 11+wide-1, 41+high-1, NULL, NULL);
    GrLoadContextFromPnm(grc,FIMAGEPPM);
    GrDestroyContext(grc);
    GrQueryPnm(FIMAGEPGM, &wide, &high, &maxval);
    GrBox(110, 140, 110+wide+1, 140+high+1, GrWhite());
    grc = GrCreateSubContext(111, 141, 111+wide-1, 141+high-1, NULL, NULL);
    GrLoadContextFromPnm(grc, FIMAGEPGM);
    GrDestroyContext(grc);
    GrQueryPnm(FIMAGEPBM, &wide, &high, &maxval);
    GrBox(210, 240, 210+wide+1, 240+high+1, GrWhite());
    grc = GrCreateSubContext(211, 241, 211+wide-1, 241+high-1, NULL, NULL);
    GrLoadContextFromPnm(grc,FIMAGEPBM2);
    GrDestroyContext(grc);
    GrTextXY(10, 20, "Press RETURN to save screen", GrBlack(), GrWhite());
    GrEventWaitKeyOrClick(&ev);

    GrSaveContextToPpm(NULL, FSCREEN, "TestPnm");
    GrClearScreen(GrWhite());
    GrTextXY(10, 20, "Press RETURN to reload screen", GrWhite(), GrBlack());
    GrEventWaitKeyOrClick(&ev);

    GrLoadContextFromPnm(NULL, FSCREEN);
    GrTextXY(10, 20, "Press RETURN to end        ", GrBlack(), GrWhite());
    GrEventWaitKeyOrClick(&ev);

    GrEventUnInit();
    GrSetMode(GR_default_text);
    return 0;
}