5
Widget toplevel, base, menubar, field;
6
Widget scorebox, highscorebox;
7
Widget endgamebox, enternamebox;
8
Widget warpbox, quitbox, newgamebox, pausebox;
9
Widget aboutbox, rulesbox, storybox;
11
/**************************/
12
/* Timer control routines */
13
/**************************/
15
void UI::restart_timer() {
16
timer = XtAppAddTimeOut (app, 250, timer_eh, NULL); /* 250 ms */
19
void UI::kill_timer() {
21
XtRemoveTimeOut(timer);
22
timer = (XtIntervalId)0;
26
void UI::pause_game() {
27
if (timer) playing = 1;
31
void UI::resume_game() {
32
if (playing && !timer) restart_timer();
40
void UI::initialize(int *argc, char **argv) {
41
static char *resources[] = {
42
"*background: #c4c4c4",
45
toplevel = XtAppInitialize (&app, "XBill", NULL, 0, argc, argv,
49
void UI::make_mainwin() {
52
Dimension winwidth, winheight;
55
XtAddEventHandler(toplevel, (EventMask)0, TRUE,
56
_XEditResCheckMessages, NULL);
58
display = XtDisplay(toplevel);
60
base = CreateRowCol ("base", toplevel);
61
menubar=CreateMenuBar("menubar", base);
62
field = CreateDrawingArea("field", base, game.scrwidth, game.scrheight);
63
XtAddEventHandler (field, ButtonPressMask, FALSE,
64
(XtEventHandler)button_press_eh, NULL);
65
XtAddEventHandler (field, ButtonReleaseMask, FALSE,
66
(XtEventHandler)button_release_eh, NULL);
67
XtAddEventHandler (field, LeaveWindowMask, FALSE,
68
(XtEventHandler)leave_window_eh, NULL);
69
XtAddEventHandler (field, EnterWindowMask, FALSE,
70
(XtEventHandler)enter_window_eh, NULL);
71
XtAddEventHandler (field, ExposureMask, FALSE,
72
(XtEventHandler)redraw_window_eh, NULL);
74
XtRealizeWidget(toplevel);
75
screen = XtScreen(toplevel);
76
depth = DefaultDepthOfScreen(screen);
77
rootwindow = RootWindowOfScreen(screen);
78
window = XtWindow(field);
80
colormap = DefaultColormapOfScreen(screen);
81
white.pixel = WhitePixelOfScreen(screen);
82
XQueryColor(display, colormap, &white);
83
black.pixel = BlackPixelOfScreen(screen);
84
XQueryColor(display, colormap, &black);
86
XtVaGetValues (toplevel, XtNwidth, &winwidth, XtNheight, &winheight,
88
h.width = h.base_width = h.min_width = h.max_width = winwidth;
89
h.height = h.base_height = h.min_height = h.max_height = winheight;
90
h.flags = USSize|PSize|PMaxSize|PMinSize;
91
XSetNormalHints(display, window, &h);
94
void UI::make_windows() {
98
XtVaSetValues (toplevel, XtNiconPixmap, icon.pix, NULL);
100
newgamebox = CreateDialog ("New Game", base, OK|CANCEL, (Pixmap)NULL,
101
newgamestr, (char *)NULL, new_game_cb);
102
pausebox = CreateDialog ("Pause Game", base, OK, icon.pix,
103
pausestr, "Continue", NULL);
104
quitbox = CreateDialog ("Quit", base, OK|CANCEL, (Pixmap)NULL,
105
quitstr, (char *)NULL, quit_game_cb);
106
warpbox = CreateEnterText ("Warp To Level", base, warpstr,
107
(XtCallbackProc) warp_apply);
110
aboutbox = CreatePixmapBox("About", base, about.pix, "");
111
rulesbox = CreatePixmapBox("Rules", base, (Pixmap)NULL, rulesstr);
112
storybox = CreatePixmapBox("Story", base, (Pixmap)NULL, storystr);
114
scorebox = CreateDialog ("Score", base, OK, (Pixmap)NULL,
115
"", (char *)NULL, NULL);
116
endgamebox = CreateDialog ("Endgame", base, OK, (Pixmap)NULL,
117
endgamestr, "Nuts!", NULL);
118
highscorebox = CreateDialog ("HighScore", base, OK, (Pixmap)NULL,
119
"", (char *)NULL, NULL);
120
enternamebox = CreateEnterText("Enter Name", base,
121
enternamestr, (XtCallbackProc) enter_name);
124
void UI::popup_dialog (int dialog) {
127
case game.ENTERNAME: w = enternamebox; break;
128
case game.HIGHSCORE: w = highscorebox; break;
129
case game.SCORE: w = scorebox; break;
130
case game.ENDGAME: w = endgamebox; break;
132
popup (NULL, &w, NULL);
135
/*********************/
136
/* Graphics routines */
137
/*********************/
139
void UI::set_cursor(int cursor) {
142
XDefineCursor(display, window, bucket.cursor.cursor); break;
144
XDefineCursor(display, window, downcursor.cursor); break;
146
XDefineCursor(display, window, defaultcursor.cursor); break;
148
XDefineCursor(display, window, OS.cursor[cursor].cursor);
152
void UI::load_cursors() {
153
defaultcursor.load("hand_up", defaultcursor.SEP_MASK);
154
XDefineCursor(display, window, defaultcursor.cursor);
155
downcursor.load("hand_down", downcursor.SEP_MASK);
158
void UI::graph_init() {
160
unsigned long gcmask;
161
gcmask = GCGraphicsExposures;
162
gcval.graphics_exposures = False;
163
stdgc = XCreateGC (display, window, gcmask, &gcval);
164
XSetLineAttributes (display, stdgc, 3, LineSolid, CapRound, JoinMiter);
165
XSetBackground(display, stdgc, white.pixel);
166
XSetForeground(display, stdgc, black.pixel);
167
whitegc = XCreateGC (display, window, gcmask, &gcval);
168
XSetBackground(display, whitegc, white.pixel);
169
XSetForeground(display, whitegc, white.pixel);
171
offscreen = XCreatePixmap(display, rootwindow, game.scrwidth,
172
game.scrheight, depth);
176
XFillRectangle (display, offscreen, whitegc, 0, 0,
177
game.scrwidth, game.scrheight);
181
XCopyArea (display, offscreen, window, stdgc, 0, 0,
182
game.scrwidth, game.scrheight, 0, 0);
185
void UI::draw (Picture pict, int x, int y) {
186
XSetClipOrigin(display, pict.gc, x, y);
187
XCopyArea (display, pict.pix, offscreen, pict.gc, 0, 0,
188
pict.width, pict.height, x, y);
191
void UI::draw_centered (Picture pict) {
192
draw (pict, (game.scrwidth - pict.width)/2,
193
(game.scrheight - pict.height)/2);
196
void UI::draw_line(int x1, int y1, int x2, int y2) {
197
XDrawLine(display, offscreen, stdgc, x1, y1, x2, y2);
200
void UI::draw_str(char *str, int x, int y) {
201
XDrawString (display, offscreen, stdgc, x, y, str, strlen(str));
209
void UI::set_pausebutton (int action) {
210
Widget w = XtNameToWidget(menubar,
212
"Game.menu.Pause game");
214
"popup_menu.menu.Pause game");
216
if (w) XtSetSensitive (w, action);
220
void UI::MainLoop() {