Multiple-button layout, but with some "Cannot convert string" messages.
authorEric S. Raymond <esr@thyrsus.com>
Wed, 13 Sep 2006 19:45:48 +0000 (19:45 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Wed, 13 Sep 2006 19:45:48 +0000 (19:45 +0000)
src/xio.c

index a84ee44192a077809e8da3bb7be703b3a89fa84b..94d3217547811fd14a8ca0e4d5c9843ea30d57dd 100644 (file)
--- a/src/xio.c
+++ b/src/xio.c
 #include <X11/Xaw/Form.h>
 #include <X11/Xaw/Command.h>
 #include <X11/Xaw/AsciiText.h>
+#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",
     /* text window resources */
     "*text.resizable: true",
     "*text.resize: ResizeBoth",
     /* layout constraints */
-    "*photons.fromHoriz: phasers",
-    "*destruct.fromHoriz: photons",
-    "*quit.fromHoriz: destruct",
+    /* navigation row */
+    //"*Move.fromHoriz:",
+    "*Impulse.fromHoriz: Move",
+    "*Rest.fromHoriz: Impulse",
+    "*Warp.fromHoriz: Rest",
+    "*Dock.fromHoriz: Warp",
+    "*Chart.fromHoriz: Dock",
+    // Weapons row
+    "*Phasers.fromVert: Move",
+    "*Torpedo.fromHoriz: Phasers",
+    "*Shields.fromHoriz: Torpedo",
+    "*Damages.fromHoriz: Shields",
+    "*Crystals.fromHoriz: Damages",
+    "*Deathray.fromHoriz: Damages",
+    "*Mayday.fromHoriz: Deathray",
+    "*Abandon.fromHoriz: Mayday",
+    // Planet row
+    "*Sensors.fromVert: Phasers",
+    "*Orbit.fromHoriz: Sensors",
+    "*Transport.fromHoriz: Orbit",
+    "*Mine.fromHoriz: Transport",
+    "*Shuttle.fromHoriz: Transport",
+    "*Planets.fromHoriz: Shuttle",
+    // Miscellany row
+    "*Report.fromVert: Sensors",
+    "*Computer.fromHoriz: Report",
+    "*Probe.fromHoriz: Computer",
+    "*Help.fromHoriz: Computer",
+    // Ending it all
+    "*Score.fromVert: Report",
+    "*Destruct.fromHoriz: Score",
+    "*Quit.fromHoriz: Destruct",
+    "*Emexit.fromHoriz: Quit",
+    "*Save.fromHoriz: Emexit",
     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 struct cmd_t commands[] = {
+    {"Phasers",                NULL,           0},
+    {"Torpedo",                NULL,           0},
+    {"Move",           NULL,           0},
+    {"Shields",                NULL,           0},
+    {"Dock",           NULL,           0},
+    {"Damages",                NULL,           0},
+    {"Chart",          NULL,           0},
+    {"Impulse",                NULL,           0},
+    {"Rest",           NULL,           0},
+    {"Warp",           NULL,           0},
+    {"Score",          NULL,           0},
+    {"Sensors",                NULL,           OPTION_PLANETS},
+    {"Orbit",          NULL,           OPTION_PLANETS},
+    {"Transport",      NULL,           OPTION_PLANETS},
+    {"Mine",           NULL,           OPTION_PLANETS},
+    {"Crystals",       NULL,           OPTION_PLANETS},
+    {"Shuttle",                NULL,           OPTION_PLANETS},
+    {"Planets",                NULL,           OPTION_PLANETS},
+    {"Report",         NULL,           0},
+    {"Computer",       NULL,           0},
+    {"Emexit",         NULL,           0},
+    {"Probe",          NULL,           OPTION_PROBE},
+    {"Save",           NULL,           0},
+    {"Abandon",                NULL,           0},
+    {"Destruct",       NULL,           0},
+    {"Deathray",       NULL,           0},
+    {"Mayday",         NULL,           0},
+    {"Quit",           quit_proc,      0},
+    {"Help",           NULL,           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, 
+    text = XtVaCreateManagedWidget("text", asciiTextWidgetClass, form, 
                                    NULL);
 
+    /* The button panel */
+    buttons  = XtVaCreateManagedWidget("form", 
+                                       formWidgetClass, form, 
+                                       XtNfromVert, text, 
+                                       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);
+    }
     /* sample text so the widget will be identifiable */
-    XtVaSetValues (text, XtNtype, XawAsciiString, 
+    XtVaSetValues(text, XtNtype, XawAsciiString, 
                       XtNstring, "Command window", NULL); 
-    XtVaSetValues (text, XtNeditType, XawtextRead, XtNdisplayCaret, False, NULL);
-    XtRealizeWidget (toplevel);
-    XtAppMainLoop (app_context);
+    XtVaSetValues(text, XtNeditType, XawtextRead, XtNdisplayCaret, False, NULL);
+    XtRealizeWidget(toplevel);
+    XtAppMainLoop(app_context);
     /* loop may be interrupted */
-    XtDestroyApplicationContext (app_context);
+    XtDestroyApplicationContext(app_context);
     exit(0);
 }