Multiple-button layout, but with some "Cannot convert string" messages.
[super-star-trek.git] / src / xio.c
1 #include <stdlib.h>
2 #include <X11/Intrinsic.h>
3 #include <X11/StringDefs.h>
4 #include <X11/Shell.h>
5 #include <X11/Xaw/Form.h>
6 #include <X11/Xaw/Command.h>
7 #include <X11/Xaw/AsciiText.h>
8 #include "sst.h"
9
10 static XtAppContext app_context;
11 static Widget toplevel, form, text, buttons; 
12
13 String fallback[] = {
14     /* text window resources */
15     "*text.resizable: true",
16     "*text.resize: ResizeBoth",
17     /* layout constraints */
18     /* navigation row */
19     //"*Move.fromHoriz:",
20     "*Impulse.fromHoriz: Move",
21     "*Rest.fromHoriz: Impulse",
22     "*Warp.fromHoriz: Rest",
23     "*Dock.fromHoriz: Warp",
24     "*Chart.fromHoriz: Dock",
25     // Weapons row
26     "*Phasers.fromVert: Move",
27     "*Torpedo.fromHoriz: Phasers",
28     "*Shields.fromHoriz: Torpedo",
29     "*Damages.fromHoriz: Shields",
30     "*Crystals.fromHoriz: Damages",
31     "*Deathray.fromHoriz: Damages",
32     "*Mayday.fromHoriz: Deathray",
33     "*Abandon.fromHoriz: Mayday",
34     // Planet row
35     "*Sensors.fromVert: Phasers",
36     "*Orbit.fromHoriz: Sensors",
37     "*Transport.fromHoriz: Orbit",
38     "*Mine.fromHoriz: Transport",
39     "*Shuttle.fromHoriz: Transport",
40     "*Planets.fromHoriz: Shuttle",
41     // Miscellany row
42     "*Report.fromVert: Sensors",
43     "*Computer.fromHoriz: Report",
44     "*Probe.fromHoriz: Computer",
45     "*Help.fromHoriz: Computer",
46     // Ending it all
47     "*Score.fromVert: Report",
48     "*Destruct.fromHoriz: Score",
49     "*Quit.fromHoriz: Destruct",
50     "*Emexit.fromHoriz: Quit",
51     "*Save.fromHoriz: Emexit",
52     NULL,
53 };
54
55 struct cmd_t {
56     char *name;
57     void (*callback)(Widget, XtPointer, XtPointer);
58     int enable;
59     Widget widget;
60 };
61
62 static void quit_proc(Widget w, XtPointer client_data, XtPointer call_data)
63
64     XtDestroyApplicationContext (app_context);
65     exit (0);
66 }
67
68 static struct cmd_t commands[] = {
69     {"Phasers",         NULL,           0},
70     {"Torpedo",         NULL,           0},
71     {"Move",            NULL,           0},
72     {"Shields",         NULL,           0},
73     {"Dock",            NULL,           0},
74     {"Damages",         NULL,           0},
75     {"Chart",           NULL,           0},
76     {"Impulse",         NULL,           0},
77     {"Rest",            NULL,           0},
78     {"Warp",            NULL,           0},
79     {"Score",           NULL,           0},
80     {"Sensors",         NULL,           OPTION_PLANETS},
81     {"Orbit",           NULL,           OPTION_PLANETS},
82     {"Transport",       NULL,           OPTION_PLANETS},
83     {"Mine",            NULL,           OPTION_PLANETS},
84     {"Crystals",        NULL,           OPTION_PLANETS},
85     {"Shuttle",         NULL,           OPTION_PLANETS},
86     {"Planets",         NULL,           OPTION_PLANETS},
87     {"Report",          NULL,           0},
88     {"Computer",        NULL,           0},
89     {"Emexit",          NULL,           0},
90     {"Probe",           NULL,           OPTION_PROBE},
91     {"Save",            NULL,           0},
92     {"Abandon",         NULL,           0},
93     {"Destruct",        NULL,           0},
94     {"Deathray",        NULL,           0},
95     {"Mayday",          NULL,           0},
96     {"Quit",            quit_proc,      0},
97     {"Help",            NULL,           0},
98 };
99
100 int main(int argc, char **argv)
101
102     struct cmd_t *cp;
103
104     toplevel = XtVaOpenApplication(&app_context, "sst2k", NULL, 0, &argc,
105                                     argv, fallback, 
106                                     applicationShellWidgetClass,
107                                     XtNallowShellResize, True, NULL);
108     form = XtVaCreateManagedWidget("form", formWidgetClass, toplevel, NULL);
109     /* the command window */
110     text = XtVaCreateManagedWidget("text", asciiTextWidgetClass, form, 
111                                     NULL);
112
113     /* The button panel */
114     buttons  = XtVaCreateManagedWidget("form", 
115                                         formWidgetClass, form, 
116                                         XtNfromVert, text, 
117                                         NULL); 
118     for (cp = commands; cp < commands + sizeof(commands)/sizeof(commands[0]); cp++) {
119         cp->widget = XtVaCreateManagedWidget(cp->name, 
120                                              commandWidgetClass, buttons, 
121                                              XtNlabel, cp->name,
122                                              NULL);
123         if (cp->callback)
124             XtAddCallback (cp->widget, XtNcallback, cp->callback, NULL);
125     }
126     /* sample text so the widget will be identifiable */
127     XtVaSetValues(text, XtNtype, XawAsciiString, 
128                        XtNstring, "Command window", NULL); 
129     XtVaSetValues(text, XtNeditType, XawtextRead, XtNdisplayCaret, False, NULL);
130     XtRealizeWidget(toplevel);
131     XtAppMainLoop(app_context);
132     /* loop may be interrupted */
133     XtDestroyApplicationContext(app_context);
134     exit(0);
135 }