home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / x / xhearts.zip / GFX.C < prev    next >
C/C++ Source or Header  |  1992-01-07  |  32KB  |  1,106 lines

  1. /*
  2.  *    Spider card bitmap drawing routines, modified for external use
  3.  *      by Mike Yang, Silicon Graphics, mikey@sgi.com.
  4.  *
  5.  */
  6.  
  7. /*
  8.  * Copyright 1990 Heather Rose and Sun Microsystems, Inc.
  9.  *
  10.  * Permission to use, copy, modify, distribute, and sell this software and its
  11.  * documentation for any purpose is hereby granted without fee, provided that
  12.  * the above copyright notice appear in all copies and that both that copyright
  13.  * notice and this permission notice appear in supporting documentation, and
  14.  * that the names of Donald Woods and Sun Microsystems not be used in
  15.  * advertising or publicity pertaining to distribution of the software without
  16.  * specific, written prior permission.  Heather Rose and Sun Microsystems not be used in
  17.  * advertising or publicity pertaining to distribution of the software without
  18.  * specific, written prior permission.  Heather Rose and Sun Microsystems make
  19.  * no representations about the suitability of this software for any purpose.
  20.  * It is provided "as is" without express or implied warranty.
  21.  *
  22.  * THE ABOVE-NAMED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  23.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT
  24.  * SHALL HEATHER ROSE OR SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  25.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  26.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  27.  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  28.  * OF THIS SOFTWARE.
  29.  *
  30.  * Author:
  31.  *        Heather Rose
  32.  *        hrose@sun.com
  33.  *
  34.  *        Sun Microsystems, Inc.
  35.  *        2550 Garcia Avenue
  36.  *        Mountain View, CA  94043
  37.  */
  38.  
  39. /*
  40.  * Copyright 1990 David Lemke and Network Computing Devices
  41.  *
  42.  * Permission to use, copy, modify, distribute, and sell this software and its
  43.  * documentation for any purpose is hereby granted without fee, provided that
  44.  * the above copyright notice appear in all copies and that both that
  45.  * copyright notice and this permission notice appear in supporting
  46.  * documentation, and that the name of Network Computing Devices not be 
  47.  * used in advertising or publicity pertaining to distribution of the 
  48.  * software without specific, written prior permission.  Network Computing 
  49.  * Devices makes no representations about the suitability of this software 
  50.  * for any purpose.  It is provided "as is" without express or implied 
  51.  * warranty.
  52.  *
  53.  * NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
  54.  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  55.  * IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL,
  56.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 
  57.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
  58.  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE 
  59.  * OR PERFORMANCE OF THIS SOFTWARE.
  60.  *
  61.  * Author:      
  62.  *        Dave Lemke
  63.  *        lemke@ncd.com
  64.  *
  65.  *        Network Computing Devices, Inc
  66.  *        350 North Bernardo Ave
  67.  *        Mountain View, CA 94043
  68.  *
  69.  *    @(#)copyright.h    2.2    90/04/27
  70.  *
  71.  */
  72.  
  73. /*
  74. % Copyright (c) 1989, Donald R. Woods and Sun Microsystems, Inc.
  75. %
  76. % Permission to use, copy, modify, distribute, and sell this software and its
  77. % documentation for any purpose is hereby granted without fee, provided that
  78. % the above copyright notice appear in all copies and that both that copyright
  79. % notice and this permission notice appear in supporting documentation, and
  80. % that the names of Donald Woods and Sun Microsystems not be used in
  81. % advertising or publicity pertaining to distribution of the software without
  82. % specific, written prior permission.  Donald Woods and Sun Microsystems make
  83. % no representations about the suitability of this software for any purpose.
  84. % It is provided "as is" without express or implied warranty.
  85. %
  86. % THE ABOVE-NAMED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  87. % INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT
  88. % SHALL DONALD WOODS OR SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  89. % CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  90. % DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  91. % TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  92. % OF THIS SOFTWARE.
  93. %
  94. % History: Spider is a solitaire card game that can be found in various books
  95. % of same; the rules are presumed to be in the public domain.  The author's
  96. % first computer implementation was on the Stanford Artificial Intelligence Lab
  97. % system (SAIL).  It was later ported to the Xerox Development Environment.
  98. % The card images are loosely based on scanned-in images but were largely
  99. % redrawn by the author with help from Larry Rosenberg.
  100. %
  101. % This program is written entirely in NeWS and runs on OPEN WINDOWS 1.0.
  102. % It could be made to run much faster if parts of it were written in C, using
  103. % NeWS mainly for its display and input capabilities, but that is left as an
  104. % exercise for the reader.  Spider may also run with little or no modification
  105. % on subsequent releases of OPEN WINDOWS, but no guarantee is made on this
  106. % point (nor any other; see above!).  To run Spider, feed this file to 'psh'.
  107. %
  108. % Author:    Don Woods
  109. %        woods@sun.com
  110. %
  111. %        Sun Microsystems, Inc.
  112. %        2550 Garcia Avenue
  113. %        Mountain View, CA  94043
  114. */
  115.  
  116. /*
  117.  * Spider card drawing routines
  118.  */
  119. #include    "gfx.h"
  120. #include    <X11/Xutil.h>
  121. #include    <stdio.h>
  122. #include    <assert.h>
  123.  
  124. /*
  125.  * spider global variables
  126.  */
  127. Display    *dpy;
  128. int    screen;
  129. Pixmap    greenmap;
  130. Pixmap    redmap;
  131. Pixmap    logomap;
  132. unsigned long    blackpixel;
  133. unsigned long    whitepixel;
  134. unsigned long    borderpixel;
  135. unsigned long    greenpixel;
  136. Bool    is_color;
  137.  
  138. static GC    cardgc;        /* gc in use when drawing cards */
  139.  
  140. /* substitue gray1 for Green on mono */
  141. #define gray1_width 16
  142. #define gray1_height 16
  143. static char gray1_bits[] = {
  144.    0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa,
  145.    0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa,
  146.    0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa};
  147.  
  148. /* logo for card backs */
  149. /* any size logo can be handled.  */
  150.  
  151. #define logo_width 64
  152. #define logo_height 64
  153. static char logo_bits[] = {
  154.  0x77,0xd5,0xd7,0xdd,0x77,0xd5,0xd7,0xdd,0xbb,0xea,0xae,0xbb,0xbb,0xea,0xae,
  155.  0xbb,0x5d,0x75,0x5d,0x77,0x5d,0x75,0x5d,0x77,0xee,0xba,0xba,0xee,0xae,0xba,
  156.  0xba,0xee,0x77,0x5d,0x75,0xdd,0x77,0x5d,0x75,0xdd,0xbb,0xae,0xea,0xba,0xbb,
  157.  0xae,0xea,0xba,0x5d,0x57,0xd5,0x75,0x5d,0x57,0xd5,0x75,0xae,0xab,0xaa,0xeb,
  158.  0xae,0xab,0xaa,0xeb,0xd7,0x55,0x55,0xd7,0xd7,0x51,0x55,0xd7,0xeb,0xae,0xaa,
  159.  0xae,0xeb,0xa2,0xaa,0xae,0x75,0x5d,0x55,0x5d,0x75,0x44,0x15,0x5d,0xba,0xbb,
  160.  0xea,0xba,0xba,0x88,0x8a,0xba,0x5d,0x77,0x75,0x75,0x1d,0x11,0x45,0x75,0xee,
  161.  0xee,0xba,0xea,0x2e,0x22,0xa2,0xea,0xd7,0xdd,0x5d,0xd5,0x57,0x44,0x10,0xd5,
  162.  0xab,0xbb,0xef,0xaa,0xab,0x88,0x88,0xaa,0x57,0x77,0x77,0xd5,0x57,0x11,0x45,
  163.  0xd5,0xae,0xee,0xba,0xea,0xae,0x22,0xa2,0xea,0x5d,0xdd,0x5d,0x75,0x5d,0x45,
  164.  0x10,0x75,0xba,0xba,0xef,0xba,0xba,0x8a,0x88,0xba,0x75,0x75,0x77,0x5d,0x75,
  165.  0x15,0x45,0x5d,0xea,0xea,0xba,0xae,0xea,0x2a,0xa2,0xae,0xdd,0xd5,0x5d,0x77,
  166.  0xdd,0x55,0x50,0x77,0xae,0xab,0xaf,0xeb,0xae,0xab,0xa8,0xeb,0xd7,0x55,0x57,
  167.  0xd7,0xd7,0x55,0x55,0xd7,0xeb,0xaa,0xaa,0xae,0xeb,0xaa,0xaa,0xae,0x75,0x57,
  168.  0x55,0x5d,0x75,0x57,0x55,0x5d,0xba,0xae,0xea,0xba,0xba,0xae,0xaa,0xba,0xdd,
  169.  0x5d,0x75,0x75,0xdd,0x5d,0x75,0x75,0xae,0xbb,0xba,0xea,0xae,0xbb,0xba,0xea,
  170.  0x77,0x77,0x5d,0xd5,0x77,0x77,0x5d,0xd5,0xeb,0xee,0xee,0xaa,0xeb,0xee,0xae,
  171.  0xaa,0xd7,0xdd,0x77,0xd5,0xd7,0xdd,0x77,0xd5,0xae,0xbb,0xbb,0xea,0xae,0xbb,
  172.  0xbb,0xea,0x5d,0x77,0x5d,0x75,0x5d,0x77,0x5d,0x75,0xba,0xee,0xee,0xba,0xba,
  173.  0xee,0xae,0xba,0x75,0xdd,0x77,0x5d,0x75,0xdd,0x77,0x5d,0xea,0xba,0xbb,0xae,
  174.  0xea,0xba,0xbb,0xae,0xd5,0x75,0x5d,0x57,0xd5,0x75,0x5d,0x57,0xaa,0xeb,0xae,
  175.  0xab,0xaa,0xeb,0xae,0xab,0x55,0xd7,0xd7,0x55,0x55,0xd7,0xd7,0x55,0xaa,0xae,
  176.  0xeb,0xae,0xaa,0xae,0xeb,0xae,0x55,0x5d,0x75,0x5d,0x55,0x5d,0x75,0x5d,0xea,
  177.  0xba,0xba,0xbb,0xea,0xba,0xba,0xbb,0x75,0x75,0x5d,0x77,0x75,0x75,0x5d,0x77,
  178.  0xba,0xea,0xee,0xee,0xba,0xea,0xee,0xee,0x5d,0xd5,0xd7,0xdd,0x5d,0xd5,0xd7,
  179.  0xdd,0xef,0xaa,0xab,0xbb,0xef,0xaa,0xab,0xbb,0x77,0xd5,0x57,0x77,0x77,0xd5,
  180.  0x57,0x77,0xba,0xea,0xae,0xee,0xba,0xea,0xae,0xee,0x5d,0x75,0x5d,0xdd,0x5d,
  181.  0x75,0x5d,0xdd,0xef,0xba,0xba,0xba,0xef,0xba,0xba,0xba,0x77,0x5d,0x75,0x75,
  182.  0x77,0x5d,0x75,0x75,0xba,0xae,0xea,0xea,0xba,0xae,0xea,0xea,0x5d,0x77,0xdd,
  183.  0xd5,0x5d,0x77,0xdd,0xd5,0xaf,0xeb,0xae,0xab,0xaf,0xeb,0xae,0xab,0x57,0xd7,
  184.  0xd7,0x55,0x57,0xd7,0xd7,0x55,0xaa,0xae,0xeb,0xaa,0xaa,0xae,0xeb,0xaa,0x55,
  185.  0x5d,0x75,0x57,0x55,0x5d,0x75,0x57,0xaa,0xba,0xba,0xae,0xaa,0xba,0xba,0xae,
  186.  0x75,0x75,0xdd,0x5d,0x55,0x75,0xdd,0x5d,0xba,0xea,0xae,0xbb,0xba,0xea,0xae,
  187.  0xbb,0x5d,0xd5,0x77,0x77,0x5d,0xd5,0x77,0x77,0xae,0xaa,0xeb,0xee,0xae,0xaa,
  188.  0xeb,0xee};
  189.  
  190. #include    "rank.bm"
  191. #include    "face.bm"
  192. #include    "suit.bm"
  193.  
  194. static Pixmap    rank_map[NUM_RANKS],    rank_r_map[NUM_RANKS];
  195. static Pixmap    rank_map_red[NUM_RANKS],    rank_r_map_red[NUM_RANKS];
  196. static Pixmap    suit_map[NUM_SUITS],    suit_r_map[NUM_SUITS];
  197. static Pixmap    suit_sm_map[NUM_SUITS],    suit_sm_r_map[NUM_SUITS];
  198. static Pixmap    suit_lg_map[NUM_SUITS];
  199. static Pixmap    jack_map[NUM_SUITS], queen_map[NUM_SUITS], king_map[NUM_SUITS];
  200.  
  201. /* clipping rectangles */
  202. static XRectangle    cliprects[1] = { 0, 0, CARD_WIDTH + 1, 0};
  203.  
  204. static GC    redgc;
  205. static GC    blackgc;
  206. static GC    whitegc;
  207. static GC    backgc;
  208.  
  209. static int    back_delta_x, back_delta_y; /* how much to modify the TS origin by */
  210.  
  211. static Bool    card_is_clipped;    /* optimizer for card drawing */
  212.  
  213. gfx_init(d, scr)
  214. Display    *d;
  215. int    scr;
  216. {
  217. XGCValues    gcv;
  218. long        gcflags;
  219. XColor        color;
  220. Colormap    cmap;
  221. Pixmap        tmpmap;
  222. GC        logogc;
  223. unsigned long    redpixel;
  224.  
  225.     /* save these off */
  226.     dpy = d;
  227.     screen = scr;
  228.  
  229.     if (DisplayCells(dpy, screen) > 2)    {
  230.         is_color = True;
  231.     }    else    {
  232.         is_color = False;
  233.     }
  234.  
  235.     blackpixel = BlackPixel(dpy, screen);
  236.     whitepixel = WhitePixel(dpy, screen);
  237.  
  238.     /* make gc for white */
  239.     gcv.foreground = WhitePixel(dpy, screen);
  240.     gcv.background = BlackPixel(dpy, screen);
  241.     gcv.graphics_exposures = False;
  242.     gcflags = GCForeground | GCBackground | GCGraphicsExposures;
  243.  
  244.     whitegc = XCreateGC(dpy, RootWindow(dpy, screen), gcflags, &gcv);
  245.  
  246.     /* make gc for black */
  247.     gcv.foreground = BlackPixel(dpy, screen);
  248.     gcv.background = WhitePixel(dpy, screen);
  249.     gcflags = GCForeground | GCBackground | GCGraphicsExposures;
  250.  
  251.     blackgc = XCreateGC(dpy, RootWindow(dpy, screen), gcflags, &gcv);
  252.  
  253.     tmpmap = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
  254.         logo_bits, logo_width, logo_height);
  255.  
  256.     logomap = XCreatePixmap(dpy, RootWindow(dpy, screen), logo_width,
  257.         logo_height, DefaultDepth(dpy, screen));
  258.  
  259.     back_delta_x = (CARD_WIDTH - logo_width)/2;
  260.     back_delta_y = (CARD_HEIGHT - logo_height)/2;
  261.  
  262.     if (is_color)    {
  263.         cmap = DefaultColormap(dpy, screen);
  264.         XAllocNamedColor(dpy, cmap, "Sea Green", &color, &color);
  265.         gcv.foreground = color.pixel;
  266.         gcv.background = WhitePixel(dpy, screen);
  267.         gcflags = GCForeground | GCBackground;
  268.         logogc = XCreateGC(dpy, RootWindow(dpy, screen), gcflags, &gcv);
  269.         XCopyPlane(dpy, tmpmap, logomap, logogc, 0, 0, 
  270.             logo_width, logo_height, 0, 0, 1);
  271.         XFreeGC(dpy, logogc);
  272.     } else    {
  273.         XCopyPlane(dpy, tmpmap, logomap, whitegc, 0, 0, 
  274.             logo_width, logo_height, 0, 0, 1);
  275.     }
  276.     XFreePixmap(dpy, tmpmap);
  277.  
  278.     gcv.tile = logomap;
  279.     gcv.fill_style = FillTiled;
  280.     gcflags |= GCTile | GCFillStyle | GCGraphicsExposures;
  281.  
  282.     backgc = XCreateGC(dpy, RootWindow(dpy, screen), gcflags, &gcv);
  283.  
  284.     borderpixel = blackpixel;
  285.  
  286.     if (is_color)    {
  287.         cmap = DefaultColormap(dpy, screen);
  288.  
  289.         color.flags = DoRed | DoGreen | DoBlue;
  290.  
  291.         /*
  292.          * color levels are the NeWS RGB values
  293.          */
  294.         color.red = 13107;    /* 0.2 */
  295.         color.green = 52428;    /* 0.8 */
  296.         color.blue = 39321;    /* 0.6 */
  297.         XAllocColor(dpy, cmap, &color);
  298.         greenpixel = color.pixel;
  299.  
  300.         color.red = 52428;    /* 0.8 */
  301.         color.green = color.blue = 0;
  302.         XAllocColor(dpy, cmap, &color);
  303.         redpixel = color.pixel;
  304.  
  305.         gcv.foreground = redpixel;
  306.         gcv.background = WhitePixel(dpy, screen);
  307.         gcflags = GCForeground | GCBackground | GCGraphicsExposures;
  308.  
  309.         redgc = XCreateGC(dpy, RootWindow(dpy, screen), gcflags, &gcv);
  310.  
  311.     } else    {
  312.         greenmap = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
  313.             gray1_bits, gray1_width, gray1_height);
  314.  
  315.         redmap = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
  316.             gray1_bits, gray1_width, gray1_height);
  317.  
  318.         gcv.tile = redmap;
  319.         gcv.fill_style = FillTiled;
  320.  
  321.         gcv.foreground = BlackPixel(dpy, screen);
  322.         gcv.background = WhitePixel(dpy, screen);
  323.  
  324.         gcflags = GCTile | GCForeground | GCBackground |
  325.             GCFillStyle | GCGraphicsExposures;
  326.  
  327.         redgc = XCreateGC(dpy, RootWindow(dpy, screen), gcflags, &gcv);
  328.     }
  329.     make_card_maps();
  330. }
  331.  
  332. /*
  333.  * make a 'red' pixmap by setting the clipmask to the desired shape and 
  334.  * pushing 'red' through it
  335.  */
  336.  
  337. static Pixmap
  338. make_red_map(bits, width, height)
  339. char    *bits;
  340. int    width, height;
  341. {
  342. Pixmap    tmpmap, newmap;
  343. static GC    cleargc = (GC) 0;
  344. XGCValues    xgcv;
  345.  
  346.  
  347.     if (cleargc == (GC) 0)    {
  348.         xgcv.function = GXclear;
  349.         cleargc = XCreateGC(dpy, RootWindow(dpy, screen), GCFunction, 
  350.                                 &xgcv);
  351.     }
  352.  
  353.     tmpmap = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
  354.         bits, width, height);
  355.  
  356.     newmap = XCreatePixmap(dpy, RootWindow(dpy, screen), width, height, 1);
  357.  
  358.     /* clear pixmap */
  359.     XFillRectangle(dpy, newmap, cleargc, 0, 0, width, height);
  360.  
  361.     XSetClipMask(dpy, redgc, tmpmap);
  362.     XFillRectangle(dpy, newmap, redgc, 0, 0, width, height);
  363.     XSetClipMask(dpy, redgc, None);
  364.     XFreePixmap(dpy, tmpmap);
  365.  
  366.     return (newmap);
  367. }
  368.  
  369. make_card_maps()
  370. {
  371. unsigned char    *new_bits;
  372. Rank    r;
  373. int    i;
  374.  
  375.     for (r = Ace; r <= King; r++)    {
  376.         rank_map[(int)r] = XCreateBitmapFromData(dpy, 
  377.             RootWindow(dpy, screen),
  378.             rank_bits[(int)r], rank_width, rank_height);
  379.  
  380.         new_bits = (unsigned char *) calloc(sizeof(rank_bits[(int)r]),
  381.                             1);
  382.         rot_180((unsigned char *)rank_bits[(int)r], new_bits, 
  383.             rank_width, rank_height);
  384.         rank_r_map[(int)r] = XCreateBitmapFromData(dpy, 
  385.             RootWindow(dpy, screen),
  386.             new_bits, rank_width, rank_height);
  387.         free((char *)new_bits);
  388.     }
  389.  
  390.     for (r = Ace; r <= King; r++)    {
  391.         new_bits = (unsigned char *) calloc(sizeof(rank_bits[(int)r]),
  392.                             1);
  393.         rot_180((unsigned char *)rank_bits[(int)r], new_bits, 
  394.                 rank_width, rank_height);
  395.         if (is_color)    {
  396.             rank_map_red[(int)r] = XCreateBitmapFromData(dpy, 
  397.                 RootWindow(dpy, screen),
  398.                 rank_bits[(int)r], rank_width, rank_height);
  399.  
  400.             rank_r_map_red[(int)r] = XCreateBitmapFromData(dpy, 
  401.                 RootWindow(dpy, screen),
  402.                 new_bits, rank_width, rank_height);
  403.         } else    {
  404.             rank_map_red[(int)r] = make_red_map(rank_bits[(int)r],
  405.                         rank_width, rank_height);
  406.  
  407.             rank_r_map_red[(int)r] = make_red_map((char *)new_bits, 
  408.                         rank_width, rank_height);
  409.         }
  410.         free((char *)new_bits);
  411.     }
  412.  
  413.     i = (int)Spade;
  414.     /* make all the card bitmaps */
  415.     suit_map[i] = XCreateBitmapFromData(dpy, 
  416.         RootWindow(dpy, screen),
  417.         spade_bits, spade_width, spade_height);
  418.  
  419.     new_bits = (unsigned char *) calloc(sizeof(spade_bits), 1);
  420.     flip_bits((unsigned char *)spade_bits, new_bits, spade_width, 
  421.                 spade_height);
  422.     suit_r_map[i] = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
  423.         new_bits, spade_width, spade_height);
  424.     free((char *)new_bits);
  425.  
  426.     suit_sm_map[i] = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
  427.         spade_sm_bits, spade_sm_width, spade_sm_height);
  428.  
  429.     new_bits = (unsigned char *) calloc(sizeof(spade_sm_bits), 1);
  430.     flip_bits((unsigned char *)spade_sm_bits, new_bits, spade_sm_width,
  431.             spade_sm_height);
  432.     suit_sm_r_map[i] = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
  433.         new_bits, spade_sm_width, spade_sm_height);
  434.     free((char *)new_bits);
  435.  
  436.     suit_lg_map[i] = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
  437.         spade_lg_bits, spade_lg_width, spade_lg_height);
  438.  
  439.     jack_map[i] = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
  440.         jack_s_bits, jack_s_width, jack_s_height);
  441.  
  442.     queen_map[i] = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
  443.         queen_s_bits, queen_s_width, queen_s_height);
  444.  
  445.     king_map[i] = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
  446.         king_s_bits, king_s_width, king_s_height);
  447.  
  448.     i = (int)Heart;
  449.     /* make all the card bitmaps */
  450.     new_bits = (unsigned char *) calloc(sizeof(heart_bits), 1);
  451.     flip_bits((unsigned char *)heart_bits, new_bits, heart_width, 
  452.                     heart_height);
  453.  
  454.     if (is_color)    {
  455.         suit_map[i] = XCreateBitmapFromData(dpy, 
  456.             RootWindow(dpy, screen),
  457.             heart_bits, heart_width, heart_height);
  458.         suit_r_map[i] = XCreateBitmapFromData(dpy, 
  459.             RootWindow(dpy, screen),
  460.             new_bits, heart_width, heart_height);
  461.     } else    {
  462.         suit_map[i] = make_red_map(heart_bits, heart_width, 
  463.                         heart_height);
  464.         suit_r_map[i] = make_red_map((char *)new_bits, heart_width, 
  465.                         heart_height);
  466.     }
  467.  
  468.     free((char *)new_bits);
  469.  
  470.     new_bits = (unsigned char *) calloc(sizeof(heart_sm_bits), 1);
  471.     flip_bits((unsigned char *)heart_sm_bits, new_bits, heart_sm_width, 
  472.         heart_sm_height);
  473.     suit_sm_r_map[i] = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
  474.         new_bits, heart_sm_width, heart_sm_height);
  475.  
  476.     if (is_color)    {
  477.         suit_sm_map[i] = XCreateBitmapFromData(dpy, 
  478.             RootWindow(dpy, screen),
  479.             heart_sm_bits, heart_sm_width, heart_sm_height);
  480.         suit_sm_r_map[i] = XCreateBitmapFromData(dpy, 
  481.             RootWindow(dpy, screen),
  482.             new_bits, heart_sm_width, heart_sm_height);
  483.     } else    {
  484.         suit_sm_map[i] = make_red_map(heart_sm_bits, heart_sm_width, 
  485.                         heart_height);
  486.         suit_sm_r_map[i] = make_red_map((char *)new_bits, 
  487.             heart_sm_width, heart_sm_height);
  488.     }
  489.     free((char *)new_bits);
  490.  
  491.     suit_lg_map[i] = suit_map[i];
  492.  
  493.     if (is_color)    {
  494.         jack_map[i] = XCreateBitmapFromData(dpy, 
  495.             RootWindow(dpy, screen),
  496.             jack_h_bits, jack_h_width, jack_h_height);
  497.  
  498.         queen_map[i] = XCreateBitmapFromData(dpy, 
  499.             RootWindow(dpy, screen),
  500.             queen_h_bits, queen_h_width, queen_h_height);
  501.  
  502.         king_map[i] = XCreateBitmapFromData(dpy, 
  503.             RootWindow(dpy, screen),
  504.             king_h_bits, king_h_width, king_h_height);
  505.     } else    {
  506.         jack_map[i] = make_red_map(jack_h_bits, jack_h_width, 
  507.                             jack_h_height);
  508.  
  509.         queen_map[i] = make_red_map(queen_h_bits, queen_h_width, 
  510.                             queen_h_height);
  511.  
  512.         king_map[i] = make_red_map(king_h_bits, king_h_width, 
  513.                             king_h_height);
  514.     }
  515.  
  516.  
  517.     i = (int)Diamond;
  518.     /* make all the card bitmaps */
  519.     new_bits = (unsigned char *) calloc(sizeof(diamond_bits), 1);
  520.     flip_bits((unsigned char *)diamond_bits, new_bits, diamond_width, 
  521.         diamond_height);
  522.  
  523.     if (is_color)    {
  524.         suit_map[i] = XCreateBitmapFromData(dpy, 
  525.             RootWindow(dpy, screen),
  526.             diamond_bits, diamond_width, diamond_height);
  527.         suit_r_map[i] = XCreateBitmapFromData(dpy, 
  528.             RootWindow(dpy, screen),
  529.             new_bits, diamond_width, diamond_height);
  530.     } else    {
  531.         suit_map[i] = make_red_map(diamond_bits, diamond_width, 
  532.                         diamond_height);
  533.         suit_r_map[i] = make_red_map((char *)new_bits, diamond_width, 
  534.                         diamond_height);
  535.     }
  536.  
  537.     free((char *)new_bits);
  538.  
  539.     new_bits = (unsigned char *) calloc(sizeof(diamond_sm_bits), 1);
  540.     flip_bits((unsigned char *)diamond_sm_bits, new_bits, 
  541.                 diamond_sm_width, diamond_sm_height);
  542.     suit_sm_r_map[i] = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
  543.         new_bits, diamond_sm_width, diamond_sm_height);
  544.  
  545.     if (is_color)    {
  546.         suit_sm_map[i] = XCreateBitmapFromData(dpy, 
  547.             RootWindow(dpy, screen),
  548.             diamond_sm_bits, diamond_sm_width, diamond_sm_height);
  549.         suit_sm_r_map[i] = XCreateBitmapFromData(dpy, 
  550.             RootWindow(dpy, screen),
  551.             new_bits, diamond_sm_width, diamond_sm_height);
  552.     } else    {
  553.         suit_sm_map[i] = make_red_map(diamond_sm_bits, diamond_sm_width, 
  554.                         diamond_height);
  555.         suit_sm_r_map[i] = make_red_map((char *)new_bits, 
  556.                 diamond_sm_width, diamond_sm_height);
  557.     }
  558.     free((char *)new_bits);
  559.  
  560.     suit_lg_map[i] = suit_map[i];
  561.  
  562.     if (is_color)    {
  563.         jack_map[i] = XCreateBitmapFromData(dpy, 
  564.             RootWindow(dpy, screen),
  565.             jack_d_bits, jack_d_width, jack_d_height);
  566.  
  567.         queen_map[i] = XCreateBitmapFromData(dpy, 
  568.             RootWindow(dpy, screen),
  569.             queen_d_bits, queen_d_width, queen_d_height);
  570.  
  571.         king_map[i] = XCreateBitmapFromData(dpy, 
  572.             RootWindow(dpy, screen),
  573.             king_d_bits, king_d_width, king_d_height);
  574.     } else    {
  575.         jack_map[i] = make_red_map(jack_d_bits, jack_d_width, 
  576.                             jack_d_height);
  577.  
  578.         queen_map[i] = make_red_map(queen_d_bits, queen_d_width, 
  579.                             queen_d_height);
  580.  
  581.         king_map[i] = make_red_map(king_d_bits, king_d_width, 
  582.                             king_d_height);
  583.     }
  584.  
  585.     i = (int)Club;
  586.     /* make all the card bitmaps */
  587.     suit_map[i] = XCreateBitmapFromData(dpy, 
  588.         RootWindow(dpy, screen),
  589.         club_bits, club_width, club_height);
  590.  
  591.     new_bits = (unsigned char *) calloc(sizeof(club_bits), 1);
  592.     flip_bits((unsigned char *)club_bits, new_bits, club_width, 
  593.         club_height);
  594.     suit_r_map[i] = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
  595.         new_bits, club_width, club_height);
  596.     free((char *)new_bits);
  597.  
  598.     suit_sm_map[i] = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
  599.         club_sm_bits, club_sm_width, club_sm_height);
  600.  
  601.     new_bits = (unsigned char *) calloc(sizeof(club_sm_bits), 1);
  602.     flip_bits((unsigned char *)club_sm_bits, new_bits, club_sm_width, 
  603.         club_sm_height);
  604.     suit_sm_r_map[i] = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
  605.         new_bits, club_sm_width, club_sm_height);
  606.     free((char *)new_bits);
  607.  
  608.     suit_lg_map[i] = suit_map[i];
  609.  
  610.  
  611.     jack_map[i] = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
  612.         jack_c_bits, jack_c_width, jack_c_height);
  613.  
  614.     queen_map[i] = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
  615.         queen_c_bits, queen_c_width, queen_c_height);
  616.  
  617.     king_map[i] = XCreateBitmapFromData(dpy, RootWindow(dpy, screen),
  618.         king_c_bits, king_c_width, king_c_height);
  619. }
  620.  
  621. static unsigned char _reverse_byte[0x100] = {
  622.     0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
  623.     0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
  624.     0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
  625.     0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
  626.     0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
  627.     0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
  628.     0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
  629.     0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
  630.     0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
  631.     0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
  632.     0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
  633.     0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
  634.     0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
  635.     0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
  636.     0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
  637.     0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
  638.     0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
  639.     0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
  640.     0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
  641.     0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
  642.     0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
  643.     0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
  644.     0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
  645.     0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
  646.     0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
  647.     0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
  648.     0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
  649.     0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
  650.     0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
  651.     0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
  652.     0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
  653.     0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
  654. };
  655.  
  656. #define S(x,y) src[(H-1-(y))*W+(x)]
  657. #define D(x,y) dst[(H-1-(y))*W+(x)]
  658.  
  659. flip_bits(src, dst, W, H)
  660. unsigned char    *src, *dst;
  661. int    W, H;
  662. {
  663. int    x, y;
  664.  
  665.     W = (W + 7)/8;
  666.     for (y = 0; y < H; y++)    {
  667.         for (x = 0; x < W; x++)    {
  668.             D (x, y) = S (x, H - 1 - y);
  669.         }
  670.     }
  671. }
  672.  
  673. rot_180(src, dst, W, H)
  674. unsigned char   *src, *dst;
  675. int    W, H;
  676. {
  677. int     x, y;
  678. int    width = W;
  679. unsigned char    *new;
  680. int    bit;
  681.  
  682.     W = (W + 7)/8;
  683.     for (y = 0; y < H; y++) {
  684.         for (x = 0; x < W; x++) {
  685.             D (x, y) = _reverse_byte[S (W - 1 - x, H - 1 - y)];
  686.         }
  687.     }
  688.  
  689.     /* shift it over */
  690.     new = (unsigned char *)calloc((unsigned)W*H, (unsigned)1);
  691.     for (y = 0; y < H; y++)    {
  692.         for (x = 0; x < W*8; x++)    {
  693.             bit = (*(dst + (x + (W*8 - width))/8 + y * W)
  694.                 & (1 << ((x + (W*8 - width)) % 8))) ? 1 : 0;
  695.             *(new + x/8 + y*W) = (bit << (x%8)) | 
  696.                 (*(new + x/8 + y*W) & ~(1 << (x%8)));
  697.         }
  698.     }
  699.     bcopy((char *)new, (char *)dst, W*H);
  700.     free((char *)new);
  701. }
  702.  
  703. /*
  704.  * delta is 0 if the card is fully showing
  705.  */
  706. paint_card(table, x, y, rank, suit, delta)
  707. Window    table;
  708. int    x,y;
  709. Rank    rank;
  710. Suit    suit;
  711. int    delta;
  712. {
  713.     if (suit == Spade || suit == Club)    {
  714.         cardgc = blackgc;
  715.     } else    {
  716.         cardgc = redgc;
  717.     }
  718.  
  719.     if (delta)    {
  720.             cliprects[0].height = delta;
  721.         XSetClipRectangles(dpy, cardgc, x, y, cliprects, 1, Unsorted);
  722.         {
  723.             /* fill the background */
  724.             XFillRectangle(dpy, table, whitegc, x, y, 
  725.                     CARD_WIDTH, delta);
  726.             /* draw border on card */
  727.             XDrawRectangle(dpy, table, blackgc, x, y, 
  728.                     CARD_WIDTH, delta);
  729.         }
  730.         card_is_clipped = True;
  731.     } else    {    /* fill all the card */
  732.         {
  733.             /* fill the background */
  734.             XFillRectangle(dpy, table, whitegc, x, y, 
  735.             CARD_WIDTH, CARD_HEIGHT);
  736.             /* draw border on card */
  737.             XDrawRectangle(dpy, table, blackgc, x, y, 
  738.             CARD_WIDTH, CARD_HEIGHT);
  739.         }
  740.         card_is_clipped = False;
  741.     }
  742.  
  743.     switch (rank)    {
  744.     case    King:
  745.         draw_king(table, suit, x, y);
  746.         break;
  747.     case    Queen:
  748.         draw_queen(table, suit, x, y);
  749.         break;
  750.     case    Jack:
  751.         draw_jack(table, suit, x, y);
  752.         break;
  753.  
  754.     case    Ten:
  755.         draw_pip(table, suit, MID_CARD_X + x, CARD_TEN_Y1 + y);
  756.         draw_did(table, suit, MID_CARD_X + x, CARD_TEN_Y2 + y);
  757.         draw_eight_pips(table, suit, x, y);
  758.         break;
  759.  
  760.     case    Nine:
  761.         draw_pip(table, suit, x + MID_CARD_X, y + MID_CARD_Y);
  762.         draw_eight_pips(table, suit, x, y);
  763.         break;
  764.  
  765.     case    Eight:
  766.         draw_did(table, suit, x + MID_CARD_X, y + CARD_EIGHT_Y);
  767.         /* fall thru */
  768.     case    Seven:
  769.         draw_pip(table, suit, MID_CARD_X + x, CARD_SEVEN_Y + y);
  770.         /* fall thru */
  771.     case    Six:
  772.         draw_six_pips(table, suit, x, y);
  773.         break;
  774.  
  775.     case    Five:
  776.         draw_pip(table, suit, x + MID_CARD_X, y + MID_CARD_Y);
  777.         /* fall thru */
  778.     case    Four:
  779.         draw_four_pips(table, suit, x, y);
  780.         break;
  781.  
  782.     case    Three:
  783.         draw_pip(table, suit, x + MID_CARD_X, y + MID_CARD_Y);
  784.         /* fall thru */
  785.     case    Deuce:
  786.         draw_two_pips(table, suit, x, y);
  787.         break;
  788.     case    Ace:
  789.         draw_center_pip(table, suit, x + MID_CARD_X, y + MID_CARD_Y);
  790.         break;
  791.     default:
  792.         assert(0);
  793.     }
  794.  
  795.     draw_rank(table, x, y, rank, suit);
  796.  
  797.     /* clear the clip mask */
  798.     XSetClipMask(dpy, cardgc, None);
  799. }
  800.  
  801. /*
  802.  * NOTE -- for all the pip drawers except the one that actually plots the
  803.  * bits, the location is the card's location.  the drawer's take the
  804.  * pip's center as location.
  805.  */
  806.  
  807. /*
  808.  * draws right-side-up pip
  809.  *
  810.  * location is for center of pip
  811.  */
  812. draw_pip(table, suit, x, y)
  813. Window    table;
  814. Suit    suit;
  815. int    x, y;
  816. {
  817. int    w, h;
  818.  
  819.     switch(suit)    {
  820.     case    Spade:
  821.         w = spade_width;
  822.         h = spade_height;
  823.         break;
  824.     case    Diamond:
  825.         x++;
  826.         w = diamond_width;
  827.         h = diamond_height;
  828.         break;
  829.     case    Heart:
  830.         y++;
  831.         w = heart_width;
  832.         h = heart_height;
  833.         break;
  834.     case    Club:
  835.         y++;
  836.         w = club_width;
  837.         h = club_height;
  838.         break;
  839.     default:
  840.         assert(0);
  841.     }
  842.     XCopyPlane(dpy, suit_map[suit], table, cardgc, 
  843.         0, 0, w, h,
  844.         x - w/2, y - h/2, 1);
  845. }
  846.  
  847. /*
  848.  * draws upside-down pip
  849.  *
  850.  * location is for center of pip
  851.  */
  852. draw_did(table, suit, x, y)
  853. Window    table;
  854. Suit    suit;
  855. int    x,y;
  856. {
  857. int    w, h;
  858.  
  859.     if (card_is_clipped)    /* a clipped card never shows any did's */
  860.         return;
  861.  
  862.     switch(suit)    {
  863.     case    Spade:
  864.         w = spade_width;
  865.         h = spade_height;
  866.         break;
  867.     case    Diamond:
  868.         x++;
  869.         w = diamond_width;
  870.         h = diamond_height;
  871.         break;
  872.     case    Heart:
  873.         y++;
  874.         w = heart_width;
  875.         h = heart_height;
  876.         break;
  877.     case    Club:
  878.         y++;
  879.         w = club_width;
  880.         h = club_height;
  881.         break;
  882.     default:
  883.         assert(0);
  884.     }
  885.     XCopyPlane(dpy, suit_r_map[suit], table, cardgc, 
  886.         0, 0, w, h,
  887.         x - w/2, y - h/2, 1);
  888. }
  889.  
  890. /*
  891.  * draws big center pip
  892.  */
  893. draw_center_pip(table, suit, x, y)
  894. Window    table;
  895. Suit    suit;
  896. int    x,y;
  897. {
  898. int    w, h;
  899.  
  900.     if (card_is_clipped)
  901.         return;
  902.  
  903.     switch(suit)    {
  904.     case    Spade:
  905.         w = spade_lg_width;
  906.         h = spade_lg_height;
  907.         break;
  908.     case    Diamond:
  909.         w = diamond_width;
  910.         h = diamond_height;
  911.         break;
  912.     case    Heart:
  913.         w = heart_width;
  914.         h = heart_height;
  915.         break;
  916.     case    Club:
  917.         w = club_width;
  918.         h = club_height;
  919.         break;
  920.     default:
  921.         assert(0);
  922.     }
  923.     XCopyPlane(dpy, suit_lg_map[suit], table, cardgc, 
  924.         0, 0, w, h,
  925.         x - w/2, y - h/2, 1);
  926. }
  927.  
  928. /* 
  929.  * draw_two_pips
  930.  */
  931. draw_two_pips(table, suit, x, y)
  932. Window    table;
  933. Suit    suit;
  934. int    x,y;
  935. {
  936.     draw_pip(table, suit, x + MID_CARD_X, y + CARD_ROW1_Y);
  937.     draw_did(table, suit, x + MID_CARD_X, y + CARD_ROW5_Y);
  938. }
  939.  
  940. /*
  941.  * draw_four_pips
  942.  */
  943. draw_four_pips(table, suit, x, y)
  944. Window    table;
  945. Suit    suit;
  946. int    x,y;
  947. {
  948.     draw_pip(table, suit, x + CARD_COL1_X, y + CARD_ROW1_Y);
  949.     draw_did(table, suit, x + CARD_COL1_X, y + CARD_ROW5_Y);
  950.  
  951.     draw_pip(table, suit, x + CARD_COL3_X, y + CARD_ROW1_Y);
  952.     draw_did(table, suit, x + CARD_COL3_X, y + CARD_ROW5_Y);
  953. }
  954.  
  955. draw_six_pips(table, suit, x, y)
  956. Window    table;
  957. Suit    suit;
  958. int    x, y;
  959. {
  960.     draw_pip(table, suit, x + CARD_COL1_X, y + CARD_ROW1_Y);
  961.  
  962.     draw_pip(table, suit, x + CARD_COL3_X, y + CARD_ROW1_Y);
  963.  
  964.     if (card_is_clipped)
  965.         return;
  966.  
  967.     /* these are only visible when its not clipped */
  968.     draw_pip(table, suit, x + CARD_COL1_X, y + CARD_ROW3_Y);
  969.     draw_did(table, suit, x + CARD_COL1_X, y + CARD_ROW5_Y);
  970.  
  971.     draw_pip(table, suit, x + CARD_COL3_X, y + CARD_ROW3_Y);
  972.     draw_did(table, suit, x + CARD_COL3_X, y + CARD_ROW5_Y);
  973. }
  974.  
  975. draw_eight_pips(table, suit, x, y)
  976. Window    table;
  977. Suit    suit;
  978. int    x,y;
  979. {
  980.     draw_pip(table, suit, x + CARD_COL1_X, y + CARD_ROW1_Y);
  981.  
  982.     draw_pip(table, suit, x + CARD_COL3_X, y + CARD_ROW1_Y);
  983.  
  984.     if (card_is_clipped)
  985.         return;
  986.  
  987.     /* these are only visible when its not clipped */
  988.     draw_pip(table, suit, x + CARD_COL1_X, y + CARD_ROW2_Y);
  989.     draw_did(table, suit, x + CARD_COL1_X, y + CARD_ROW4_Y);
  990.     draw_did(table, suit, x + CARD_COL1_X, y + CARD_ROW5_Y);
  991.  
  992.     draw_pip(table, suit, x + CARD_COL3_X, y + CARD_ROW2_Y);
  993.     draw_did(table, suit, x + CARD_COL3_X, y + CARD_ROW4_Y);
  994.     draw_did(table, suit, x + CARD_COL3_X, y + CARD_ROW5_Y);
  995. }
  996.  
  997. draw_jack(table, suit, x, y)
  998. Window    table;
  999. Suit    suit;
  1000. int    x,y;
  1001. {
  1002.     XCopyPlane(dpy, jack_map[suit], table, cardgc, 
  1003.         0, 0, FACECARD_WIDTH, FACECARD_HEIGHT,
  1004.         x + (CARD_WIDTH - FACECARD_WIDTH)/2, 
  1005.         y + (CARD_HEIGHT - FACECARD_HEIGHT)/2, 1);
  1006.  
  1007.     XDrawRectangle(dpy, table, cardgc,
  1008.         x + (CARD_WIDTH - FACECARD_WIDTH)/2, 
  1009.         y + (CARD_HEIGHT - FACECARD_HEIGHT)/2,
  1010.         FACECARD_WIDTH, FACECARD_HEIGHT);
  1011. }
  1012.  
  1013. draw_queen(table, suit, x, y)
  1014. Window    table;
  1015. Suit    suit;
  1016. int    x,y;
  1017. {
  1018.     XCopyPlane(dpy, queen_map[suit], table, cardgc,
  1019.         0, 0, FACECARD_WIDTH, FACECARD_HEIGHT,
  1020.         x + (CARD_WIDTH - FACECARD_WIDTH)/2, 
  1021.         y + (CARD_HEIGHT - FACECARD_HEIGHT)/2, 1);
  1022.  
  1023.     XDrawRectangle(dpy, table, cardgc,
  1024.         x + (CARD_WIDTH - FACECARD_WIDTH)/2, 
  1025.         y + (CARD_HEIGHT - FACECARD_HEIGHT)/2,
  1026.         FACECARD_WIDTH, FACECARD_HEIGHT);
  1027. }
  1028.  
  1029. draw_king(table, suit, x, y)
  1030. Window    table;
  1031. Suit    suit;
  1032. int    x,y;
  1033. {
  1034.     XCopyPlane(dpy, king_map[suit], table, cardgc,
  1035.         0, 0, FACECARD_WIDTH, FACECARD_HEIGHT,
  1036.         x + (CARD_WIDTH - FACECARD_WIDTH)/2, 
  1037.         y + (CARD_HEIGHT - FACECARD_HEIGHT)/2, 1);
  1038.  
  1039.     XDrawRectangle(dpy, table, cardgc,
  1040.         x + (CARD_WIDTH - FACECARD_WIDTH)/2, 
  1041.         y + (CARD_HEIGHT - FACECARD_HEIGHT)/2,
  1042.         FACECARD_WIDTH, FACECARD_HEIGHT);
  1043. }
  1044.  
  1045. draw_rank(table, x, y, rank, suit)
  1046. Window    table;
  1047. int    x, y;
  1048. Rank    rank;
  1049. Suit    suit;
  1050. {
  1051. int    w, h;
  1052.  
  1053.     if (suit == Heart || suit == Diamond)    {
  1054.         XCopyPlane(dpy, rank_map_red[rank], table, cardgc,
  1055.             0, 0, RANK_WIDTH, RANK_HEIGHT,
  1056.             x + RANK_LOC_X, y + RANK_LOC_Y, 1);
  1057.  
  1058.         if (!card_is_clipped)
  1059.             XCopyPlane(dpy, rank_r_map_red[rank], table, cardgc,
  1060.             0, 0, RANK_WIDTH, RANK_HEIGHT,
  1061.             x + (CARD_WIDTH - RANK_WIDTH - RANK_LOC_X), 
  1062.             y + (CARD_HEIGHT - RANK_HEIGHT - RANK_LOC_Y), 1);
  1063.     } else    {
  1064.         XCopyPlane(dpy, rank_map[rank], table, cardgc,
  1065.             0, 0, RANK_WIDTH, RANK_HEIGHT,
  1066.             x + RANK_LOC_X, y + RANK_LOC_Y, 1);
  1067.  
  1068.         if (!card_is_clipped)
  1069.             XCopyPlane(dpy, rank_r_map[rank], table, cardgc,
  1070.             0, 0, RANK_WIDTH, RANK_HEIGHT,
  1071.             x + (CARD_WIDTH - RANK_WIDTH - RANK_LOC_X), 
  1072.             y + (CARD_HEIGHT - RANK_HEIGHT - RANK_LOC_Y), 1);
  1073.     }
  1074.  
  1075.     switch (suit)    {
  1076.         case    Spade:
  1077.             w = spade_sm_width;
  1078.             h = spade_sm_height;
  1079.             break;
  1080.         case    Heart:
  1081.             w = heart_sm_width;
  1082.             h = heart_sm_height;
  1083.             break;
  1084.         case    Diamond:
  1085.             x++;    /* offset the smaller width */
  1086.             w = diamond_sm_width;
  1087.             h = diamond_sm_height;
  1088.             break;
  1089.         case    Club:
  1090.             w = club_sm_width;
  1091.             h = club_sm_height;
  1092.             break;
  1093.         default:
  1094.             assert(0);
  1095.     }
  1096.     XCopyPlane(dpy, suit_sm_map[suit], table, cardgc,
  1097.         0, 0, w, h,
  1098.         x + SMALL_LOC_X, y + SMALL_LOC_Y, 1);
  1099.  
  1100.     if (!card_is_clipped)
  1101.         XCopyPlane(dpy, suit_sm_r_map[suit], table, cardgc,
  1102.         0, 0, w, h,
  1103.         x + (CARD_WIDTH - w - SMALL_LOC_X), 
  1104.         y + (CARD_HEIGHT - h - SMALL_LOC_Y), 1);
  1105. }
  1106.