/* Free complete structure bm (with the structure itself) */ void ws_freebitmap(struct ws_bitmap *bm) { my_assert(bm); if (bm->bitmap) { GrDestroyContext( (GrContext *)bm->bitmap ); } free(bm); }
static void paint_screen(void) { GrContext *grc; paint_board(&brd); paint_button_group(bgact); paint_board(&brdimg); grc = GrCreateSubContext(brdimg.x + 4, brdimg.y + 4, brdimg.x + brdimg.wide - 5, brdimg.y + brdimg.high - 5, grcglob, NULL); if (bgact == &bgp1) GrLoadContextFromPnm(grc, "pnmtest.ppm"); else GrLoadContextFromPnm(grc, "pnmtest2.ppm"); GrDestroyContext(grc); the_info(500, 215); drawing(400, 290, 200, 150, BROWN, DARKGRAY); the_title(500, 330); paint_foot("Hold down left mouse buttom to see a comment"); }
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; }
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; }