1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include "objects.h"
#include "x11.h"
static int in_popup = 0;
/**********************/
/* Callback functions */
/**********************/
void new_game_cb (Widget w, XtPointer client_data, XtPointer call_data) {
game.start(1);
}
void quit_game_cb (Widget w, XtPointer client_data, XtPointer call_data) {
game.quit();
}
void get_coords (Position *x, Position *y) {
XWindowAttributes wattr;
Window junk;
int rx, ry;
XGetWindowAttributes (ui.display, ui.window, &wattr);
XTranslateCoordinates (ui.display, ui.window, wattr.root,
-wattr.border_width, -wattr.border_width, &rx, &ry, &junk);
*x=rx+20;
*y=ry+40;
}
void popup (Widget w, Widget *box, XtPointer call_data) {
Position x, y;
in_popup = 1;
#ifdef athena
get_coords(&x, &y);
XtMoveWidget(XtParent(*box), x, y);
#endif
XtManageChild(*box);
XtAddCallback(XtParent(*box), XtNpopdownCallback,
(XtCallbackProc) popdown, NULL);
XtPopup(XtParent(*box), XtGrabExclusive);
while (in_popup || XtAppPending(ui.app))
XtAppProcessEvent(ui.app, XtIMXEvent);
}
void popdown (Widget w, XtPointer client_data, XtPointer call_data) {
in_popup = 0;
}
/******************/
/* Event handlers */
/******************/
void leave_window_eh(Widget w, XtPointer client_data, XEvent *event) {
ui.pause_game();
}
void enter_window_eh(Widget w, XtPointer client_data, XEvent *event) {
ui.resume_game();
}
void redraw_window_eh(Widget w, XtPointer client_data, XEvent *event) {
ui.refresh();
}
void button_press_eh(Widget w, XtPointer data, XButtonEvent *event) {
game.button_press(event->x, event->y);
}
void button_release_eh(Widget w, XtPointer data, XButtonEvent *event) {
game.button_release(event->x, event->y);
}
void timer_eh(XtPointer client_data, XtIntervalId *timer_id) {
ui.restart_timer();
game.update();
}
|