/* $Id: about.c,v 1.4 2002/03/02 21:02:21 sverrehu Exp $ */ /************************************************************************** * * FILE about.c * MODULE OF Card game. * * WRITTEN BY Sverre H. Huseby * **************************************************************************/ #include #include #include #include #include #include #include #include #include #include "win.h" #include "game.h" #include "about.h" /************************************************************************** * * * P R I V A T E D A T A * * * **************************************************************************/ #include "shapes.xpm" static char *title = "About sol"; static char *copyright = "sol " VERSION " - Solitaire card game\n" "\n" "by Sverre H. Huseby, Norway\n" "\n" "\n" "This program is free:\n" " Copy it and use it as you wish.\n"; static Widget aboutWidget, aboutParent, aboutImage, aboutStatus; static Pixmap aboutPixmap; static int isPoppedUp = 0; /************************************************************************** * * * P R I V A T E F U N C T I O N S * * * **************************************************************************/ static void callbackOk(Widget w, XtPointer clientData, XtPointer callData) { XtPopdown(aboutWidget); XFreePixmap(XtDisplayOfObject(aboutWidget), aboutPixmap); XtSetSensitive(aboutButton, 1); isPoppedUp = 0; } static void createPixmap(char **data, Pixmap *pix) { int err; XpmAttributes xa; xa.valuemask = 0; xa.closeness = 40000; xa.valuemask |= XpmCloseness; err = XpmCreatePixmapFromData(XtDisplay(aboutParent), XtWindow(aboutParent), data, pix, NULL, &xa); if (err == XpmSuccess) return; else if (err > 0) msgFatal("Xpm: %s\n", XpmGetErrorString(err)); } /************************************************************************** * * * P U B L I C F U N C T I O N S * * * **************************************************************************/ void aboutInit(Widget parent) { Widget form, text, button; aboutParent = parent; aboutWidget = XtVaCreatePopupShell("aboutWindow", transientShellWidgetClass, parent, XtNtitle, title, NULL); form = XtVaCreateManagedWidget("about", formWidgetClass, aboutWidget, XtNdefaultDistance, 8, NULL); aboutImage = XtVaCreateManagedWidget("shapes", coreWidgetClass, form, XtNwidth, 160, XtNheight, 100, XtNborderWidth, 1, NULL); text = XtVaCreateManagedWidget("copyright", asciiTextWidgetClass, form, XtNwidth, 250, XtNheight, 100, XtNborderWidth, 0, XtNfromHoriz, aboutImage, XtNstring, copyright, XtNdisplayCaret, 0, XtNsensitive, 0, NULL); button = XtVaCreateManagedWidget("ok", commandWidgetClass, form, XtNlabel, "OK", XtNfromHoriz, text, NULL); aboutStatus = XtVaCreateManagedWidget("status", asciiTextWidgetClass, form, XtNwidth, 450, XtNheight, 24, XtNborderWidth, 0, XtNfromVert, aboutImage, XtNdisplayCaret, 0, XtNsensitive, 0, XtNwrap, XawtextWrapWord, NULL); XtAddCallback(button, XtNcallback, callbackOk, 0); } void aboutFinish(void) { } void aboutPopup(void) { Dimension popWidth, popHeight, parWidth, parHeight; Position x, y; char statusMsg[320], s1[20], s2[20]; if (isPoppedUp) return; XtSetSensitive(aboutButton, 0); isPoppedUp = 1; createPixmap(shapes, &aboutPixmap); if (!gameNumPlayed) { sprintf(statusMsg, "You haven't played the game yet. Go on, try it!"); } else if (gameNumPlayed == 1) { sprintf(statusMsg, "In %s, you have played one game.", gameTimeToVerboseStr(gameTotalTime)); } else { strcpy(s1, gameCountToStr(gameNumPlayed)); strcpy(s2, gameCountToStr(gameNumSolved)); sprintf(statusMsg, "In %s, you have played %s games, of which %s are solved.", gameTimeToVerboseStr(gameTotalTime), s1, s2); } XtVaSetValues(aboutStatus, XtNstring, statusMsg, NULL); /* must temporarily realize the widget to be able to get it's size */ XtRealizeWidget(aboutWidget); XtUnrealizeWidget(aboutWidget); XtVaGetValues(aboutWidget, XtNwidth, &popWidth, XtNheight, &popHeight, NULL); XtVaGetValues(aboutParent, XtNwidth, &parWidth, XtNheight, &parHeight, NULL); XtTranslateCoords(aboutParent, (Position) (parWidth - popWidth) / 2, (Position) (parHeight - popHeight) / 2, &x, &y); XtVaSetValues(aboutWidget, XtNx, x, XtNy, y, NULL); XtVaSetValues(aboutImage, XtNbackgroundPixmap, aboutPixmap, NULL); XtPopup(aboutWidget, XtGrabNone); }