home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
games
/
volume13
/
xsokoban
/
part01
/
initx.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-01-12
|
4KB
|
114 lines
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "sokoban.h"
#include "initx.h"
#include "obj.h"
#include "icon.xbm"
#include "cursor.xbm"
#include "ground.xbm"
#include "packet.xbm"
#include "player.xbm"
#include "playerstore.xbm"
#include "save.xbm"
#include "store.xbm"
#include "wall.xbm"
Display *dpy;
Window win;
GC gc,gclear;
Pixmap bitmap,
cursor_bitmap;
Cursor cursor;
XColor fg,bg,dummy;
unsigned long attribmask;
XGCValues gcv;
XSizeHints xsh;
XSetWindowAttributes xswa;
XWMHints xwmh;
Font font;
char sline[80];
XSizeHints hints;
Pixmap icon;
void load_pieces();
void killx()
{
XDestroyWindow(dpy,win);
XCloseDisplay(dpy);
}
void initx()
{
if ((dpy = XOpenDisplay(NULL)) == NULL) {
fprintf(stderr,"\tCannot open %s\n",DISPLAYNAME);
exit(1);
}
xswa.colormap = COLORMAP;
xswa.bit_gravity = CenterGravity;
xswa.border_pixel = BLACKPIXEL;
xswa.background_pixel = WHITEPIXEL;
attribmask = ( CWColormap | CWBitGravity | CWBorderPixel | CWBackPixel);
win = XCreateWindow(dpy,ROOT,XORIGIN,YORIGIN,PIXMAPX*MAXCOL,
PIXMAPY*MAXROW+20,BORDERWIDTH,DEPTH,InputOutput,CopyFromParent,attribmask,&xswa);
if ((win==BadMatch)||(win==BadAlloc)||(win==BadColor)||
(win==BadCursor)||(win==BadPixmap)||(win==BadValue)||(win==BadWindow)) {
fprintf(stderr,"\tHeeeeeeeyyy mon, can't create window\n");
exit (-1);
}
cursor_bitmap = XCreateBitmapFromData(dpy,win,cursor_bits,cursor_width,cursor_height);
icon = XCreateBitmapFromData(dpy,ROOT,icon_bits,icon_width,icon_height);
XLookupColor(dpy,COLORMAP,"black",&dummy,&fg);
XLookupColor(dpy,COLORMAP,"white",&dummy,&bg);
xswa.cursor = XCreatePixmapCursor(dpy,cursor_bitmap,cursor_bitmap,&fg,&bg,16,4);
XChangeWindowAttributes(dpy,win,CWCursor,&xswa);
xwmh.initial_state = NormalState;
xwmh.flags = StateHint;
XSetWMHints(dpy,win,&xwmh);
hints.width = hints.min_width = hints.max_width = PIXMAPX*MAXCOL;
hints.height = hints.min_height = hints.max_height = PIXMAPY*MAXROW+20;
hints.flags = PMinSize|PMaxSize|PSize;
XSetStandardProperties(dpy,win,TITLE,TITLE,icon,NULL,0,&hints);
load_pieces();
font = XLoadFont(dpy,"9x15");
gcv.function = GXcopy;
gcv.font = font;
gcv.foreground = BLACKPIXEL;
gcv.background = WHITEPIXEL;
gcv.graphics_exposures = FALSE;
gc = XCreateGC(dpy,win,(GCFont|GCGraphicsExposures|GCForeground|GCBackground|GCFunction),&gcv);
gcv.function = GXcopy;
gcv.font = font;
gcv.foreground = WHITEPIXEL;
gcv.background = BLACKPIXEL;
gcv.graphics_exposures = FALSE;
gclear = XCreateGC(dpy,win,(GCFont|GCGraphicsExposures|GCForeground|GCBackground|GCFunction),&gcv);
XMapRaised(dpy,win);
showscreen();
sprintf(sline," Level: Packets: Saved: Moves: Pushes:");
XSync(dpy,False);
}
void load_pieces()
{
player.obj_display = XCreateBitmapFromData(dpy,win,player_bits,player_width,player_height);
playerstore.obj_display = XCreateBitmapFromData(dpy,win,playerstore_bits,playerstore_width,playerstore_height);
wall.obj_display = XCreateBitmapFromData(dpy,win,wall_bits,wall_width,wall_height);
store.obj_display = XCreateBitmapFromData(dpy,win,store_bits,store_width,store_height);
packet.obj_display = XCreateBitmapFromData(dpy,win,packet_bits,packet_width,packet_height);
save.obj_display = XCreateBitmapFromData(dpy,win,save_bits,save_width,save_height);
ground.obj_display = XCreateBitmapFromData(dpy,win,ground_bits,ground_width,ground_height);
}