Ejemplo n.º 1
0
static void paint_animation(void)
{
    static int pos = 620;
    static int ini = 0;
    static GrContext *grc;
    int ltext, wtext;

    if (!ini) {
	grc = GrCreateContext(620, 30, NULL, NULL);
	if (grc == NULL)
	    return;
	ini = 1;
    }

    grt_left.txo_fgcolor.v = CYAN;
    grt_left.txo_font = grf_std;
    ltext = strlen(animatedtext);
    wtext = GrStringWidth(animatedtext, ltext, &grt_left);

    GrSetContext(grc);
    GrClearContext(DARKGRAY);
    GrDrawString(animatedtext, ltext, pos, 15, &grt_left);
    GrSetContext(grcglob);
    GrBitBlt(NULL, 10, 8, grc, 0, 0, 629, 29, GrWRITE);

    pos -= 1;
    if (pos <= -wtext)
	pos = 620;
}
Ejemplo n.º 2
0
static void TestFunc(void)
{
  int  x = GrSizeX();
  int  y = GrSizeY();
  int  ww = (x / 2) - 10;
  int  wh = (y / 2) - 10;
  GrColor c;

  GrContext *w1 = GrCreateSubContext(5, 5, ww+4, wh+4, NULL, NULL);
  GrContext *w2 = GrCreateSubContext(15+ww, 5, ww+ww+14, wh+4, NULL, NULL);
  GrContext *w3 = GrCreateSubContext(5, 15+wh, ww+4, wh+wh+14, NULL, NULL);
  GrContext *w4 = GrCreateSubContext(15+ww, 15+wh, ww+ww+14, wh+wh+14, NULL, NULL);

  GrSetContext(w1);
  c = GrAllocColor(200, 100, 100);
  drawing(0, 0, ww, wh, c, GrBlack());
  GrBox(0, 0, ww-1, wh-1, c);

  GrSetContext(w2);
  c = GrAllocColor(100, 200, 200);
  drawing(0, 0, ww, wh, c, GrBlack());
  GrBox(0, 0, ww-1, wh-1, c);

  GrSetContext(w3);
  c = GrAllocColor(200, 200, 0);
  drawing(0, 0, ww, wh, c, GrBlack());
  GrBox(0, 0,ww-1, wh-1, c);

  GrSetContext(w4);
  c = GrAllocColor(0, 100, 200);
  drawing(0, 0, ww, wh, c, GrBlack());
  GrBox(0, 0, ww-1, wh-1, c);

  GrSetContext(NULL);
}
Ejemplo n.º 3
0
static void draw_special(void)
{
    int xpos  = MSCURSOR->xcord;
    int ypos  = MSCURSOR->ycord;
    int check = MOUINFO->docheck;
    GrContext csave;

    MOUINFO->docheck = FALSE;
    GrSaveContext(&csave);
    GrSetContext(SCRN);
    switch (CURSORMODE) {
    case GR_M_CUR_RUBBER:
        GrBox(xpos, ypos, MOUINFO->x1, MOUINFO->y1, MOUINFO->curscolor);
        break;
    case GR_M_CUR_LINE:
        GrLine(xpos, ypos, MOUINFO->x1, MOUINFO->y1, MOUINFO->curscolor);
        break;
    case GR_M_CUR_BOX:
        GrBox((xpos+MOUINFO->x1), (ypos+MOUINFO->y1),
              (xpos+MOUINFO->x2), (ypos+MOUINFO->y2), MOUINFO->curscolor);
        break;
    }
    GrSetContext(&csave);
    MOUINFO->docheck = check;
}
Ejemplo n.º 4
0
int GrSaveContextToPgm( GrContext *grc, char *pgmfn, char *docn )
{
  FILE *f;
  GrContext grcaux;
  char cab[81];
  unsigned char grey;
  int rgb[3];
  int x, y;

  if( (f = fopen( pgmfn,"wb" )) == NULL ) return -1;
  
  GrSaveContext( &grcaux );
  if( grc != NULL ) GrSetContext( grc );
  sprintf( cab,"P5\n#" );
  fwrite( cab,1,strlen( cab ),f );
  if( docn != NULL ) fwrite( docn,1,strlen( docn ), f );
  sprintf( cab,"\n%d %d\n255\n",GrSizeX(),GrSizeY() );
  fwrite( cab,1,strlen( cab ),f );
  for( y=0; y<GrSizeY(); y++ )
    for( x=0; x<GrSizeX(); x++ ){
      GrQueryColor( GrPixel( x,y ),&rgb[0],&rgb[1],&rgb[2] );
      grey = (0.229 * rgb[0]) + (0.587 * rgb[1]) + (0.114 * rgb[2]);
      fwrite( &grey,1,1,f );
      }
  GrSetContext( &grcaux );
  fclose( f );

  return 0;
}
Ejemplo n.º 5
0
void ws_bmdrawtext(struct ws_bitmap *bm, int x, int y, int w, const char *txt,
                   GrColor fg,
                   GrColor bg)
{
    char buffer[256];
    int clen = ws_charstrlen(w);


    my_assert(txt != NULL);

    if (clen > 255) {
        clen = 255;
    }

    strncpy(buffer, txt, clen);
    buffer[clen] = 0;

    if (strlen(buffer) == 0) {
        return;
    }

    ws_private.textopt.txo_bgcolor.v = bg == -1 ? GrOR : bg;
    ws_private.textopt.txo_fgcolor.v = fg;
    GrSetContext( (GrContext *)bm->bitmap );
    GrDrawString(buffer, strlen(buffer), x, y, &ws_private.textopt);
    GrSetContext(NULL);
}
Ejemplo n.º 6
0
int GrSaveContextToPpm( GrContext *grc, char *ppmfn, char *docn )
{
  FILE *f;
  GrContext grcaux;
  char cab[81];
  unsigned char brgb[3];
  int x, y, r, g, b;

  if( (f = fopen( ppmfn,"wb" )) == NULL ) return -1;
  
  GrSaveContext( &grcaux );
  if( grc != NULL ) GrSetContext( grc );
  sprintf( cab,"P6\n#" );
  fwrite( cab,1,strlen( cab ),f );
  if( docn != NULL ) fwrite( docn,1,strlen( docn ), f );
  sprintf( cab,"\n%d %d\n255\n",GrSizeX(),GrSizeY() );
  fwrite( cab,1,strlen( cab ),f );
  for( y=0; y<GrSizeY(); y++ )
    for( x=0; x<GrSizeX(); x++ ){
      GrQueryColor( GrPixel( x,y ),&r,&g,&b );
      brgb[0] = r;
      brgb[1] = g;
      brgb[2] = b;
      fwrite( brgb,1,3,f );
      }
  GrSetContext( &grcaux );
  fclose( f );

  return 0;
}
Ejemplo n.º 7
0
void GrClearScreen(GrColor bg)
{
    GrContext save;
    GrSaveContext(&save);
    GrSetContext(SCRN);
    GrClearContext(bg);
    GrSetContext(&save);
}
Ejemplo n.º 8
0
/* Draw a line with color c to bitmap bm. */
void ws_bmdrawline(struct ws_bitmap *bm, int x1, int y1, int x2, int y2,
                   int c,
                   int xor)
{
    GrSetContext( (GrContext *)bm->bitmap );
    GrLine( x1, y1, x2, y2, c | (xor ? GrXOR : 0) );
    GrSetContext(NULL);
}
Ejemplo n.º 9
0
int GrSaveContextToPng( GrContext *grc, char *pngfn )
{
  GrContext grcaux;
  FILE *f;
  int r;
  
  f = fopen( pngfn,"wb" );
  if( f == NULL ) return -1;

  GrSaveContext( &grcaux );
  if( grc != NULL ) GrSetContext( grc );
  r = writepng( f,grc );
  GrSetContext( &grcaux );

  fclose( f );

  return r;
}
Ejemplo n.º 10
0
int GrLoadContextFromPng( GrContext *grc, char *pngfn, int use_alpha )
{
  GrContext grcaux;
  FILE *f;
  int r;
  
  f = fopen( pngfn,"rb" );
  if( f == NULL ) return -1;

  GrSaveContext( &grcaux );
  if( grc != NULL ) GrSetContext( grc );
  r = readpng( f,grc,use_alpha );
  GrSetContext( &grcaux );

  fclose( f );

  return r;
}
Ejemplo n.º 11
0
/* Create bitmap with bm inside. */
struct ws_bitmap *ws_createbitmap(int xsize, int ysize, char *bm) {
    GrContext *gc;
    struct ws_bitmap *bmap;
    char *mem[4];


    if (bm != NULL) {
        mem[0] = bm;
        mem[1] = mem[2] = mem[3] = NULL;
    }

    if ( xsize < 0 || ysize < 0 || xsize > GrSizeX() || ysize > GrSizeY() ) {
        return NULL;
    }

    if ( ( bmap = MALLOC( sizeof(struct ws_bitmap) ) ) == NULL ) {
        return NULL;
    }

    if ( ( gc =
              GrCreateContext(xsize, ysize, bm != NULL ? mem : NULL,
                              NULL) ) == NULL ) {
        FREE(bmap);
        return NULL;
    }

    if (bm == NULL) {
        GrSetContext(gc);
        GrClearContext(notes.colindex[cv_winfill]);
        GrSetContext(NULL);
    }

    bmap->bitmap = (void *)gc;
    bmap->xpos = 0;
    bmap->ypos = 0;
    bmap->xsize = xsize;
    bmap->ysize = ysize;
    bmap->w = NULL;
    return bmap;
}
Ejemplo n.º 12
0
int GrSaveContextToPbm( GrContext *grc, char *pbmfn, char *docn )
{
  FILE *f;
  GrContext grcaux;
  char cab[81];
  int currentbyte = 0, currentbit = 7;
  int x, y;

  if( (f = fopen( pbmfn,"wb" )) == NULL ) return -1;
  
  GrSaveContext( &grcaux );
  if( grc != NULL ) GrSetContext( grc );
  sprintf( cab,"P4\n#" );
  fwrite( cab,1,strlen( cab ),f );
  if( docn != NULL ) fwrite( docn,1,strlen( docn ), f );
  sprintf( cab,"\n%d %d\n",GrSizeX(),GrSizeY() );
  fwrite( cab,1,strlen( cab ),f );
  for( y=0; y<GrSizeY(); y++ ){
    for( x=0; x<GrSizeX(); x++ ){
      if( GrPixel( x,y ) == GrBlack() )
        currentbyte |= 1 << currentbit;
      currentbit--;
      if( currentbit < 0 ){
        fwrite( &currentbyte,1,1,f );
        currentbyte = 0;
        currentbit = 7;
        }
      }
    if( currentbit < 7 ){
      fwrite( &currentbyte,1,1,f );
      currentbyte = 0;
      currentbit = 7;
      }
    }
  GrSetContext( &grcaux );
  fclose( f );

  return 0;
}
Ejemplo n.º 13
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);
    }
}
Ejemplo n.º 14
0
/* Clear the bitmap (fill it with color c) */
void ws_clearbitmap(struct ws_bitmap *b, int c) {
    GrSetContext( (GrContext *)b->bitmap );
    GrClearContext(c);
    GrSetContext(NULL);
}
Ejemplo n.º 15
0
int main(void)
{
    GrContext *pContext;
    int sizex = 40;
    int sizey = 40;
    int x = 0;
    int y = 40;
    GrColor fcolor, bcolor;
    int k;
    GrEvent ev;

    GrSetMode(GR_default_graphics);
    GrEventInit();
    GrMouseDisplayCursor();
    /* Create a 1bpp bitmap */
    pContext = GrCreateFrameContext(GR_frameRAM1, sizex, sizey, NULL, NULL);
    /* draw something (black and white) into the bitmap */
    GrSetContext(pContext);
    GrClearContext(GrBlack());
    GrLine(0, 0, sizex-1, sizey-1, GrWhite());
    GrLine(0, sizey-1, sizex-1, 0, GrWhite());

    GrSetContext(NULL);
    fcolor = GrAllocColor(255, 0, 0);
    bcolor = GrAllocColor(0, 0, 255);
    GrTextXY(0, 0, "Type u d l r U D L R to move, 1 2 to change color, q to quit",
           GrWhite(), GrNOCOLOR);
    GrSetClipBox(0, 40, GrScreenX(), GrScreenY());

    /* Put the bitmap into the screen */
    GrBitBlt1bpp(NULL, x, y, pContext, 0, 0, sizex-1, sizey-1, fcolor, bcolor);

    while (1) {
        k = '\0';
        GrEventWait(&ev);
        if (ev.type == GREV_KEY) k = ev.p1;
        if (k == 'q') break;
        switch (k) {
            case 'u': y--; break;
            case 'd': y++; break;
            case 'l': x--; break;
            case 'r': x++; break;
            case 'U': y -= 10; break;
            case 'D': y += 10; break;
            case 'L': x -= 10; break;
            case 'R': x += 10; break;
            case '1': fcolor = GrAllocColor(255, 0, 0);
                      bcolor = GrAllocColor(0, 0, 255);
                      break;
            case '2': fcolor = GrAllocColor(0, 255, 255);
                      bcolor = GrAllocColor(255, 255, 0);
                      break;
            default:  continue;
        }
        if (x < -40) x = -40;
        if (x > GrScreenX()) x = GrScreenX();
        if (y < 0) y = 0;
        if (y > GrScreenY()) y = GrScreenY();
        GrBitBlt1bpp( NULL, x, y, pContext, 0, 0, sizex-1, sizey-1, fcolor, bcolor);
    }

    /* Destroy */
    GrDestroyContext(pContext);

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