Mergeed "Status" section into "Misc".
[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, planets, misc; 
14 static Widget navlabel, weaplabel, 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     printf("Button %s pressed\n", XtName(w));
43 }
44
45 static struct cmd_t commands[] = {
46     {"Move",            NULL,           &navigation,    0},
47     {"Dock",            noargs_proc,    &navigation,    0},
48     {"Chart",           noargs_proc,    &navigation,    0},
49     {"Impulse",         NULL,           &navigation,    0},
50     {"Rest",            NULL,           &navigation,    0},
51     {"Warp",            NULL,           &navigation,    0},
52     {"Probe",           NULL,           &navigation,    OPTION_PROBE},
53
54     {"Phasers",         NULL,           &weapons,       0},
55     {"Torpedo",         NULL,           &weapons,       0},
56     {"Shields",         NULL,           &weapons,       0},
57     {"Damages",         noargs_proc,    &weapons,       0},
58     {"Abandon",         noargs_proc,    &weapons,       0},
59     {"Destruct",        noargs_proc,    &weapons,       0},
60     {"Deathray",        noargs_proc,    &weapons,       0},
61     {"Mayday",          noargs_proc,    &weapons,       0},
62
63     {"Sensors",         noargs_proc,    &planets,       OPTION_PLANETS},
64     {"Orbit",           noargs_proc,    &planets,       OPTION_PLANETS},
65     {"Transport",       noargs_proc,    &planets,       OPTION_PLANETS},
66     {"Mine",            noargs_proc,    &planets,       OPTION_PLANETS},
67     {"Crystals",        noargs_proc,    &planets,       OPTION_PLANETS},
68     {"Shuttle",         noargs_proc,    &planets,       OPTION_PLANETS},
69     {"Planets",         noargs_proc,    &planets,       OPTION_PLANETS},
70
71     {"Score",           noargs_proc,    &misc,          0},
72     {"Report",          noargs_proc,    &misc,          0},
73     {"Computer",        noargs_proc,    &misc,          0},
74     {"Save",            NULL,           &misc,          0},
75     {"Quit",            quit_proc,      &misc,          0},
76     {"Help",            noargs_proc,    &misc,          0},
77 };
78
79 #define MAXWIDTH        640
80 #define TEXTHEIGHT      200
81
82 static void instantiate_main(int argc, char **argv)
83
84     struct cmd_t *cp;
85
86     toplevel = XtVaOpenApplication(&app_context, "sst2k", NULL, 0, &argc,
87                                     argv, fallback, 
88                                     applicationShellWidgetClass,
89                                     XtNallowShellResize, True, NULL);
90     form = XtVaCreateManagedWidget("form", formWidgetClass, toplevel, NULL);
91     /* the command window */
92     text = XtVaCreateManagedWidget("text", asciiTextWidgetClass, form, 
93                                    XtNwidth, MAXWIDTH, XtNheight, TEXTHEIGHT,
94                                    NULL);
95     XtVaSetValues(text, XtNeditType,XawtextRead, XtNdisplayCaret,False, NULL);
96     /* The button panels */
97     navigation  = XtVaCreateManagedWidget("navigation", 
98                                           boxWidgetClass, form,
99                                           XtNborderWidth, 0,
100                                           XtNfromVert, text,
101                                           XtNorientation, XtorientHorizontal,
102                                           NULL); 
103     navlabel  = XtVaCreateManagedWidget("Navigation:   ", 
104                                         labelWidgetClass, navigation,
105                                         XtNborderWidth, 0,
106                                         NULL); 
107     weapons  = XtVaCreateManagedWidget("weapons", 
108                                        boxWidgetClass, form,
109                                        XtNborderWidth, 0,
110                                        XtNfromVert, navigation, 
111                                        XtNorientation, XtorientHorizontal,
112                                        NULL); 
113     weaplabel  = XtVaCreateManagedWidget("Weapons:      ", 
114                                          labelWidgetClass, weapons,
115                                          XtNborderWidth, 0,
116                                          NULL); 
117     planets  = XtVaCreateManagedWidget("planets", 
118                                        boxWidgetClass, form,
119                                        XtNborderWidth, 0,
120                                        XtNfromVert, weapons, 
121                                        XtNorientation, XtorientHorizontal,
122                                        NULL); 
123     planlabel  = XtVaCreateManagedWidget("Planets:      ", 
124                                          labelWidgetClass, planets,
125                                          XtNborderWidth, 0,
126                                          NULL); 
127     misc  = XtVaCreateManagedWidget("misc", 
128                                        boxWidgetClass, form,
129                                        XtNborderWidth, 0,
130                                        XtNfromVert, planets, 
131                                        XtNorientation, XtorientHorizontal,
132                                        NULL); 
133     misclabel  = XtVaCreateManagedWidget("Miscellaneous:", 
134                                          labelWidgetClass, misc,
135                                          XtNborderWidth, 0,
136                                          NULL); 
137     for (cp = commands; cp < commands + sizeof(commands)/sizeof(commands[0]); cp++) {
138         cp->widget = XtVaCreateManagedWidget(cp->name, 
139                                              commandWidgetClass, 
140                                              *cp->parent, 
141                                              XtNlabel, cp->name,
142                                              NULL);
143         if (cp->callback)
144             XtAddCallback (cp->widget, XtNcallback, cp->callback, NULL);
145     }
146     XtRealizeWidget(toplevel);
147     XtAppMainLoop(app_context);
148     /* loop may be interrupted */
149     XtDestroyApplicationContext(app_context);
150 }
151
152 int main(int argc, char **argv)
153 {
154     instantiate_main(argc, argv);
155     exit(0);
156 }