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