More reasonably-sized windows.
[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 #define MAXWIDTH        640
81 #define TEXTHEIGHT      200
82
83 int main(int argc, char **argv)
84
85     struct cmd_t *cp;
86
87     toplevel = XtVaOpenApplication(&app_context, "sst2k", NULL, 0, &argc,
88                                     argv, fallback, 
89                                     applicationShellWidgetClass,
90                                     XtNallowShellResize, True, NULL);
91     form = XtVaCreateManagedWidget("form", formWidgetClass, toplevel, NULL);
92     /* the command window */
93     text = XtVaCreateManagedWidget("text", asciiTextWidgetClass, form, 
94                                    XtNwidth, MAXWIDTH, XtNheight, TEXTHEIGHT,
95                                    NULL);
96     XtVaSetValues(text, XtNeditType,XawtextRead, XtNdisplayCaret,False, NULL);
97     /* The button panels */
98     navigation  = XtVaCreateManagedWidget("navigation", 
99                                           boxWidgetClass, form,
100                                           XtNborderWidth, 0,
101                                           XtNfromVert, text,
102                                           XtNorientation, XtorientHorizontal,
103                                           NULL); 
104     navlabel  = XtVaCreateManagedWidget("Navigation:   ", 
105                                         labelWidgetClass, navigation,
106                                         XtNborderWidth, 0,
107                                         NULL); 
108     weapons  = XtVaCreateManagedWidget("weapons", 
109                                        boxWidgetClass, form,
110                                        XtNborderWidth, 0,
111                                        XtNfromVert, navigation, 
112                                        XtNorientation, XtorientHorizontal,
113                                        NULL); 
114     weaplabel  = XtVaCreateManagedWidget("Weapons:      ", 
115                                          labelWidgetClass, weapons,
116                                          XtNborderWidth, 0,
117                                          NULL); 
118     status   = XtVaCreateManagedWidget("status", 
119                                        boxWidgetClass, form,
120                                        XtNborderWidth, 0,
121                                        XtNfromVert, weapons, 
122                                        XtNorientation, XtorientHorizontal,
123                                        NULL); 
124     statlabel  = XtVaCreateManagedWidget("Status:       ", 
125                                          labelWidgetClass, status,
126                                          XtNborderWidth, 0,
127                                          NULL); 
128     planets  = XtVaCreateManagedWidget("planets", 
129                                        boxWidgetClass, form,
130                                        XtNborderWidth, 0,
131                                        XtNfromVert, status, 
132                                        XtNorientation, XtorientHorizontal,
133                                        NULL); 
134     planlabel  = XtVaCreateManagedWidget("Planets:      ", 
135                                          labelWidgetClass, planets,
136                                          XtNborderWidth, 0,
137                                          NULL); 
138     misc  = XtVaCreateManagedWidget("misc", 
139                                        boxWidgetClass, form,
140                                        XtNborderWidth, 0,
141                                        XtNfromVert, planets, 
142                                        XtNorientation, XtorientHorizontal,
143                                        NULL); 
144     misclabel  = XtVaCreateManagedWidget("Miscellaneous:", 
145                                          labelWidgetClass, misc,
146                                          XtNborderWidth, 0,
147                                          NULL); 
148     for (cp = commands; cp < commands + sizeof(commands)/sizeof(commands[0]); cp++) {
149         cp->widget = XtVaCreateManagedWidget(cp->name, 
150                                              commandWidgetClass, 
151                                              *cp->parent, 
152                                              XtNlabel, cp->name,
153                                              NULL);
154         if (cp->callback)
155             XtAddCallback (cp->widget, XtNcallback, cp->callback, NULL);
156     }
157     XtRealizeWidget(toplevel);
158     XtAppMainLoop(app_context);
159     /* loop may be interrupted */
160     XtDestroyApplicationContext(app_context);
161     exit(0);
162 }