X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=src%2Fxio.c;h=2eb8e5ce0af8d160654cddba421997257dc825c0;hp=ed095115cc696fa2e65553a1eb071bd357b22e95;hb=15d68102df5e20a52ecec9439e455d86591825a3;hpb=3d0b2461fe5709cec1c27a1935dc07b635a8bd31 diff --git a/src/xio.c b/src/xio.c index ed09511..2eb8e5c 100644 --- a/src/xio.c +++ b/src/xio.c @@ -2,68 +2,104 @@ #include #include #include +#include #include #include #include +#include "sst.h" -XtAppContext app_context; -Widget toplevel, form, text; -Widget buttons, phasers, photons, destruct, quit; +static XtAppContext app_context; +static Widget toplevel, form, text, buttons; -String fallback[] = { - /* button labels */ - "*phasers.label: Phasers", - "*photons.label: Torps", - "*destruct.label: Destruct", - "*quit.label: Quit", - /* layout constraints */ - "*photons.fromHoriz: phasers", - "*destruct.fromHoriz: photons", - "*quit.fromHoriz: destruct", +static String fallback[] = { + /* text window resources */ + "*text.resizable: true", + "*text.resize: ResizeBoth", NULL, }; -static void quit_proc (Widget w, XtPointer client_data, XtPointer call_data) +struct cmd_t { + char *name; + void (*callback)(Widget, XtPointer, XtPointer); + int enable; + Widget widget; +}; + +static void quit_proc(Widget w, XtPointer client_data, XtPointer call_data) { XtDestroyApplicationContext (app_context); exit (0); } -int main (int argc, char **argv) +static void noargs_proc(Widget w, XtPointer client_data, XtPointer call_data) +/* use this for commands that take no arguments */ +{ + /* currently a stub */ +} + +static struct cmd_t commands[] = { + {"Phasers", NULL, 0}, + {"Torpedo", NULL, 0}, + {"Move", NULL, 0}, + {"Shields", NULL, 0}, + {"Dock", noargs_proc, 0}, + {"Damages", noargs_proc, 0}, + {"Chart", noargs_proc, 0}, + {"Impulse", NULL, 0}, + {"Rest", NULL, 0}, + {"Warp", NULL, 0}, + {"Score", noargs_proc, 0}, + {"Sensors", noargs_proc, OPTION_PLANETS}, + {"Orbit", noargs_proc, OPTION_PLANETS}, + {"Transport", noargs_proc, OPTION_PLANETS}, + {"Mine", noargs_proc, OPTION_PLANETS}, + {"Crystals", noargs_proc, OPTION_PLANETS}, + {"Shuttle", noargs_proc, OPTION_PLANETS}, + {"Planets", noargs_proc, OPTION_PLANETS}, + {"Report", noargs_proc, 0}, + {"Computer", noargs_proc, 0}, + {"Emexit", noargs_proc, 0}, + {"Probe", NULL, OPTION_PROBE}, + {"Save", NULL, 0}, + {"Abandon", noargs_proc, 0}, + {"Destruct", noargs_proc, 0}, + {"Deathray", noargs_proc, 0}, + {"Mayday", noargs_proc, 0}, + {"Quit", quit_proc, 0}, + {"Help", noargs_proc, 0}, +}; + +int main(int argc, char **argv) { - toplevel = XtVaOpenApplication (&app_context, "sst2k", NULL, 0, &argc, + struct cmd_t *cp; + + toplevel = XtVaOpenApplication(&app_context, "sst2k", NULL, 0, &argc, argv, fallback, applicationShellWidgetClass, XtNallowShellResize, True, NULL); - form = XtVaCreateManagedWidget ("form", formWidgetClass, toplevel, NULL); - /* The button panel */ - buttons = XtVaCreateManagedWidget ("form", formWidgetClass, form, NULL); - phasers = XtVaCreateManagedWidget("phasers", - commandWidgetClass, buttons, - NULL); - photons = XtVaCreateManagedWidget("photons", - commandWidgetClass, buttons, - NULL); - destruct = XtVaCreateManagedWidget("destruct", - commandWidgetClass, buttons, - NULL); - quit = XtVaCreateManagedWidget("quit", - commandWidgetClass, buttons, - NULL); - XtAddCallback (quit, XtNcallback, quit_proc, NULL); + form = XtVaCreateManagedWidget("form", formWidgetClass, toplevel, NULL); /* the command window */ - text = XtVaCreateManagedWidget ("text", asciiTextWidgetClass, form, - XtNfromVert, buttons, - XtNresize, XawtextResizeBoth, - XtNresizable, True, NULL); - - /* sample text so the widget will be identifiable */ - XtVaSetValues (text, XtNtype, XawAsciiString, - XtNstring, "Command window", NULL); - XtVaSetValues (text, XtNeditType, XawtextRead, XtNdisplayCaret, False, NULL); - XtRealizeWidget (toplevel); - XtAppMainLoop (app_context); + text = XtVaCreateManagedWidget("text", asciiTextWidgetClass, form, + XtNwidth, 400, XtNheight, 200, + NULL); + XtVaSetValues(text, XtNeditType,XawtextRead, XtNdisplayCaret,False, NULL); + /* The button panel */ + buttons = XtVaCreateManagedWidget("form", + boxWidgetClass, form, + XtNfromVert, text, + XtNorientation, XtorientHorizontal, + NULL); + for (cp = commands; cp < commands + sizeof(commands)/sizeof(commands[0]); cp++) { + cp->widget = XtVaCreateManagedWidget(cp->name, + commandWidgetClass, buttons, + XtNlabel, cp->name, + NULL); + if (cp->callback) + XtAddCallback (cp->widget, XtNcallback, cp->callback, NULL); + } + XtRealizeWidget(toplevel); + XtAppMainLoop(app_context); /* loop may be interrupted */ - XtDestroyApplicationContext (app_context); + XtDestroyApplicationContext(app_context); exit(0); }