--- angband-282/src/main-x11.c Wed Feb 4 00:28:54 1998 *************** *** 381,386 **** --- 381,392 ---- static infofnt *Infofnt = (infofnt*)(NULL); + XImage *ReadRaw( Display *disp, char Name[], int width, int height ); + + XImage *RemapColors( Display *disp, XImage *Im, unsigned long ColT[] ); + + XImage *ResizeImage( Display *disp, XImage *Im, + int ix, int iy, int ox, int oy ); /**** Available code ****/ *************** *** 1448,1460 **** infowin *outer; infowin *inner; }; /* * The number of term data structures */ ! #define MAX_TERM_DATA 8 /* * The array of term data structures --- 1454,1470 ---- infowin *outer; infowin *inner; + + /* For Gfx */ + + XImage *Tiles; }; /* * The number of term data structures */ ! #define MAX_TERM_DATA 4 /* * The array of term data structures *************** *** 1883,1889 **** return (0); } - /* * Handle a "special request" */ --- 1893,1898 ---- *************** *** 1960,1968 **** /* * Draw a number of characters (XXX Consider using "cpy" mode) */ ! static errr Term_text_x11(int x, int y, int n, byte a, cptr s) { ! /* Draw the text in Xor */ Infoclr_set(clr[a]); /* Draw the text */ --- 1969,1979 ---- /* * Draw a number of characters (XXX Consider using "cpy" mode) */ ! static errr Term_text_x11(int x, int y, int n, byte a, cptr s ) { ! int i; ! char c; ! Infoclr_set(clr[a]); /* Draw the text */ *************** *** 1972,1977 **** --- 1983,2034 ---- return (0); } + static errr Term_pict_x11(int x, int y, int n, const byte *ap, const char *cp ) + { + char a, c; + int i; + + term_data *td = (term_data*)(Term->data); + + for( i=0; ipclass * 10 + p_ptr->prace) >> 5 ) + 12; + c = (( p_ptr->pclass * 10 + p_ptr->prace) & 0x1f ); + } + else + { + a = *ap; + c = *cp; + } + y *= Infofnt->hgt; + x *= Infofnt->wid; + XPutImage( Metadpy->dpy, td->inner->win, clr[17]->gc, + td->Tiles, + (c&0x7F)*td->fnt->wid+1, (a&0x7F)*td->fnt->hgt+1, + x, y, + td->fnt->wid, td->fnt->hgt ); + x += td->fnt->wid; + } + else + { + Infoclr_set(clr[*ap]); + + /* Draw the text */ + Infofnt_text_std(x, y, cp, 1); + } + ap++; + cp++; + } + /* Success */ + return (0); + } + /* * Initialize a term_data *************** *** 2026,2035 **** --- 2083,2100 ---- t->curs_hook = Term_curs_x11; t->wipe_hook = Term_wipe_x11; t->text_hook = Term_text_x11; + t->pict_hook = Term_pict_x11; /* Save the data */ t->data = td; + /* Gfx */ + t->always_text = FALSE; + t->always_pict = FALSE; + t->higher_pict = TRUE; + + td->Tiles = NULL; + /* Activate (important) */ Term_activate(t); *************** *** 2051,2056 **** --- 2116,2126 ---- char buf[80]; + unsigned long ColTable[256]; + + XImage *Tiles, *Tmp; + + /* Parse args */ for (i = 1; i < argc; i++) *************** *** 2079,2084 **** --- 2149,2157 ---- } + use_graphics = TRUE; + process_pref_file( "color.prf" ); + /* Init the Metadpy if possible */ if (Metadpy_init_name(dpy_name)) return (-1); *************** *** 2110,2119 **** --- 2183,2198 ---- /* Initialize the color */ Infoclr_init_ccn(cname, "bg", "cpy", 0); + ColTable[i] = clr[i]->fg; + /* Save the color info */ strcpy(color_info[i], cname); } + /* Reading Gfx */ + Tiles = ReadRaw( Metadpy->dpy, "./lib/xtra/gfx/tiles.raw", 256, 256 ); + Tmp = RemapColors( Metadpy->dpy, Tiles, ColTable ); + XDestroyImage( Tiles ); /* Initialize the windows */ for (i = 0; i < num_term; i++) *************** *** 2143,2152 **** --- 2222,2241 ---- /* Initialize the term_data */ term_data_init(&data[i], TRUE, name, fnt_name); + /* Adjust Gfx to the size of the font */ + + data[i].Tiles = ResizeImage( Metadpy->dpy, Tmp, + 8, 8, + data[i].fnt->wid, + data[i].fnt->hgt ); + /* : data[0].Tiles;*/ + /* Save global entry */ angband_term[i] = Term; } + /*XDestroyImage( Tmp );*/ + /* Activate the "Angband" window screen */ Term_activate(&data[0].t); *************** *** 2157,2162 **** --- 2246,2381 ---- /* Success */ return (0); + } + + XImage *ReadRaw( Display *disp, char Name[], int width, int height ) + { + FILE *f; + XImage *Res = NULL; + int Depth, i; + char *Data; + + if( (f = fopen( Name, "r" )) != NULL ) + { + Depth = 4; + + if( (Data = (char *)calloc( width * height * Depth / 8, 1 )) != NULL ) + { + if( (Res = XCreateImage( disp, + DefaultVisual( disp, + DefaultScreen( disp ) ), + Depth, XYPixmap, 0, Data, width, height, + 8, 0 )) != NULL ) + for( i=0; i<4; i++ ) + fread( Data+(3-i)*(width*height/8), width>>3, height, f ); + else + free( Data ); + } + fclose( f ); + } + + return Res; + } + + XImage *RemapColors( Display *disp, XImage *Im, unsigned long ColT[] ) + { + XImage *Tmp = NULL; + char *Data; + int width, height, depth, x = 1, y; + + y = ((depth = DefaultDepth( disp, DefaultScreen( disp ) ))-1)>>2; + width = Im->width; + height = Im->height; + + while( y>>=1 ) x<<=1; + + if( (Data = (char *)malloc( width * height * x )) != NULL ) + { + if( (Tmp = XCreateImage( disp, DefaultVisual( disp, DefaultScreen(disp) ), + depth, ZPixmap, 0, Data, width, height, 32, 0 )) + != NULL ) + for( y=0; ywidth; + height1 = Im->height; + + width2 = ox * width1 / ix; + height2 = oy * height1 / iy; + + Data = (char *)malloc( width2 * height2 * Im->bits_per_pixel / 8 ); + Tmp = XCreateImage( disp, DefaultVisual( disp, DefaultScreen( disp ) ), + Im->depth, ZPixmap, 0, Data, width2, height2, + 32, 0 ); + + if( ix > ox ) + { + px1 = &x1; + px2 = &x2; + dx1 = &ix; + dx2 = &ox; + } + else + { + px1 = &x2; + px2 = &x1; + dx1 = &ox; + dx2 = &ix; + } + + if( iy > oy ) + { + py1 = &y1; + py2 = &y2; + dy1 = &iy; + dy2 = &oy; + } + else + { + py1 = &y2; + py2 = &y1; + dy1 = &oy; + dy2 = &iy; + } + + Ty = *dy1; + for( y1=0, y2=0; (y1