void main() { int gd=DETECT,gm,i,j,x,y,color,startcolor,height,width; struct palettetype palette; struct viewporttype vp; initgraph(&gd,&gm,"d:\\tc\\bgi"); getpalette(&palette); rectangle(0,20,639,479); outtextxy(200,10,"Palette demonstration"); getviewsettings(&vp); width=(vp.right-vp.left)/16; height=(vp.bottom-vp.top-20)/16; x=0; y=20; startcolor=0; for(j=0;j<=15;j++) { color=startcolor; for(i=0;i<=15;i++) { setfillstyle(SOLID_FILL,color++); bar(x,y,x+width,y+height); x=x+width+1; } startcolor++; x=0; y+=height+1; } getch(); while(!kbhit()) setpalette(random(16),random(65)); setallpalette(&palette); getch(); closegraph(); restorecrtmode(); }
static int bgi_0to2(char * window_name,char * icon_file) { unsigned int depth; XSizeHints size_hints; char *dsp_name = NULL; Pixmap icon_pixmap; XSetWindowAttributes setwinattr; if((display = XOpenDisplay (dsp_name))==NULL) return -3; screen=DefaultScreen(display); cmap=DefaultColormap(display,screen); depth=DefaultDepth(display,screen); if((bgi_font=XLoadQueryFont(display,BGI_DEFAULT_FONT))==NULL) { fprintf(stderr,"Warning Graphical font not found : %s\n",BGI_DEFAULT_FONT); fprintf(stderr,"Font \"fixed\" is used instead\n"); if((bgi_font=XLoadQueryFont(display,"fixed"))==NULL) { fprintf(stderr,"Font \"fixed\" not found too. Program terminated\n"); X_IO_Error_H(NULL); } } if((text_font=XLoadQueryFont(display, BGI_TEXT_FONT))==NULL) { fprintf(stderr,"Text font not found : %s\n",BGI_TEXT_FONT); fprintf(stderr,"Font \"fixed\" is used instead\n"); text_font=XLoadQueryFont(display,"fixed"); } xw_fn_w=text_font->max_bounds.width; xw_fn_h=text_font->ascent+text_font->descent; isProportional=(xw_fn_w!=text_font->min_bounds.width); if (isProportional) { fprintf(stderr, "\n Warning: Text font is proportional\n"); } bgi_maxx=text_font->max_bounds.width*CRT_X-1; bgi_maxy=(text_font->ascent+text_font->descent)*CRT_Y-1; if(bgi_maxcolor && depth >= 3 ) { bgi_maxcolor= (1 << depth)-1; if(bgi_maxcolor>15) bgi_maxcolor=15; } else bgi_maxcolor=0; win=XCreateWindow( display, RootWindow(display,screen), 0, 0, bgi_maxx+1, bgi_maxy+1, 3, depth, InputOutput, CopyFromParent, 0, &setwinattr); { int hx,hy; unsigned w,h; if(XReadBitmapFile(display,win,icon_file,&w,&h,&icon_pixmap,&hx,&hy) !=BitmapSuccess)icon_pixmap=None; } size_hints.flags=PSize|PMinSize; size_hints.width=bgi_maxx+1; size_hints.height=bgi_maxy+1; size_hints.min_width=bgi_maxx+1; size_hints.min_height=bgi_maxy+1; XSetStandardProperties( display, win, window_name, window_name, icon_pixmap, NULL, 0, &size_hints); XSelectInput( display, win, ExposureMask| KeyPressMask| StructureNotifyMask| ButtonPressMask| ButtonReleaseMask); XSetErrorHandler(X_Error_H); XSetIOErrorHandler(X_IO_Error_H); { unsigned long valuemask = 0; XGCValues values; XEvent report; gc=XCreateGC(display,win,valuemask,&values); XMapWindow(display,win); XMaskEvent(display,ExposureMask,&report) ; } XSetFont(display,gc,text_font->fid); XSetForeground(display,gc,BlackPixel(display,screen)); xw_graphic=0; setallpalette(); XFillRectangle(display,win,gc,0,0,bgi_maxx+1,bgi_maxy+1); return 0; }