home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / games / volume13 / xsokoban / part01 / initx.c < prev    next >
C/C++ Source or Header  |  1992-01-12  |  4KB  |  114 lines

  1. #include <stdio.h>
  2. #include <X11/Xlib.h>
  3. #include <X11/Xutil.h>
  4. #include "sokoban.h"
  5. #include "initx.h"
  6. #include "obj.h"
  7.  
  8. #include "icon.xbm"  
  9. #include "cursor.xbm"
  10. #include "ground.xbm"
  11. #include "packet.xbm"
  12. #include "player.xbm"
  13. #include "playerstore.xbm"
  14. #include "save.xbm"
  15. #include "store.xbm"
  16. #include "wall.xbm"
  17.  
  18. Display                *dpy;
  19. Window                win;
  20. GC                    gc,gclear;
  21. Pixmap                bitmap,
  22.                     cursor_bitmap;
  23. Cursor                cursor;
  24. XColor                fg,bg,dummy;
  25. unsigned long             attribmask;
  26. XGCValues             gcv;
  27. XSizeHints            xsh;
  28. XSetWindowAttributes    xswa;
  29. XWMHints                 xwmh;
  30. Font                    font;
  31. char                    sline[80];
  32. XSizeHints                hints;
  33. Pixmap                icon;
  34.  
  35. void load_pieces();
  36.  
  37. void killx()
  38. {
  39.     XDestroyWindow(dpy,win);
  40.      XCloseDisplay(dpy);
  41. }
  42. void initx()
  43. {
  44.  
  45.     if ((dpy = XOpenDisplay(NULL)) == NULL) {
  46.         fprintf(stderr,"\tCannot open %s\n",DISPLAYNAME);
  47.         exit(1);
  48.     }
  49.  
  50.     xswa.colormap = COLORMAP;
  51.     xswa.bit_gravity = CenterGravity;
  52.     xswa.border_pixel = BLACKPIXEL;
  53.     xswa.background_pixel = WHITEPIXEL;
  54.     attribmask = ( CWColormap | CWBitGravity | CWBorderPixel | CWBackPixel);
  55.     win = XCreateWindow(dpy,ROOT,XORIGIN,YORIGIN,PIXMAPX*MAXCOL,
  56.         PIXMAPY*MAXROW+20,BORDERWIDTH,DEPTH,InputOutput,CopyFromParent,attribmask,&xswa);
  57.     if ((win==BadMatch)||(win==BadAlloc)||(win==BadColor)||
  58.         (win==BadCursor)||(win==BadPixmap)||(win==BadValue)||(win==BadWindow))    {
  59.         fprintf(stderr,"\tHeeeeeeeyyy mon, can't create window\n");
  60.         exit (-1);
  61.     }    
  62.  
  63.     cursor_bitmap = XCreateBitmapFromData(dpy,win,cursor_bits,cursor_width,cursor_height);
  64.     icon = XCreateBitmapFromData(dpy,ROOT,icon_bits,icon_width,icon_height);    
  65.  
  66.      XLookupColor(dpy,COLORMAP,"black",&dummy,&fg);
  67.      XLookupColor(dpy,COLORMAP,"white",&dummy,&bg);
  68.      xswa.cursor = XCreatePixmapCursor(dpy,cursor_bitmap,cursor_bitmap,&fg,&bg,16,4);
  69.      XChangeWindowAttributes(dpy,win,CWCursor,&xswa);
  70.     xwmh.initial_state = NormalState;
  71.     xwmh.flags = StateHint; 
  72.     XSetWMHints(dpy,win,&xwmh); 
  73.  
  74.     hints.width = hints.min_width = hints.max_width = PIXMAPX*MAXCOL;
  75.     hints.height = hints.min_height = hints.max_height = PIXMAPY*MAXROW+20;
  76.     hints.flags = PMinSize|PMaxSize|PSize;
  77.  
  78.     XSetStandardProperties(dpy,win,TITLE,TITLE,icon,NULL,0,&hints);
  79.     load_pieces();
  80.  
  81.     font = XLoadFont(dpy,"9x15");
  82.           
  83.     gcv.function = GXcopy;
  84.     gcv.font = font;
  85.     gcv.foreground = BLACKPIXEL;
  86.     gcv.background = WHITEPIXEL;
  87.     gcv.graphics_exposures = FALSE;
  88.     gc = XCreateGC(dpy,win,(GCFont|GCGraphicsExposures|GCForeground|GCBackground|GCFunction),&gcv);
  89.  
  90.     gcv.function = GXcopy;
  91.     gcv.font = font;
  92.     gcv.foreground = WHITEPIXEL;
  93.     gcv.background = BLACKPIXEL;
  94.     gcv.graphics_exposures = FALSE;
  95.     gclear = XCreateGC(dpy,win,(GCFont|GCGraphicsExposures|GCForeground|GCBackground|GCFunction),&gcv);
  96.  
  97.  
  98.     XMapRaised(dpy,win);
  99.     showscreen();
  100.     sprintf(sline," Level:       Packets:       Saved:      Moves:       Pushes:");
  101.  
  102.     XSync(dpy,False);
  103. }
  104. void load_pieces()
  105. {
  106.     player.obj_display = XCreateBitmapFromData(dpy,win,player_bits,player_width,player_height);
  107.     playerstore.obj_display = XCreateBitmapFromData(dpy,win,playerstore_bits,playerstore_width,playerstore_height);
  108.     wall.obj_display = XCreateBitmapFromData(dpy,win,wall_bits,wall_width,wall_height);
  109.     store.obj_display = XCreateBitmapFromData(dpy,win,store_bits,store_width,store_height);
  110.     packet.obj_display = XCreateBitmapFromData(dpy,win,packet_bits,packet_width,packet_height);
  111.     save.obj_display = XCreateBitmapFromData(dpy,win,save_bits,save_width,save_height);
  112.     ground.obj_display = XCreateBitmapFromData(dpy,win,ground_bits,ground_width,ground_height);
  113. }
  114.