|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T i
Length: 20387 (0x4fa3) Types: TextFile Names: »icon.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/X/Xwanderer/icon.c«
#include "wand_head.h" /* declare all of the pixmaps */ #ifdef XWANDER #include "icons/font.h" int use_icons; Font regular_icon_font; Font tiny_icon_font; GC regular_icon_gc; GC tiny_icon_gc; unsigned long fg, bg; void paint_small_square(); extern playerfacing; extern tinymode; /* first the 'large' pixmaps (64x64) */ Pixmap space_pm, wall_pm, larrow_pm, rarrow_pm, rock_pm, dirt_pm, fwdslide_pm, backslide_pm, diamond_pm, brick_pm, playerl_pm, playerr_pm, wayout_pm, landmine_pm, monster_pm, sprite_pm, timecapsule_pm, cage_pm, teleport_pm, whoops_pm; /* the 'tiny' pixmaps (16x16) */ Pixmap space_tpm, wall_tpm, larrow_tpm, rarrow_tpm, rock_tpm, dirt_tpm, fwdslide_tpm, backslide_tpm, diamond_tpm, brick_tpm, player_tpm, wayout_tpm, landmine_tpm, monster_tpm, sprite_tpm, timecapsule_tpm, cage_tpm, teleport_tpm, whoops_tpm; int scorefonthigh, scorefonta, msgfonthigh, msgfonta, tablefonthigh, tablefonta; int tablefontwide; XFontStruct *scorefont, *msgfont, *tablefont; GC scorefontgc, msgfontgc, linegc, tablegc; #endif int do_repaint = 1; #ifndef XWANDER void draw_symbol(x,y,ch) int x,y; char ch; { char icon[2][4], (*iconrow)[4] = icon; switch(ch) { case ' ': strcpy((*iconrow++)," "); strcpy((*iconrow)," "); break; case '#': strcpy(*iconrow++,"###"); strcpy(*iconrow,"###"); break; case '<': strcpy(*iconrow++,"<--"); strcpy(*iconrow,"<--"); break; case '>': strcpy(*iconrow++,"-->"); strcpy(*iconrow,"-->"); break; case 'O': strcpy(*iconrow++,"/^\\"); strcpy(*iconrow,"\\_/"); break; case ':': strcpy(*iconrow++,". ."); strcpy(*iconrow," . "); break; case '/': strcpy(*iconrow++," _/"); strcpy(*iconrow,"/ "); break; case '\\': strcpy(*iconrow++,"\\_ "); strcpy(*iconrow," \\"); break; case '*': strcpy(*iconrow++,"/$\\"); strcpy(*iconrow, "\\$/"); break; case '=': strcpy(*iconrow++,"=-="); strcpy(*iconrow, "-=-"); break; case '@': strcpy(*iconrow++," o "); strcpy(*iconrow, "<|>"); break; case 'T': strcpy(*iconrow++,"(*)"); strcpy(*iconrow, "(*)"); break; case 'X': strcpy(*iconrow++,"Way"); strcpy(*iconrow, "Out"); break; case '!': strcpy(*iconrow++," I "); strcpy(*iconrow, " o "); break; case 'M': strcpy(*iconrow++,"}o{"); strcpy(*iconrow, "/^\\"); break; case 'S': strcpy(*iconrow++,"-o-"); strcpy(*iconrow, "/*\\"); break; case 'C': strcpy(*iconrow++," "); strcpy(*iconrow, "<O>"); break; case '+': strcpy(*iconrow++,"TTT"); strcpy(*iconrow, "III"); break; default: strcpy(*iconrow++,"OOO"); strcpy(*iconrow, "OOO"); break; }; move(y+1,x+1); iconrow--; addstr(*iconrow++); move(y+2,x+1); addstr(*iconrow); } xydrawsymbol(x,y,ch) { draw_symbol(x, y, ch); } #else Pixmap tiny_symbol_pixmap(), symbol_pixmap(); GC symbol_gc(); static int drawn_data[ROWLEN+1+1][NOOFROWS+1+1]; static int onscreen_data[ROWLEN+1+1][NOOFROWS+1+1]; #define check_x(x) (((x) < -1 || (x) > ROWLEN+1) ? abort() : 0) #define check_y(y) (((y) < -1 || (y) > NOOFROWS+1) ? abort() : 0) #define range_check(x,y) (check_x(x), check_y(y)) #define drawn(x,y) (range_check(x,y),drawn_data[(x)+1][(y)+1]) #define onscreen(x,y) (range_check(x,y),onscreen_data[x+1][y+1]) #define set_drawn(x,y,c) (range_check(x,y),(drawn_data[(x)+1][(y)+1] = (c))) #define set_onscreen(x,y,c) (range_check(x,y),(onscreen_data[x+1][y+1] = (c))) static int screenmode = -1; void draw_symbol(x,y,ch) int x,y; char ch; { int xp, yp, width, height; if (do_repaint || screenmode != tinymode) { int i, j; for (i = -1; i < ROWLEN+1; i++) for (j = -1; j < NOOFROWS+1; j++) { set_drawn(i,j, -1); set_onscreen(i,j, -1); } do_repaint = 0; screenmode = tinymode; } /* only paint area if we have to */ if (drawn(x,y) != ch) { if (use_icons) { Pixmap p; GC g = symbol_gc(ch); if (tinymode) { p = tiny_symbol_pixmap(ch); xp = x * SMALL_WIDE + 13; yp = SMALL_HIGH + 83; width = SMALL_WIDE; height = SMALL_HIGH; } else { p = symbol_pixmap (ch); xp = x * ICON_WIDE + 5; yp = y * ICON_HIGH + 5; width = ICON_WIDE; height = ICON_HIGH; } XCopyArea(dpy, p, win, g, 0, 0, width, height, xp, yp); } set_drawn(x,y, ch); } } xydrawsymbol(x,y,ch) { if (use_icons) { Pixmap p = (Pixmap) symbol_pixmap(ch); GC g = (GC) symbol_gc(ch); XCopyArea(dpy, p, win, g, 0, 0, ICON_WIDE, ICON_HIGH, x * tablefontwide + 10, y * tablefonthigh + 10); } else { char c; int xp, yp; GC g = regular_icon_gc; xp = x * tablefontwide + 10; yp = y * tablefonthigh + 10 + ICON_HIGH; c = symbol_fontchar (ch); XDrawImageString (dpy, win, g, xp, yp, &c, 1); } } update_symbols () { char line[ROWLEN+1+1]; int start; int i, j, xp, yp; GC g; if (!use_icons) { start = -2; for (j = -1; j < NOOFROWS+1; j++) { for (i = -1; i <= ROWLEN+1; i++) { if (i != ROWLEN+1 && drawn(i,j) != onscreen(i,j)) { if (start == -2) start = i; line[i+1] = symbol_fontchar(drawn(i,j)); set_onscreen(i,j, drawn(i,j)); } else if (start != -2) { if (tinymode) { g = tiny_icon_gc; xp = start * SMALL_WIDE + 13; yp = (j + 1) * SMALL_HIGH + 83; } else { g = regular_icon_gc; xp = start * ICON_WIDE + 5; yp = (j + 1) * ICON_HIGH + 5; } XDrawImageString (dpy, win, g, xp, yp, &line[start+1], i - start); start = -2; } } } } XFlush (dpy); } int symbol_fontchar(ch) int ch; { int picture; switch(ch) { case ' ': picture = W_space; break; case '#': picture = W_wall; break; case '<': picture = W_larrow; break; case '>': picture = W_rarrow; break; case 'O': picture = W_rock; break; case ':': picture = W_dirt; break; case '/': picture = W_fwdslide; break; case '\\': picture = W_backslide; break; case '*': picture = W_diamond; break; case '=': picture = W_brick; break; case '@': if (playerfacing == 1) picture = W_playerl; else picture = W_playerr; break; case 'T': picture = W_teleport; break; case 'X': picture = W_wayout; break; case '!': picture = W_landmine; break; case 'M': picture = W_monster; break; case 'S': picture = W_sprite; break; case 'C': picture = W_timecapsule; break; case '+': picture = W_cage; break; default: picture = W_brick; break; } return(picture); } Pixmap symbol_pixmap(ch) int ch; { Pixmap picture; switch(ch) { case ' ': picture = space_pm; break; case '#': picture = wall_pm; break; case '<': picture = larrow_pm; break; case '>': picture = rarrow_pm; break; case 'O': picture = rock_pm; break; case ':': picture = dirt_pm; break; case '/': picture = fwdslide_pm; break; case '\\': picture = backslide_pm; break; case '*': picture = diamond_pm; break; case '=': picture = brick_pm; break; case '@': if (playerfacing == 1) picture = playerl_pm; else picture = playerr_pm; break; case 'T': picture = teleport_pm; break; case 'X': picture = wayout_pm; break; case '!': picture = landmine_pm; break; case 'M': picture = monster_pm; break; case 'S': picture = sprite_pm; break; case 'C': picture = timecapsule_pm; break; case '+': picture = cage_pm; break; default: picture = brick_pm; break; } return(picture); } void paint_small_square(x,y,ch) int x,y; char ch; { if (ch == ' ' && !tinymode) return; draw_symbol (x, y, ch); } Pixmap tiny_symbol_pixmap(ch) int ch; { Pixmap picture; switch(ch) { case ' ': picture = space_tpm; break; case '#': picture = wall_tpm; break; case '<': picture = larrow_tpm; break; case '>': picture = rarrow_tpm; break; case 'O': picture = rock_tpm; break; case ':': picture = dirt_tpm; break; case '/': picture = fwdslide_tpm; break; case '\\': picture = backslide_tpm; break; case '*': picture = diamond_tpm; break; case '=': picture = brick_tpm; break; case '@': picture = player_tpm; break; case 'T': picture = teleport_tpm; break; case 'X': picture = wayout_tpm; break; case '!': picture = landmine_tpm; break; case 'M': picture = monster_tpm; break; case 'S': picture = sprite_tpm; break; case 'C': picture = timecapsule_tpm; break; case '+': picture = cage_tpm; break; default: picture = brick_pm; break; } return(picture); } GC symbol_gc(ch) int ch; { /* this should return an appropriate GC when color is added */ return(globgc); } Pixmap MakePixmap(dpy, root, data ,width, height) Display *dpy; Drawable root; short *data; unsigned int width, height; { XImage ximage; GC pgc; XGCValues gcv; Pixmap pid; pid = XCreatePixmap(dpy,root,width,height, DefaultDepth(dpy,DefaultScreen(dpy))); gcv.foreground = fg; gcv.background = bg; pgc = XCreateGC(dpy, pid, GCForeground | GCBackground, &gcv); ximage.height = height; ximage.width = width; ximage.xoffset = 0; ximage.format = XYBitmap; ximage.data = (char *) data; ximage.byte_order = LSBFirst; ximage.bitmap_unit = 16; ximage.bitmap_bit_order = LSBFirst; ximage.bitmap_pad = 16; ximage.bytes_per_line = (width + 15) / 16 * 2; ximage.depth = 1; XPutImage(dpy,pid,pgc,&ximage,0,0,0,0,width,height); XFreeGC(dpy,pgc); return(pid); } /* the big pixmaps */ #include "icons/space_bm" #include "icons/wall_bm" #include "icons/larrow_bm" #include "icons/rarrow_bm" #include "icons/rock_bm" #include "icons/dirt_bm" #include "icons/fwdslide_bm" #include "icons/backslide_bm" #include "icons/diamond_bm" #include "icons/brick_bm" #include "icons/playerr_bm" #include "icons/playerl_bm" #include "icons/wayout_bm" #include "icons/landmine_bm" #include "icons/monster_bm" #include "icons/sprite_bm" #include "icons/timecapsule_bm" #include "icons/cage_bm" #include "icons/teleport_bm" #include "icons/whoops_bm" /* the tiny pixmaps */ #include "icons/space_tbm" #include "icons/wall_tbm" #include "icons/larrow_tbm" #include "icons/rarrow_tbm" #include "icons/rock_tbm" #include "icons/dirt_tbm" #include "icons/fwdslide_tbm" #include "icons/backslide_tbm" #include "icons/diamond_tbm" #include "icons/brick_tbm" #include "icons/player_tbm" #include "icons/wayout_tbm" #include "icons/landmine_tbm" #include "icons/monster_tbm" #include "icons/sprite_tbm" #include "icons/timecapsule_tbm" #include "icons/cage_tbm" #include "icons/teleport_tbm" #include "icons/whoops_tbm" build_pixmaps() { char *cp; XFontStruct *regular_info; XFontStruct *tiny_info; XGCValues gcv; int mask = GCForeground|GCBackground; regular_info = XLoadQueryFont (dpy, NORMAL_NAME); tiny_info = XLoadQueryFont (dpy, TINY_NAME); fg = WhitePixel (dpy, DefaultScreen (dpy)); bg = BlackPixel (dpy, DefaultScreen (dpy)); gcv.foreground = fg; gcv.background = bg; if (!regular_info || !tiny_info) use_icons = 1; else { regular_icon_font = regular_info->fid; gcv.font = regular_icon_font; regular_icon_gc = XCreateGC (dpy, win, GCForeground|GCBackground|GCFont, &gcv); tiny_icon_font = tiny_info->fid; gcv.font = tiny_icon_font; tiny_icon_gc = XCreateGC (dpy, win, GCForeground|GCBackground|GCFont, &gcv); } if (use_icons) { space_pm = MakePixmap(dpy, win, space_bm_bits, 64, 64); wall_pm = MakePixmap(dpy, win, wall_bm_bits, 64, 64); larrow_pm = MakePixmap(dpy, win, larrow_bm_bits, 64, 64); rarrow_pm = MakePixmap(dpy, win, rarrow_bm_bits, 64, 64); rock_pm = MakePixmap(dpy, win, rock_bm_bits, 64, 64); dirt_pm = MakePixmap(dpy, win, dirt_bm_bits, 64, 64); fwdslide_pm = MakePixmap(dpy, win, fwdslide_bm_bits, 64, 64); backslide_pm = MakePixmap(dpy, win, backslide_bm_bits, 64, 64); diamond_pm = MakePixmap(dpy, win, diamond_bm_bits, 64, 64); brick_pm = MakePixmap(dpy, win, brick_bm_bits, 64, 64); playerl_pm = MakePixmap(dpy, win, playerl_bm_bits, 64, 64); playerr_pm = MakePixmap(dpy, win, playerr_bm_bits, 64, 64); wayout_pm = MakePixmap(dpy, win, wayout_bm_bits, 64, 64); landmine_pm = MakePixmap(dpy, win, landmine_bm_bits, 64, 64); monster_pm = MakePixmap(dpy, win, monster_bm_bits, 64, 64); sprite_pm = MakePixmap(dpy, win, sprite_bm_bits, 64, 64); timecapsule_pm = MakePixmap(dpy, win, timecapsule_bm_bits, 64, 64); cage_pm = MakePixmap(dpy, win, cage_bm_bits, 64, 64); teleport_pm = MakePixmap(dpy, win, teleport_bm_bits, 64, 64); whoops_pm = MakePixmap(dpy, win, whoops_bm_bits, 64, 64); space_tpm = MakePixmap(dpy, win, space_tbm_bits, 16, 16); wall_tpm = MakePixmap(dpy, win, wall_tbm_bits, 16, 16); larrow_tpm = MakePixmap(dpy, win, larrow_tbm_bits, 16, 16); rarrow_tpm = MakePixmap(dpy, win, rarrow_tbm_bits, 16, 16); rock_tpm = MakePixmap(dpy, win, rock_tbm_bits, 16, 16); dirt_tpm = MakePixmap(dpy, win, dirt_tbm_bits, 16, 16); fwdslide_tpm = MakePixmap(dpy, win, fwdslide_tbm_bits, 16, 16); backslide_tpm = MakePixmap(dpy, win, backslide_tbm_bits, 16, 16); diamond_tpm = MakePixmap(dpy, win, diamond_tbm_bits, 16, 16); brick_tpm = MakePixmap(dpy, win, brick_tbm_bits, 16, 16); player_tpm = MakePixmap(dpy, win, player_tbm_bits, 16, 16); wayout_tpm = MakePixmap(dpy, win, wayout_tbm_bits, 16, 16); landmine_tpm = MakePixmap(dpy, win, landmine_tbm_bits, 16, 16); monster_tpm = MakePixmap(dpy, win, monster_tbm_bits, 16, 16); sprite_tpm = MakePixmap(dpy, win, sprite_tbm_bits, 16, 16); timecapsule_tpm = MakePixmap(dpy, win, timecapsule_tbm_bits, 16, 16); cage_tpm = MakePixmap(dpy, win, cage_tbm_bits, 16, 16); teleport_tpm = MakePixmap(dpy, win, teleport_tbm_bits, 16, 16); whoops_tpm = MakePixmap(dpy, win, whoops_tbm_bits, 16, 16); } /* build all of the GC's here too! */ globgc = XCreateGC(dpy, win, mask, &gcv); /* create the message font gc and load the message font */ msgfontgc = XCreateGC(dpy, win, mask, &gcv); linegc = XCreateGC(dpy, win, mask, &gcv); XSetLineAttributes(dpy,linegc, 2, LineSolid, CapButt, JoinMiter); cp = (char *)getenv("MSGFONT"); if (!cp) cp = "fixed"; msgfont = XLoadQueryFont(dpy, cp); if (msgfont == 0) { fprintf(stderr,"Can't load (msgfont) %s. Bye!\n",cp); exit(1); } msgfonthigh = msgfont->max_bounds.ascent+msgfont->max_bounds.descent; msgfonta = msgfont->max_bounds.ascent; XSetFont(dpy, msgfontgc, msgfont->fid); /* create the highscore table gc and load the font */ tablegc = XCreateGC(dpy, win, mask, &gcv); cp =(char *) getenv("TABLEFONT"); if (!cp) cp = "fixed"; tablefont = XLoadQueryFont(dpy, cp); if (tablefont == 0) { fprintf(stderr,"Can't load (tablefont) %s. Bye!\n",cp); exit(1); } tablefonthigh = tablefont->max_bounds.ascent+tablefont->max_bounds.descent; tablefontwide = tablefont->max_bounds.width; tablefonta = tablefont->max_bounds.ascent; XSetFont(dpy, tablegc, tablefont->fid); /* create the score font gc and load the score font */ scorefontgc = XCreateGC(dpy, win, mask, &gcv); cp = (char*)getenv("SCOREFONT"); if (!cp) cp = "fixed"; scorefont = XLoadQueryFont(dpy,cp); if (scorefont == 0) { fprintf(stderr,"Can't load (scorefont). Bye!\n"); exit(1); } scorefonthigh = scorefont->max_bounds.ascent+msgfont->max_bounds.descent; scorefonta = msgfont->max_bounds.ascent; XSetFont(dpy,scorefontgc, scorefont->fid); } display_monster(mx) { /* Pixmap m = symbol_pixmap((mx != (-1) ? 'M' : ' ')); GC mgc = symbol_gc((mx != (-1) ? 'M' : ' ')); */ int x1 = ICON_WIDE * 12 + 54; int x2 = x1 + (ICON_WIDE) + 6; int y1 = scorefonthigh * 10 + 10; int y2 = y1 + (ICON_HIGH) + 6; XDrawLine(dpy, win, linegc, x1, y1, x2, y1); XDrawLine(dpy, win, linegc, x2, y1, x2, y2); XDrawLine(dpy, win, linegc, x2, y2, x1, y2); XDrawLine(dpy, win, linegc, x1, y2, x1, y1); xydrawsymbol(x1 + 3, y1 + 3, mx != (-1) ? 'M' : ' '); /* XCopyArea(dpy, m, win, mgc, 0, 0, ICON_WIDE, ICON_HIGH, x1 + 3, y1 + 3); */ /* score_message(9," Monster Detector"); */ } table_message(y,fmt,s1,s2,s3,s4,s5,s6,s7,s8) char *fmt,*s1,*s2,*s3,*s4,*s5,*s6,*s7,*s8; { char buf[256]; sprintf(buf,fmt,s1,s2,s3,s4,s5,s6,s7,s8); XDrawImageString(dpy, win, tablegc,30, (tablefonthigh*y)+10+tablefonta, buf, strlen(buf)); } message(y,fmt,s1,s2,s3,s4,s5,s6,s7,s8) char *fmt,*s1,*s2,*s3,*s4,*s5,*s6,*s7,*s8; { char buf[256]; sprintf(buf,fmt,s1,s2,s3,s4,s5,s6,s7,s8); XDrawImageString(dpy, win, msgfontgc,5, (msgfonthigh*y)+(ICON_HIGH*7)+20+msgfonta, buf, strlen(buf)); } erase_message(n) { /* fprintf(stderr,"XClearArea: %d %d %d %d\n", 5, (msgfonthigh*n)+(ICON_HIGH*7)+20,ICON_WIDE*11+10,msgfonthigh); */ XClearArea(dpy, win, 5, (msgfonthigh*n)+(ICON_HIGH*7)+20, ICON_WIDE * 11 + 10, msgfonthigh, 0); } score_message(y,fmt,s1,s2,s3,s4,s5,s6,s7,s8) char *fmt,*s1,*s2,*s3,*s4,*s5,*s6,*s7,*s8; { char buf[256]; sprintf(buf,fmt,s1,s2,s3,s4,s5,s6,s7,s8); XDrawImageString(dpy, win, scorefontgc, ICON_WIDE*11+20, scorefonthigh*y+10+scorefonta, buf, strlen(buf)); } XBeep() /* There has to be a better way to do this.. */ { XFlush(dpy); printf("\07"); fflush(stdout); } /* takes over the standard getchar */ getchar(sx, sy, frow, score, nf, diamonds, num, maxmoves, mx) char (*frow)[ROWLEN+1]; int *score; { XEvent event, ev; int i; char buf[3]; /* printf("In getchar\n"); */ while (1) { update_symbols (); XNextEvent(dpy, &(event)); switch(event.type) { case Expose: if (event.xexpose.count != 0) { /* fprintf(stderr,"xwanderer: %d expose events to follow\n", event.xexpose.count); */ /* XXX - anyone want to optimize this? */ /* what we do here is look at the number of expose * events that are supposed to follow this one * and throw them away then we do a big redraw */ for (i = 0; i < event.xexpose.count != 0; i++) { XPeekEvent(dpy, &(ev)); /* peek */ if (ev.type != Expose) /* is the event expose? */ break; /* yep, we'll proc. later */ XNextEvent(dpy,&ev); /* nope, toss event */ } } if (sx != (-1)) { do_repaint = 1; if (!tinymode) display(sx,sy,frow,*score); else drawmap(frow,1); repaint_score(*score, nf, diamonds, num, maxmoves, mx); } break; case KeyPress: buf[0] = 0; XLookupString(&(event), buf, 1, NULL, NULL); buf[1] = 0; /* printf("buf[0] = %c %d\n", buf[0], buf[0]); */ if (buf[0] == 13) buf[0] = 10; if (buf[0] == 12) { do_repaint = 1; if (sx != (-1)) if (tinymode) drawmap(frow,1); else display(sx,sy,frow,*score); } else if (buf[0] != 0) return(buf[0]); break; } } } repaint_score(score, nf, diamonds, num, maxmoves, mx) { score_message(0,"Score Diamonds"); score_message(1," Found Total"); score_message(2,"%7d %3d %3d ", score, nf, diamonds); score_message(6,"Current Screen %d ",num); if (maxmoves != -1) score_message(15,"Moves Remaining = %d ", maxmoves); else score_message(15," Unlimited moves "); display_monster(mx); } #endif