1 #include <string.h>
2 #include <X11/Xlib.h>
3 #include <X11/Xutil.h>
4 #include "handwave.h"
5 #include "spelllist.h"
6 #include "xspell.h"
7
8 #include "ba.bm"
9 #include "bc.bm"
10 #include "bd.bm"
11 #include "bf.bm"
12 #include "bk.bm"
13 #include "bn.bm"
14 #include "bp.bm"
15 #include "bs.bm"
16 #include "bu.bm"
17 #include "bw.bm"
18 #include "bva.bm"
19 #include "bvc.bm"
20 #include "bvd.bm"
21 #include "bvf.bm"
22 #include "bvk.bm"
23 #include "bvp.bm"
24 #include "bvs.bm"
25 #include "bvw.bm"
26
27 #include "sc.bm"
28 #include "sd.bm"
29 #include "sd2.bm"
30 #include "sf.bm"
31 #include "sf2.bm"
32 #include "sp.bm"
33 #include "sp2.bm"
34 #include "ss.bm"
35 #include "ss2.bm"
36 #include "sw.bm"
37 #include "sw2.bm"
38 #include "sdot.bm"
39
40 #define COLUMN_SIZE (8)
41 #define COLUMN_X (476)
42 #define COLUMN_Y (33)
43 #define GEST_SPACE (50)
44
init_bitmaps(py)45 void init_bitmaps(py)
46 struct player *py;
47 {
48 py->gesturebm[0][0] = XCreatePixmapFromBitmapData(py->dpy, py->win, bn_bits,
49 GEST_SIZE, GEST_SIZE, 1, 0, 1);
50 py->gesturebm[0][1] = XCreatePixmapFromBitmapData(py->dpy, py->win, bp_bits,
51 GEST_SIZE, GEST_SIZE, 1, 0, 1);
52 py->gesturebm[0][2] = XCreatePixmapFromBitmapData(py->dpy, py->win, bd_bits,
53 GEST_SIZE, GEST_SIZE, 1, 0, 1);
54 py->gesturebm[0][3] = XCreatePixmapFromBitmapData(py->dpy, py->win, bf_bits,
55 GEST_SIZE, GEST_SIZE, 1, 0, 1);
56 py->gesturebm[0][4] = XCreatePixmapFromBitmapData(py->dpy, py->win, bw_bits,
57 GEST_SIZE, GEST_SIZE, 1, 0, 1);
58 py->gesturebm[0][5] = XCreatePixmapFromBitmapData(py->dpy, py->win, bc_bits,
59 GEST_SIZE, GEST_SIZE, 1, 0, 1);
60 py->gesturebm[0][6] = XCreatePixmapFromBitmapData(py->dpy, py->win, bs_bits,
61 GEST_SIZE, GEST_SIZE, 1, 0, 1);
62 py->gesturebm[0][7] = XCreatePixmapFromBitmapData(py->dpy, py->win, bk_bits,
63 GEST_SIZE, GEST_SIZE, 1, 0, 1);
64 py->gesturebm[0][8] = XCreatePixmapFromBitmapData(py->dpy, py->win, ba_bits,
65 GEST_SIZE, GEST_SIZE, 1, 0, 1);
66 py->gesturebm[0][9] = XCreatePixmapFromBitmapData(py->dpy, py->win, bu_bits,
67 GEST_SIZE, GEST_SIZE, 1, 0, 1);
68
69 py->gesturebm[1][0] = XCreatePixmapFromBitmapData(py->dpy, py->win, bn_bits,
70 GEST_SIZE, GEST_SIZE, 1, 0, 1);
71 py->gesturebm[1][1] = XCreatePixmapFromBitmapData(py->dpy, py->win, bvp_bits,
72 GEST_SIZE, GEST_SIZE, 1, 0, 1);
73 py->gesturebm[1][2] = XCreatePixmapFromBitmapData(py->dpy, py->win, bvd_bits,
74 GEST_SIZE, GEST_SIZE, 1, 0, 1);
75 py->gesturebm[1][3] = XCreatePixmapFromBitmapData(py->dpy, py->win, bvf_bits,
76 GEST_SIZE, GEST_SIZE, 1, 0, 1);
77 py->gesturebm[1][4] = XCreatePixmapFromBitmapData(py->dpy, py->win, bvw_bits,
78 GEST_SIZE, GEST_SIZE, 1, 0, 1);
79 py->gesturebm[1][5] = XCreatePixmapFromBitmapData(py->dpy, py->win, bvc_bits,
80 GEST_SIZE, GEST_SIZE, 1, 0, 1);
81 py->gesturebm[1][6] = XCreatePixmapFromBitmapData(py->dpy, py->win, bvs_bits,
82 GEST_SIZE, GEST_SIZE, 1, 0, 1);
83 py->gesturebm[1][7] = XCreatePixmapFromBitmapData(py->dpy, py->win, bvk_bits,
84 GEST_SIZE, GEST_SIZE, 1, 0, 1);
85 py->gesturebm[1][8] = XCreatePixmapFromBitmapData(py->dpy, py->win, bva_bits,
86 GEST_SIZE, GEST_SIZE, 1, 0, 1);
87 py->gesturebm[1][9] = XCreatePixmapFromBitmapData(py->dpy, py->win, bu_bits,
88 GEST_SIZE, GEST_SIZE, 1, 0, 1);
89
90 py->spelllistbm[0][0] = XCreatePixmapFromBitmapData(py->dpy, py->win, sp_bits,
91 GEST_SMALL, GEST_SMALL, 1, 0, 1);
92 py->spelllistbm[0][1] = XCreatePixmapFromBitmapData(py->dpy, py->win, sd_bits,
93 GEST_SMALL, GEST_SMALL, 1, 0, 1);
94 py->spelllistbm[0][2] = XCreatePixmapFromBitmapData(py->dpy, py->win, sf_bits,
95 GEST_SMALL, GEST_SMALL, 1, 0, 1);
96 py->spelllistbm[0][3] = XCreatePixmapFromBitmapData(py->dpy, py->win, sw_bits,
97 GEST_SMALL, GEST_SMALL, 1, 0, 1);
98 py->spelllistbm[0][4] = 0; /* there is no single clap */
99 py->spelllistbm[0][5] = XCreatePixmapFromBitmapData(py->dpy, py->win, ss_bits,
100 GEST_SMALL, GEST_SMALL, 1, 0, 1);
101 py->spelllistbm[0][6] = XCreatePixmapFromBitmapData(py->dpy, py->win, sdot_bits,
102 GEST_SMALL, GEST_SMALL, 1, 0, 1);
103
104 py->spelllistbm[1][0] = XCreatePixmapFromBitmapData(py->dpy, py->win, sp2_bits,
105 GEST_SMALL, GEST_SMALL, 1, 0, 1);
106 py->spelllistbm[1][1] = XCreatePixmapFromBitmapData(py->dpy, py->win, sd2_bits,
107 GEST_SMALL, GEST_SMALL, 1, 0, 1);
108 py->spelllistbm[1][2] = XCreatePixmapFromBitmapData(py->dpy, py->win, sf2_bits,
109 GEST_SMALL, GEST_SMALL, 1, 0, 1);
110 py->spelllistbm[1][3] = XCreatePixmapFromBitmapData(py->dpy, py->win, sw2_bits,
111 GEST_SMALL, GEST_SMALL, 1, 0, 1);
112 py->spelllistbm[1][4] = XCreatePixmapFromBitmapData(py->dpy, py->win, sc_bits,
113 GEST_SMALL, GEST_SMALL, 1, 0, 1);
114 py->spelllistbm[1][5] = XCreatePixmapFromBitmapData(py->dpy, py->win, ss2_bits,
115 GEST_SMALL, GEST_SMALL, 1, 0, 1);
116 py->spelllistbm[1][6] = 0; /* no double dots */
117
118 }
119
redraw_column(py)120 void redraw_column(py)
121 struct player *py;
122 {
123 int buf[COLUMN_SIZE+1];
124 int ix, gx;
125 int vall, valr;
126 int posx, posy;
127 int pnum = py-players;
128
129 if (turnstate==State_Init) {
130 return;
131 }
132
133 for (ix=0; ix<numplayers; ix++) {
134 posx = COLUMN_X + ix*(2*GEST_SIZE + 20);
135 posy = COLUMN_Y;
136
137 DrawStringCentered(py, NameOfBeing(gameval, QuVal_Target_Wizard, ix),
138 posx+GEST_SIZE, posy-py->lineheight+py->ascent);
139
140 if (turnstate!=State_Top) {
141 SeeGesture(gameval, ix, pnum, buf, COLUMN_SIZE);
142 gx=0;
143 if (turnstate==State_EQueries && ix!=pnum) {
144 buf[0] = (Gesture_UNCLEAR<<5) + Gesture_UNCLEAR;
145 }
146 }
147 else {
148 SeeGesture(gameval, ix, pnum, buf+1, COLUMN_SIZE);
149 gx=1;
150 if (ix==pnum) {
151 vall = py->gesture_chosen[0];
152 valr = py->gesture_chosen[1];
153 }
154 else {
155 vall = Gesture_UNCLEAR;
156 valr = Gesture_UNCLEAR;
157 }
158 XCopyPlane(py->dpy, py->gesturebm[0][vall], py->win, py->blackgc,
159 0, 0, GEST_SIZE, GEST_SIZE, posx,
160 posy+(GEST_SPACE)*(COLUMN_SIZE-1), 1);
161 XCopyPlane(py->dpy, py->gesturebm[1][valr], py->win, py->blackgc,
162 0, 0, GEST_SIZE, GEST_SIZE, posx+GEST_SPACE,
163 posy+(GEST_SPACE)*(COLUMN_SIZE-1), 1);
164 }
165 for (/* gx is set */; gx<COLUMN_SIZE; gx++) {
166 if (buf[gx]==(-1)) {
167 valr = Gesture_NOTHING;
168 vall = Gesture_NOTHING;
169 }
170 else {
171 valr = buf[gx] >> 5;
172 vall = buf[gx] & 31; /* 31==01111 */
173 }
174 XCopyPlane(py->dpy, py->gesturebm[0][vall], py->win, py->blackgc,
175 0, 0, GEST_SIZE, GEST_SIZE, posx,
176 posy+(GEST_SPACE)*(COLUMN_SIZE-(gx+1)), 1);
177 XCopyPlane(py->dpy, py->gesturebm[1][valr], py->win, py->blackgc,
178 0, 0, GEST_SIZE, GEST_SIZE, posx+GEST_SPACE,
179 posy+(GEST_SPACE)*(COLUMN_SIZE-(gx+1)), 1);
180 }
181 }
182 }
183
draw_frame(py,mrec)184 void draw_frame(py, mrec)
185 struct player *py;
186 struct rect *mrec;
187 {
188 XClearArea(py->dpy, py->win, mrec->x, mrec->y, mrec->w, mrec->h, 0);
189
190 XDrawRectangle(py->dpy, py->win, py->blackgc, mrec->x, mrec->y,
191 mrec->w-FRAME_SHADOW, mrec->h-FRAME_SHADOW);
192 XDrawRectangle(py->dpy, py->win, py->blackgc, mrec->x+1, mrec->y+1,
193 mrec->w-FRAME_SHADOW-2, mrec->h-FRAME_SHADOW-2);
194 XFillRectangle(py->dpy, py->win, py->blackgc, mrec->x+mrec->w-FRAME_SHADOW,
195 mrec->y+FRAME_SHADOW, FRAME_SHADOW, mrec->h-FRAME_SHADOW);
196 XFillRectangle(py->dpy, py->win, py->blackgc, mrec->x+FRAME_SHADOW,
197 mrec->y+mrec->h-FRAME_SHADOW, mrec->w-FRAME_SHADOW, FRAME_SHADOW);
198 }
199
draw_gesture_menu(py)200 void draw_gesture_menu(py)
201 struct player *py;
202 {
203 static char gesture_prompt[2][128];
204 int ix, jx;
205 int posx, posy;
206
207 draw_frame(py, &py->gesture_rect);
208 sprintf(gesture_prompt[0], "What gesture do you want to");
209 sprintf(gesture_prompt[1], "make with your %s hand?",
210 py->gesture_hand?"right":"left");
211 XDrawImageString(py->dpy, py->win, py->blackgc, py->gesture_rect.x+20,
212 py->gesture_rect.y+10+py->lineheight, gesture_prompt[0],
213 strlen(gesture_prompt[0]));
214 XDrawImageString(py->dpy, py->win, py->blackgc, py->gesture_rect.x+20,
215 py->gesture_rect.y+10+2*py->lineheight, gesture_prompt[1],
216 strlen(gesture_prompt[1]));
217
218 posx = py->gesture_rect.x+20;
219 posy = py->gesture_rect.y+60;
220 for (jx=0; jx<2; jx++)
221 for (ix=0; ix<4; ix++) {
222 XCopyPlane(py->dpy, py->gesturebm[py->gesture_hand][jx*4+ix],
223 py->win, py->blackgc, 0, 0, GEST_SIZE, GEST_SIZE,
224 posx+ix*GEST_SPACE, posy+jx*GEST_SPACE, 1);
225 }
226 }
227
in_gesture_box(py,xpos,ypos)228 int in_gesture_box(py, xpos, ypos)
229 struct player *py;
230 int xpos, ypos;
231 {
232 return (xpos >= COLUMN_X
233 && xpos < COLUMN_X + numplayers*(2*GEST_SIZE + 20)
234 && ypos >= COLUMN_Y
235 && ypos < COLUMN_Y + GEST_SPACE*COLUMN_SIZE);
236 }
237
gesture_hit(py,xpos,ypos,button)238 int gesture_hit(py, xpos, ypos, button)
239 struct player *py;
240 int xpos, ypos; /* relative to column pos */
241 int button;
242 {
243 int pnum = py-players;
244 int hitcol, hitrow, hithand;
245
246 xpos -= COLUMN_X;
247 ypos -= COLUMN_Y;
248
249 if (!py->turn_active || py->turn_done)
250 return ms_None;
251
252 hitcol = xpos / (2*GEST_SIZE + 20);
253 hitrow = ypos / GEST_SPACE;
254 hithand = (xpos % (2*GEST_SIZE + 20)) / GEST_SPACE;
255 if (hithand < 0 || hithand > 1)
256 return ms_None;
257
258 if (hitrow==COLUMN_SIZE-1 && hitcol==pnum && button==1 && turnstate==State_Top) {
259 py->gesture_rect.w = 240;
260 py->gesture_rect.h = 180;
261 py->gesture_rect.x = xpos + COLUMN_X - py->gesture_rect.w/2;
262 py->gesture_rect.y = ypos + COLUMN_Y - py->gesture_rect.h/2;
263 py->gesture_hand = hithand;
264 py->gesture_sel = (-1);
265 adjust_rect(&py->gesture_rect);
266 backing_store(py, &py->gesture_rect);
267 draw_gesture_menu(py);
268 gesture_motion(py, xpos+COLUMN_X, ypos+COLUMN_Y, button);
269 return ms_Gesture;
270 }
271
272 return ms_None;
273 }
274
gesture_motion(py,xpos,ypos,button)275 int gesture_motion(py, xpos, ypos, button)
276 struct player *py;
277 int xpos, ypos;
278 int button;
279 {
280 int hitx, hity, hit;
281 int posx, posy;
282
283 posx = py->gesture_rect.x+20;
284 posy = py->gesture_rect.y+60;
285
286 hitx = (xpos - posx + GEST_SPACE) / GEST_SPACE - 1;
287 hity = (ypos - posy + GEST_SPACE) / GEST_SPACE - 1;
288
289 if (hitx>=0 && hitx<4 && hity>=0 && hity<2)
290 hit = hity*4 + hitx;
291 else
292 hit = (-1);
293
294 if (hit==py->gesture_sel)
295 return;
296
297 if (py->gesture_sel != (-1)) {
298 /* erase old */
299 hitx = py->gesture_sel % 4;
300 hity = py->gesture_sel / 4;
301 XDrawRectangle(py->dpy, py->win, py->whitegc, posx+hitx*GEST_SPACE-1,
302 posy+hity*GEST_SPACE-1, GEST_SIZE+1, GEST_SIZE+1);
303 XDrawRectangle(py->dpy, py->win, py->whitegc, posx+hitx*GEST_SPACE-2,
304 posy+hity*GEST_SPACE-2, GEST_SIZE+3, GEST_SIZE+3);
305 }
306
307 py->gesture_sel = hit;
308
309 if (py->gesture_sel != (-1)) {
310 /* draw new */
311 hitx = py->gesture_sel % 4;
312 hity = py->gesture_sel / 4;
313 XDrawRectangle(py->dpy, py->win, py->blackgc, posx+hitx*GEST_SPACE-1,
314 posy+hity*GEST_SPACE-1, GEST_SIZE+1, GEST_SIZE+1);
315 XDrawRectangle(py->dpy, py->win, py->blackgc, posx+hitx*GEST_SPACE-2,
316 posy+hity*GEST_SPACE-2, GEST_SIZE+3, GEST_SIZE+3);
317 }
318 }
319
gesture_release(py,xpos,ypos,button)320 int gesture_release(py, xpos, ypos, button)
321 struct player *py;
322 int xpos, ypos; /* relative to column pos */
323 int button;
324 {
325 int posx, posy;
326 int pnum = py-players;
327
328 xpos -= COLUMN_X;
329 ypos -= COLUMN_Y;
330
331 backing_restore(py);
332 if (py->gesture_sel != (-1))
333 py->gesture_chosen[py->gesture_hand] = py->gesture_sel;
334
335 posx = COLUMN_X + pnum*(2*GEST_SIZE + 20);
336 posy = COLUMN_Y;
337 XCopyPlane(py->dpy, py->gesturebm[0][py->gesture_chosen[0]], py->win,
338 py->blackgc, 0, 0, GEST_SIZE, GEST_SIZE, posx,
339 posy+(GEST_SPACE)*(COLUMN_SIZE-1), 1);
340 XCopyPlane(py->dpy, py->gesturebm[1][py->gesture_chosen[1]], py->win,
341 py->blackgc, 0, 0, GEST_SIZE, GEST_SIZE, posx+GEST_SPACE,
342 posy+(GEST_SPACE)*(COLUMN_SIZE-1), 1);
343 }
344