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 #undef length /* ugh -- must get rid of ugly #defines */
13 static XtAppContext app_context;
14 static Widget toplevel, text, form;
15 static Widget navigation, weapons, planets, misc;
16 static Widget navlabel, weaplabel, planlabel, misclabel;
18 static String fallback[] = {
19 "*text.resizable: true",
20 "*text.resize: ResizeBoth",
23 "*text.autoFill: True",
24 "*text.scrollVertical: Always",
25 "*text.scrollHorizontal: WhenNeeded",
26 "*text.displayCaret: True",
27 "*navigation.fromVert: text",
28 "*navigation.borderWidth: 0",
29 "*navlabel.label: Navigation: ",
30 "*navlabel.borderWidth: 0",
31 "*weapons.fromVert: navigation",
32 "*weapons.borderWidth: 0",
33 "*weaplabel.label: Weapons: ",
34 "*weaplabel.borderWidth: 0",
35 "*planets.fromVert: weapons",
36 "*planets.borderWidth: 0",
37 "*planlabel.label: Planets: ",
38 "*planlabel.borderWidth: 0",
39 "*misc.fromVert: planets",
40 "*misc.borderWidth: 0",
41 "*misclabel.label: Miscellaneous:",
42 "*misclabel.borderWidth: 0",
48 void (*callback)(Widget, XtPointer, XtPointer);
55 static void quit_proc(Widget w, XtPointer client_data, XtPointer call_data)
57 XtDestroyApplicationContext (app_context);
61 static void text_append_to(Widget w, String str)
62 /* append text to a specified text widget */
65 XawTextPosition textend = XawTextGetInsertionPoint(w);
68 txtblk.length = strlen(str);
70 txtblk.format = FMT8BIT;
72 XawTextReplace(w, textend, textend, &txtblk);
75 static void noargs_proc(Widget w, XtPointer client_data, XtPointer call_data)
76 /* use this for commands that take no arguments */
78 /* currently a stub */
79 text_append_to(w, XtName(w));
80 printf("Button %s pressed\n", XtName(w));
83 static struct cmd_t commands[] = {
84 {"Move", NULL, &navigation, 0},
85 {"Dock", noargs_proc, &navigation, 0},
86 {"Chart", noargs_proc, &navigation, 0},
87 {"Impulse", NULL, &navigation, 0},
88 {"Rest", NULL, &navigation, 0},
89 {"Warp", NULL, &navigation, 0},
90 {"Probe", NULL, &navigation, OPTION_PROBE},
92 {"Phasers", NULL, &weapons, 0},
93 {"Torpedo", NULL, &weapons, 0},
94 {"Shields", NULL, &weapons, 0},
95 {"Damages", noargs_proc, &weapons, 0},
96 {"Abandon", noargs_proc, &weapons, 0},
97 {"Destruct", noargs_proc, &weapons, 0},
98 {"Deathray", noargs_proc, &weapons, 0},
99 {"Mayday", noargs_proc, &weapons, 0},
101 {"Sensors", noargs_proc, &planets, OPTION_PLANETS},
102 {"Orbit", noargs_proc, &planets, OPTION_PLANETS},
103 {"Transport", noargs_proc, &planets, OPTION_PLANETS},
104 {"Mine", noargs_proc, &planets, OPTION_PLANETS},
105 {"Crystals", noargs_proc, &planets, OPTION_PLANETS},
106 {"Shuttle", noargs_proc, &planets, OPTION_PLANETS},
107 {"Planets", noargs_proc, &planets, OPTION_PLANETS},
109 {"Score", noargs_proc, &misc, 0},
110 {"Report", noargs_proc, &misc, 0},
111 {"Computer", noargs_proc, &misc, 0},
112 {"Save", NULL, &misc, 0},
113 {"Quit", quit_proc, &misc, 0},
114 {"Help", noargs_proc, &misc, 0},
117 static void instantiate_main(int argc, char **argv)
121 toplevel = XtVaOpenApplication(&app_context, "sst2k", NULL, 0, &argc,
123 applicationShellWidgetClass,
124 XtNallowShellResize, True, NULL);
125 form = XtVaCreateManagedWidget("form", formWidgetClass, toplevel, NULL);
126 /* the command window */
127 text = XtVaCreateManagedWidget("text",
128 asciiTextWidgetClass, form,
129 XtNeditType, XawtextEdit,
131 /* The button panels */
132 navigation = XtVaCreateManagedWidget("navigation",
133 boxWidgetClass, form,
134 XtNorientation, XtorientHorizontal,
136 navlabel = XtVaCreateManagedWidget("navlabel",
137 labelWidgetClass, navigation,
139 weapons = XtVaCreateManagedWidget("weapons",
140 boxWidgetClass, form,
141 XtNorientation, XtorientHorizontal,
143 weaplabel = XtVaCreateManagedWidget("weaplabel",
144 labelWidgetClass, weapons,
146 planets = XtVaCreateManagedWidget("planets",
147 boxWidgetClass, form,
148 XtNorientation, XtorientHorizontal,
150 planlabel = XtVaCreateManagedWidget("planlabel",
151 labelWidgetClass, planets,
154 misc = XtVaCreateManagedWidget("misc",
155 boxWidgetClass, form,
156 XtNorientation, XtorientHorizontal,
158 misclabel = XtVaCreateManagedWidget("misclabel",
159 labelWidgetClass, misc,
161 for (cp = commands; cp < commands + sizeof(commands)/sizeof(commands[0]); cp++) {
162 cp->widget = XtVaCreateManagedWidget(cp->name,
168 XtAddCallback (cp->widget, XtNcallback, cp->callback, NULL);
170 XtRealizeWidget(toplevel);
171 XtAppMainLoop(app_context);
172 /* loop may be interrupted */
173 XtDestroyApplicationContext(app_context);
176 int main(int argc, char **argv)
178 instantiate_main(argc, argv);