1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-98 Artsoft Entertainment *
8 * phone: ++49 +521 290471 *
9 * email: aeglos@valinor.owl.de *
10 *----------------------------------------------------------*
12 ***********************************************************/
22 /* some positions in the video tape control window */
23 #define VIDEO_BUTTON_EJECT_XPOS (VIDEO_CONTROL_XPOS + 0 * VIDEO_BUTTON_XSIZE)
24 #define VIDEO_BUTTON_STOP_XPOS (VIDEO_CONTROL_XPOS + 1 * VIDEO_BUTTON_XSIZE)
25 #define VIDEO_BUTTON_PAUSE_XPOS (VIDEO_CONTROL_XPOS + 2 * VIDEO_BUTTON_XSIZE)
26 #define VIDEO_BUTTON_REC_XPOS (VIDEO_CONTROL_XPOS + 3 * VIDEO_BUTTON_XSIZE)
27 #define VIDEO_BUTTON_PLAY_XPOS (VIDEO_CONTROL_XPOS + 4 * VIDEO_BUTTON_XSIZE)
28 #define VIDEO_BUTTON_ANY_YPOS (VIDEO_CONTROL_YPOS)
29 #define VIDEO_DATE_LABEL_XPOS (VIDEO_DISPLAY1_XPOS)
30 #define VIDEO_DATE_LABEL_YPOS (VIDEO_DISPLAY1_YPOS)
31 #define VIDEO_DATE_LABEL_XSIZE (VIDEO_DISPLAY_XSIZE)
32 #define VIDEO_DATE_LABEL_YSIZE (VIDEO_DISPLAY_YSIZE)
33 #define VIDEO_DATE_XPOS (VIDEO_DISPLAY1_XPOS+1)
34 #define VIDEO_DATE_YPOS (VIDEO_DISPLAY1_YPOS+14)
35 #define VIDEO_DATE_XSIZE (VIDEO_DISPLAY_XSIZE)
36 #define VIDEO_DATE_YSIZE 16
37 #define VIDEO_REC_LABEL_XPOS (VIDEO_DISPLAY2_XPOS)
38 #define VIDEO_REC_LABEL_YPOS (VIDEO_DISPLAY2_YPOS)
39 #define VIDEO_REC_LABEL_XSIZE 20
40 #define VIDEO_REC_LABEL_YSIZE 12
41 #define VIDEO_REC_SYMBOL_XPOS (VIDEO_DISPLAY2_XPOS+20)
42 #define VIDEO_REC_SYMBOL_YPOS (VIDEO_DISPLAY2_YPOS)
43 #define VIDEO_REC_SYMBOL_XSIZE 16
44 #define VIDEO_REC_SYMBOL_YSIZE 16
45 #define VIDEO_PLAY_LABEL_XPOS (VIDEO_DISPLAY2_XPOS+65)
46 #define VIDEO_PLAY_LABEL_YPOS (VIDEO_DISPLAY2_YPOS)
47 #define VIDEO_PLAY_LABEL_XSIZE 22
48 #define VIDEO_PLAY_LABEL_YSIZE 12
49 #define VIDEO_PLAY_SYMBOL_XPOS (VIDEO_DISPLAY2_XPOS+52)
50 #define VIDEO_PLAY_SYMBOL_YPOS (VIDEO_DISPLAY2_YPOS)
51 #define VIDEO_PLAY_SYMBOL_XSIZE 11
52 #define VIDEO_PLAY_SYMBOL_YSIZE 13
53 #define VIDEO_PAUSE_LABEL_XPOS (VIDEO_DISPLAY2_XPOS)
54 #define VIDEO_PAUSE_LABEL_YPOS (VIDEO_DISPLAY2_YPOS+20)
55 #define VIDEO_PAUSE_LABEL_XSIZE 35
56 #define VIDEO_PAUSE_LABEL_YSIZE 8
57 #define VIDEO_PAUSE_SYMBOL_XPOS (VIDEO_DISPLAY2_XPOS+35)
58 #define VIDEO_PAUSE_SYMBOL_YPOS (VIDEO_DISPLAY2_YPOS)
59 #define VIDEO_PAUSE_SYMBOL_XSIZE 17
60 #define VIDEO_PAUSE_SYMBOL_YSIZE 13
61 #define VIDEO_TIME_XPOS (VIDEO_DISPLAY2_XPOS+38)
62 #define VIDEO_TIME_YPOS (VIDEO_DISPLAY2_YPOS+14)
63 #define VIDEO_TIME_XSIZE 50
64 #define VIDEO_TIME_YSIZE 16
67 #define VIDEO_PBEND_LABEL_XPOS 6
68 #define VIDEO_PBEND_LABEL_YPOS 220
69 #define VIDEO_PBEND_LABEL_XSIZE 35
70 #define VIDEO_PBEND_LABEL_YSIZE 30
72 #define ON_VIDEO_BUTTON(x,y) ((x)>=(VX+VIDEO_CONTROL_XPOS) && \
73 (x)< (VX+VIDEO_CONTROL_XPOS + \
74 VIDEO_CONTROL_XSIZE) && \
75 (y)>=(VY+VIDEO_CONTROL_YPOS) && \
76 (y)< (VY+VIDEO_CONTROL_YPOS + \
78 #define VIDEO_BUTTON(x) (((x)-(VX+VIDEO_CONTROL_XPOS))/VIDEO_BUTTON_XSIZE)
80 #define VIDEO_STATE_OFF (VIDEO_STATE_PLAY_OFF | \
81 VIDEO_STATE_REC_OFF | \
82 VIDEO_STATE_PAUSE_OFF | \
83 VIDEO_STATE_FFWD_OFF | \
84 VIDEO_STATE_PBEND_OFF | \
85 VIDEO_STATE_DATE_OFF | \
87 #define VIDEO_PRESS_OFF (VIDEO_PRESS_PLAY_OFF | \
88 VIDEO_PRESS_REC_OFF | \
89 VIDEO_PRESS_PAUSE_OFF | \
90 VIDEO_PRESS_STOP_OFF | \
91 VIDEO_PRESS_EJECT_OFF)
92 #define VIDEO_ALL_OFF (VIDEO_STATE_OFF | VIDEO_PRESS_OFF)
94 #define VIDEO_STATE_ON (VIDEO_STATE_PLAY_ON | \
95 VIDEO_STATE_REC_ON | \
96 VIDEO_STATE_PAUSE_ON | \
97 VIDEO_STATE_FFWD_ON | \
98 VIDEO_STATE_PBEND_ON | \
99 VIDEO_STATE_DATE_ON | \
101 #define VIDEO_PRESS_ON (VIDEO_PRESS_PLAY_ON | \
102 VIDEO_PRESS_REC_ON | \
103 VIDEO_PRESS_PAUSE_ON | \
104 VIDEO_PRESS_STOP_ON | \
105 VIDEO_PRESS_EJECT_ON)
106 #define VIDEO_ALL_ON (VIDEO_STATE_ON | VIDEO_PRESS_ON)
108 #define VIDEO_STATE (VIDEO_STATE_ON | VIDEO_STATE_OFF)
109 #define VIDEO_PRESS (VIDEO_PRESS_ON | VIDEO_PRESS_OFF)
110 #define VIDEO_ALL (VIDEO_ALL_ON | VIDEO_ALL_OFF)
113 /* some positions in the sound control window */
114 #define SOUND_BUTTON_XSIZE 30
115 #define SOUND_BUTTON_YSIZE 30
116 #define SOUND_CONTROL_XPOS 5
117 #define SOUND_CONTROL_YPOS 245
118 #define SOUND_CONTROL_XSIZE (3*SOUND_BUTTON_XSIZE)
119 #define SOUND_CONTROL_YSIZE (1*SOUND_BUTTON_YSIZE)
120 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_CONTROL_XPOS + 0 * SOUND_BUTTON_XSIZE)
121 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_CONTROL_XPOS + 1 * SOUND_BUTTON_XSIZE)
122 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_CONTROL_XPOS + 2 * SOUND_BUTTON_XSIZE)
123 #define SOUND_BUTTON_ANY_YPOS (SOUND_CONTROL_YPOS)
125 #define ON_SOUND_BUTTON(x,y) ((x)>=(DX+SOUND_CONTROL_XPOS) && \
126 (x)< (DX+SOUND_CONTROL_XPOS + \
127 SOUND_CONTROL_XSIZE) && \
128 (y)>=(DY+SOUND_CONTROL_YPOS) && \
129 (y)< (DY+SOUND_CONTROL_YPOS + \
130 SOUND_CONTROL_YSIZE))
131 #define SOUND_BUTTON(x) (((x)-(DX+SOUND_CONTROL_XPOS))/SOUND_BUTTON_XSIZE)
133 /* some positions in the game control window */
134 #define GAME_BUTTON_STOP_XPOS (GAME_CONTROL_XPOS + 0 * GAME_BUTTON_XSIZE)
135 #define GAME_BUTTON_STOP_YPOS (GAME_CONTROL_YPOS)
136 #define GAME_BUTTON_PAUSE_XPOS (GAME_CONTROL_XPOS + 1 * GAME_BUTTON_XSIZE)
137 #define GAME_BUTTON_PAUSE_YPOS (GAME_CONTROL_YPOS)
138 #define GAME_BUTTON_PLAY_XPOS (GAME_CONTROL_XPOS + 2 * GAME_BUTTON_XSIZE)
139 #define GAME_BUTTON_PLAY_YPOS (GAME_CONTROL_YPOS)
140 #define GAME_BUTTON_ANY_YPOS (GAME_CONTROL_YPOS)
142 #define ON_GAME_BUTTON(x,y) ((x)>=(DX+GAME_CONTROL_XPOS) && \
143 (x)< (DX+GAME_CONTROL_XPOS + \
144 GAME_CONTROL_XSIZE) && \
145 (y)>=(DY+GAME_CONTROL_YPOS) && \
146 (y)< (DY+GAME_CONTROL_YPOS + \
148 #define GAME_BUTTON(x) (((x)-(DX+GAME_CONTROL_XPOS))/GAME_BUTTON_XSIZE)
150 /* some positions in the asking window */
151 #define OK_BUTTON_XPOS 2
152 #define OK_BUTTON_YPOS 250
153 #define OK_BUTTON_GFX_YPOS 0
154 #define OK_BUTTON_XSIZE 46
155 #define OK_BUTTON_YSIZE 28
156 #define NO_BUTTON_XPOS 52
157 #define NO_BUTTON_YPOS OK_BUTTON_YPOS
158 #define NO_BUTTON_XSIZE OK_BUTTON_XSIZE
159 #define NO_BUTTON_YSIZE OK_BUTTON_YSIZE
160 #define CONFIRM_BUTTON_XPOS 2
161 #define CONFIRM_BUTTON_GFX_YPOS 30
162 #define CONFIRM_BUTTON_YPOS OK_BUTTON_YPOS
163 #define CONFIRM_BUTTON_XSIZE 96
164 #define CONFIRM_BUTTON_YSIZE OK_BUTTON_YSIZE
166 #define ON_YESNO_BUTTON(x,y) (((x)>=(DX+OK_BUTTON_XPOS) && \
167 (x)< (DX+OK_BUTTON_XPOS + \
168 OK_BUTTON_XSIZE) && \
169 (y)>=(DY+OK_BUTTON_YPOS) && \
170 (y)< (DY+OK_BUTTON_YPOS + \
171 OK_BUTTON_YSIZE)) || \
172 ((x)>=(DX+NO_BUTTON_XPOS) && \
173 (x)< (DX+NO_BUTTON_XPOS + \
174 NO_BUTTON_XSIZE) && \
175 (y)>=(DY+NO_BUTTON_YPOS) && \
176 (y)< (DY+NO_BUTTON_YPOS + \
178 #define ON_CONFIRM_BUTTON(x,y) (((x)>=(DX+CONFIRM_BUTTON_XPOS) && \
179 (x)< (DX+CONFIRM_BUTTON_XPOS + \
180 CONFIRM_BUTTON_XSIZE) && \
181 (y)>=(DY+CONFIRM_BUTTON_YPOS) && \
182 (y)< (DY+CONFIRM_BUTTON_YPOS + \
183 CONFIRM_BUTTON_YSIZE)))
184 #define YESNO_BUTTON(x) (((x)-(DX+OK_BUTTON_XPOS))/OK_BUTTON_XSIZE)
186 /* some positions in the choose player window */
187 #define PLAYER_BUTTON_XSIZE 30
188 #define PLAYER_BUTTON_YSIZE 30
189 #define PLAYER_BUTTON_GFX_XPOS 5
190 #define PLAYER_BUTTON_GFX_YPOS (215-30)
191 #define PLAYER_CONTROL_XPOS (5 + PLAYER_BUTTON_XSIZE/2)
192 #define PLAYER_CONTROL_YPOS (215 - PLAYER_BUTTON_YSIZE/2)
193 #define PLAYER_CONTROL_XSIZE (2*PLAYER_BUTTON_XSIZE)
194 #define PLAYER_CONTROL_YSIZE (2*PLAYER_BUTTON_YSIZE)
195 #define PLAYER_BUTTON_1_XPOS (PLAYER_CONTROL_XPOS + 0 * PLAYER_BUTTON_XSIZE)
196 #define PLAYER_BUTTON_2_XPOS (PLAYER_CONTROL_XPOS + 1 * PLAYER_BUTTON_XSIZE)
197 #define PLAYER_BUTTON_3_XPOS (PLAYER_CONTROL_XPOS + 0 * PLAYER_BUTTON_XSIZE)
198 #define PLAYER_BUTTON_4_XPOS (PLAYER_CONTROL_XPOS + 1 * PLAYER_BUTTON_XSIZE)
199 #define PLAYER_BUTTON_1_YPOS (PLAYER_CONTROL_YPOS + 0 * PLAYER_BUTTON_YSIZE)
200 #define PLAYER_BUTTON_2_YPOS (PLAYER_CONTROL_YPOS + 0 * PLAYER_BUTTON_YSIZE)
201 #define PLAYER_BUTTON_3_YPOS (PLAYER_CONTROL_YPOS + 1 * PLAYER_BUTTON_YSIZE)
202 #define PLAYER_BUTTON_4_YPOS (PLAYER_CONTROL_YPOS + 1 * PLAYER_BUTTON_YSIZE)
204 #define ON_PLAYER_BUTTON(x,y) ((x)>=(DX+PLAYER_CONTROL_XPOS) && \
205 (x)< (DX+PLAYER_CONTROL_XPOS + \
206 PLAYER_CONTROL_XSIZE) && \
207 (y)>=(DY+PLAYER_CONTROL_YPOS) && \
208 (y)< (DY+PLAYER_CONTROL_YPOS + \
209 PLAYER_CONTROL_YSIZE))
210 #define PLAYER_BUTTON(x,y) ((((x)-(DX+PLAYER_CONTROL_XPOS)) / \
211 PLAYER_BUTTON_XSIZE) + 2 * \
212 (((y)-(DY+PLAYER_CONTROL_YPOS)) / \
213 PLAYER_BUTTON_YSIZE))
216 /* some definitions for the editor control window */
218 #define ON_EDIT_BUTTON(x,y) (((x)>=(VX+ED_BUTTON_CTRL_XPOS) && \
219 (x)< (VX+ED_BUTTON_CTRL_XPOS + \
220 ED_BUTTON_CTRL_XSIZE) && \
221 (y)>=(VY+ED_BUTTON_CTRL_YPOS) && \
222 (y)< (VY+ED_BUTTON_CTRL_YPOS + \
223 ED_BUTTON_CTRL_YSIZE + \
224 ED_BUTTON_FILL_YSIZE)) || \
225 ((x)>=(VX+ED_BUTTON_LEFT_XPOS) && \
226 (x)< (VX+ED_BUTTON_LEFT_XPOS + \
227 ED_BUTTON_LEFT_XSIZE + \
228 ED_BUTTON_UP_XSIZE + \
229 ED_BUTTON_RIGHT_XSIZE) && \
230 (y)>=(VY+ED_BUTTON_LEFT_YPOS) && \
231 (y)< (VY+ED_BUTTON_LEFT_YPOS + \
232 ED_BUTTON_LEFT_YSIZE)) || \
233 ((x)>=(VX+ED_BUTTON_UP_XPOS) && \
234 (x)< (VX+ED_BUTTON_UP_XPOS + \
235 ED_BUTTON_UP_XSIZE) && \
236 (y)>=(VY+ED_BUTTON_UP_YPOS) && \
237 (y)< (VY+ED_BUTTON_UP_YPOS + \
238 ED_BUTTON_UP_YSIZE + \
239 ED_BUTTON_DOWN_YSIZE)))
241 #define ON_CTRL_BUTTON(x,y) ((x)>=(VX+ED_BUTTON_EDIT_XPOS) && \
242 (x)< (VX+ED_BUTTON_EDIT_XPOS + \
243 ED_BUTTON_EDIT_XSIZE) && \
244 (y)>=(VY+ED_BUTTON_EDIT_YPOS) && \
245 (y)< (VY+ED_BUTTON_EDIT_YPOS + \
246 ED_BUTTON_EDIT_YSIZE + \
247 ED_BUTTON_CLEAR_YSIZE + \
248 ED_BUTTON_UNDO_YSIZE + \
249 ED_BUTTON_EXIT_YSIZE))
251 #define ON_ELEM_BUTTON(x,y) (((x)>=(DX+ED_BUTTON_EUP_XPOS) && \
252 (x)< (DX+ED_BUTTON_EUP_XPOS + \
253 ED_BUTTON_EUP_XSIZE) && \
254 (y)>=(DY+ED_BUTTON_EUP_YPOS) && \
255 (y)< (DY+ED_BUTTON_EUP_YPOS + \
256 ED_BUTTON_EUP_YSIZE)) || \
257 ((x)>=(DX+ED_BUTTON_EDOWN_XPOS) && \
258 (x)< (DX+ED_BUTTON_EDOWN_XPOS + \
259 ED_BUTTON_EDOWN_XSIZE) && \
260 (y)>=(DY+ED_BUTTON_EDOWN_YPOS) && \
261 (y)< (DY+ED_BUTTON_EDOWN_YPOS + \
262 ED_BUTTON_EDOWN_YSIZE)) || \
263 ((x)>=(DX+ED_BUTTON_ELEM_XPOS) && \
264 (x)< (DX+ED_BUTTON_ELEM_XPOS + \
265 MAX_ELEM_X*ED_BUTTON_ELEM_XSIZE) && \
266 (y)>=(DY+ED_BUTTON_ELEM_YPOS) && \
267 (y)< (DY+ED_BUTTON_ELEM_YPOS + \
268 MAX_ELEM_Y*ED_BUTTON_ELEM_YSIZE)))
270 #define ON_COUNT_BUTTON(x,y) (((((x)>=ED_COUNT_GADGET_XPOS && \
271 (x)<(ED_COUNT_GADGET_XPOS + \
272 ED_BUTTON_MINUS_XSIZE)) || \
273 ((x)>=(ED_COUNT_GADGET_XPOS + \
274 (ED_BUTTON_PLUS_XPOS - \
275 ED_BUTTON_MINUS_XPOS)) && \
276 (x)<(ED_COUNT_GADGET_XPOS + \
277 (ED_BUTTON_PLUS_XPOS - \
278 ED_BUTTON_MINUS_XPOS) + \
279 ED_BUTTON_PLUS_XSIZE))) && \
280 ((y)>=ED_COUNT_GADGET_YPOS && \
281 (y)<(ED_COUNT_GADGET_YPOS + \
282 16*ED_COUNT_GADGET_YSIZE)) && \
283 (((y)-ED_COUNT_GADGET_YPOS) % \
284 ED_COUNT_GADGET_YSIZE) < \
285 ED_BUTTON_MINUS_YSIZE) || \
286 ((((x)>=ED_SIZE_GADGET_XPOS && \
287 (x)<(ED_SIZE_GADGET_XPOS + \
288 ED_BUTTON_MINUS_XSIZE)) || \
289 ((x)>=(ED_SIZE_GADGET_XPOS + \
290 (ED_BUTTON_PLUS_XPOS - \
291 ED_BUTTON_MINUS_XPOS)) && \
292 (x)<(ED_SIZE_GADGET_XPOS + \
293 (ED_BUTTON_PLUS_XPOS - \
294 ED_BUTTON_MINUS_XPOS) + \
295 ED_BUTTON_PLUS_XSIZE))) && \
296 ((y)>=ED_SIZE_GADGET_YPOS && \
297 (y)<(ED_SIZE_GADGET_YPOS + \
298 2*ED_SIZE_GADGET_YSIZE)) && \
299 (((y)-ED_SIZE_GADGET_YPOS) % \
300 ED_SIZE_GADGET_YSIZE) < \
301 ED_BUTTON_MINUS_YSIZE))
303 #define EDIT_BUTTON(x,y) (((y) < (VY + ED_BUTTON_CTRL_YPOS + \
304 ED_BUTTON_CTRL_YSIZE)) ? 0 : \
305 ((y) < (VY + ED_BUTTON_CTRL_YPOS + \
306 ED_BUTTON_CTRL_YSIZE + \
307 ED_BUTTON_FILL_YSIZE)) ? 1 : \
308 ((x) < (VX + ED_BUTTON_LEFT_XPOS + \
309 ED_BUTTON_LEFT_XSIZE) ? 2 : \
310 (x) > (VX + ED_BUTTON_LEFT_XPOS + \
311 ED_BUTTON_LEFT_XSIZE + \
312 ED_BUTTON_UP_XSIZE) ? 5 : \
313 3+(((y)-(VY + ED_BUTTON_CTRL_YPOS + \
314 ED_BUTTON_CTRL_YSIZE + \
315 ED_BUTTON_FILL_YSIZE)) / \
316 ED_BUTTON_UP_YSIZE)))
318 #define CTRL_BUTTON(x,y) (((y) < (VY + ED_BUTTON_EDIT_YPOS + \
319 ED_BUTTON_EDIT_YSIZE)) ? 0 : \
320 1+(((y)-(VY + ED_BUTTON_EDIT_YPOS + \
321 ED_BUTTON_EDIT_YSIZE)) / \
322 ED_BUTTON_CLEAR_YSIZE))
324 #define ELEM_BUTTON(x,y) (((y) < (DY + ED_BUTTON_EUP_YPOS + \
325 ED_BUTTON_EUP_YSIZE)) ? 0 : \
326 ((y) > (DY + ED_BUTTON_EDOWN_YPOS)) ? 1 : \
327 2+(((y) - (DY + ED_BUTTON_ELEM_YPOS)) / \
328 ED_BUTTON_ELEM_YSIZE)*MAX_ELEM_X + \
329 ((x) - (DX + ED_BUTTON_ELEM_XPOS)) / \
330 ED_BUTTON_ELEM_XSIZE)
332 #define COUNT_BUTTON(x,y) ((x) < ED_SIZE_GADGET_XPOS ? \
333 ((((y) - ED_COUNT_GADGET_YPOS) / \
334 ED_COUNT_GADGET_YSIZE)*2 + \
335 ((x) < (ED_COUNT_GADGET_XPOS + \
336 ED_BUTTON_MINUS_XSIZE) ? 0 : 1)) : \
337 32+((((y) - ED_SIZE_GADGET_YPOS) / \
338 ED_SIZE_GADGET_YSIZE)*2 + \
339 ((x) < (ED_SIZE_GADGET_XPOS + \
340 ED_BUTTON_MINUS_XSIZE) ? 0 : 1)))
342 /****************************************************************/
343 /********** drawing buttons and corresponding displays **********/
344 /****************************************************************/
346 void OLD_DrawVideoDisplay(unsigned long state, unsigned long value)
349 int part_label = 0, part_symbol = 1;
350 int xpos = 0, ypos = 1, xsize = 2, ysize = 3;
351 static char *monatsname[12] =
353 "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
354 "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
356 static int video_pos[5][2][4] =
358 {{ VIDEO_PLAY_LABEL_XPOS, VIDEO_PLAY_LABEL_YPOS,
359 VIDEO_PLAY_LABEL_XSIZE,VIDEO_PLAY_LABEL_YSIZE },
360 { VIDEO_PLAY_SYMBOL_XPOS, VIDEO_PLAY_SYMBOL_YPOS,
361 VIDEO_PLAY_SYMBOL_XSIZE,VIDEO_PLAY_SYMBOL_YSIZE }},
363 {{ VIDEO_REC_LABEL_XPOS, VIDEO_REC_LABEL_YPOS,
364 VIDEO_REC_LABEL_XSIZE,VIDEO_REC_LABEL_YSIZE },
365 { VIDEO_REC_SYMBOL_XPOS, VIDEO_REC_SYMBOL_YPOS,
366 VIDEO_REC_SYMBOL_XSIZE,VIDEO_REC_SYMBOL_YSIZE }},
368 {{ VIDEO_PAUSE_LABEL_XPOS, VIDEO_PAUSE_LABEL_YPOS,
369 VIDEO_PAUSE_LABEL_XSIZE,VIDEO_PAUSE_LABEL_YSIZE },
370 { VIDEO_PAUSE_SYMBOL_XPOS, VIDEO_PAUSE_SYMBOL_YPOS,
371 VIDEO_PAUSE_SYMBOL_XSIZE,VIDEO_PAUSE_SYMBOL_YSIZE }},
373 {{ VIDEO_DATE_LABEL_XPOS, VIDEO_DATE_LABEL_YPOS,
374 VIDEO_DATE_LABEL_XSIZE,VIDEO_DATE_LABEL_YSIZE },
375 { VIDEO_DATE_XPOS, VIDEO_DATE_YPOS,
376 VIDEO_DATE_XSIZE,VIDEO_DATE_YSIZE }},
380 { VIDEO_TIME_XPOS, VIDEO_TIME_YPOS,
381 VIDEO_TIME_XSIZE,VIDEO_TIME_YSIZE }}
384 if (state & VIDEO_STATE_PBEND_OFF)
386 int cx = DOOR_GFX_PAGEX3, cy = DOOR_GFX_PAGEY2;
388 XCopyArea(display,pix[PIX_DOOR],drawto,gc,
389 cx + VIDEO_REC_LABEL_XPOS,
390 cy + VIDEO_REC_LABEL_YPOS,
391 VIDEO_PBEND_LABEL_XSIZE,
392 VIDEO_PBEND_LABEL_YSIZE,
393 VX + VIDEO_REC_LABEL_XPOS,
394 VY + VIDEO_REC_LABEL_YPOS);
401 int pos = i/2, cx, cy = DOOR_GFX_PAGEY2;
403 if (i%2) /* i ungerade => STATE_ON / PRESS_OFF */
404 cx = DOOR_GFX_PAGEX4;
406 cx = DOOR_GFX_PAGEX3; /* i gerade => STATE_OFF / PRESS_ON */
408 if (video_pos[pos][part_label][0] && value != VIDEO_DISPLAY_SYMBOL_ONLY)
409 XCopyArea(display,pix[PIX_DOOR],drawto,gc,
410 cx + video_pos[pos][part_label][xpos],
411 cy + video_pos[pos][part_label][ypos],
412 video_pos[pos][part_label][xsize],
413 video_pos[pos][part_label][ysize],
414 VX + video_pos[pos][part_label][xpos],
415 VY + video_pos[pos][part_label][ypos]);
416 if (video_pos[pos][part_symbol][0] && value != VIDEO_DISPLAY_LABEL_ONLY)
417 XCopyArea(display,pix[PIX_DOOR],drawto,gc,
418 cx + video_pos[pos][part_symbol][xpos],
419 cy + video_pos[pos][part_symbol][ypos],
420 video_pos[pos][part_symbol][xsize],
421 video_pos[pos][part_symbol][ysize],
422 VX + video_pos[pos][part_symbol][xpos],
423 VY + video_pos[pos][part_symbol][ypos]);
427 if (state & VIDEO_STATE_FFWD_ON)
429 int cx = DOOR_GFX_PAGEX4, cy = DOOR_GFX_PAGEY2;
431 XCopyArea(display,pix[PIX_DOOR],drawto,gc,
432 cx + VIDEO_PLAY_SYMBOL_XPOS,
433 cy + VIDEO_PLAY_SYMBOL_YPOS,
434 VIDEO_PLAY_SYMBOL_XSIZE - 2,
435 VIDEO_PLAY_SYMBOL_YSIZE,
436 VX + VIDEO_PLAY_SYMBOL_XPOS - 9,
437 VY + VIDEO_PLAY_SYMBOL_YPOS);
440 if (state & VIDEO_STATE_PBEND_ON)
442 int cx = DOOR_GFX_PAGEX6, cy = DOOR_GFX_PAGEY1;
444 XCopyArea(display,pix[PIX_DOOR],drawto,gc,
445 cx + VIDEO_PBEND_LABEL_XPOS,
446 cy + VIDEO_PBEND_LABEL_YPOS,
447 VIDEO_PBEND_LABEL_XSIZE,
448 VIDEO_PBEND_LABEL_YSIZE,
449 VX + VIDEO_REC_LABEL_XPOS,
450 VY + VIDEO_REC_LABEL_YPOS);
453 if (state & VIDEO_STATE_DATE_ON)
455 int tag = value % 100;
456 int monat = (value/100) % 100;
457 int jahr = (value/10000);
459 DrawText(VX+VIDEO_DATE_XPOS,VY+VIDEO_DATE_YPOS,
460 int2str(tag,2),FS_SMALL,FC_SPECIAL1);
461 DrawText(VX+VIDEO_DATE_XPOS+27,VY+VIDEO_DATE_YPOS,
462 monatsname[monat],FS_SMALL,FC_SPECIAL1);
463 DrawText(VX+VIDEO_DATE_XPOS+64,VY+VIDEO_DATE_YPOS,
464 int2str(jahr,2),FS_SMALL,FC_SPECIAL1);
467 if (state & VIDEO_STATE_TIME_ON)
469 int min = value / 60;
470 int sec = value % 60;
472 DrawText(VX+VIDEO_TIME_XPOS,VY+VIDEO_TIME_YPOS,
473 int2str(min,2),FS_SMALL,FC_SPECIAL1);
474 DrawText(VX+VIDEO_TIME_XPOS+27,VY+VIDEO_TIME_YPOS,
475 int2str(sec,2),FS_SMALL,FC_SPECIAL1);
478 if (state & VIDEO_STATE_DATE)
479 redraw_mask |= REDRAW_VIDEO_1;
480 if ((state & ~VIDEO_STATE_DATE) & VIDEO_STATE)
481 redraw_mask |= REDRAW_VIDEO_2;
482 if (state & VIDEO_PRESS)
483 redraw_mask |= REDRAW_VIDEO_3;
486 void DrawVideoDisplay(unsigned long state, unsigned long value)
489 int part_label = 0, part_symbol = 1;
490 int xpos = 0, ypos = 1, xsize = 2, ysize = 3;
491 static char *monatsname[12] =
493 "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
494 "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
496 static int video_pos[10][2][4] =
498 {{ VIDEO_PLAY_LABEL_XPOS, VIDEO_PLAY_LABEL_YPOS,
499 VIDEO_PLAY_LABEL_XSIZE,VIDEO_PLAY_LABEL_YSIZE },
500 { VIDEO_PLAY_SYMBOL_XPOS, VIDEO_PLAY_SYMBOL_YPOS,
501 VIDEO_PLAY_SYMBOL_XSIZE,VIDEO_PLAY_SYMBOL_YSIZE }},
503 {{ VIDEO_REC_LABEL_XPOS, VIDEO_REC_LABEL_YPOS,
504 VIDEO_REC_LABEL_XSIZE,VIDEO_REC_LABEL_YSIZE },
505 { VIDEO_REC_SYMBOL_XPOS, VIDEO_REC_SYMBOL_YPOS,
506 VIDEO_REC_SYMBOL_XSIZE,VIDEO_REC_SYMBOL_YSIZE }},
508 {{ VIDEO_PAUSE_LABEL_XPOS, VIDEO_PAUSE_LABEL_YPOS,
509 VIDEO_PAUSE_LABEL_XSIZE,VIDEO_PAUSE_LABEL_YSIZE },
510 { VIDEO_PAUSE_SYMBOL_XPOS, VIDEO_PAUSE_SYMBOL_YPOS,
511 VIDEO_PAUSE_SYMBOL_XSIZE,VIDEO_PAUSE_SYMBOL_YSIZE }},
513 {{ VIDEO_DATE_LABEL_XPOS, VIDEO_DATE_LABEL_YPOS,
514 VIDEO_DATE_LABEL_XSIZE,VIDEO_DATE_LABEL_YSIZE },
515 { VIDEO_DATE_XPOS, VIDEO_DATE_YPOS,
516 VIDEO_DATE_XSIZE,VIDEO_DATE_YSIZE }},
520 { VIDEO_TIME_XPOS, VIDEO_TIME_YPOS,
521 VIDEO_TIME_XSIZE,VIDEO_TIME_YSIZE }},
523 {{ VIDEO_BUTTON_PLAY_XPOS, VIDEO_BUTTON_ANY_YPOS,
524 VIDEO_BUTTON_XSIZE,VIDEO_BUTTON_YSIZE },
528 {{ VIDEO_BUTTON_REC_XPOS, VIDEO_BUTTON_ANY_YPOS,
529 VIDEO_BUTTON_XSIZE,VIDEO_BUTTON_YSIZE },
533 {{ VIDEO_BUTTON_PAUSE_XPOS, VIDEO_BUTTON_ANY_YPOS,
534 VIDEO_BUTTON_XSIZE,VIDEO_BUTTON_YSIZE },
538 {{ VIDEO_BUTTON_STOP_XPOS, VIDEO_BUTTON_ANY_YPOS,
539 VIDEO_BUTTON_XSIZE,VIDEO_BUTTON_YSIZE },
543 {{ VIDEO_BUTTON_EJECT_XPOS, VIDEO_BUTTON_ANY_YPOS,
544 VIDEO_BUTTON_XSIZE,VIDEO_BUTTON_YSIZE },
549 if (state & VIDEO_STATE_PBEND_OFF)
551 int cx = DOOR_GFX_PAGEX3, cy = DOOR_GFX_PAGEY2;
553 XCopyArea(display,pix[PIX_DOOR],drawto,gc,
554 cx + VIDEO_REC_LABEL_XPOS,
555 cy + VIDEO_REC_LABEL_YPOS,
556 VIDEO_PBEND_LABEL_XSIZE,
557 VIDEO_PBEND_LABEL_YSIZE,
558 VX + VIDEO_REC_LABEL_XPOS,
559 VY + VIDEO_REC_LABEL_YPOS);
566 int pos = i/2, cx, cy = DOOR_GFX_PAGEY2;
568 if (i%2) /* i ungerade => STATE_ON / PRESS_OFF */
569 cx = DOOR_GFX_PAGEX4;
571 cx = DOOR_GFX_PAGEX3; /* i gerade => STATE_OFF / PRESS_ON */
573 if (video_pos[pos][part_label][0] && value != VIDEO_DISPLAY_SYMBOL_ONLY)
574 XCopyArea(display,pix[PIX_DOOR],drawto,gc,
575 cx + video_pos[pos][part_label][xpos],
576 cy + video_pos[pos][part_label][ypos],
577 video_pos[pos][part_label][xsize],
578 video_pos[pos][part_label][ysize],
579 VX + video_pos[pos][part_label][xpos],
580 VY + video_pos[pos][part_label][ypos]);
581 if (video_pos[pos][part_symbol][0] && value != VIDEO_DISPLAY_LABEL_ONLY)
582 XCopyArea(display,pix[PIX_DOOR],drawto,gc,
583 cx + video_pos[pos][part_symbol][xpos],
584 cy + video_pos[pos][part_symbol][ypos],
585 video_pos[pos][part_symbol][xsize],
586 video_pos[pos][part_symbol][ysize],
587 VX + video_pos[pos][part_symbol][xpos],
588 VY + video_pos[pos][part_symbol][ypos]);
592 if (state & VIDEO_STATE_FFWD_ON)
594 int cx = DOOR_GFX_PAGEX4, cy = DOOR_GFX_PAGEY2;
596 XCopyArea(display,pix[PIX_DOOR],drawto,gc,
597 cx + VIDEO_PLAY_SYMBOL_XPOS,
598 cy + VIDEO_PLAY_SYMBOL_YPOS,
599 VIDEO_PLAY_SYMBOL_XSIZE - 2,
600 VIDEO_PLAY_SYMBOL_YSIZE,
601 VX + VIDEO_PLAY_SYMBOL_XPOS - 9,
602 VY + VIDEO_PLAY_SYMBOL_YPOS);
605 if (state & VIDEO_STATE_PBEND_ON)
607 int cx = DOOR_GFX_PAGEX6, cy = DOOR_GFX_PAGEY1;
609 XCopyArea(display,pix[PIX_DOOR],drawto,gc,
610 cx + VIDEO_PBEND_LABEL_XPOS,
611 cy + VIDEO_PBEND_LABEL_YPOS,
612 VIDEO_PBEND_LABEL_XSIZE,
613 VIDEO_PBEND_LABEL_YSIZE,
614 VX + VIDEO_REC_LABEL_XPOS,
615 VY + VIDEO_REC_LABEL_YPOS);
618 if (state & VIDEO_STATE_DATE_ON)
620 int tag = value % 100;
621 int monat = (value/100) % 100;
622 int jahr = (value/10000);
624 DrawText(VX+VIDEO_DATE_XPOS,VY+VIDEO_DATE_YPOS,
625 int2str(tag,2),FS_SMALL,FC_SPECIAL1);
626 DrawText(VX+VIDEO_DATE_XPOS+27,VY+VIDEO_DATE_YPOS,
627 monatsname[monat],FS_SMALL,FC_SPECIAL1);
628 DrawText(VX+VIDEO_DATE_XPOS+64,VY+VIDEO_DATE_YPOS,
629 int2str(jahr,2),FS_SMALL,FC_SPECIAL1);
632 if (state & VIDEO_STATE_TIME_ON)
634 int min = value / 60;
635 int sec = value % 60;
637 DrawText(VX+VIDEO_TIME_XPOS,VY+VIDEO_TIME_YPOS,
638 int2str(min,2),FS_SMALL,FC_SPECIAL1);
639 DrawText(VX+VIDEO_TIME_XPOS+27,VY+VIDEO_TIME_YPOS,
640 int2str(sec,2),FS_SMALL,FC_SPECIAL1);
643 if (state & VIDEO_STATE_DATE)
644 redraw_mask |= REDRAW_VIDEO_1;
645 if ((state & ~VIDEO_STATE_DATE) & VIDEO_STATE)
646 redraw_mask |= REDRAW_VIDEO_2;
647 if (state & VIDEO_PRESS)
648 redraw_mask |= REDRAW_VIDEO_3;
651 void DrawCompleteVideoDisplay()
653 XCopyArea(display,pix[PIX_DOOR],drawto,gc,
654 DOOR_GFX_PAGEX3,DOOR_GFX_PAGEY2, VXSIZE,VYSIZE, VX,VY);
655 XCopyArea(display,pix[PIX_DOOR],drawto,gc,
656 DOOR_GFX_PAGEX4+VIDEO_CONTROL_XPOS,
657 DOOR_GFX_PAGEY2+VIDEO_CONTROL_YPOS,
658 VIDEO_CONTROL_XSIZE,VIDEO_CONTROL_YSIZE,
659 VX+VIDEO_CONTROL_XPOS,VY+VIDEO_CONTROL_YPOS);
661 DrawVideoDisplay(VIDEO_ALL_OFF,0);
662 if (tape.date && tape.length)
664 DrawVideoDisplay(VIDEO_STATE_DATE_ON,tape.date);
665 DrawVideoDisplay(VIDEO_STATE_TIME_ON,tape.length_seconds);
668 XCopyArea(display,drawto,pix[PIX_DB_DOOR],gc,
669 VX,VY, VXSIZE,VYSIZE, DOOR_GFX_PAGEX1,DOOR_GFX_PAGEY2);
672 void DrawSoundDisplay(unsigned long state)
674 int pos, cx = DOOR_GFX_PAGEX4, cy = 0;
676 pos = (state & BUTTON_SOUND_MUSIC ? SOUND_BUTTON_MUSIC_XPOS :
677 state & BUTTON_SOUND_LOOPS ? SOUND_BUTTON_LOOPS_XPOS :
678 SOUND_BUTTON_SIMPLE_XPOS);
680 if (state & BUTTON_ON)
681 cy -= SOUND_BUTTON_YSIZE;
683 if (state & BUTTON_PRESSED)
684 cx = DOOR_GFX_PAGEX3;
686 XCopyArea(display,pix[PIX_DOOR],drawto,gc,
687 cx + pos,cy + SOUND_BUTTON_ANY_YPOS,
688 SOUND_BUTTON_XSIZE,SOUND_BUTTON_YSIZE,
689 DX + pos,DY + SOUND_BUTTON_ANY_YPOS);
691 redraw_mask |= REDRAW_DOOR_1;
694 void DrawGameButton(unsigned long state)
696 int pos, cx = DOOR_GFX_PAGEX4, cy = -GAME_BUTTON_YSIZE;
698 pos = (state & BUTTON_GAME_STOP ? GAME_BUTTON_STOP_XPOS :
699 state & BUTTON_GAME_PAUSE ? GAME_BUTTON_PAUSE_XPOS :
700 GAME_BUTTON_PLAY_XPOS);
702 if (state & BUTTON_PRESSED)
703 cx = DOOR_GFX_PAGEX3;
705 XCopyArea(display,pix[PIX_DOOR],drawto,gc,
706 cx + pos,cy + GAME_BUTTON_ANY_YPOS,
707 GAME_BUTTON_XSIZE,GAME_BUTTON_YSIZE,
708 DX + pos,DY + GAME_BUTTON_ANY_YPOS);
710 redraw_mask |= REDRAW_DOOR_1;
713 void DrawYesNoButton(unsigned long state, int mode)
715 Drawable dest_drawto;
716 int dest_xoffset, dest_yoffset;
717 int xpos, cx = DOOR_GFX_PAGEX4;
721 dest_drawto = pix[PIX_DB_DOOR];
722 dest_xoffset = DOOR_GFX_PAGEX1;
727 dest_drawto = drawto;
732 xpos = (state & BUTTON_OK ? OK_BUTTON_XPOS : NO_BUTTON_XPOS);
734 if (state & BUTTON_PRESSED)
735 cx = DOOR_GFX_PAGEX3;
737 XCopyArea(display, pix[PIX_DOOR], dest_drawto, gc,
738 cx + xpos, OK_BUTTON_GFX_YPOS,
739 OK_BUTTON_XSIZE, OK_BUTTON_YSIZE,
740 dest_xoffset + xpos, dest_yoffset + OK_BUTTON_YPOS);
742 redraw_mask |= REDRAW_DOOR_1;
745 void DrawConfirmButton(unsigned long state, int mode)
747 Drawable dest_drawto;
748 int dest_xoffset, dest_yoffset;
749 int cx = DOOR_GFX_PAGEX4;
753 dest_drawto = pix[PIX_DB_DOOR];
754 dest_xoffset = DOOR_GFX_PAGEX1;
759 dest_drawto = drawto;
764 if (state & BUTTON_PRESSED)
765 cx = DOOR_GFX_PAGEX3;
767 XCopyArea(display, pix[PIX_DOOR], dest_drawto, gc,
768 cx + CONFIRM_BUTTON_XPOS, CONFIRM_BUTTON_GFX_YPOS,
769 CONFIRM_BUTTON_XSIZE, CONFIRM_BUTTON_YSIZE,
770 dest_xoffset + CONFIRM_BUTTON_XPOS,
771 dest_yoffset + CONFIRM_BUTTON_YPOS);
773 redraw_mask |= REDRAW_DOOR_1;
776 void DrawPlayerButton(unsigned long state, int mode)
778 Drawable dest_drawto;
779 int dest_xoffset, dest_yoffset;
780 int graphic = GFX_SPIELER1; /* default */
781 int graphic_offset = (PLAYER_BUTTON_XSIZE - TILEX/2)/2;
783 int cx = DOOR_GFX_PAGEX4, cy = 0;
787 dest_drawto = pix[PIX_DB_DOOR];
788 dest_xoffset = DOOR_GFX_PAGEX1;
793 dest_drawto = drawto;
798 if (state & BUTTON_PLAYER_1)
799 graphic = GFX_SPIELER1;
800 else if (state & BUTTON_PLAYER_2)
801 graphic = GFX_SPIELER2;
802 else if (state & BUTTON_PLAYER_3)
803 graphic = GFX_SPIELER3;
804 else if (state & BUTTON_PLAYER_4)
805 graphic = GFX_SPIELER4;
807 xpos = (state & BUTTON_PLAYER_1 || state & BUTTON_PLAYER_3 ?
808 PLAYER_BUTTON_1_XPOS : PLAYER_BUTTON_2_XPOS);
809 ypos = (state & BUTTON_PLAYER_1 || state & BUTTON_PLAYER_2 ?
810 PLAYER_BUTTON_1_YPOS : PLAYER_BUTTON_3_YPOS);
812 if (state & BUTTON_PRESSED)
814 cx = DOOR_GFX_PAGEX3;
818 XCopyArea(display, pix[PIX_DOOR], dest_drawto, gc,
819 cx + PLAYER_BUTTON_GFX_XPOS, cy + PLAYER_BUTTON_GFX_YPOS,
820 PLAYER_BUTTON_XSIZE, PLAYER_BUTTON_YSIZE,
821 dest_xoffset + xpos, dest_yoffset + ypos);
822 DrawMiniGraphicExt(dest_drawto,gc,
823 dest_xoffset + xpos + graphic_offset,
824 dest_yoffset + ypos + graphic_offset,
827 redraw_mask |= REDRAW_DOOR_1;
830 /* several buttons in the level editor */
832 void DrawEditButton(unsigned long state)
835 int xpos = 0, ypos = 1, xsize = 2, ysize = 3;
836 int cx = DOOR_GFX_PAGEX6, cy = DOOR_GFX_PAGEY2;
837 static int edit_pos[6][4] =
839 {ED_BUTTON_CTRL_XPOS,ED_BUTTON_CTRL_YPOS,
840 ED_BUTTON_CTRL_XSIZE,ED_BUTTON_CTRL_YSIZE},
842 {ED_BUTTON_FILL_XPOS,ED_BUTTON_FILL_YPOS,
843 ED_BUTTON_FILL_XSIZE,ED_BUTTON_FILL_YSIZE},
845 {ED_BUTTON_LEFT_XPOS,ED_BUTTON_LEFT_YPOS,
846 ED_BUTTON_LEFT_XSIZE,ED_BUTTON_LEFT_YSIZE},
848 {ED_BUTTON_UP_XPOS,ED_BUTTON_UP_YPOS,
849 ED_BUTTON_UP_XSIZE,ED_BUTTON_UP_YSIZE},
851 {ED_BUTTON_DOWN_XPOS,ED_BUTTON_DOWN_YPOS,
852 ED_BUTTON_DOWN_XSIZE,ED_BUTTON_DOWN_YSIZE},
854 {ED_BUTTON_RIGHT_XPOS,ED_BUTTON_RIGHT_YPOS,
855 ED_BUTTON_RIGHT_XSIZE,ED_BUTTON_RIGHT_YSIZE}
858 if (state & ED_BUTTON_PRESSED)
859 cx = DOOR_GFX_PAGEX5;
864 XCopyArea(display,pix[PIX_DOOR],drawto,gc,
865 cx + edit_pos[i][xpos],
866 cy + edit_pos[i][ypos],
869 VX + edit_pos[i][xpos],
870 VY + edit_pos[i][ypos]);
873 redraw_mask |= REDRAW_DOOR_2;
876 void DrawCtrlButton(unsigned long state)
879 int xpos = 0, ypos = 1, xsize = 2, ysize = 3;
880 int cx = DOOR_GFX_PAGEX4, cy = DOOR_GFX_PAGEY1+80;
881 static int edit_pos[4][4] =
883 {ED_BUTTON_EDIT_XPOS,ED_BUTTON_EDIT_YPOS,
884 ED_BUTTON_EDIT_XSIZE,ED_BUTTON_EDIT_YSIZE},
886 {ED_BUTTON_CLEAR_XPOS,ED_BUTTON_CLEAR_YPOS,
887 ED_BUTTON_CLEAR_XSIZE,ED_BUTTON_CLEAR_YSIZE},
889 {ED_BUTTON_UNDO_XPOS,ED_BUTTON_UNDO_YPOS,
890 ED_BUTTON_UNDO_XSIZE,ED_BUTTON_UNDO_YSIZE},
892 {ED_BUTTON_EXIT_XPOS,ED_BUTTON_EXIT_YPOS,
893 ED_BUTTON_EXIT_XSIZE,ED_BUTTON_EXIT_YSIZE}
896 if (state & ED_BUTTON_PRESSED)
897 cx = DOOR_GFX_PAGEX3;
901 if (state & (1<<(i+6)))
902 XCopyArea(display,pix[PIX_DOOR],drawto,gc,
903 cx + edit_pos[i][xpos],
904 cy + edit_pos[i][ypos],
907 VX + edit_pos[i][xpos],
908 VY + edit_pos[i][ypos]);
911 redraw_mask |= REDRAW_DOOR_2;
914 void DrawElemButton(int button_nr, int button_state)
916 int xpos = 0, ypos = 1, xsize = 2, ysize = 3;
917 int cx = DOOR_GFX_PAGEX6, cy = DOOR_GFX_PAGEY1;
918 int from_x, from_y, to_x,to_y, size_x, size_y;
919 static int edit_pos[3][4] =
921 {ED_BUTTON_EUP_XPOS,ED_BUTTON_EUP_YPOS,
922 ED_BUTTON_EUP_XSIZE,ED_BUTTON_EUP_YSIZE},
924 {ED_BUTTON_EDOWN_XPOS,ED_BUTTON_EDOWN_YPOS,
925 ED_BUTTON_EDOWN_XSIZE,ED_BUTTON_EDOWN_YSIZE},
927 {ED_BUTTON_ELEM_XPOS,ED_BUTTON_ELEM_YPOS,
928 ED_BUTTON_ELEM_XSIZE,ED_BUTTON_ELEM_YSIZE}
931 if (button_nr<ED_BUTTON_ELEM)
935 from_x = cx + edit_pos[pos][xpos];
936 from_y = cy + edit_pos[pos][ypos];
937 size_x = edit_pos[pos][xsize];
938 size_y = edit_pos[pos][ysize];
939 to_x = DX + edit_pos[pos][xpos];
940 to_y = DY + edit_pos[pos][ypos];
942 if (button_state & ED_BUTTON_PRESSED)
944 if (button_nr==ED_BUTTON_EUP)
945 from_y = cy + ED_BUTTON_EUP_Y2POS;
947 from_y = cy + ED_BUTTON_EDOWN_Y2POS;
950 XCopyArea(display,pix[PIX_DOOR],drawto,gc,
951 from_x,from_y, size_x,size_y, to_x,to_y);
955 int pos = ED_BUTTON_ELEM;
956 int elem_pos = button_nr-ED_BUTTON_ELEM;
957 int x = elem_pos % MAX_ELEM_X;
958 int y = elem_pos / MAX_ELEM_X;
962 if (elem_pos+element_shift < elements_in_list)
963 graphic = el2gfx(editor_element[elem_pos+element_shift]);
965 graphic = GFX_LEERRAUM;
967 from_x = cx + edit_pos[pos][xpos];
968 from_y = cy + edit_pos[pos][ypos];
969 size_x = edit_pos[pos][xsize];
970 size_y = edit_pos[pos][ysize];
971 to_x = DX + edit_pos[pos][xpos] + x * ED_BUTTON_ELEM_XSIZE;
972 to_y = DY + edit_pos[pos][ypos] + y * ED_BUTTON_ELEM_YSIZE;
974 if (button_state & ED_BUTTON_PRESSED)
976 from_y = ED_BUTTON_ELEM_Y2POS;
980 XCopyArea(display,pix[PIX_DOOR],drawto,gc,
981 from_x,from_y, size_x,size_y, to_x,to_y);
983 DrawMiniGraphicExt(drawto,gc,
984 DX+ED_BUTTON_ELEM_XPOS+3+shift +
985 (elem_pos % MAX_ELEM_X)*ED_BUTTON_ELEM_XSIZE,
986 DY+ED_BUTTON_ELEM_YPOS+3+shift +
987 (elem_pos / MAX_ELEM_X)*ED_BUTTON_ELEM_YSIZE,
991 redraw_mask |= REDRAW_DOOR_1;
994 void DrawCountButton(int button_nr, int button_state)
996 int from_x, from_y, to_x,to_y, size_x, size_y;
999 DOOR_GFX_PAGEX4+(button_nr%2 ? ED_BUTTON_PLUS_XPOS : ED_BUTTON_MINUS_XPOS);
1000 from_y = DOOR_GFX_PAGEY1 + ED_BUTTON_MINUS_YPOS;
1001 size_x = ED_BUTTON_MINUS_XSIZE;
1002 size_y = ED_BUTTON_MINUS_YSIZE;
1003 to_x = (button_nr<32 ? ED_COUNT_GADGET_XPOS : ED_SIZE_GADGET_XPOS);
1005 to_x += (ED_BUTTON_PLUS_XPOS - ED_BUTTON_MINUS_XPOS);
1006 to_y = (button_nr<32 ? ED_COUNT_GADGET_YPOS : ED_SIZE_GADGET_YPOS) +
1007 ((button_nr<32 ? button_nr : button_nr-32)/2)*ED_COUNT_GADGET_YSIZE;
1009 if (button_state & ED_BUTTON_PRESSED)
1012 XCopyArea(display,pix[PIX_DOOR],drawto,gc,
1013 from_x,from_y, size_x,size_y, to_x,to_y);
1014 XCopyArea(display,pix[PIX_DOOR],window,gc,
1015 from_x,from_y, size_x,size_y, to_x,to_y);
1018 /**********************************************************************/
1019 /********** checking buttons (and redrawing them, if needed) **********/
1020 /**********************************************************************/
1022 int CheckVideoButtons(int mx, int my, int button)
1024 int return_code = 0;
1025 static int choice = -1;
1026 static boolean pressed = FALSE;
1027 static int video_button[5] =
1029 VIDEO_PRESS_EJECT_ON,
1030 VIDEO_PRESS_STOP_ON,
1031 VIDEO_PRESS_PAUSE_ON,
1038 if (!motion_status) /* Maustaste neu gedrückt */
1040 if (ON_VIDEO_BUTTON(mx,my))
1042 choice = VIDEO_BUTTON(mx);
1044 DrawVideoDisplay(video_button[choice],0);
1047 else /* Mausbewegung bei gedrückter Maustaste */
1049 if ((!ON_VIDEO_BUTTON(mx,my) || VIDEO_BUTTON(mx)!=choice) &&
1050 choice>=0 && pressed)
1053 DrawVideoDisplay(video_button[choice]<<1,0);
1055 else if (ON_VIDEO_BUTTON(mx,my) && VIDEO_BUTTON(mx)==choice && !pressed)
1058 DrawVideoDisplay(video_button[choice],0);
1062 else /* Maustaste wieder losgelassen */
1064 if (ON_VIDEO_BUTTON(mx,my) && VIDEO_BUTTON(mx)==choice && pressed)
1066 DrawVideoDisplay(video_button[choice]<<1,0);
1067 return_code = choice+1;
1079 return(return_code);
1082 int CheckSoundButtons(int mx, int my, int button)
1084 int return_code = 0;
1085 static int choice = -1;
1086 static boolean pressed = FALSE;
1089 sound_state[0] = BUTTON_SOUND_MUSIC | (BUTTON_ON * setup.sound_music);
1090 sound_state[1] = BUTTON_SOUND_LOOPS | (BUTTON_ON * setup.sound_loops);
1091 sound_state[2] = BUTTON_SOUND_SIMPLE | (BUTTON_ON * setup.sound_simple);
1095 if (!motion_status) /* Maustaste neu gedrückt */
1097 if (ON_SOUND_BUTTON(mx,my))
1099 choice = SOUND_BUTTON(mx);
1101 DrawSoundDisplay(sound_state[choice] | BUTTON_PRESSED);
1104 else /* Mausbewegung bei gedrückter Maustaste */
1106 if ((!ON_SOUND_BUTTON(mx,my) || SOUND_BUTTON(mx)!=choice) &&
1107 choice>=0 && pressed)
1110 DrawSoundDisplay(sound_state[choice] | BUTTON_RELEASED);
1112 else if (ON_SOUND_BUTTON(mx,my) && SOUND_BUTTON(mx)==choice && !pressed)
1115 DrawSoundDisplay(sound_state[choice] | BUTTON_PRESSED);
1119 else /* Maustaste wieder losgelassen */
1121 if (ON_SOUND_BUTTON(mx,my) && SOUND_BUTTON(mx)==choice && pressed)
1123 DrawSoundDisplay(sound_state[choice] | BUTTON_RELEASED);
1124 return_code = 1<<choice;
1136 return(return_code);
1139 int CheckGameButtons(int mx, int my, int button)
1141 int return_code = 0;
1142 static int choice = -1;
1143 static boolean pressed = FALSE;
1153 if (!motion_status) /* Maustaste neu gedrückt */
1155 if (ON_GAME_BUTTON(mx,my))
1157 choice = GAME_BUTTON(mx);
1159 DrawGameButton(game_state[choice] | BUTTON_PRESSED);
1162 else /* Mausbewegung bei gedrückter Maustaste */
1164 if ((!ON_GAME_BUTTON(mx,my) || GAME_BUTTON(mx)!=choice) &&
1165 choice>=0 && pressed)
1168 DrawGameButton(game_state[choice] | BUTTON_RELEASED);
1170 else if (ON_GAME_BUTTON(mx,my) && GAME_BUTTON(mx)==choice && !pressed)
1173 DrawGameButton(game_state[choice] | BUTTON_PRESSED);
1177 else /* Maustaste wieder losgelassen */
1179 if (ON_GAME_BUTTON(mx,my) && GAME_BUTTON(mx)==choice && pressed)
1181 DrawGameButton(game_state[choice] | BUTTON_RELEASED);
1182 return_code = 1<<choice;
1194 return(return_code);
1197 int CheckYesNoButtons(int mx, int my, int button)
1199 int return_code = 0;
1200 static int choice = -1;
1201 static boolean pressed = FALSE;
1202 static int yesno_button[5] =
1210 if (!motion_status) /* Maustaste neu gedrückt */
1212 if (ON_YESNO_BUTTON(mx,my))
1214 choice = YESNO_BUTTON(mx);
1216 DrawYesNoButton(yesno_button[choice] | BUTTON_PRESSED, DB_NORMAL);
1219 else /* Mausbewegung bei gedrückter Maustaste */
1221 if ((!ON_YESNO_BUTTON(mx,my) || YESNO_BUTTON(mx)!=choice) &&
1222 choice>=0 && pressed)
1225 DrawYesNoButton(yesno_button[choice] | BUTTON_RELEASED, DB_NORMAL);
1227 else if (ON_YESNO_BUTTON(mx,my) && YESNO_BUTTON(mx)==choice && !pressed)
1230 DrawYesNoButton(yesno_button[choice] | BUTTON_PRESSED, DB_NORMAL);
1234 else /* Maustaste wieder losgelassen */
1236 if (ON_YESNO_BUTTON(mx,my) && YESNO_BUTTON(mx)==choice && pressed)
1238 DrawYesNoButton(yesno_button[choice] | BUTTON_RELEASED, DB_NORMAL);
1239 return_code = choice+1;
1251 return(return_code);
1254 int CheckConfirmButton(int mx, int my, int button)
1256 int return_code = 0;
1257 static int choice = -1;
1258 static boolean pressed = FALSE;
1262 if (!motion_status) /* Maustaste neu gedrückt */
1264 if (ON_CONFIRM_BUTTON(mx,my))
1268 DrawConfirmButton(BUTTON_PRESSED, DB_NORMAL);
1271 else /* Mausbewegung bei gedrückter Maustaste */
1273 if (!ON_CONFIRM_BUTTON(mx,my) && choice>=0 && pressed)
1276 DrawConfirmButton(BUTTON_RELEASED, DB_NORMAL);
1278 else if (ON_CONFIRM_BUTTON(mx,my) && !pressed)
1281 DrawConfirmButton(BUTTON_PRESSED, DB_NORMAL);
1285 else /* Maustaste wieder losgelassen */
1287 if (ON_CONFIRM_BUTTON(mx,my) && pressed)
1289 DrawConfirmButton(BUTTON_RELEASED, DB_NORMAL);
1290 return_code = BUTTON_CONFIRM;
1302 return(return_code);
1305 int CheckPlayerButtons(int mx, int my, int button)
1307 int return_code = 0;
1308 static int choice = -1;
1309 static boolean pressed = FALSE;
1310 int player_state[4] =
1320 if (!motion_status) /* Maustaste neu gedrückt */
1322 if (ON_PLAYER_BUTTON(mx,my))
1324 choice = PLAYER_BUTTON(mx,my);
1326 DrawPlayerButton(player_state[choice] | BUTTON_PRESSED, DB_NORMAL);
1329 else /* Mausbewegung bei gedrückter Maustaste */
1331 if ((!ON_PLAYER_BUTTON(mx,my) || PLAYER_BUTTON(mx,my)!=choice) &&
1332 choice>=0 && pressed)
1335 DrawPlayerButton(player_state[choice] | BUTTON_RELEASED, DB_NORMAL);
1337 else if (ON_PLAYER_BUTTON(mx,my) && PLAYER_BUTTON(mx,my)==choice && !pressed)
1340 DrawPlayerButton(player_state[choice] | BUTTON_PRESSED, DB_NORMAL);
1344 else /* Maustaste wieder losgelassen */
1346 if (ON_PLAYER_BUTTON(mx,my) && PLAYER_BUTTON(mx,my)==choice && pressed)
1348 DrawPlayerButton(player_state[choice] | BUTTON_RELEASED, DB_NORMAL);
1349 return_code = player_state[choice];
1361 return(return_code);
1364 /* several buttons in the level editor */
1366 int CheckEditButtons(int mx, int my, int button)
1368 int return_code = 0;
1369 static int choice = -1;
1370 static boolean pressed = FALSE;
1371 static int edit_button[6] =
1383 if (!motion_status) /* Maustaste neu gedrückt */
1385 if (ON_EDIT_BUTTON(mx,my))
1387 choice = EDIT_BUTTON(mx,my);
1389 DrawEditButton(edit_button[choice] | ED_BUTTON_PRESSED);
1390 if (edit_button[choice]!=ED_BUTTON_CTRL &&
1391 edit_button[choice]!=ED_BUTTON_FILL)
1392 return_code = 1<<choice;
1395 else /* Mausbewegung bei gedrückter Maustaste */
1397 if ((!ON_EDIT_BUTTON(mx,my) || EDIT_BUTTON(mx,my)!=choice) &&
1398 choice>=0 && pressed)
1401 DrawEditButton(edit_button[choice] | ED_BUTTON_RELEASED);
1403 else if (ON_EDIT_BUTTON(mx,my) && EDIT_BUTTON(mx,my)==choice)
1406 DrawEditButton(edit_button[choice] | ED_BUTTON_PRESSED);
1408 if (edit_button[choice]!=ED_BUTTON_CTRL &&
1409 edit_button[choice]!=ED_BUTTON_FILL)
1410 return_code = 1<<choice;
1414 else /* Maustaste wieder losgelassen */
1416 if (ON_EDIT_BUTTON(mx,my) && EDIT_BUTTON(mx,my)==choice && pressed)
1418 DrawEditButton(edit_button[choice] | ED_BUTTON_RELEASED);
1419 if (edit_button[choice]==ED_BUTTON_CTRL ||
1420 edit_button[choice]==ED_BUTTON_FILL)
1421 return_code = 1<<choice;
1433 return(return_code);
1436 int CheckCtrlButtons(int mx, int my, int button)
1438 int return_code = 0;
1439 static int choice = -1;
1440 static boolean pressed = FALSE;
1441 static int ctrl_button[4] =
1451 if (!motion_status) /* Maustaste neu gedrückt */
1453 if (ON_CTRL_BUTTON(mx,my))
1455 choice = CTRL_BUTTON(mx,my);
1457 DrawCtrlButton(ctrl_button[choice] | ED_BUTTON_PRESSED);
1460 else /* Mausbewegung bei gedrückter Maustaste */
1462 if ((!ON_CTRL_BUTTON(mx,my) || CTRL_BUTTON(mx,my)!=choice) &&
1463 choice>=0 && pressed)
1466 DrawCtrlButton(ctrl_button[choice] | ED_BUTTON_RELEASED);
1468 else if (ON_CTRL_BUTTON(mx,my) && CTRL_BUTTON(mx,my)==choice && !pressed)
1471 DrawCtrlButton(ctrl_button[choice] | ED_BUTTON_PRESSED);
1475 else /* Maustaste wieder losgelassen */
1477 if (ON_CTRL_BUTTON(mx,my) && CTRL_BUTTON(mx,my)==choice && pressed)
1479 DrawCtrlButton(ctrl_button[choice] | ED_BUTTON_RELEASED);
1480 return_code = 1<<(choice+6);
1492 return(return_code);
1495 int CheckElemButtons(int mx, int my, int button)
1497 int return_code = -1;
1498 static int choice = -1;
1499 static boolean pressed = FALSE;
1503 if (!motion_status) /* Maustaste neu gedrückt */
1505 if (ON_ELEM_BUTTON(mx,my))
1507 choice = ELEM_BUTTON(mx,my);
1509 DrawElemButton(choice,ED_BUTTON_PRESSED);
1510 if (choice==ED_BUTTON_EUP ||
1511 choice==ED_BUTTON_EDOWN)
1512 return_code = choice;
1515 else /* Mausbewegung bei gedrückter Maustaste */
1517 if ((!ON_ELEM_BUTTON(mx,my) || ELEM_BUTTON(mx,my)!=choice) &&
1518 choice>=0 && pressed)
1521 DrawElemButton(choice,ED_BUTTON_RELEASED);
1523 else if (ON_ELEM_BUTTON(mx,my) && ELEM_BUTTON(mx,my)==choice)
1526 DrawElemButton(choice,ED_BUTTON_PRESSED);
1528 if (choice==ED_BUTTON_EUP ||
1529 choice==ED_BUTTON_EDOWN)
1530 return_code = choice;
1534 else /* Maustaste wieder losgelassen */
1536 if (ON_ELEM_BUTTON(mx,my) && ELEM_BUTTON(mx,my)==choice && pressed)
1538 DrawElemButton(choice,ED_BUTTON_RELEASED);
1539 if (choice!=ED_BUTTON_EUP &&
1540 choice!=ED_BUTTON_EDOWN)
1541 return_code = choice;
1553 return(return_code);
1556 int CheckCountButtons(int mx, int my, int button)
1558 int return_code = -1;
1559 static int choice = -1;
1560 static boolean pressed = FALSE;
1564 if (!motion_status) /* Maustaste neu gedrückt */
1566 if (ON_COUNT_BUTTON(mx,my))
1568 choice = COUNT_BUTTON(mx,my);
1570 DrawCountButton(choice,ED_BUTTON_PRESSED);
1571 return_code = choice;
1574 else /* Mausbewegung bei gedrückter Maustaste */
1576 if ((!ON_COUNT_BUTTON(mx,my) || COUNT_BUTTON(mx,my)!=choice) &&
1577 choice>=0 && pressed)
1580 DrawCountButton(choice,ED_BUTTON_RELEASED);
1582 else if (ON_COUNT_BUTTON(mx,my) && COUNT_BUTTON(mx,my)==choice)
1585 DrawCountButton(choice,ED_BUTTON_PRESSED);
1587 return_code = choice;
1591 else /* Maustaste wieder losgelassen */
1593 if (ON_COUNT_BUTTON(mx,my) && COUNT_BUTTON(mx,my)==choice && pressed)
1595 DrawCountButton(choice,ED_BUTTON_RELEASED);
1607 return(return_code);
1611 /* NEW GADGET STUFF -------------------------------------------------------- */
1614 static struct GadgetInfo *gadget_list_first_entry = NULL;
1615 static struct GadgetInfo *gadget_list_last_entry = NULL;
1616 static int next_free_gadget_id = 1;
1617 static boolean gadget_id_wrapped = FALSE;
1619 static struct GadgetInfo *getGadgetInfoFromGadgetID(int id)
1621 struct GadgetInfo *gi = gadget_list_first_entry;
1623 while (gi && gi->id != id)
1629 static int getNewGadgetID()
1631 int id = next_free_gadget_id++;
1633 if (next_free_gadget_id <= 0) /* counter overrun */
1635 gadget_id_wrapped = TRUE; /* now we must check each ID */
1636 next_free_gadget_id = 0;
1639 if (gadget_id_wrapped)
1641 next_free_gadget_id++;
1642 while (getGadgetInfoFromGadgetID(next_free_gadget_id) != NULL)
1643 next_free_gadget_id++;
1646 if (next_free_gadget_id <= 0) /* cannot get new gadget id */
1647 Error(ERR_EXIT, "too much gadgets -- this should not happen");
1652 static struct GadgetInfo *getGadgetInfoFromMousePosition(int mx, int my)
1654 struct GadgetInfo *gi = gadget_list_first_entry;
1659 mx >= gi->x && mx < gi->x + gi->width &&
1660 my >= gi->y && my < gi->y + gi->height)
1664 if (gi->type & GD_TYPE_SCROLLBAR)
1668 if (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL)
1679 if (mpos >= gpos + gi->scrollbar.position &&
1680 mpos < gpos + gi->scrollbar.position + gi->scrollbar.size)
1695 static void default_callback_info(void *ptr)
1697 if (game_status == LEVELED)
1698 HandleEditorGadgetInfoText(ptr);
1701 static void default_callback_action(void *ptr)
1706 struct GadgetInfo *CreateGadget(int first_tag, ...)
1708 struct GadgetInfo *new_gadget = checked_malloc(sizeof(struct GadgetInfo));
1709 int tag = first_tag;
1712 va_start(ap, first_tag);
1714 /* always start with reliable default values */
1715 memset(new_gadget, 0, sizeof(struct GadgetInfo)); /* zero all fields */
1716 new_gadget->id = getNewGadgetID();
1717 new_gadget->callback_info = default_callback_info;
1718 new_gadget->callback_action = default_callback_action;
1720 while (tag != GDI_END)
1725 new_gadget->custom_id = va_arg(ap, int);
1730 int max_textsize = MAX_INFO_TEXTSIZE;
1732 strncpy(new_gadget->info_text, va_arg(ap, char *), max_textsize);
1733 new_gadget->info_text[max_textsize] = '\0';
1738 new_gadget->x = va_arg(ap, int);
1742 new_gadget->y = va_arg(ap, int);
1746 new_gadget->width = va_arg(ap, int);
1750 new_gadget->height = va_arg(ap, int);
1754 new_gadget->type = va_arg(ap, unsigned long);
1758 new_gadget->state = va_arg(ap, unsigned long);
1762 new_gadget->checked = va_arg(ap, boolean);
1766 new_gadget->radio_nr = va_arg(ap, unsigned long);
1769 case GDI_NUMBER_VALUE:
1770 new_gadget->text.number_value = va_arg(ap, long);
1771 sprintf(new_gadget->text.value, "%d", new_gadget->text.number_value);
1772 new_gadget->text.cursor_position = strlen(new_gadget->text.value);
1775 case GDI_NUMBER_MIN:
1776 new_gadget->text.number_min = va_arg(ap, long);
1777 if (new_gadget->text.number_value < new_gadget->text.number_min)
1779 new_gadget->text.number_value = new_gadget->text.number_min;
1780 sprintf(new_gadget->text.value, "%d", new_gadget->text.number_value);
1784 case GDI_NUMBER_MAX:
1785 new_gadget->text.number_max = va_arg(ap, long);
1786 if (new_gadget->text.number_value > new_gadget->text.number_max)
1788 new_gadget->text.number_value = new_gadget->text.number_max;
1789 sprintf(new_gadget->text.value, "%d", new_gadget->text.number_value);
1793 case GDI_TEXT_VALUE:
1795 int max_textsize = MAX_GADGET_TEXTSIZE;
1797 if (new_gadget->text.size)
1798 max_textsize = MIN(new_gadget->text.size, MAX_GADGET_TEXTSIZE - 1);
1800 strncpy(new_gadget->text.value, va_arg(ap, char *), max_textsize);
1801 new_gadget->text.value[max_textsize] = '\0';
1802 new_gadget->text.cursor_position = strlen(new_gadget->text.value);
1808 int tag_value = va_arg(ap, int);
1809 int max_textsize = MIN(tag_value, MAX_GADGET_TEXTSIZE - 1);
1811 new_gadget->text.size = max_textsize;
1812 new_gadget->text.value[max_textsize] = '\0';
1814 if (new_gadget->width == 0 && new_gadget->height == 0)
1816 new_gadget->width = (new_gadget->text.size + 1) * FONT2_XSIZE + 6;
1817 new_gadget->height = ED_WIN_COUNT_YSIZE;
1822 case GDI_DESIGN_UNPRESSED:
1823 new_gadget->design[GD_BUTTON_UNPRESSED].pixmap = va_arg(ap, Pixmap);
1824 new_gadget->design[GD_BUTTON_UNPRESSED].x = va_arg(ap, int);
1825 new_gadget->design[GD_BUTTON_UNPRESSED].y = va_arg(ap, int);
1828 case GDI_DESIGN_PRESSED:
1829 new_gadget->design[GD_BUTTON_PRESSED].pixmap = va_arg(ap, Pixmap);
1830 new_gadget->design[GD_BUTTON_PRESSED].x = va_arg(ap, int);
1831 new_gadget->design[GD_BUTTON_PRESSED].y = va_arg(ap, int);
1834 case GDI_ALT_DESIGN_UNPRESSED:
1835 new_gadget->alt_design[GD_BUTTON_UNPRESSED].pixmap= va_arg(ap, Pixmap);
1836 new_gadget->alt_design[GD_BUTTON_UNPRESSED].x = va_arg(ap, int);
1837 new_gadget->alt_design[GD_BUTTON_UNPRESSED].y = va_arg(ap, int);
1840 case GDI_ALT_DESIGN_PRESSED:
1841 new_gadget->alt_design[GD_BUTTON_PRESSED].pixmap = va_arg(ap, Pixmap);
1842 new_gadget->alt_design[GD_BUTTON_PRESSED].x = va_arg(ap, int);
1843 new_gadget->alt_design[GD_BUTTON_PRESSED].y = va_arg(ap, int);
1846 case GDI_DESIGN_BORDER:
1847 new_gadget->design_border = va_arg(ap, int);
1850 case GDI_EVENT_MASK:
1851 new_gadget->event_mask = va_arg(ap, unsigned long);
1855 new_gadget->drawing.area_xsize = va_arg(ap, int);
1856 new_gadget->drawing.area_ysize = va_arg(ap, int);
1858 /* determine dependent values for drawing area gadget, if needed */
1859 if (new_gadget->width == 0 &&
1860 new_gadget->height == 0 &&
1861 new_gadget->drawing.item_xsize !=0 &&
1862 new_gadget->drawing.item_ysize !=0)
1865 new_gadget->drawing.area_xsize * new_gadget->drawing.item_xsize;
1866 new_gadget->height =
1867 new_gadget->drawing.area_ysize * new_gadget->drawing.item_ysize;
1869 else if (new_gadget->drawing.item_xsize == 0 &&
1870 new_gadget->drawing.item_ysize == 0 &&
1871 new_gadget->width != 0 &&
1872 new_gadget->height != 0)
1874 new_gadget->drawing.item_xsize =
1875 new_gadget->width / new_gadget->drawing.area_xsize;
1876 new_gadget->drawing.item_ysize =
1877 new_gadget->height / new_gadget->drawing.area_ysize;
1882 new_gadget->drawing.item_xsize = va_arg(ap, int);
1883 new_gadget->drawing.item_ysize = va_arg(ap, int);
1885 /* determine dependent values for drawing area gadget, if needed */
1886 if (new_gadget->width == 0 &&
1887 new_gadget->height == 0 &&
1888 new_gadget->drawing.area_xsize !=0 &&
1889 new_gadget->drawing.area_ysize !=0)
1892 new_gadget->drawing.area_xsize * new_gadget->drawing.item_xsize;
1893 new_gadget->height =
1894 new_gadget->drawing.area_ysize * new_gadget->drawing.item_ysize;
1896 else if (new_gadget->drawing.area_xsize == 0 &&
1897 new_gadget->drawing.area_ysize == 0 &&
1898 new_gadget->width != 0 &&
1899 new_gadget->height != 0)
1901 new_gadget->drawing.area_xsize =
1902 new_gadget->width / new_gadget->drawing.item_xsize;
1903 new_gadget->drawing.area_ysize =
1904 new_gadget->height / new_gadget->drawing.item_ysize;
1908 case GDI_SCROLLBAR_ITEMS_MAX:
1909 new_gadget->scrollbar.items_max = va_arg(ap, int);
1912 case GDI_SCROLLBAR_ITEMS_VISIBLE:
1913 new_gadget->scrollbar.items_visible = va_arg(ap, int);
1916 case GDI_SCROLLBAR_ITEM_POSITION:
1917 new_gadget->scrollbar.item_position = va_arg(ap, int);
1920 case GDI_CALLBACK_INFO:
1921 new_gadget->callback_info = va_arg(ap, gadget_function);
1924 case GDI_CALLBACK_ACTION:
1925 new_gadget->callback_action = va_arg(ap, gadget_function);
1929 Error(ERR_EXIT, "CreateGadget(): unknown tag %d", tag);
1932 tag = va_arg(ap, int); /* read next tag */
1937 /* check if gadget complete */
1938 if (new_gadget->type != GD_TYPE_DRAWING_AREA &&
1939 (!new_gadget->design[GD_BUTTON_UNPRESSED].pixmap ||
1940 !new_gadget->design[GD_BUTTON_PRESSED].pixmap))
1941 Error(ERR_EXIT, "gadget incomplete (missing Pixmap)");
1943 if (new_gadget->type & GD_TYPE_SCROLLBAR)
1945 struct GadgetScrollbar *gs = &new_gadget->scrollbar;
1947 if (new_gadget->width == 0 || new_gadget->height == 0 ||
1948 gs->items_max == 0 || gs->items_visible == 0)
1949 Error(ERR_EXIT, "scrollbar gadget incomplete (missing tags)");
1951 /* calculate internal scrollbar values */
1952 gs->size_max = (new_gadget->type == GD_TYPE_SCROLLBAR_VERTICAL ?
1953 new_gadget->height : new_gadget->width);
1954 gs->size = gs->size_max * gs->items_visible / gs->items_max;
1955 gs->position = gs->size_max * gs->item_position / gs->items_max;
1956 gs->position_max = gs->size_max - gs->size;
1959 /* insert new gadget into global gadget list */
1960 if (gadget_list_last_entry)
1962 gadget_list_last_entry->next = new_gadget;
1963 gadget_list_last_entry = gadget_list_last_entry->next;
1966 gadget_list_first_entry = gadget_list_last_entry = new_gadget;
1971 void FreeGadget(struct GadgetInfo *gi)
1973 struct GadgetInfo *gi_previous = gadget_list_first_entry;
1975 while (gi_previous && gi_previous->next != gi)
1976 gi_previous = gi_previous->next;
1978 if (gi == gadget_list_first_entry)
1979 gadget_list_first_entry = gi->next;
1981 if (gi == gadget_list_last_entry)
1982 gadget_list_last_entry = gi_previous;
1984 gi_previous->next = gi->next;
1988 /* values for DrawGadget() */
1989 #define DG_UNPRESSED 0
1990 #define DG_PRESSED 1
1991 #define DG_BUFFERED 0
1994 static void CheckRangeOfNumericInputGadget(struct GadgetInfo *gi)
1996 if (gi->type != GD_TYPE_TEXTINPUT_NUMERIC)
1999 gi->text.number_value = atoi(gi->text.value);
2001 if (gi->text.number_value < gi->text.number_min)
2002 gi->text.number_value = gi->text.number_min;
2003 if (gi->text.number_value > gi->text.number_max)
2004 gi->text.number_value = gi->text.number_max;
2006 sprintf(gi->text.value, "%d", gi->text.number_value);
2008 if (gi->text.cursor_position < 0)
2009 gi->text.cursor_position = 0;
2010 else if (gi->text.cursor_position > strlen(gi->text.value))
2011 gi->text.cursor_position = strlen(gi->text.value);
2014 static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
2016 int state = (pressed ? 1 : 0);
2017 struct GadgetDesign *gd = (gi->checked ?
2018 &gi->alt_design[state] :
2019 &gi->design[state]);
2023 case GD_TYPE_NORMAL_BUTTON:
2024 case GD_TYPE_CHECK_BUTTON:
2025 case GD_TYPE_RADIO_BUTTON:
2026 XCopyArea(display, gd->pixmap, drawto, gc,
2027 gd->x, gd->y, gi->width, gi->height, gi->x, gi->y);
2030 case GD_TYPE_TEXTINPUT_ALPHANUMERIC:
2031 case GD_TYPE_TEXTINPUT_NUMERIC:
2035 char cursor_string[3];
2036 char text[MAX_GADGET_TEXTSIZE + 1];
2037 int font_color = FC_YELLOW;
2038 int border = gi->design_border;
2039 strcpy(text, gi->text.value);
2042 /* left part of gadget */
2043 XCopyArea(display, gd->pixmap, drawto, gc,
2044 gd->x, gd->y, border, gi->height, gi->x, gi->y);
2046 /* middle part of gadget */
2047 for (i=0; i<=gi->text.size; i++)
2048 XCopyArea(display, gd->pixmap, drawto, gc,
2049 gd->x + border, gd->y, FONT2_XSIZE, gi->height,
2050 gi->x + border + i * FONT2_XSIZE, gi->y);
2052 /* right part of gadget */
2053 XCopyArea(display, gd->pixmap, drawto, gc,
2054 gd->x + ED_WIN_COUNT_XSIZE - border, gd->y,
2055 border, gi->height, gi->x + gi->width - border, gi->y);
2057 /* gadget text value */
2058 DrawText(gi->x + border, gi->y + border, text, FS_SMALL, font_color);
2060 cursor_letter = gi->text.value[gi->text.cursor_position];
2061 cursor_string[0] = '~';
2062 cursor_string[1] = (cursor_letter != '\0' ? cursor_letter : ' ');
2063 cursor_string[2] = '\0';
2065 /* draw cursor, if active */
2067 DrawText(gi->x + border + gi->text.cursor_position * FONT2_XSIZE,
2068 gi->y + border, cursor_string, FS_SMALL, font_color);
2072 case GD_TYPE_SCROLLBAR_VERTICAL:
2076 int ypos = gi->y + gi->scrollbar.position;
2077 int design_full = gi->width;
2078 int design_body = design_full - 2 * gi->design_border;
2079 int size_full = gi->scrollbar.size;
2080 int size_body = size_full - 2 * gi->design_border;
2081 int num_steps = size_body / design_body;
2082 int step_size_remain = size_body - num_steps * design_body;
2084 /* clear scrollbar area */
2085 XFillRectangle(display, backbuffer, gc,
2086 gi->x, gi->y, gi->width, gi->height);
2088 /* upper part of gadget */
2089 XCopyArea(display, gd->pixmap, drawto, gc,
2091 gi->width, gi->design_border,
2094 /* middle part of gadget */
2095 for (i=0; i<num_steps; i++)
2096 XCopyArea(display, gd->pixmap, drawto, gc,
2097 gd->x, gd->y + gi->design_border,
2098 gi->width, design_body,
2099 xpos, ypos + gi->design_border + i * design_body);
2101 /* remaining middle part of gadget */
2102 if (step_size_remain > 0)
2103 XCopyArea(display, gd->pixmap, drawto, gc,
2104 gd->x, gd->y + gi->design_border,
2105 gi->width, step_size_remain,
2106 xpos, ypos + gi->design_border + num_steps * design_body);
2108 /* lower part of gadget */
2109 XCopyArea(display, gd->pixmap, drawto, gc,
2110 gd->x, gd->y + design_full - gi->design_border,
2111 gi->width, gi->design_border,
2112 xpos, ypos + size_full - gi->design_border);
2116 case GD_TYPE_SCROLLBAR_HORIZONTAL:
2119 int xpos = gi->x + gi->scrollbar.position;
2121 int design_full = gi->height;
2122 int design_body = design_full - 2 * gi->design_border;
2123 int size_full = gi->scrollbar.size;
2124 int size_body = size_full - 2 * gi->design_border;
2125 int num_steps = size_body / design_body;
2126 int step_size_remain = size_body - num_steps * design_body;
2128 /* clear scrollbar area */
2129 XFillRectangle(display, backbuffer, gc,
2130 gi->x, gi->y, gi->width, gi->height);
2132 /* left part of gadget */
2133 XCopyArea(display, gd->pixmap, drawto, gc,
2135 gi->design_border, gi->height,
2138 /* middle part of gadget */
2139 for (i=0; i<num_steps; i++)
2140 XCopyArea(display, gd->pixmap, drawto, gc,
2141 gd->x + gi->design_border, gd->y,
2142 design_body, gi->height,
2143 xpos + gi->design_border + i * design_body, ypos);
2145 /* remaining middle part of gadget */
2146 if (step_size_remain > 0)
2147 XCopyArea(display, gd->pixmap, drawto, gc,
2148 gd->x + gi->design_border, gd->y,
2149 step_size_remain, gi->height,
2150 xpos + gi->design_border + num_steps * design_body, ypos);
2152 /* right part of gadget */
2153 XCopyArea(display, gd->pixmap, drawto, gc,
2154 gd->x + design_full - gi->design_border, gd->y,
2155 gi->design_border, gi->height,
2156 xpos + size_full - gi->design_border, ypos);
2165 XCopyArea(display, drawto, window, gc,
2166 gi->x, gi->y, gi->width, gi->height, gi->x, gi->y);
2168 redraw_mask |= REDRAW_ALL;
2171 void ClickOnGadget(struct GadgetInfo *gi)
2173 /* simulate releasing mouse button over last gadget, if still pressed */
2175 HandleGadgets(-1, -1, 0);
2177 /* simulate pressing mouse button over specified gadget */
2178 HandleGadgets(gi->x, gi->y, 1);
2180 /* simulate releasing mouse button over specified gadget */
2181 HandleGadgets(gi->x, gi->y, 0);
2184 void AdjustScrollbar(struct GadgetInfo *gi, int items_max, int item_pos)
2186 struct GadgetScrollbar *gs = &gi->scrollbar;
2188 gs->items_max = items_max;
2189 gs->item_position = item_pos;
2191 gs->size = gs->size_max * gs->items_visible / gs->items_max;
2192 gs->position = gs->size_max * gs->item_position / gs->items_max;
2193 gs->position_max = gs->size_max - gs->size;
2195 /* finetuning for maximal right/bottom position */
2196 if (gs->item_position == gs->items_max - gs->items_visible)
2197 gs->position = gs->position_max;
2200 DrawGadget(gi, DG_UNPRESSED, DG_DIRECT);
2203 void ModifyTextInputTextValue(struct GadgetInfo *gi, char *new_text)
2205 struct GadgetTextInput *text = &gi->text;
2206 int max_textsize = MAX_GADGET_TEXTSIZE;
2209 max_textsize = MIN(text->size, MAX_GADGET_TEXTSIZE - 1);
2211 strncpy(text->value, new_text, max_textsize);
2212 text->value[max_textsize] = '\0';
2213 text->cursor_position = strlen(text->value);
2216 DrawGadget(gi, DG_UNPRESSED, DG_DIRECT);
2219 void ModifyTextInputNumberValue(struct GadgetInfo *gi, int new_value)
2221 struct GadgetTextInput *text = &gi->text;
2223 text->number_value = (new_value < text->number_min ? text->number_min :
2224 new_value > text->number_max ? text->number_max :
2227 sprintf(text->value, "%d", text->number_value);
2230 DrawGadget(gi, DG_UNPRESSED, DG_DIRECT);
2233 /* global pointer to gadget actually in use (when mouse button pressed) */
2234 static struct GadgetInfo *last_gi = NULL;
2236 void MapGadget(struct GadgetInfo *gi)
2238 if (gi == NULL || gi->mapped)
2243 DrawGadget(gi, DG_UNPRESSED, DG_BUFFERED);
2246 void UnmapGadget(struct GadgetInfo *gi)
2248 if (gi == NULL || !gi->mapped)
2257 void HandleGadgets(int mx, int my, int button)
2259 static struct GadgetInfo *last_info_gi = NULL;
2260 static unsigned long pressed_delay = 0;
2261 static int last_button = 0;
2262 static int last_mx = 0, last_my = 0;
2263 int scrollbar_mouse_pos;
2264 struct GadgetInfo *new_gi, *gi;
2265 boolean press_event;
2266 boolean release_event;
2267 boolean mouse_moving;
2268 boolean gadget_pressed;
2269 boolean gadget_pressed_repeated;
2270 boolean gadget_moving;
2271 boolean gadget_moving_inside;
2272 boolean gadget_moving_off_borders;
2273 boolean gadget_released;
2274 boolean gadget_released_inside;
2275 boolean gadget_released_off_borders;
2276 boolean changed_position = FALSE;
2278 /* check if there are any gadgets defined */
2279 if (gadget_list_first_entry == NULL)
2282 /* check which gadget is under the mouse pointer */
2283 new_gi = getGadgetInfoFromMousePosition(mx, my);
2285 /* check if button state has changed since last invocation */
2286 press_event = (button != 0 && last_button == 0);
2287 release_event = (button == 0 && last_button != 0);
2288 last_button = button;
2290 /* check if mouse has been moved since last invocation */
2291 mouse_moving = ((mx != last_mx || my != last_my) && motion_status);
2295 /* special treatment for text and number input gadgets */
2296 if (last_gi && last_gi->type & GD_TYPE_TEXTINPUT && last_gi->mapped &&
2297 button != 0 && !motion_status)
2299 struct GadgetInfo *gi = last_gi;
2301 if (new_gi == last_gi)
2303 /* if mouse button pressed inside activated text gadget, set cursor */
2304 gi->text.cursor_position = (mx - gi->x) / FONT2_XSIZE;
2306 if (gi->text.cursor_position < 0)
2307 gi->text.cursor_position = 0;
2308 else if (gi->text.cursor_position > strlen(gi->text.value))
2309 gi->text.cursor_position = strlen(gi->text.value);
2311 DrawGadget(gi, DG_PRESSED, DG_DIRECT);
2315 /* if mouse button pressed outside text input gadget, deactivate it */
2316 CheckRangeOfNumericInputGadget(gi);
2317 DrawGadget(gi, DG_UNPRESSED, DG_DIRECT);
2319 if (gi->event_mask & GD_EVENT_TEXT_LEAVING)
2320 gi->callback_action(gi);
2327 (button != 0 && last_gi == NULL && new_gi != NULL && press_event);
2328 gadget_pressed_repeated =
2329 (button != 0 && last_gi != NULL && new_gi == last_gi);
2331 gadget_released = (release_event && last_gi != NULL);
2332 gadget_released_inside = (gadget_released && new_gi == last_gi);
2333 gadget_released_off_borders = (gadget_released && new_gi != last_gi);
2335 gadget_moving = (button != 0 && last_gi != NULL && mouse_moving);
2336 gadget_moving_inside = (gadget_moving && new_gi == last_gi);
2337 gadget_moving_off_borders = (gadget_moving && new_gi != last_gi);
2339 /* if new gadget pressed, store this gadget */
2343 /* 'gi' is actually handled gadget */
2346 /* if gadget is scrollbar, choose mouse position value */
2347 if (gi && gi->type & GD_TYPE_SCROLLBAR)
2348 scrollbar_mouse_pos =
2349 (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? mx - gi->x : my - gi->y);
2351 /* if mouse button released, no gadget needs to be handled anymore */
2352 if (button == 0 && last_gi && !(last_gi->type & GD_TYPE_TEXTINPUT))
2355 /* modify event position values even if no gadget is pressed */
2356 if (button == 0 && !release_event)
2361 int last_x = gi->event.x;
2362 int last_y = gi->event.y;
2364 gi->event.x = mx - gi->x;
2365 gi->event.y = my - gi->y;
2367 if (gi->type == GD_TYPE_DRAWING_AREA)
2369 gi->event.x /= gi->drawing.item_xsize;
2370 gi->event.y /= gi->drawing.item_ysize;
2372 if (last_x != gi->event.x || last_y != gi->event.y)
2373 changed_position = TRUE;
2377 /* handle gadget popup info text */
2378 if (last_info_gi != new_gi ||
2379 (new_gi && new_gi->type == GD_TYPE_DRAWING_AREA && changed_position))
2381 last_info_gi = new_gi;
2383 if (new_gi != NULL && (button == 0 || new_gi == last_gi))
2385 new_gi->event.type = 0;
2386 new_gi->callback_info(new_gi);
2389 default_callback_info(NULL);
2394 if (gi->type == GD_TYPE_CHECK_BUTTON)
2396 gi->checked = !gi->checked;
2398 else if (gi->type == GD_TYPE_RADIO_BUTTON)
2400 struct GadgetInfo *rgi = gadget_list_first_entry;
2405 rgi->type == GD_TYPE_RADIO_BUTTON &&
2406 rgi->radio_nr == gi->radio_nr &&
2409 rgi->checked = FALSE;
2410 DrawGadget(rgi, DG_UNPRESSED, DG_DIRECT);
2418 else if (gi->type & GD_TYPE_SCROLLBAR)
2422 if (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL)
2433 if (mpos >= gpos + gi->scrollbar.position &&
2434 mpos < gpos + gi->scrollbar.position + gi->scrollbar.size)
2436 /* drag scrollbar */
2437 gi->scrollbar.drag_position =
2438 scrollbar_mouse_pos - gi->scrollbar.position;
2442 /* click scrollbar one scrollbar length up/left or down/right */
2444 struct GadgetScrollbar *gs = &gi->scrollbar;
2445 int old_item_position = gs->item_position;
2447 changed_position = FALSE;
2449 gs->item_position +=
2450 gs->items_visible * (mpos < gpos + gi->scrollbar.position ? -1 : +1);
2452 if (gs->item_position < 0)
2453 gs->item_position = 0;
2454 if (gs->item_position > gs->items_max - gs->items_visible)
2455 gs->item_position = gs->items_max - gs->items_visible;
2457 if (old_item_position != gs->item_position)
2459 gi->event.item_position = gs->item_position;
2460 changed_position = TRUE;
2463 AdjustScrollbar(gi, gs->items_max, gs->item_position);
2465 gi->state = GD_BUTTON_UNPRESSED;
2466 gi->event.type = GD_EVENT_MOVING;
2467 gi->event.off_borders = FALSE;
2469 if (gi->event_mask & GD_EVENT_MOVING && changed_position)
2470 gi->callback_action(gi);
2472 /* don't handle this scrollbar anymore while mouse button pressed */
2479 DrawGadget(gi, DG_PRESSED, DG_DIRECT);
2481 gi->state = GD_BUTTON_PRESSED;
2482 gi->event.type = GD_EVENT_PRESSED;
2483 gi->event.button = button;
2484 gi->event.off_borders = FALSE;
2486 /* initialize delay counter */
2487 DelayReached(&pressed_delay, 0);
2489 if (gi->event_mask & GD_EVENT_PRESSED)
2490 gi->callback_action(gi);
2493 if (gadget_pressed_repeated)
2495 if (gi->event_mask & GD_EVENT_REPEATED &&
2496 DelayReached(&pressed_delay, GADGET_FRAME_DELAY))
2497 gi->callback_action(gi);
2502 if (gi->type & GD_TYPE_BUTTON)
2504 if (gadget_moving_inside && gi->state == GD_BUTTON_UNPRESSED)
2505 DrawGadget(gi, DG_PRESSED, DG_DIRECT);
2506 else if (gadget_moving_off_borders && gi->state == GD_BUTTON_PRESSED)
2507 DrawGadget(gi, DG_UNPRESSED, DG_DIRECT);
2510 if (gi->type & GD_TYPE_SCROLLBAR)
2512 struct GadgetScrollbar *gs = &gi->scrollbar;
2513 int old_item_position = gs->item_position;
2515 gs->position = scrollbar_mouse_pos - gs->drag_position;
2517 if (gs->position < 0)
2519 if (gs->position > gs->position_max)
2520 gs->position = gs->position_max;
2522 gs->item_position = gs->items_max * gs->position / gs->size_max;
2524 if (old_item_position != gs->item_position)
2526 gi->event.item_position = gs->item_position;
2527 changed_position = TRUE;
2530 DrawGadget(gi, DG_PRESSED, DG_DIRECT);
2533 gi->state = (gadget_moving_inside || gi->type & GD_TYPE_SCROLLBAR ?
2534 GD_BUTTON_PRESSED : GD_BUTTON_UNPRESSED);
2535 gi->event.type = GD_EVENT_MOVING;
2536 gi->event.off_borders = gadget_moving_off_borders;
2538 if (gi->event_mask & GD_EVENT_MOVING && changed_position &&
2539 (gadget_moving_inside || gi->event_mask & GD_EVENT_OFF_BORDERS))
2540 gi->callback_action(gi);
2543 if (gadget_released_inside)
2545 if (!(gi->type & GD_TYPE_TEXTINPUT))
2546 DrawGadget(gi, DG_UNPRESSED, DG_DIRECT);
2548 gi->state = GD_BUTTON_UNPRESSED;
2549 gi->event.type = GD_EVENT_RELEASED;
2551 if (gi->event_mask & GD_EVENT_RELEASED)
2552 gi->callback_action(gi);
2555 if (gadget_released_off_borders)
2557 if (gi->type & GD_TYPE_SCROLLBAR)
2558 DrawGadget(gi, DG_UNPRESSED, DG_DIRECT);
2560 gi->event.type = GD_EVENT_RELEASED;
2562 if (gi->event_mask & GD_EVENT_RELEASED &&
2563 gi->event_mask & GD_EVENT_OFF_BORDERS)
2564 gi->callback_action(gi);
2568 void HandleGadgetsKeyInput(KeySym key)
2570 struct GadgetInfo *gi = last_gi;
2571 char text[MAX_GADGET_TEXTSIZE];
2575 boolean legal_letter;
2577 if (gi == NULL || !(gi->type & GD_TYPE_TEXTINPUT) || !gi->mapped)
2580 text_length = strlen(gi->text.value);
2581 cursor_pos = gi->text.cursor_position;
2582 letter = getCharFromKeySym(key);
2583 legal_letter = (gi->type == GD_TYPE_TEXTINPUT_NUMERIC ?
2584 letter >= '0' && letter <= '9' :
2587 if (legal_letter && text_length < gi->text.size)
2589 strcpy(text, gi->text.value);
2590 strcpy(&gi->text.value[cursor_pos + 1], &text[cursor_pos]);
2591 gi->text.value[cursor_pos] = letter;
2592 gi->text.cursor_position++;
2593 DrawGadget(gi, DG_PRESSED, DG_DIRECT);
2595 else if (key == XK_Left && cursor_pos > 0)
2597 gi->text.cursor_position--;
2598 DrawGadget(gi, DG_PRESSED, DG_DIRECT);
2600 else if (key == XK_Right && cursor_pos < text_length)
2602 gi->text.cursor_position++;
2603 DrawGadget(gi, DG_PRESSED, DG_DIRECT);
2605 else if (key == XK_BackSpace && cursor_pos > 0)
2607 strcpy(text, gi->text.value);
2608 strcpy(&gi->text.value[cursor_pos - 1], &text[cursor_pos]);
2609 gi->text.cursor_position--;
2610 DrawGadget(gi, DG_PRESSED, DG_DIRECT);
2612 else if (key == XK_Delete && cursor_pos < text_length)
2614 strcpy(text, gi->text.value);
2615 strcpy(&gi->text.value[cursor_pos], &text[cursor_pos + 1]);
2616 DrawGadget(gi, DG_PRESSED, DG_DIRECT);
2618 else if (key == XK_Return)
2620 CheckRangeOfNumericInputGadget(gi);
2621 DrawGadget(gi, DG_UNPRESSED, DG_DIRECT);
2623 if (gi->event_mask & GD_EVENT_TEXT_RETURN)
2624 gi->callback_action(gi);