~ubuntu-branches/ubuntu/natty/xbill/natty

« back to all changes in this revision

Viewing changes to UI.cc

  • Committer: Bazaar Package Importer
  • Author(s): Adrian Bridgett
  • Date: 2004-09-07 09:52:14 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040907095214-d0m46ojc8f7upuqm
Tags: 2.1-4
maintainer upload of NMU - many thanks Tollef (closes: #268885) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "objects.h"
2
 
#include "x11.h"
3
 
#include "Strings.h"
4
 
 
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;
10
 
 
11
 
/**************************/
12
 
/* Timer control routines */
13
 
/**************************/
14
 
 
15
 
void UI::restart_timer() {
16
 
        timer = XtAppAddTimeOut (app, 250, timer_eh, NULL); /* 250 ms */
17
 
}
18
 
 
19
 
void UI::kill_timer() {
20
 
        if (timer) {
21
 
                XtRemoveTimeOut(timer);
22
 
                timer = (XtIntervalId)0;
23
 
        }
24
 
}
25
 
 
26
 
void UI::pause_game() {
27
 
        if (timer) playing = 1;
28
 
        kill_timer();
29
 
}
30
 
 
31
 
void UI::resume_game() {
32
 
        if (playing && !timer) restart_timer();
33
 
        playing = 0;
34
 
}
35
 
 
36
 
/*******************/
37
 
/* Window routines */
38
 
/*******************/
39
 
 
40
 
void UI::initialize(int *argc, char **argv) {
41
 
        static char *resources[] = {
42
 
                "*background: #c4c4c4",
43
 
                NULL
44
 
        };
45
 
        toplevel = XtAppInitialize (&app, "XBill", NULL, 0, argc, argv,
46
 
                resources, NULL, 0);
47
 
}
48
 
 
49
 
void UI::make_mainwin() {
50
 
        Screen *screen;
51
 
        XSizeHints h;
52
 
        Dimension winwidth, winheight;
53
 
 
54
 
/*
55
 
        XtAddEventHandler(toplevel, (EventMask)0, TRUE,
56
 
                _XEditResCheckMessages, NULL);
57
 
*/
58
 
        display = XtDisplay(toplevel);
59
 
 
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);
73
 
 
74
 
        XtRealizeWidget(toplevel);
75
 
        screen = XtScreen(toplevel);
76
 
        depth = DefaultDepthOfScreen(screen);
77
 
        rootwindow = RootWindowOfScreen(screen);
78
 
        window = XtWindow(field);
79
 
 
80
 
        colormap = DefaultColormapOfScreen(screen);
81
 
        white.pixel = WhitePixelOfScreen(screen);
82
 
        XQueryColor(display, colormap, &white);
83
 
        black.pixel = BlackPixelOfScreen(screen);
84
 
        XQueryColor(display, colormap, &black);
85
 
 
86
 
        XtVaGetValues (toplevel, XtNwidth, &winwidth, XtNheight, &winheight,
87
 
                NULL);
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);
92
 
}
93
 
 
94
 
void UI::make_windows() {
95
 
        Picture about;
96
 
 
97
 
        icon.load("icon");
98
 
        XtVaSetValues (toplevel, XtNiconPixmap, icon.pix, NULL);
99
 
 
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);
108
 
        about.load("about");
109
 
 
110
 
        aboutbox = CreatePixmapBox("About", base, about.pix, "");
111
 
        rulesbox = CreatePixmapBox("Rules", base, (Pixmap)NULL, rulesstr);
112
 
        storybox = CreatePixmapBox("Story", base, (Pixmap)NULL, storystr);
113
 
 
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);
122
 
}
123
 
 
124
 
void UI::popup_dialog (int dialog) {
125
 
        Widget w;
126
 
        switch (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;
131
 
        }
132
 
        popup (NULL, &w, NULL);
133
 
}
134
 
 
135
 
/*********************/
136
 
/* Graphics routines */
137
 
/*********************/
138
 
 
139
 
void UI::set_cursor(int cursor) {
140
 
        switch (cursor) {
141
 
        case game.BUCKETC:
142
 
                XDefineCursor(display, window, bucket.cursor.cursor); break;
143
 
        case game.DOWNC:
144
 
                XDefineCursor(display, window, downcursor.cursor); break;
145
 
        case game.DEFAULTC:
146
 
                XDefineCursor(display, window, defaultcursor.cursor); break;
147
 
        default:
148
 
                XDefineCursor(display, window, OS.cursor[cursor].cursor);
149
 
        }
150
 
}
151
 
 
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);
156
 
}
157
 
 
158
 
void UI::graph_init() {
159
 
        XGCValues gcval;
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);
170
 
 
171
 
        offscreen = XCreatePixmap(display, rootwindow, game.scrwidth,
172
 
                game.scrheight, depth);
173
 
}
174
 
 
175
 
void UI::clear() {
176
 
        XFillRectangle (display, offscreen, whitegc, 0, 0,
177
 
                game.scrwidth, game.scrheight);
178
 
}
179
 
 
180
 
void UI::refresh() {
181
 
        XCopyArea (display, offscreen, window, stdgc, 0, 0,
182
 
                game.scrwidth, game.scrheight, 0, 0);
183
 
}
184
 
 
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);
189
 
}
190
 
 
191
 
void UI::draw_centered (Picture pict) {
192
 
        draw (pict, (game.scrwidth - pict.width)/2,
193
 
                (game.scrheight - pict.height)/2);
194
 
}
195
 
 
196
 
void UI::draw_line(int x1, int y1, int x2, int y2) {
197
 
        XDrawLine(display, offscreen, stdgc, x1, y1, x2, y2);
198
 
}
199
 
 
200
 
void UI::draw_str(char *str, int x, int y) {
201
 
        XDrawString (display, offscreen, stdgc, x, y, str, strlen(str));
202
 
}
203
 
 
204
 
 
205
 
/******************/
206
 
/* Other routines */
207
 
/******************/
208
 
 
209
 
void UI::set_pausebutton (int action) {
210
 
        Widget w = XtNameToWidget(menubar,
211
 
#ifdef athena
212
 
                "Game.menu.Pause game");
213
 
#else
214
 
                "popup_menu.menu.Pause game");
215
 
#endif
216
 
        if (w) XtSetSensitive (w, action);
217
 
}
218
 
 
219
 
 
220
 
void UI::MainLoop() {
221
 
        XtAppMainLoop(app);
222
 
}