5
#include <X11/Xaw/XawInit.h>
6
#include <X11/Xaw/Label.h>
7
#include <X11/Xaw/Box.h>
8
#include <X11/Xaw/MenuButton.h>
9
#include <X11/Xaw/SimpleMenu.h>
10
#include <X11/Xaw/SmeBSB.h>
11
#include <X11/Xaw/SmeLine.h>
12
#include <X11/Xaw/AsciiText.h>
14
extern Widget scorebox, highscorebox;
16
Widget CreateMenuBar(const char *name, Widget parent) {
19
menubar = XtVaCreateManagedWidget(name, boxWidgetClass, parent,
20
XtNborderWidth, 0, XtNorientation, XtEhorizontal, NULL);
21
for (j=0; j<menu.size; j++) {
22
temp = XtCreateManagedWidget(menu.submenu[j].name,
23
menuButtonWidgetClass, menubar, NULL, 0);
24
menu.submenu[j].pshell = XtCreatePopupShell("menu",
25
simpleMenuWidgetClass, temp, NULL, 0);
26
for (i=0; i<menu.submenu[j].size; i++) {
27
if (strlen(menu.submenu[j].button[i].name)) {
28
temp = XtCreateManagedWidget(
29
menu.submenu[j].button[i].name,
31
menu.submenu[j].pshell, NULL, 0);
32
XtAddCallback(temp, XtNcallback,
33
(XtCallbackProc)popup,
34
menu.submenu[j].button[i].dialog);
36
else XtCreateManagedWidget("", smeLineObjectClass,
37
menu.submenu[j].pshell, NULL, 0);
43
void close_window (Widget w, XtPointer client_data, XtPointer call_data) {
44
XtPopdown(XtParent(XtParent(w)));
47
Widget CreatePixmapBox(const char *name, Widget parent, Pixmap pixmap,
50
Widget base, pshell, button;
52
pshell = XtCreatePopupShell(name, transientShellWidgetClass,
55
base = CreateRowCol("", pshell);
57
XtVaCreateManagedWidget("", labelWidgetClass, base,
58
XtNbitmap, game.logo.pix, XtNborderWidth, 0, NULL);
60
if (pixmap) XtVaCreateManagedWidget("", labelWidgetClass, base,
61
XtNbitmap, pixmap, XtNborderWidth, 0, NULL);
63
XtVaCreateManagedWidget("", labelWidgetClass, base,
64
XtNlabel, text, XtNborderWidth, 0, NULL);
66
button = XtVaCreateManagedWidget("OK", commandWidgetClass, base, NULL);
67
XtAddCallback(button, XtNcallback, (XtCallbackProc)close_window, NULL);
71
void warp_apply (Widget w, Widget text, XtPointer client_data) {
73
XtVaGetValues(text, XtNstring, &str, NULL);
74
game.warp_to_level (atoi(str));
77
void enter_name (Widget w, Widget text, XtPointer client_data) {
79
XtVaGetValues(text, XtNstring, &str, NULL);
80
if (!str[0]) strcpy(str, "Anonymous");
81
else if ((nl = strchr(str,'\n'))) *nl=0;
82
if (strlen(str)>20) str[20] = 0; /* truncate string if too long */
86
Widget CreateEnterText (const char *name, Widget parent, const char *text,
87
XtCallbackProc callback)
89
Widget base, pshell, button, textfield;
90
pshell = XtCreatePopupShell(name, transientShellWidgetClass,
92
base = CreateRowCol("", pshell);
93
XtVaCreateManagedWidget("", labelWidgetClass, base,
94
XtNlabel, text, XtNborderWidth, 0, NULL);
96
textfield = XtVaCreateManagedWidget("", asciiTextWidgetClass, base,
97
XtNeditType, XawtextEdit, XtNstring, "", XtNwidth, 200, NULL);
99
button = XtVaCreateManagedWidget("OK", commandWidgetClass, base, NULL);
100
XtAddCallback(button, XtNcallback, (XtCallbackProc)callback, textfield);
101
XtAddCallback(button, XtNcallback, (XtCallbackProc)close_window, NULL);
102
button = XtVaCreateManagedWidget("Cancel", commandWidgetClass, base,
104
XtAddCallback(button, XtNcallback, (XtCallbackProc)close_window, NULL);
108
Widget CreateDialog (const char *name, Widget parent, int buttonmask,
109
Pixmap icon, const char *text, const char *buttonlabel,
110
XtCallbackProc callback)
112
Widget base, pshell, button;
113
char *ttext= (char*)malloc(strlen(text)+5);
114
pshell = XtCreatePopupShell(name, transientShellWidgetClass,
116
base = CreateRowCol("base", pshell);
118
if (strlen(ttext)<12) strcat(ttext, " ");
119
XtVaCreateManagedWidget("label", labelWidgetClass, base,
120
XtNlabel, ttext, XtNborderWidth, 0, NULL);
122
XtVaCreateManagedWidget("", labelWidgetClass, base,
123
XtNbitmap, icon, XtNborderWidth, 0, NULL);
125
if (!buttonlabel) buttonlabel="OK";
126
button = XtVaCreateManagedWidget(buttonlabel,
127
commandWidgetClass, base, NULL);
129
XtAddCallback(button, XtNcallback,
130
(XtCallbackProc)callback, NULL);
131
XtAddCallback(button, XtNcallback,
132
(XtCallbackProc)close_window, NULL);
134
if (buttonmask&CANCEL) {
135
button = XtVaCreateManagedWidget("Cancel", commandWidgetClass,
137
XtAddCallback(button, XtNcallback,
138
(XtCallbackProc)close_window, NULL);
143
Widget CreateDrawingArea(const char *name, Widget parent, int width, int height)
145
return XtVaCreateManagedWidget(name, coreWidgetClass, parent, XtNwidth,
146
width, XtNheight, height, NULL);
149
void UI::update_hsbox(char *str) {
151
XtVaGetValues(highscorebox, XtNchildren, &t, NULL);
152
XtVaSetValues(t[0], XtNlabel, str, NULL);
155
void UI::update_scorebox(int level, int score) {
158
sprintf (str, "After Level %d: \nYour score: %d\n", level, score);
159
XtVaGetValues(scorebox, XtNchildren, &t, NULL);
160
XtVaSetValues(t[0], XtNlabel, str, NULL);
163
Widget CreateRowCol(const char *name, Widget parent) {
164
return XtCreateManagedWidget(name, boxWidgetClass, parent, NULL, 0);