2 #include <X11/Intrinsic.h>
3 #include <X11/StringDefs.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>
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;
16 static String fallback[] = {
17 "*text.resizable: true",
18 "*text.resize: ResizeBoth",
21 "*text.autoFill: True",
22 "*text.scrollVertical: Always",
23 "*text.scrollHorizontal: WhenNeeded",
24 "*text.displayCaret: True",
25 "*navigation.fromVert: text",
26 "*navigation.borderWidth: 0",
27 "*navlabel.label: Navigation: ",
28 "*navlabel.borderWidth: 0",
29 "*weapons.fromVert: navigation",
30 "*weapons.borderWidth: 0",
31 "*weaplabel.label: Weapons: ",
32 "*weaplabel.borderWidth: 0",
33 "*planets.fromVert: weapons",
34 "*planets.borderWidth: 0",
35 "*planlabel.label: Planets: ",
36 "*planlabel.borderWidth: 0",
37 "*misc.fromVert: planets",
38 "*misc.borderWidth: 0",
39 "*misclabel.label: Miscellaneous:",
40 "*misclabel.borderWidth: 0",
46 void (*callback)(Widget, XtPointer, XtPointer);
53 static void quit_proc(Widget w, XtPointer client_data, XtPointer call_data)
55 XtDestroyApplicationContext (app_context);
59 static void text_append_to(Widget w, String str)
60 /* append text to a specified text widget */
63 XawTextPosition textend = XawTextGetInsertionPoint(w);
66 txtblk.length = strlen(str);
68 txtblk.format = FMT8BIT;
70 XawTextReplace(w, textend, textend, &txtblk);
73 static void noargs_proc(Widget w, XtPointer client_data, XtPointer call_data)
74 /* use this for commands that take no arguments */
76 /* currently a stub */
77 text_append_to(w, XtName(w));
78 printf("Button %s pressed\n", XtName(w));
81 static struct cmd_t commands[] = {
82 {"Move", NULL, &navigation, 0},
83 {"Dock", noargs_proc, &navigation, 0},
84 {"Chart", noargs_proc, &navigation, 0},
85 {"Impulse", NULL, &navigation, 0},
86 {"Rest", NULL, &navigation, 0},
87 {"Warp", NULL, &navigation, 0},
88 {"Probe", NULL, &navigation, OPTION_PROBE},
90 {"Phasers", NULL, &weapons, 0},
91 {"Torpedo", NULL, &weapons, 0},
92 {"Shields", NULL, &weapons, 0},
93 {"Damages", noargs_proc, &weapons, 0},
94 {"Abandon", noargs_proc, &weapons, 0},
95 {"Destruct", noargs_proc, &weapons, 0},
96 {"Deathray", noargs_proc, &weapons, 0},
97 {"Mayday", noargs_proc, &weapons, 0},
99 {"Sensors", noargs_proc, &planets, OPTION_PLANETS},
100 {"Orbit", noargs_proc, &planets, OPTION_PLANETS},
101 {"Transport", noargs_proc, &planets, OPTION_PLANETS},
102 {"Mine", noargs_proc, &planets, OPTION_PLANETS},
103 {"Crystals", noargs_proc, &planets, OPTION_PLANETS},
104 {"Shuttle", noargs_proc, &planets, OPTION_PLANETS},
105 {"Planets", noargs_proc, &planets, OPTION_PLANETS},
107 {"Score", noargs_proc, &misc, 0},
108 {"Report", noargs_proc, &misc, 0},
109 {"Computer", noargs_proc, &misc, 0},
110 {"Save", NULL, &misc, 0},
111 {"Quit", quit_proc, &misc, 0},
112 {"Help", noargs_proc, &misc, 0},
115 static void instantiate_main(int argc, char **argv)
119 toplevel = XtVaOpenApplication(&app_context, "sst2k", NULL, 0, &argc,
121 applicationShellWidgetClass,
122 XtNallowShellResize, True, NULL);
123 form = XtVaCreateManagedWidget("form", formWidgetClass, toplevel, NULL);
124 /* the command window */
125 text = XtVaCreateManagedWidget("text",
126 asciiTextWidgetClass, form,
127 XtNeditType, XawtextEdit,
129 /* The button panels */
130 navigation = XtVaCreateManagedWidget("navigation",
131 boxWidgetClass, form,
132 XtNorientation, XtorientHorizontal,
134 navlabel = XtVaCreateManagedWidget("navlabel",
135 labelWidgetClass, navigation,
137 weapons = XtVaCreateManagedWidget("weapons",
138 boxWidgetClass, form,
139 XtNorientation, XtorientHorizontal,
141 weaplabel = XtVaCreateManagedWidget("weaplabel",
142 labelWidgetClass, weapons,
144 planets = XtVaCreateManagedWidget("planets",
145 boxWidgetClass, form,
146 XtNorientation, XtorientHorizontal,
148 planlabel = XtVaCreateManagedWidget("planlabel",
149 labelWidgetClass, planets,
152 misc = XtVaCreateManagedWidget("misc",
153 boxWidgetClass, form,
154 XtNorientation, XtorientHorizontal,
156 misclabel = XtVaCreateManagedWidget("misclabel",
157 labelWidgetClass, misc,
159 for (cp = commands; cp < commands + sizeof(commands)/sizeof(commands[0]); cp++) {
160 cp->widget = XtVaCreateManagedWidget(cp->name,
166 XtAddCallback (cp->widget, XtNcallback, cp->callback, NULL);
168 XtRealizeWidget(toplevel);
169 XtAppMainLoop(app_context);
170 /* loop may be interrupted */
171 XtDestroyApplicationContext(app_context);
174 int main(int argc, char **argv)
176 instantiate_main(argc, argv);