home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
x
/
volume15
/
xhearts
/
part02
< prev
next >
Wrap
Text File
|
1992-02-03
|
56KB
|
1,803 lines
Newsgroups: comp.sources.x
Path: uunet!elroy.jpl.nasa.gov!ames!pasteur!nntp
From: mikey@sgi.com (Mike Yang)
Subject: v15i169: xhearts (w/ patch #1), Part02/06
Message-ID: <1992Feb4.141903.9244@pasteur.Berkeley.EDU>
Sender: dcmartin@msi.com (David C. Martin - Moderator)
Nntp-Posting-Host: postgres.berkeley.edu
Organization: University of California, at Berkeley
References: <csx-15i168-xhearts@uunet.UU.NET>
Date: Tue, 4 Feb 1992 14:19:03 GMT
Approved: dcmartin@msi.com
Submitted-by: mikey@sgi.com (Mike Yang)
Posting-number: Volume 15, Issue 169
Archive-name: xhearts/part02
# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".
# The tool that generated this appeared in the comp.sources.unix newsgroup;
# send mail to comp-sources-unix@uunet.uu.net if you want that tool.
# If this archive is complete, you will see the following message at the end:
# "End of archive 2 (of 6)."
# Contents: connect.c xawclient.c
# Wrapped by dcmartin@fascet on Wed Jan 15 06:30:34 1992
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'connect.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'connect.c'\"
else
echo shar: Extracting \"'connect.c'\" \(1157 characters\)
sed "s/^X//" >'connect.c' <<'END_OF_FILE'
X/*
X * connect.c
X *
X * client connection to hearts server
X */
X
X#include <stdio.h>
X#include "defs.h"
X#include "local.h"
X
Xchar *getenv();
X
X/*
X * Make connection to host running the hearts distributor server,
X * return fd of new socket.
X */
Xconnect_to(servhost, port)
Xchar *servhost; /* name of host running server */
Xint port;
X{
X int sock;
X struct hostent *host;
X struct servent *distributor;
X struct sockaddr_in sockaddr;
X char buf[64];
X
X if ((host = gethostbyname(servhost)) == NULL) {
X perror("gethostbyname");
X exit(1);
X }
X if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
X perror("socket");
X exit(1);
X }
X bzero((char *) &sockaddr, sizeof (sockaddr));
X bcopy(host->h_addr, (char *) &sockaddr.sin_addr, host->h_length);
X sockaddr.sin_family = AF_INET;
X if (port)
X sockaddr.sin_port = htons(port);
X else {
X if ((distributor = getservbyname(SERVICE, PROTO)) == NULL) {
X (void) sprintf(buf, "%s: service not found\n", SERVICE);
X fputs(buf, stderr);
X exit(1);
X }
X sockaddr.sin_port = distributor->s_port;
X }
X if (connect(sock, (struct sockaddr *) &sockaddr, sizeof(sockaddr)) < 0) {
X (void) close (sock);
X return(0);
X }
X return(sock);
X}
END_OF_FILE
if test 1157 -ne `wc -c <'connect.c'`; then
echo shar: \"'connect.c'\" unpacked with wrong size!
fi
# end of 'connect.c'
fi
if test -f 'xawclient.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xawclient.c'\"
else
echo shar: Extracting \"'xawclient.c'\" \(50694 characters\)
sed "s/^X//" >'xawclient.c' <<'END_OF_FILE'
X/*****************************************************************
XCopyright 1992 by Silicon Graphics Incorporated, Mountain View, CA,
Xand the Massachusetts Institute of Technology, Cambridge, Massachusetts.
X
X All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the names of SGI or MIT not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.
X
XSGI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XSGI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
X/*
X * xawclient.c - X11/Xaw client interface to hearts
X *
X * Author: Mike Yang (mikey@sgi.com)
X * Silicon Graphics, Inc.
X * Date: Fri Jan 3 1992
X * Copyright (c) 1992 Mike Yang
X */
X
X#include <stdlib.h>
X#include <malloc.h>
X#include <sys/errno.h>
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <fcntl.h>
X#include "misc.h"
X#include "defs.h"
X#include "local.h"
X#include "client.h"
X#include "gfx.h"
X#ifdef SYSV
X#include <sys/termio.h>
X#endif
X#include <X11/cursorfont.h>
X#include <X11/Intrinsic.h>
X#include <X11/StringDefs.h>
X#include <X11/Shell.h>
X#include <X11/Xaw/Form.h>
X#include <X11/Xaw/Command.h>
X#include <X11/Xaw/Label.h>
X#include <X11/Xaw/AsciiText.h>
X#include <X11/Xaw/Text.h>
X#include <X11/Xaw/Simple.h>
X
X#ifdef X11R4
X#define XawChainTop XtChainTop
X#define XawChainBottom XtChainBottom
X#define XawChainLeft XtChainLeft
X#define XawChainRight XtChainRight
X#endif
X
X#define NUM_TABLES_ROWS 2
X#define NUM_TABLES_COLS 4
X#define NUM_TABLES (NUM_TABLES_ROWS*NUM_TABLES_COLS)
X
Xstatic int count;
Xstatic Arg args[20];
X
Xtypedef struct _CardInfo {
X int rank;
X int suit;
X struct _CardInfo *next;
X} CardInfo;
X
Xtypedef struct {
X CardInfo *head;
X} SuitInfo;
X
XSuitInfo my_hand[MAX_SUIT+1];
X
XXtAppContext appContext;
XWidget toplevel, form, displayFrame, displayArea, playArea, scoreArea;
XWidget messageLabel, messageArea, messageEntry;
XWidget commandArea, showButton = NULL, autoButton = NULL;
XWidget quitButton, helpButton;
XWidget displayLabels, roundLabel, leadLabel, textArea, playLabelArea;
XWidget scorePlayer, scoreScore, scoreTotal;
XWidget playerLabels[5], scoreLabels[5], totalLabels[5];
XWidget playLabels[4];
XWidget optionForm, helpDialog = NULL, playForm, optionHeader;
XWidget gameBox, anotherGame, newGame, moreGames, quitGame, helpGame;
XWidget gamesHeader, gamesFrame, gamesRC, gamesMessage;
XBoolean showOld, *anotherPtr;
XCardInfo playCards[4], lastCards[4];
Xchar playNames[4][256], lastNames[4][256];
XXtInputId distId = None, dealerId = None;
XBoolean readingCard;
XCursor cardCursor = None;
XDimension globalTableHeight;
X
XresizeWidget(w, width, height)
XWidget w;
XDimension width, height;
X{
X Dimension bw;
X Position x, y;
X
X count = 0;
X if (!width) {
X XtSetArg(args[count], XtNwidth, &width); count++;
X }
X if (!height) {
X XtSetArg(args[count], XtNheight, &height); count++;
X }
X XtSetArg(args[count], XtNborderWidth, &bw); count++;
X XtSetArg(args[count], XtNx, &x); count++;
X XtSetArg(args[count], XtNy, &y); count++;
X XtGetValues(w, args, count);
X count = 0;
X XtSetArg(args[count], XtNwidth, width); count++;
X XtSetArg(args[count], XtNheight, height); count++;
X XtSetValues(w, args, count);
X XtConfigureWidget(w, x, y, width, height, bw);
X}
X
XupdateLabel(w)
XWidget w;
X{
X XEvent event;
X
X while (XCheckTypedWindowEvent(XtDisplay(w), XtWindow(w), Expose, &event)) {
X XtDispatchEvent(&event);
X }
X}
X
XupdateDisplay()
X{
X int i;
X
X for (i=0; i<4; i++) {
X updateLabel(playLabels[i]);
X }
X updateLabel(roundLabel);
X updateLabel(leadLabel);
X}
X
XRank
XconvertRank(rank)
Xint rank;
X{
X if (rank == 13) {
X return Ace;
X } else {
X return rank;
X }
X}
X
XSuit
XconvertSuit(suit)
Xint suit;
X{
X Suit s;
X
X switch (suit) {
X case SPADES:
X s = Spade;
X break;
X case HEARTS:
X s = Heart;
X break;
X case DIAMONDS:
X s = Diamond;
X break;
X case CLUBS:
X s = Club;
X break;
X }
X return s;
X}
X
Xvoid
XshowPlayArea(cards, names)
XCardInfo *cards;
Xchar names[4][256];
X{
X int i;
X
X for (i=0; i<4; i++) {
X if (cards[i].rank) {
X paint_card(XtWindow(playArea), i*STACK_WIDTH, 0,
X convertRank(cards[i].rank), convertSuit(cards[i].suit), 0);
X } else {
X XClearArea(XtDisplay(playArea), XtWindow(playArea), i*STACK_WIDTH, 0,
X STACK_WIDTH, 0, False);
X }
X count = 0;
X if (cards[i].rank) {
X XtSetArg(args[count], XtNlabel, names[i]); count++;
X } else {
X XtSetArg(args[count], XtNlabel, " "); count++;
X }
X XtSetValues(playLabels[i], args, count);
X }
X}
X
Xvoid
XsetShowOld(v)
XBoolean v;
X{
X if (showOld != v) {
X showOld = v;
X if (showOld) {
X showPlayArea(lastCards, lastNames);
X } else {
X showPlayArea(playCards, playNames);
X }
X }
X}
X
Xvoid
XsetReadingCard(v)
XBoolean v;
X{
X if (readingCard != v) {
X readingCard = v;
X if (cardCursor == None) {
X cardCursor = XCreateFontCursor(XtDisplay(toplevel), XC_hand1);
X }
X if (XtIsRealized(displayArea)) {
X if (readingCard) {
X XDefineCursor(XtDisplay(displayArea), XtWindow(displayArea),
X cardCursor);
X } else {
X XUndefineCursor(XtDisplay(displayArea), XtWindow(displayArea));
X }
X XFlush(XtDisplay(displayArea));
X }
X if (!readingCard && showOld) {
X setShowOld(False);
X }
X }
X}
X
X/**********************************************************************/
X
Xvoid
XexposeDisplayArea(w, client_data, call_data)
XWidget w;
XXtPointer client_data;
XXtPointer call_data;
X{
X Suit suit;
X
X for (suit=CLUBS; suit<=SPADES; suit++) {
X print_cards(suit);
X }
X}
X
Xvoid
XdisplaySelect(w, client_data, event)
XWidget w;
XXtPointer client_data;
XXEvent *event;
X{
X int suit, card, count;
X CardInfo *ptr, *cardSelected;
X char rch, sch;
X static char rnames[] = " 23456789TJQKA";
X
X cardSelected = NULL;
X if (readingCard &&
X event->type == ButtonPress && event->xbutton.button == Button1) {
X suit = (event->xbutton.x/STACK_WIDTH)+1;
X card = (event->xbutton.y/CARD_DELTA)+1;
X if (event->xbutton.x % STACK_WIDTH > CARD_WIDTH) {
X /* clicked on space between stacks */
X } else if (suit > 4) {
X /* clicked outside stacks */
X } else {
X ptr = my_hand[suit].head;
X count = 0;
X while (count < card && ptr->next) {
X count++;
X ptr = ptr->next;
X }
X if (count == card) {
X cardSelected = ptr;
X } else if (count < card &&
X event->xbutton.y-(count-1)*CARD_DELTA < CARD_HEIGHT) {
X /* clicked on last card */
X cardSelected = ptr;
X } else {
X /* clicked below stack */
X }
X }
X }
X if (cardSelected) {
X rch = rnames[cardSelected->rank];
X switch (cardSelected->suit) {
X case SPADES:
X sch = 's';
X break;
X case HEARTS:
X sch = 'h';
X break;
X case DIAMONDS:
X sch = 'd';
X break;
X case CLUBS:
X sch = 'c';
X break;
X }
X send_card(rch, sch);
X setReadingCard(False);
X erase_window(TEXT_WINDOW);
X } else {
X XBell(XtDisplay(toplevel), 0);
X }
X}
X
Xvoid
Xshow_button(w, client_data, call_data)
XWidget w;
XXtPointer client_data;
XXtPointer call_data;
X{
X if (readingCard) {
X setShowOld(!showOld);
X }
X}
X
Xvoid
Xauto_play(w, client_data, call_data)
XWidget w;
XXtPointer client_data;
XXtPointer call_data;
X{
X if (readingCard) {
X send_auto();
X setReadingCard(False);
X erase_window(TEXT_WINDOW);
X }
X}
X
Xvoid
Xquit_game(w, client_data, call_data)
XWidget w;
XXtPointer client_data;
XXtPointer call_data;
X{
X wimp_out();
X}
X
Xvoid
Xhelp_away(w, client_data, call_data)
XWidget w;
XXtPointer client_data;
XXtPointer call_data;
X{
X XtPopdown(helpDialog);
X}
X
Xvoid
Xhelp_me(w, client_data, call_data)
XWidget w;
XXtPointer client_data;
XXtPointer call_data;
X{
X Widget form, text, okButton, label;
X char filename[256];
X int fildes;
X struct stat buf;
X char *data;
X
X if (!helpDialog) {
X count = 0;
X helpDialog = XtCreatePopupShell("xawhearts help", topLevelShellWidgetClass,
X toplevel, args, count);
X count = 0;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X form = XtCreateManagedWidget("helpForm", formWidgetClass, helpDialog,
X args, count);
X
X count = 0;
X XtSetArg(args[count], XtNscrollVertical, True); count++;
X XtSetArg(args[count], XtNheight, 200); count++;
X XtSetArg(args[count], XtNwidth, 700); count++;
X text = XtCreateManagedWidget("helpText", asciiTextWidgetClass, form,
X args, count);
X
X count = 0;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNfromVert, text); count++;
X XtSetArg(args[count], XtNvertDistance, 10); count++;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNlabel, "Xawhearts, an Xaw interface to hearts. Mike Yang, Silicon Graphics, mikey@sgi.com"); count++;
X label = XtCreateManagedWidget("label", labelWidgetClass, form,
X args, count);
X
X count = 0;
X XtSetArg(args[count], XtNfromVert, text); count++;
X XtSetArg(args[count], XtNvertDistance, 10); count++;
X XtSetArg(args[count], XtNfromHoriz, label); count++;
X XtSetArg(args[count], XtNhorizDistance, 10); count++;
X XtSetArg(args[count], XtNleft, XawChainRight); count++;
X XtSetArg(args[count], XtNright, XawChainRight); count++;
X XtSetArg(args[count], XtNtop, XawChainBottom); count++;
X XtSetArg(args[count], XtNbottom, XawChainBottom); count++;
X XtSetArg(args[count], XtNlabel, "OK"); count++;
X okButton = XtCreateManagedWidget("helpOK", commandWidgetClass, form,
X args, count);
X XtAddCallback(okButton, XtNcallback, help_away, NULL);
X
X sprintf(filename, "%s/%s", HEARTSLIB, INSTRUCT);
X if ((fildes = open(filename, O_RDONLY)) != -1) {
X fstat(fildes, &buf);
X data = (char *) malloc((size_t) buf.st_size+1);
X read(fildes, data, (unsigned) buf.st_size);
X data[buf.st_size] = '\0';
X close(fildes);
X count = 0;
X XtSetArg(args[count], XtNstring, data); count++;
X XtSetValues(text, args, count);
X free(data);
X } else {
X count = 0;
X XtSetArg(args[count], XtNstring, "Help file missing.\n"); count++;
X XtSetValues(text, args, count);
X }
X }
X XtPopup(helpDialog, XtGrabNone);
X}
X
Xvoid
XexposePlayArea(w, client_data, call_data)
XWidget w;
XXtPointer client_data;
XXtPointer call_data;
X{
X if (showOld) {
X showPlayArea(lastCards, lastNames);
X } else {
X showPlayArea(playCards, playNames);
X }
X}
X
Xvoid
Xanother_game(w, client_data, call_data)
XWidget w;
XXtPointer client_data;
XXtPointer call_data;
X{
X *anotherPtr = TRUE;
X if (!first_game) {
X joined = TRUE;
X }
X}
X
Xvoid
Xnew_game(w, client_data, call_data)
XWidget w;
XXtPointer client_data;
XXtPointer call_data;
X{
X start_new_game();
X joined = TRUE;
X}
X
Xvoid
Xmore_games(w, client_data, call_data)
XWidget w;
XXtPointer client_data;
XXtPointer call_data;
X{
X if (table_count > NUM_TABLES) {
X if ((cur_screen_table += NUM_TABLES) > table_count) {
X cur_screen_table = 1;
X }
X show_tables(cur_screen_table);
X }
X}
X
Xvoid
XtableSelect(w, client_data, event)
XWidget w;
XXtPointer client_data;
XXEvent *event;
X{
X int i;
X Widget *widgets;
X table_ptr cur_ptr;
X
X if (table_count && first_game &&
X event->type == ButtonPress && event->xbutton.button == Button1) {
X cur_ptr = first_table;
X for (i=0; i<table_count; i++) {
X if (cur_ptr->data && !cur_ptr->closed) {
X widgets = (Widget *) cur_ptr->data;
X if (w == widgets[1]) {
X join_game(cur_ptr->table_id);
X joined = TRUE;
X return;
X }
X }
X cur_ptr = cur_ptr->next_table;
X }
X } else if (XtIsSensitive(anotherGame)) {
X another_game(w, NULL, NULL);
X }
X}
X
Xvoid
Xsend_msg(w, event, params, num_params)
XWidget w;
XXEvent *event;
XString *params;
XCardinal *num_params;
X{
X char *msg;
X
X count = 0;
X XtSetArg(args[count], XtNstring, &msg); count++;
X XtGetValues(messageEntry, args, count);
X count = 0;
X XtSetArg(args[count], XtNstring, ""); count++;
X XtSetValues(messageEntry, args, count);
X send_message(msg);
X XtFree(msg);
X}
X
X/**********************************************************************/
X
Xvoid
XdealerInput(client_data, source, id)
XXtPointer client_data;
Xint *source;
XXtInputId *id;
X{
X fd_type read_fd;
X int nready;
X struct timeval timeout;
X
X timeout.tv_sec = 0;
X timeout.tv_usec = 0;
X fd_init(dealer_socket, &read_fd);
X while (dealerId &&
X (nready = select(WIDTH, &read_fd, (fd_type *) 0, (fd_type *) 0,
X &timeout)) && nready > 0) {
X do_socket();
X }
X}
X
Xvoid
XdistInput(client_data, source, id)
XXtPointer client_data;
Xint *source;
XXtInputId *id;
X{
X fd_type read_fd;
X int nready;
X struct timeval timeout;
X
X timeout.tv_sec = 0;
X timeout.tv_usec = 0;
X fd_init(dist_socket, &read_fd);
X while (distId &&
X (nready = select(WIDTH, &read_fd, (fd_type *) 0, (fd_type *) 0,
X &timeout)) && nready > 0) {
X do_dist();
X }
X}
X
XWidget
XbuildScoreLabels(parent, header, array)
XWidget parent;
Xchar *header;
XWidget *array;
X{
X Widget rc, last;
X Dimension width;
X int each;
X
X count = 0;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X rc = XtCreateManagedWidget("scoresColumn", formWidgetClass, parent,
X args, count);
X count = 0;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X if (array == playerLabels) {
X XtSetArg(args[count], XtNjustify, XtJustifyLeft); count++;
X } else {
X XtSetArg(args[count], XtNjustify, XtJustifyRight); count++;
X }
X XtSetArg(args[count], XtNlabel, header); count++;
X array[0] = XtCreateManagedWidget("header", labelWidgetClass, rc,
X args, count);
X count = 0;
X XtSetArg(args[count], XtNwidth, &width); count++;
X XtGetValues(array[0], args, count);
X last = array[0];
X for (each=1; each<=4; each++) {
X count = 0;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X if (array == playerLabels) {
X XtSetArg(args[count], XtNjustify, XtJustifyLeft); count++;
X } else {
X XtSetArg(args[count], XtNjustify, XtJustifyRight); count++;
X }
X XtSetArg(args[count], XtNlabel, " "); count++;
X XtSetArg(args[count], XtNfromVert, last); count++;
X XtSetArg(args[count], XtNwidth, width); count++;
X array[each] = XtCreateManagedWidget("label", labelWidgetClass, rc,
X args, count);
X last = array[each];
X }
X return rc;
X}
X
Xvoid
XbuildScoreArea(parent)
XWidget parent;
X{
X Widget rc, p, s, t;
X
X count = 0;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X rc = XtCreateManagedWidget("scoreArea", formWidgetClass, parent,
X args, count);
X p = buildScoreLabels(rc, "Player: ", playerLabels);
X s = buildScoreLabels(rc, "Score:", scoreLabels);
X count = 0;
X XtSetArg(args[count], XtNfromHoriz, p); count++;
X XtSetValues(s, args, count);
X t = buildScoreLabels(rc, "Total:", totalLabels);
X count = 0;
X XtSetArg(args[count], XtNfromHoriz, s); count++;
X XtSetValues(t, args, count);
X}
X
Xvoid
XbuildCommandArea(parent)
XWidget parent;
X{
X Widget rc;
X
X count = 0;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X rc = XtCreateManagedWidget("commandArea", formWidgetClass, parent,
X args, count);
X count = 0;
X XtSetArg(args[count], XtNlabel, "Toggle Last"); count++;
X showButton = XtCreateManagedWidget("showButton", commandWidgetClass, rc,
X args, count);
X XtAddCallback(showButton, XtNcallback, show_button, NULL);
X count = 0;
X XtSetArg(args[count], XtNlabel, "Auto Play"); count++;
X XtSetArg(args[count], XtNfromHoriz, showButton); count++;
X autoButton = XtCreateManagedWidget("autoButton", commandWidgetClass, rc,
X args, count);
X XtAddCallback(autoButton, XtNcallback, auto_play, NULL);
X count = 0;
X XtSetArg(args[count], XtNlabel, "Quit"); count++;
X XtSetArg(args[count], XtNfromHoriz, autoButton); count++;
X quitButton = XtCreateManagedWidget("quitButton", commandWidgetClass, rc,
X args, count);
X XtAddCallback(quitButton, XtNcallback, quit_game, NULL);
X count = 0;
X XtSetArg(args[count], XtNlabel, "Help"); count++;
X XtSetArg(args[count], XtNfromHoriz, quitButton); count++;
X helpButton = XtCreateManagedWidget("helpButton", commandWidgetClass, rc,
X args, count);
X XtAddCallback(helpButton, XtNcallback, help_me, NULL);
X}
X
Xvoid
XbuildInterface(parent)
XWidget parent;
X{
X Widget form;
X
X static String textTranslations = "<Key>Return:doreturn()";
X static XtActionsRec actionTable[] = {
X {"doreturn", send_msg},
X {NULL, NULL},
X };
X
X count = 0;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X form = XtCreateManagedWidget("form", formWidgetClass, parent, args, count);
X
X count = 0;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainLeft); count++;
X XtSetArg(args[count], XtNtop, XawChainTop); count++;
X XtSetArg(args[count], XtNbottom, XawChainTop); count++;
X XtSetArg(args[count], XtNdefaultDistance, STACK_SPACING); count++;
X displayFrame = XtCreateManagedWidget("displayFrame", formWidgetClass, form,
X args, count);
X
X count = 0;
X XtSetArg(args[count], XtNvertDistance, 10); count++;
X XtSetArg(args[count], XtNhorizDistance, 10); count++;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNwidth, 4*STACK_WIDTH-STACK_SPACING+2); count++;
X XtSetArg(args[count], XtNheight, 12*CARD_DELTA+CARD_HEIGHT+2); count++;
X displayArea = XtCreateManagedWidget("displayArea", simpleWidgetClass,
X displayFrame, args, count);
X XtAddEventHandler(displayArea, ExposureMask, False, exposeDisplayArea, NULL);
X XtAddEventHandler(displayArea, ButtonPressMask, False, displaySelect, NULL);
X
X count = 0;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainLeft); count++;
X XtSetArg(args[count], XtNtop, XawChainTop); count++;
X XtSetArg(args[count], XtNbottom, XawChainTop); count++;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNfromVert, displayFrame); count++;
X XtSetArg(args[count], XtNvertDistance, 10); count++;
X/* adjust for display frame margin */
X XtSetArg(args[count], XtNhorizDistance, 10); count++;
X XtSetArg(args[count], XtNwidth, 4*STACK_WIDTH-STACK_SPACING+2); count++;
X XtSetArg(args[count], XtNheight, CARD_HEIGHT+2); count++;
X playArea = XtCreateManagedWidget("playArea", formWidgetClass,
X form, args, count);
X XtAddEventHandler(playArea, ExposureMask, False, exposePlayArea, NULL);
X
X count = 0;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainLeft); count++;
X XtSetArg(args[count], XtNtop, XawChainTop); count++;
X XtSetArg(args[count], XtNbottom, XawChainTop); count++;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNfromVert, playArea); count++;
X XtSetArg(args[count], XtNvertDistance, 10); count++;
X/* adjust for display frame margin */
X XtSetArg(args[count], XtNhorizDistance, 10); count++;
X playLabelArea = XtCreateManagedWidget("playLabelArea", formWidgetClass,
X form, args, count);
X
X count = 0;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNlabel, " "); count++;
X XtSetArg(args[count], XtNwidth, CARD_WIDTH); count++;
X XtSetArg(args[count], XtNresize, False); count++;
X playLabels[0] = XtCreateManagedWidget("playLabel", labelWidgetClass,
X playLabelArea, args, count);
X count = 0;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNlabel, " "); count++;
X XtSetArg(args[count], XtNwidth, CARD_WIDTH); count++;
X XtSetArg(args[count], XtNfromHoriz, playLabels[0]); count++;
X XtSetArg(args[count], XtNhorizDistance, STACK_SPACING); count++;
X XtSetArg(args[count], XtNresize, False); count++;
X playLabels[1] = XtCreateManagedWidget("playLabel", labelWidgetClass,
X playLabelArea, args, count);
X count = 0;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNlabel, " "); count++;
X XtSetArg(args[count], XtNwidth, CARD_WIDTH); count++;
X XtSetArg(args[count], XtNfromHoriz, playLabels[1]); count++;
X XtSetArg(args[count], XtNhorizDistance, STACK_SPACING); count++;
X XtSetArg(args[count], XtNresize, False); count++;
X playLabels[2] = XtCreateManagedWidget("playLabel", labelWidgetClass,
X playLabelArea, args, count);
X count = 0;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNlabel, " "); count++;
X XtSetArg(args[count], XtNwidth, CARD_WIDTH); count++;
X XtSetArg(args[count], XtNfromHoriz, playLabels[2]); count++;
X XtSetArg(args[count], XtNhorizDistance, STACK_SPACING); count++;
X XtSetArg(args[count], XtNresize, False); count++;
X playLabels[3] = XtCreateManagedWidget("playLabel", labelWidgetClass,
X playLabelArea, args, count);
X
X count = 0;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainRight); count++;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNfromHoriz, displayFrame); count++;
X XtSetArg(args[count], XtNhorizDistance, 10); count++;
X displayLabels = XtCreateManagedWidget("displayLabels", formWidgetClass,
X form, args, count);
X
X count = 0;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainRight); count++;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNlabel, "New hand..."); count++;
X XtSetArg(args[count], XtNjustify, XtJustifyLeft); count++;
X XtSetArg(args[count], XtNwidth, 10); count++;
X roundLabel = XtCreateManagedWidget("roundLabel", labelWidgetClass,
X displayLabels, args, count);
X
X count = 0;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainRight); count++;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNlabel, "Round: 1"); count++;
X XtSetArg(args[count], XtNjustify, XtJustifyLeft); count++;
X XtSetArg(args[count], XtNfromVert, roundLabel); count++;
X XtSetArg(args[count], XtNwidth, 10); count++;
X leadLabel = XtCreateManagedWidget("roundLabel", labelWidgetClass,
X displayLabels, args, count);
X
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainRight); count++;
X XtSetArg(args[count], XtNtop, XawChainTop); count++;
X XtSetArg(args[count], XtNbottom, XawChainTop); count++;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNlabel, " "); count++;
X XtSetArg(args[count], XtNjustify, XtJustifyLeft); count++;
X XtSetArg(args[count], XtNfromVert, leadLabel); count++;
X XtSetArg(args[count], XtNwidth, 10); count++;
X textArea = XtCreateManagedWidget("textArea", labelWidgetClass,
X displayLabels, args, count);
X count = 0;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainLeft); count++;
X XtSetArg(args[count], XtNtop, XawChainTop); count++;
X XtSetArg(args[count], XtNbottom, XawChainTop); count++;
X scoreArea = XtCreateManagedWidget("scoreArea", formWidgetClass,
X form, args, count);
X XtManageChild(scoreArea);
X buildScoreArea(scoreArea);
X
X count = 0;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainLeft); count++;
X XtSetArg(args[count], XtNtop, XawChainTop); count++;
X XtSetArg(args[count], XtNbottom, XawChainTop); count++;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNlabel, "Messages:"); count++;
X XtSetArg(args[count], XtNfromVert, scoreArea); count++;
X XtSetArg(args[count], XtNvertDistance, 10); count++;
X XtSetArg(args[count], XtNfromHoriz, displayFrame); count++;
X XtSetArg(args[count], XtNhorizDistance, 10); count++;
X XtSetArg(args[count], XtNjustify, XtJustifyLeft); count++;
X messageLabel = XtCreateManagedWidget("messageLabel", labelWidgetClass,
X form, args, count);
X
X count = 0;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainRight); count++;
X XtSetArg(args[count], XtNtop, XawChainTop); count++;
X XtSetArg(args[count], XtNbottom, XawChainBottom); count++;
X XtSetArg(args[count], XtNscrollVertical, True); count++;
X/* The height is important, so that the buttons line up with the bottom
X of the screen. Unfortunately, I can't figure out how to do the
X form constraints to make this happen cleanly. */
X XtSetArg(args[count], XtNheight, 430); count++;
X XtSetArg(args[count], XtNwidth, 500); count++;
X XtSetArg(args[count], XtNfromVert, messageLabel); count++;
X XtSetArg(args[count], XtNfromHoriz, displayFrame); count++;
X XtSetArg(args[count], XtNhorizDistance, 10); count++;
X messageArea = XtCreateManagedWidget("messageArea", asciiTextWidgetClass,
X form, args, count);
X
X count = 0;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainRight); count++;
X XtSetArg(args[count], XtNtop, XawChainBottom); count++;
X XtSetArg(args[count], XtNbottom, XawChainBottom); count++;
X XtSetArg(args[count], XtNwidth, 500); count++;
X XtSetArg(args[count], XtNfromVert, messageArea); count++;
X XtSetArg(args[count], XtNfromHoriz, displayFrame); count++;
X XtSetArg(args[count], XtNhorizDistance, 10); count++;
X XtSetArg(args[count], XtNeditType, XawtextEdit); count++;
X messageEntry = XtCreateManagedWidget("messageEntry", asciiTextWidgetClass,
X form, args, count);
X XtOverrideTranslations(messageEntry,
X XtParseTranslationTable(textTranslations));
X XtAppAddActions(XtWidgetToApplicationContext(messageEntry),
X actionTable, XtNumber(actionTable));
X
X count = 0;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainLeft); count++;
X XtSetArg(args[count], XtNtop, XawChainBottom); count++;
X XtSetArg(args[count], XtNbottom, XawChainBottom); count++;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNfromVert, messageEntry); count++;
X XtSetArg(args[count], XtNvertDistance, 10); count++;
X XtSetArg(args[count], XtNfromHoriz, displayFrame); count++;
X XtSetArg(args[count], XtNhorizDistance, 10); count++;
X commandArea = XtCreateManagedWidget("commandArea", formWidgetClass,
X form, args, count);
X buildCommandArea(commandArea);
X}
X
Xvoid
XbuildOptionInterface(parent)
XWidget parent;
X{
X count = 0;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X optionForm = XtCreateManagedWidget("optionForm", formWidgetClass,
X parent, args, count);
X
X count = 0;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainLeft); count++;
X XtSetArg(args[count], XtNtop, XawChainTop); count++;
X XtSetArg(args[count], XtNbottom, XawChainTop); count++;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNlabel, "Welcome to the Game of Hearts"); count++;
X XtSetArg(args[count], XtNjustify, XtJustifyCenter); count++;
X XtSetArg(args[count], XtNresize, False); count++;
X optionHeader = XtCreateManagedWidget("optionHeader", labelWidgetClass,
X optionForm, args, count);
X
X count = 0;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainLeft); count++;
X XtSetArg(args[count], XtNtop, XawChainTop); count++;
X XtSetArg(args[count], XtNbottom, XawChainTop); count++;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNfromVert, optionHeader); count++;
X XtSetArg(args[count], XtNvertDistance, 20); count++;
X XtSetArg(args[count], XtNjustify, XtJustifyCenter); count++;
X if (MIKEYJ) {
X XtSetArg(args[count], XtNlabel,
X "(the Jack of Diamonds scores -10)"); count++;
X } else {
X XtSetArg(args[count], XtNlabel, " "); count++;
X }
X gamesMessage= XtCreateManagedWidget("gamesMessage", labelWidgetClass,
X optionForm, args, count);
X
X count = 0;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainLeft); count++;
X XtSetArg(args[count], XtNtop, XawChainTop); count++;
X XtSetArg(args[count], XtNbottom, XawChainTop); count++;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNfromVert, gamesMessage); count++;
X XtSetArg(args[count], XtNvertDistance, 20); count++;
X XtSetArg(args[count], XtNjustify, XtJustifyLeft); count++;
X XtSetArg(args[count], XtNlabel, "Current Games:"); count++;
X gamesHeader = XtCreateManagedWidget("gamesHeader", labelWidgetClass,
X optionForm, args, count);
X
X count = 0;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainLeft); count++;
X XtSetArg(args[count], XtNtop, XawChainTop); count++;
X XtSetArg(args[count], XtNbottom, XawChainBottom); count++;
X XtSetArg(args[count], XtNfromVert, gamesHeader); count++;
X XtSetArg(args[count], XtNdefaultDistance, 0); count++;
X gamesFrame = XtCreateManagedWidget("gamesFrame", formWidgetClass,
X optionForm, args, count);
X
X count = 0;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainRight); count++;
X XtSetArg(args[count], XtNtop, XawChainTop); count++;
X XtSetArg(args[count], XtNbottom, XawChainBottom); count++;
X XtSetArg(args[count], XtNdefaultDistance, 0); count++;
X XtSetArg(args[count], XtNwidth, 10); count++;
X XtSetArg(args[count], XtNheight, 10); count++;
X gamesRC = XtCreateManagedWidget("gamesRC", formWidgetClass,
X gamesFrame, args, count);
X
X count = 0;
X XtSetArg(args[count], XtNleft, XawChainRight); count++;
X XtSetArg(args[count], XtNright, XawChainRight); count++;
X XtSetArg(args[count], XtNtop, XawChainBottom); count++;
X XtSetArg(args[count], XtNbottom, XawChainBottom); count++;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNfromVert, gamesFrame); count++;
X XtSetArg(args[count], XtNvertDistance, 10); count++;
X gameBox = XtCreateManagedWidget("gameBox", formWidgetClass,
X optionForm, args, count);
X
X count = 0;
X XtSetArg(args[count], XtNlabel, "Another Game"); count++;
X anotherGame = XtCreateManagedWidget("anotherGame", commandWidgetClass,
X gameBox, args, count);
X XtAddCallback(anotherGame, XtNcallback, another_game, NULL);
X
X count = 0;
X XtSetArg(args[count], XtNlabel, "New Game"); count++;
X XtSetArg(args[count], XtNfromHoriz, anotherGame); count++;
X newGame = XtCreateManagedWidget("newGame", commandWidgetClass,
X gameBox, args, count);
X XtAddCallback(newGame, XtNcallback, new_game, NULL);
X
X count = 0;
X XtSetArg(args[count], XtNlabel, "More Games"); count++;
X XtSetArg(args[count], XtNfromHoriz, newGame); count++;
X moreGames = XtCreateManagedWidget("moreGames", commandWidgetClass,
X gameBox, args, count);
X XtAddCallback(moreGames, XtNcallback, more_games, NULL);
X
X count = 0;
X XtSetArg(args[count], XtNlabel, "Quit"); count++;
X XtSetArg(args[count], XtNfromHoriz, moreGames); count++;
X quitGame = XtCreateManagedWidget("quitGame", commandWidgetClass,
X gameBox, args, count);
X XtAddCallback(quitGame, XtNcallback, quit_game, NULL);
X
X count = 0;
X XtSetArg(args[count], XtNlabel, "Help"); count++;
X XtSetArg(args[count], XtNfromHoriz, quitGame); count++;
X helpGame = XtCreateManagedWidget("helpGame", commandWidgetClass,
X gameBox, args, count);
X XtAddCallback(helpGame, XtNcallback, help_me, NULL);
X
X playForm = form;
X}
X
Xinit(argc_p, argv)
Xint *argc_p;
Xchar **argv;
X{
X char ch, *pager, buffer[128];
X int suit;
X CardInfo *card;
X
X toplevel = XtInitialize(argv[0], "Xawhearts", NULL, 0, argc_p, argv);
X appContext = XtWidgetToApplicationContext(toplevel);
X
X count = 0;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X form = XtCreateManagedWidget("form", formWidgetClass,
X toplevel, args, count);
X
X buildInterface(form);
X buildOptionInterface(form);
X gfx_init(XtDisplay(toplevel), XScreenNumberOfScreen(XtScreen(toplevel)));
X
X XtRealizeWidget(toplevel);
X fixupLayout();
X XtAddEventHandler(form, StructureNotifyMask, False,
X (XtEventHandler) fixupLayout, NULL);
X
X for (suit=CLUBS; suit<=SPADES; suit++) {
X card = (CardInfo *) malloc(sizeof(CardInfo));
X card->rank = card->suit = 0;
X card->next = NULL;
X my_hand[suit].head = card;
X }
X playCards[0].rank = 0;
X playCards[1].rank = 0;
X playCards[2].rank = 0;
X playCards[3].rank = 0;
X playNames[0][0] = '\0';
X playNames[1][0] = '\0';
X playNames[2][0] = '\0';
X playNames[3][0] = '\0';
X lastCards[0].rank = 0;
X lastCards[1].rank = 0;
X lastCards[2].rank = 0;
X lastCards[3].rank = 0;
X lastNames[0][0] = '\0';
X lastNames[1][0] = '\0';
X lastNames[2][0] = '\0';
X lastNames[3][0] = '\0';
X setReadingCard(False);
X}
X
Xprint_cards(suit)
Xint suit;
X{
X CardInfo *ptr;
X int y;
X Rank r;
X Suit s;
X
X s = convertSuit(suit);
X ptr = my_hand[suit].head;
X y = 0;
X while (ptr->next) {
X ptr = ptr->next;
X r = convertRank(ptr->rank);
X paint_card(XtWindow(displayArea), (suit-1)*STACK_WIDTH, y, r, s,
X ptr->next ? CARD_DELTA : 0);
X y += CARD_DELTA;
X }
X if (y) {
X XClearArea(XtDisplay(displayArea), XtWindow(displayArea),
X (suit-1)*STACK_WIDTH, y+CARD_HEIGHT-CARD_DELTA+1 /* bw */,
X STACK_WIDTH, 0, False);
X } else {
X XClearArea(XtDisplay(displayArea), XtWindow(displayArea),
X (suit-1)*STACK_WIDTH, 0,
X STACK_WIDTH, 0, False);
X }
X}
X
Xvoid
XdisplayMessage(msg)
Xchar *msg;
X{
X count = 0;
X XtSetArg(args[count], XtNlabel, msg); count++;
X XtSetValues(textArea, args, count);
X}
X
X
Xvoid
XpositionTables()
X{
X int i, ct;
X table_ptr cur_ptr;
X Widget *widgets;
X Dimension width, height, tableHeight, tableWidth, spacing;
X Dimension marginWidth, marginHeight, bw;
X Position x, y;
X
X ct = 0;
X cur_ptr = first_table;
X /* make the gamesRC as large as the gamesFrame */
X count = 0;
X XtSetArg(args[count], XtNwidth, &width); count++;
X XtSetArg(args[count], XtNheight, &height); count++;
X XtGetValues(gamesFrame, args, count);
X resizeWidget(gamesRC, width, height);
X marginWidth = 10;
X marginHeight = 10;
X spacing = 10;
X for (i=0; i<table_count; i++) {
X if (cur_ptr->data) {
X widgets = (Widget *) cur_ptr->data;
X if (XtIsManaged(widgets[0])) {
X count = 0;
X XtSetArg(args[count], XtNheight, &tableHeight); count++;
X XtSetArg(args[count], XtNborderWidth, &bw); count++;
X XtGetValues(widgets[0], args, count);
X tableHeight = globalTableHeight;
X if (width >
X 2*marginWidth+NUM_TABLES_COLS*4+(NUM_TABLES_COLS-1)*spacing) {
X tableWidth = (width-2*marginWidth-NUM_TABLES_COLS*4-
X (NUM_TABLES_COLS-1)*spacing)/NUM_TABLES_COLS;
X y = marginHeight+tableHeight*(ct/NUM_TABLES_COLS);
X x = marginWidth+(ct % NUM_TABLES_COLS)*(tableWidth+spacing);
X XtConfigureWidget(widgets[0], x, y, tableWidth, tableHeight, bw);
X XtConfigureWidget(widgets[1], 0, 0, tableWidth, tableHeight, 0);
X ct++;
X }
X }
X }
X cur_ptr = cur_ptr->next_table;
X }
X
X}
X
XfixupLayout()
X{
X Dimension formWidth, formHeight, width, height, bw;
X Position x, y;
X int hd, dd;
X
X /*****************************************************************/
X /* Grrr. I hate Xaw. The form widget is not expressive enough. */
X /* Or, I just can't figure it out.
X /*****************************************************************/
X
X /* make option form as big as play form */
X count = 0;
X XtSetArg(args[count], XtNwidth, &formWidth); count++;
X XtSetArg(args[count], XtNheight, &formHeight); count++;
X XtGetValues(playForm, args, count);
X resizeWidget(optionForm, formWidth-2, formHeight-2);
X
X /* make the labels and table container as wide as the option form */
X count = 0;
X XtSetArg(args[count], XtNwidth, &formWidth); count++;
X XtSetArg(args[count], XtNdefaultDistance, &dd); count++;
X XtGetValues(optionForm, args, count);
X count = 0;
X XtSetArg(args[count], XtNhorizDistance, &hd); count++;
X XtGetValues(optionHeader, args, count);
X resizeWidget(optionHeader, formWidth-2*hd-2*dd, 0);
X resizeWidget(gamesMessage, formWidth-2*hd-2*dd, 0);
X resizeWidget(gamesHeader, formWidth-2*hd-2*dd, 0);
X count = 0;
X XtSetArg(args[count], XtNborderWidth, &bw); count++;
X XtGetValues(gamesFrame, args, count);
X resizeWidget(gamesFrame, formWidth-2*hd-2*dd-2*bw, 0);
X
X /* Expand labels area, move score area to the right of the play form */
X count = 0;
X XtSetArg(args[count], XtNwidth, &formWidth); count++;
X XtSetArg(args[count], XtNdefaultDistance, &dd); count++;
X XtGetValues(playForm, args, count);
X count = 0;
X XtSetArg(args[count], XtNwidth, &width); count++;
X XtSetArg(args[count], XtNheight, &height); count++;
X XtSetArg(args[count], XtNx, &x); count++;
X XtSetArg(args[count], XtNy, &y); count++;
X XtSetArg(args[count], XtNborderWidth, &bw); count++;
X XtGetValues(scoreArea, args, count);
X/* I have no idea why I need this fudge factor to line things up... */
X#define FUDGE_FACTOR 8
X count = 0;
X XtSetArg(args[count], XtNx, formWidth-width-dd-2*bw-FUDGE_FACTOR); count++;
X XtSetValues(scoreArea, args, count);
X XtConfigureWidget(scoreArea, formWidth-width-dd-2*bw-FUDGE_FACTOR, y,
X width, height, bw);
X count = 0;
X XtSetArg(args[count], XtNwidth, &width); count++;
X XtGetValues(scoreArea, args, count);
X count = 0;
X XtSetArg(args[count], XtNx, &x); count++;
X XtGetValues(displayLabels, args, count);
X if (x > formWidth-width-dd-2*bw-FUDGE_FACTOR) {
X resizeWidget(displayLabels, 1, 0);
X } else {
X resizeWidget(displayLabels, formWidth-width-dd-2*bw-x-FUDGE_FACTOR, 0);
X }
X
X /* move the play buttons to the lower right of the play form */
X count = 0;
X XtSetArg(args[count], XtNwidth, &formWidth); count++;
X XtSetArg(args[count], XtNdefaultDistance, &dd); count++;
X XtGetValues(playForm, args, count);
X count = 0;
X XtSetArg(args[count], XtNwidth, &width); count++;
X XtSetArg(args[count], XtNheight, &height); count++;
X XtSetArg(args[count], XtNx, &x); count++;
X XtSetArg(args[count], XtNy, &y); count++;
X XtSetArg(args[count], XtNborderWidth, &bw); count++;
X XtGetValues(commandArea, args, count);
X count = 0;
X XtSetArg(args[count], XtNx, formWidth-width-dd-2*bw); count++;
X XtSetValues(commandArea, args, count);
X XtConfigureWidget(commandArea, formWidth-width-dd-2*bw, y,
X width, height, bw);
X
X positionTables();
X}
X
X/**********************************************************************/
X
Xenter_card(rank, suit)
Xint rank, suit;
X{
X CardInfo *card, *ptr;
X
X card = (CardInfo *) malloc(sizeof(CardInfo));
X card->rank = rank;
X card->suit = suit;
X ptr = my_hand[suit].head;
X while (ptr->next && ptr->next->rank > rank) {
X ptr = ptr->next;
X }
X card->next = ptr->next;
X ptr->next = card;
X print_cards(suit);
X}
X
Xremove_card(rank, suit)
Xint rank, suit;
X{
X CardInfo *card, *ptr;
X
X ptr = my_hand[suit].head;
X while (ptr->next) {
X if (ptr->next->rank == rank) {
X card = ptr->next;
X ptr->next = card->next;
X free((char *) card);
X break;
X } else {
X ptr = ptr->next;
X }
X }
X print_cards(suit);
X}
X
Xerase_window(window_num)
Xint window_num;
X{
X if (window_num == PLAY_WINDOW) {
X/* if PLAY_WINDOW then save it for showing last */
X lastCards[0] = playCards[0];
X lastCards[1] = playCards[1];
X lastCards[2] = playCards[2];
X lastCards[3] = playCards[3];
X strcpy(lastNames[0], playNames[0]);
X strcpy(lastNames[1], playNames[1]);
X strcpy(lastNames[2], playNames[2]);
X strcpy(lastNames[3], playNames[3]);
X playCards[0].rank = 0;
X playCards[1].rank = 0;
X playCards[2].rank = 0;
X playCards[3].rank = 0;
X playNames[0][0] = '\0';
X playNames[1][0] = '\0';
X playNames[2][0] = '\0';
X playNames[3][0] = '\0';
X XClearArea(XtDisplay(playArea), XtWindow(playArea), 0, 0,
X 0, 0, False);
X count = 0;
X XtSetArg(args[count], XtNlabel, " "); count++;
X XtSetValues(playLabels[0], args, count);
X XtSetValues(playLabels[1], args, count);
X XtSetValues(playLabels[2], args, count);
X XtSetValues(playLabels[3], args, count);
X } else if (window_num == TEXT_WINDOW) {
X displayMessage("");
X }
X}
X
Xread_card()
X{
X setReadingCard(True);
X}
X
Xplay_card(player, rch, sch, msg)
Xint player, rch, sch;
Xchar *msg;
X{
X playCards[player-1].rank = get_rank(rch);
X playCards[player-1].suit = get_suit(sch);
X if (!showOld) {
X paint_card(XtWindow(playArea), (player-1)*STACK_WIDTH, 0,
X convertRank(playCards[player-1].rank),
X convertSuit(playCards[player-1].suit),
X 0);
X }
X if (*msg != '\0') {
X strcpy(playNames[player-1], msg);
X if (!showOld) {
X count = 0;
X XtSetArg(args[count], XtNlabel, msg); count++;
X XtSetValues(playLabels[player-1], args, count);
X }
X }
X XSync(XtDisplay(playArea), False);
X updateDisplay();
X sleep(1);
X}
X
Xscore_points(player, pts, total_pts, msg)
Xint player, pts, total_pts;
Xchar *msg;
X{
X char str[256];
X
X count = 0;
X XtSetArg(args[count], XtNlabel, msg); count++;
X XtSetValues(playerLabels[player], args, count);
X sprintf(str, "%d ", pts);
X count = 0;
X XtSetArg(args[count], XtNlabel, str); count++;
X XtSetValues(scoreLabels[player], args, count);
X sprintf(str, "%d ", total_pts);
X count = 0;
X XtSetArg(args[count], XtNlabel, str); count++;
X XtSetValues(totalLabels[player], args, count);
X}
X
Xdisplay_message(window_num, msg)
Xint window_num;
Xchar *msg;
X{
X char *str, *str2;
X
X if (window_num == MESG_WINDOW || window_num == PLAY_WINDOW) {
X count = 0;
X XtSetArg(args[count], XtNstring, &str); count++;
X XtGetValues(messageArea, args, count);
X str2 = malloc(strlen(str)+strlen(msg)+2);
X strcpy(str2, str);
X strcat(str2, msg);
X strcat(str2, "\n");
X count = 0;
X XtSetArg(args[count], XtNstring, str2); count++;
X XtSetValues(messageArea, args, count);
X free(str2);
X XtFree(str);
X } else {
X count = 0;
X XtSetArg(args[count], XtNlabel, msg); count++;
X if (window_num == TEXT_WINDOW) {
X XtSetValues(textArea, args, count);
X } else if (window_num == ROUND_WINDOW) {
X XtSetValues(roundLabel, args, count);
X } else if (window_num == LEAD_WINDOW) {
X XtSetValues(leadLabel, args, count);
X }
X }
X}
X
Xgame_is_over()
X{
X Boolean buttonPressed;
X XEvent event;
X
X display_message(MESG_WINDOW,
X "--------------------------------------------------------");
X display_message(MESG_WINDOW, "");
X display_message(MESG_WINDOW, "Click the left mouse button to continue...");
X
X buttonPressed = False;
X XGrabPointer(XtDisplay(messageArea), XtWindow(messageArea), True,
X ButtonPressMask, GrabModeAsync, GrabModeAsync,
X XtWindow(messageArea), None, CurrentTime);
X while (!buttonPressed) {
X if (XCheckTypedWindowEvent(XtDisplay(messageArea),
X XtWindow(messageArea),
X ButtonPress, &event)) {
X XtDispatchEvent(&event);
X XUngrabPointer(XtDisplay(messageArea), event.xbutton.time);
X XSync(XtDisplay(messageArea), False);
X buttonPressed = True;
X }
X }
X}
X
Xstart_game()
X{
X XLowerWindow(XtDisplay(optionForm), XtWindow(optionForm));
X XSync(XtDisplay(optionForm), False);
X showOld = False;
X
X playCards[0].rank = 0;
X playCards[1].rank = 0;
X playCards[2].rank = 0;
X playCards[3].rank = 0;
X playNames[0][0] = '\0';
X playNames[1][0] = '\0';
X playNames[2][0] = '\0';
X playNames[3][0] = '\0';
X lastCards[0].rank = 0;
X lastCards[1].rank = 0;
X lastCards[2].rank = 0;
X lastCards[3].rank = 0;
X lastNames[0][0] = '\0';
X lastNames[1][0] = '\0';
X lastNames[2][0] = '\0';
X lastNames[3][0] = '\0';
X
X count = 0;
X XtSetArg(args[count], XtNstring, ""); count++;
X XtSetValues(messageArea, args, count);
X}
X
X/*
X * Scan input for redraw screen requests or ':' messages.
X * Also scan socket for incoming commands.
X */
Xscan()
X{
X static XEvent event;
X
X XtAppNextEvent(appContext, &event);
X XtDispatchEvent(&event);
X}
X
Xterminate()
X{
X XtDestroyWidget(toplevel);
X}
X
X/*
X * show_table - display table which is position table_pos on screen.
X */
Xshow_table(cur_ptr, table_pos)
Xtable_ptr cur_ptr;
Xint table_pos;
X{
X Dimension width, height, marginWidth, marginHeight, spacing;
X Widget *widgets;
X char str[256];
X int each;
X
X count = 0;
X XtSetArg(args[count], XtNwidth, &width); count++;
X XtSetArg(args[count], XtNheight, &height); count++;
X marginWidth = 10;
X marginHeight = 10;
X spacing = 10;
X XtGetValues(gamesRC, args, count);
X
X if (!cur_ptr->data) {
X widgets = (Widget *) malloc(8*sizeof(Widget));
X count = 0;
X XtSetArg(args[count], XtNresize, False); count++;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainLeft); count++;
X XtSetArg(args[count], XtNtop, XawChainTop); count++;
X XtSetArg(args[count], XtNbottom, XawChainTop); count++;
X XtSetArg(args[count], XtNdefaultDistance, 0); count++;
X XtSetArg(args[count], XtNwidth, 10); count++;
X XtSetArg(args[count], XtNheight, 10); count++;
X widgets[0] = XtCreateManagedWidget("tableFrame", formWidgetClass,
X gamesRC, args, count);
X count = 0;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainRight); count++;
X XtSetArg(args[count], XtNtop, XawChainTop); count++;
X XtSetArg(args[count], XtNbottom, XawChainBottom); count++;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNresize, False); count++;
X XtSetArg(args[count], XtNdefaultDistance, 0); count++;
X XtSetArg(args[count], XtNwidth, 10); count++;
X XtSetArg(args[count], XtNheight, 10); count++;
X widgets[1] = XtCreateManagedWidget("tableW", formWidgetClass,
X widgets[0], args, count);
X XtAddEventHandler(widgets[1], ButtonPressMask, False, tableSelect, NULL);
X globalTableHeight = 0;
X for (each=0; each<6; each++) {
X count = 0;
X XtSetArg(args[count], XtNlabel, " "); count++;
X XtSetArg(args[count], XtNborderWidth, 0); count++;
X XtSetArg(args[count], XtNresize, False); count++;
X XtSetArg(args[count], XtNleft, XawChainLeft); count++;
X XtSetArg(args[count], XtNright, XawChainRight); count++;
X XtSetArg(args[count], XtNtop, XawChainTop); count++;
X XtSetArg(args[count], XtNbottom, XawChainTop); count++;
X XtSetArg(args[count], XtNwidth, 10); count++;
X if (each) {
X XtSetArg(args[count], XtNfromVert, widgets[each+1]); count++;
X }
X widgets[each+2] = XtCreateManagedWidget("tableLabel", labelWidgetClass,
X widgets[1], args, count);
X count = 0;
X XtSetArg(args[count], XtNheight, &height); count++;
X XtGetValues(widgets[each+2], args, count);
X globalTableHeight += height;
X }
X cur_ptr->data = (char *) widgets;
X } else {
X widgets = (Widget *) cur_ptr->data;
X XtManageChild(widgets[0]);
X }
X
X sprintf(str, "Table %d", table_pos+1);
X count = 0;
X XtSetArg(args[count], XtNlabel, str); count++;
X XtSetValues(widgets[2], args, count);
X
X if (cur_ptr->closed) {
X count = 0;
X XtSetArg(args[count], XtNlabel, "<game over>"); count++;
X XtSetValues(widgets[3], args, count);
X count = 0;
X XtSetArg(args[count], XtNlabel, " "); count++;
X XtSetValues(widgets[4], args, count);
X XtSetValues(widgets[5], args, count);
X XtSetValues(widgets[6], args, count);
X XtSetValues(widgets[7], args, count);
X } else {
X if (!cur_ptr->hand) {
X sprintf(str, "<starting>");
X } else {
X sprintf(str, "Hand: %d Round: %d", cur_ptr->hand, cur_ptr->round);
X }
X count = 0;
X XtSetArg(args[count], XtNlabel, str); count++;
X XtSetValues(widgets[3], args, count);
X
X for (each=0; each<4; each++) {
X count = 0;
X XtSetArg(args[count], XtNlabel, cur_ptr->player_name[each]); count++;
X XtSetValues(widgets[4+each], args, count);
X }
X }
X
X /* Make the row column the right width */
X count = 0;
X XtSetArg(args[count], XtNwidth,
X (width-2*marginWidth-NUM_TABLES_COLS*4-
X (NUM_TABLES_COLS-1)*spacing)/NUM_TABLES_COLS); count++;
X for (each=2; each<8; each++) {
X XtSetValues(widgets[each], args, count);
X }
X}
X
X/*
X * show_tables - display up to NUM_TABLES tables starting with table # start_id.
X */
Xshow_tables(start_id)
Xint start_id;
X{
X table_ptr cur_ptr;
X int cur_id, i;
X char str[256];
X Widget *widgets;
X
X XtSetSensitive(moreGames, (table_count > 8));
X cur_ptr = first_table;
X for (i=0; i<table_count; i++) {
X if (cur_ptr->data) {
X widgets = (Widget *) cur_ptr->data;
X XtUnmanageChild(widgets[0]);
X }
X cur_ptr = cur_ptr->next_table;
X }
X count = 0;
X if (table_count) {
X sprintf(str, "Current Games (page %d of %d):",
X (start_id + NUM_TABLES-1) / NUM_TABLES,
X (table_count + NUM_TABLES-1) / NUM_TABLES);
X XtSetArg(args[count], XtNlabel, str); count++;
X } else {
X XtSetArg(args[count], XtNlabel, "Current Games:"); count++;
X }
X XtSetValues(gamesHeader, args, count);
X cur_ptr = first_table;
X for (cur_id = 1; cur_id < start_id; cur_id++) {
X cur_ptr = cur_ptr->next_table;
X }
X XtUnmanageChild(gamesRC);
X for (cur_id = 0; (cur_id < NUM_TABLES) && cur_ptr;
X cur_ptr = cur_ptr->next_table) {
X show_table(cur_ptr, cur_id++);
X }
X positionTables();
X XtManageChild(gamesRC);
X}
X
Xoption_scan(another)
Xchar *another;
X{
X XEvent event;
X
X anotherPtr = another;
X *anotherPtr = FALSE;
X XtAppNextEvent(appContext, &event);
X XtDispatchEvent(&event);
X}
X
Xoption_init()
X{
X if (distId) {
X XtRemoveInput(distId);
X }
X distId = XtAppAddInput(appContext, dist_socket,
X (XtPointer) XtInputReadMask, distInput, NULL);
X XtSetSensitive(anotherGame, !first_game);
X XtSetSensitive(newGame, first_game);
X XRaiseWindow(XtDisplay(optionForm), XtWindow(optionForm));
X XSync(XtDisplay(optionForm), False);
X}
X
Xinit_socket()
X{
X if (dealerId) {
X XtRemoveInput(dealerId);
X }
X dealerId = XtAppAddInput(appContext, dealer_socket,
X (XtPointer) XtInputReadMask, dealerInput, NULL);
X}
X
Xclose_socket(s)
Xint s;
X{
X if (s == dealer_socket && dealerId) {
X XtRemoveInput(dealerId);
X dealerId = None;
X } else if (s == dist_socket && distId) {
X XtRemoveInput(distId);
X distId = None;
X }
X}
X
Xoption_clear()
X{
X table_ptr cur_ptr;
X int i;
X Widget *widgets;
X
X cur_ptr = first_table;
X for (i=0; i<table_count; i++) {
X if (cur_ptr->data) {
X widgets = (Widget *) cur_ptr->data;
X XtDestroyWidget(widgets[0]);
X cur_ptr->data = NULL;
X }
X cur_ptr = cur_ptr->next_table;
X }
X}
END_OF_FILE
if test 50694 -ne `wc -c <'xawclient.c'`; then
echo shar: \"'xawclient.c'\" unpacked with wrong size!
fi
# end of 'xawclient.c'
fi
echo shar: End of archive 2 \(of 6\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 3 4 5 6 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 6 archives.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0
--
Molecular Simulations, Inc. mail: dcmartin@postgres.berkeley.edu
796 N. Pastoria Avenue uucp: uwvax!ucbvax!dcmartin
Sunnyvale, California 94086 at&t: 408/522-9236