9c5e03cf3221099515bbaaa3f03c0f24f813e29e
[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/Box.h>
6 #include <X11/Xaw/Form.h>
7 #include <X11/Xaw/Command.h>
8 #include <X11/Xaw/AsciiText.h>
9 #include "sst.h"
10
11 static XtAppContext app_context;
12 static Widget toplevel, text, form; 
13 static Widget navigation, weapons, status, planets, misc; 
14
15 static String fallback[] = {
16     /* text window resources */
17     "*text.resizable: true",
18     "*text.resize: ResizeBoth",
19     NULL,
20 };
21
22 struct cmd_t {
23     char *name;
24     void (*callback)(Widget, XtPointer, XtPointer);
25     Widget *parent;
26     int enable;
27     Widget widget;
28
29 };
30
31 static void quit_proc(Widget w, XtPointer client_data, XtPointer call_data)
32
33     XtDestroyApplicationContext (app_context);
34     exit (0);
35 }
36
37 static void noargs_proc(Widget w, XtPointer client_data, XtPointer call_data)
38 /* use this for commands that take no arguments */
39 {
40     /* currently a stub */
41 }
42
43 static struct cmd_t commands[] = {
44     {"Move",            NULL,           &navigation,    0},
45     {"Dock",            noargs_proc,    &navigation,    0},
46     {"Chart",           noargs_proc,    &navigation,    0},
47     {"Impulse",         NULL,           &navigation,    0},
48     {"Rest",            NULL,           &navigation,    0},
49     {"Warp",            NULL,           &navigation,    0},
50     {"Probe",           NULL,           &navigation,    OPTION_PROBE},
51
52     {"Phasers",         NULL,           &weapons,       0},
53     {"Torpedo",         NULL,           &weapons,       0},
54     {"Shields",         NULL,           &weapons,       0},
55     {"Damages",         noargs_proc,    &weapons,       0},
56     {"Abandon",         noargs_proc,    &weapons,       0},
57     {"Destruct",        noargs_proc,    &weapons,       0},
58     {"Deathray",        noargs_proc,    &weapons,       0},
59     {"Mayday",          noargs_proc,    &weapons,       0},
60
61     {"Score",           noargs_proc,    &status,        0},
62     {"Report",          noargs_proc,    &status,        0},
63     {"Computer",        noargs_proc,    &status,        0},
64
65     {"Sensors",         noargs_proc,    &planets,       OPTION_PLANETS},
66     {"Orbit",           noargs_proc,    &planets,       OPTION_PLANETS},
67     {"Transport",       noargs_proc,    &planets,       OPTION_PLANETS},
68     {"Mine",            noargs_proc,    &planets,       OPTION_PLANETS},
69     {"Crystals",        noargs_proc,    &planets,       OPTION_PLANETS},
70     {"Shuttle",         noargs_proc,    &planets,       OPTION_PLANETS},
71     {"Planets",         noargs_proc,    &planets,       OPTION_PLANETS},
72
73     {"Emexit",          noargs_proc,    &misc,          0},
74     {"Save",            NULL,           &misc,          0},
75     {"Quit",            quit_proc,      &misc,          0},
76     {"Help",            noargs_proc,    &misc,          0},
77 };
78
79 int main(int argc, char **argv)
80
81     struct cmd_t *cp;
82
83     toplevel = XtVaOpenApplication(&app_context, "sst2k", NULL, 0, &argc,
84                                     argv, fallback, 
85                                     applicationShellWidgetClass,
86                                     XtNallowShellResize, True, NULL);
87     form = XtVaCreateManagedWidget("form", formWidgetClass, toplevel, NULL);
88     /* the command window */
89     text = XtVaCreateManagedWidget("text", asciiTextWidgetClass, form, 
90                                    XtNwidth, 400, XtNheight, 200,
91                                    NULL);
92     XtVaSetValues(text, XtNeditType,XawtextRead, XtNdisplayCaret,False, NULL);
93     /* The button panels */
94     navigation  = XtVaCreateManagedWidget("navigation", 
95                                        boxWidgetClass, form,
96                                        XtNfromVert, text, 
97                                        XtNorientation, XtorientHorizontal,
98                                        NULL); 
99     weapons  = XtVaCreateManagedWidget("weapons", 
100                                        boxWidgetClass, form,
101                                        XtNfromVert, navigation, 
102                                        XtNorientation, XtorientHorizontal,
103                                        NULL); 
104     status   = XtVaCreateManagedWidget("status", 
105                                        boxWidgetClass, form,
106                                        XtNfromVert, weapons, 
107                                        XtNorientation, XtorientHorizontal,
108                                        NULL); 
109     planets  = XtVaCreateManagedWidget("planets", 
110                                        boxWidgetClass, form,
111                                        XtNfromVert, status, 
112                                        XtNorientation, XtorientHorizontal,
113                                        NULL); 
114     misc  = XtVaCreateManagedWidget("misc", 
115                                        boxWidgetClass, form,
116                                        XtNfromVert, planets, 
117                                        XtNorientation, XtorientHorizontal,
118                                        NULL); 
119     for (cp = commands; cp < commands + sizeof(commands)/sizeof(commands[0]); cp++) {
120         cp->widget = XtVaCreateManagedWidget(cp->name, 
121                                              commandWidgetClass, 
122                                              *cp->parent, 
123                                              XtNlabel, cp->name,
124                                              NULL);
125         if (cp->callback)
126             XtAddCallback (cp->widget, XtNcallback, cp->callback, NULL);
127     }
128     XtRealizeWidget(toplevel);
129     XtAppMainLoop(app_context);
130     /* loop may be interrupted */
131     XtDestroyApplicationContext(app_context);
132     exit(0);
133 }