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