1
1
/* bubbles.c - frying pan / soft drink in a glass simulation */
3
/*$Id: bubbles.c,v 1.17 2000/07/19 06:38:42 jwz Exp $*/
3
/*$Id: bubbles.c,v 1.18 2002/01/17 02:16:04 jwz Exp $*/
6
6
* Copyright (C) 1995-1996 James Macnicol
93
94
XrmOptionDescRec options [] = {
94
95
{ "-simple", ".simple", XrmoptionNoArg, "true" },
96
97
{ "-broken", ".broken", XrmoptionNoArg, "true" },
98
99
{ "-quiet", ".quiet", XrmoptionNoArg, "true" },
99
100
{ "-nodelay", ".nodelay", XrmoptionNoArg, "true" },
100
101
{ "-3D", ".3D", XrmoptionNoArg, "true" },
137
138
static int *bubble_droppages;
138
139
static GC draw_gc, erase_gc;
141
142
static int num_bubble_pixmaps;
142
143
static Bubble_Step **step_pixmaps;
143
#endif /* HAVE_XPM */
145
146
/* Options stuff */
147
148
static Bool simple = False;
149
150
static Bool simple = True;
225
226
bb->radius, bb->x, bb->y, bb->magic, bb->cell_index);
226
227
die_bad_bubble(bb);
230
231
if ((bb->x < 0) || (bb->x > screen_width) ||
231
232
(bb->y < 0) || (bb->y > screen_height) ||
443
444
maxarea = bubble_areas[bubble_max_radius+1];
445
446
maxarea = step_pixmaps[num_bubble_pixmaps]->area;
447
#else /* !FANCY_BUBBLES */
447
448
maxarea = bubble_areas[bubble_max_radius+1];
448
#endif /* HAVE_XPM */
449
#endif /* !FANCY_BUBBLES */
449
450
maxvalue = (double)screen_width * 2.0 * (double)maxarea;
450
451
factor = (long)ceil(maxvalue / (double)LONG_MAX);
451
452
if (factor > 1) {
452
453
/* Overflow will occur in weighted_mean(). We must divide areas
453
454
each by factor so it will never do so. */
456
457
for (i = bubble_min_radius; i <= bubble_max_radius+1; i++) {
457
458
bubble_areas[i] /= factor;
471
472
#endif /* DEBUG */
475
#else /* !FANCY_BUBBLES */
475
476
for (i = bubble_min_radius; i <= bubble_max_radius+1; i++) {
476
477
bubble_areas[i] /= factor;
477
478
if (bubble_areas[i] == 0)
478
479
bubble_areas[i] = 1;
480
#endif /* HAVE_XPM */
481
#endif /* !FANCY_BUBBLES */
483
484
printf("maxarea = %ld\n", maxarea);
508
509
rv->radius = bubble_min_radius;
509
510
rv->area = bubble_areas[bubble_min_radius];
513
514
rv->radius = step_pixmaps[0]->radius;
514
515
rv->area = step_pixmaps[0]->area;
515
#endif /* HAVE_XPM */
516
#endif /* FANCY_BUBBLES */
518
519
rv->magic = BUBBLE_MAGIC;
540
541
(bb->y - bb->radius), bb->radius*2, bb->radius*2, 0,
544
545
XSetClipOrigin(defdsp, step_pixmaps[bb->step]->draw_gc,
545
546
(bb->x - bb->radius),
546
547
(bb->y - bb->radius));
573
574
(bb->y - bb->radius), bb->radius*2, bb->radius*2, 0,
578
579
XSetClipOrigin(defdsp, step_pixmaps[bb->step]->erase_gc,
579
580
(bb->x - bb->radius), (bb->y - bb->radius));
761
762
if ((simple) && (diner->area > bubble_areas[bubble_max_radius])) {
762
763
diner->area = bubble_areas[bubble_max_radius];
765
766
if ((! simple) && (diner->area > step_pixmaps[num_bubble_pixmaps]->area)) {
766
767
diner->area = step_pixmaps[num_bubble_pixmaps]->area;
768
#endif /* HAVE_XPM */
769
#endif /* FANCY_BUBBLES */
771
772
if ((simple) && (diner->area > bubble_areas[bubble_max_radius])) {
772
773
delete_bubble_in_mesh(diner, DELETE_BUBBLE);
776
777
if ((! simple) && (diner->area >
777
778
step_pixmaps[num_bubble_pixmaps]->area)) {
778
779
delete_bubble_in_mesh(diner, DELETE_BUBBLE);
781
#endif /* HAVE_XPM */
782
#endif /* FANCY_BUBBLES */
998
999
(bb->y) += (bubble_droppages[bb->radius] * drop_dir);
1000
#ifdef FANCY_BUBBLES
1001
1002
(bb->y) += (step_pixmaps[bb->step]->droppage * drop_dir);
1002
#endif /* HAVE_XPM */
1003
#endif /* FANCY_BUBBLES */
1003
1004
if ((bb->y < 0) || (bb->y > screen_height)) {
1004
1005
delete_bubble_in_mesh( bb, DELETE_BUBBLE );
1196
bl->xpmattrs.valuemask = 0;
1199
bl->xpmattrs.valuemask |= XpmCloseness;
1200
bl->xpmattrs.closeness = 40000;
1203
bl->xpmattrs.valuemask |= XpmVisual;
1204
bl->xpmattrs.visual = defvisual;
1207
bl->xpmattrs.valuemask |= XpmDepth;
1208
bl->xpmattrs.depth = screen_depth;
1211
bl->xpmattrs.valuemask |= XpmColormap;
1212
bl->xpmattrs.colormap = defcmap;
1216
/* This is the only line which is different from make_pixmap_from_file() */
1217
result = XpmCreatePixmapFromData(defdsp, defwin, pixmap_data, &bl->ball,
1218
&bl->shape_mask, &bl->xpmattrs);
1222
fprintf(stderr, "xpm: color substitution performed\n");
1225
bl->radius = MAX(bl->xpmattrs.width, bl->xpmattrs.height) / 2;
1196
#ifdef FANCY_BUBBLES
1199
bl->ball = xpm_data_to_pixmap (defdsp, defwin, (char **) pixmap_data,
1200
&w, &h, &bl->shape_mask);
1201
bl->radius = MAX(w, h) / 2;
1226
1202
bl->area = calc_bubble_area(bl->radius);
1228
case XpmColorFailed:
1229
fprintf(stderr, "xpm: color allocation failed\n");
1232
fprintf(stderr, "xpm: out of memory\n");
1235
fprintf(stderr, "xpm: unknown error code %d\n", result);
1204
#endif /* FANCY_BUBBLES */
1239
1206
gcv.plane_mask = AllPlanes;
1240
1207
gcv.foreground = default_fg_pixel;
1241
1208
gcv.function = GXcopy;
1338
1305
fprintf(stderr, "-broken not available in simple mode\n");
1307
#ifndef FANCY_BUBBLES
1309
#else /* FANCY_BUBBLES */
1343
1310
broken = get_boolean_resource("broken", "Boolean");
1344
#endif /* HAVE_XPM */
1311
#endif /* FANCY_BUBBLES */
1402
1369
mesh_length = (2 * bubble_max_radius) + 3;
1371
#ifndef FANCY_BUBBLES
1405
1372
fprintf(stderr,
1406
"Bug: simple mode code not set but HAVE_XPM not defined\n");
1373
"Bug: simple mode code not set but FANCY_BUBBLES not defined\n");
1375
#else /* FANCY_BUBBLES */
1409
1376
/* Make sure all #ifdef sort of things have been taken care of in
1410
1377
get_resources(). */
1411
1378
default_to_pixmaps();
1413
1380
/* Set mesh length */
1414
1381
mesh_length = (2 * step_pixmaps[num_bubble_pixmaps-1]->radius) + 3;
1415
#endif /* HAVE_XPM */
1382
#endif /* FANCY_BUBBLES */
1417
1384
/* Am I missing something in here??? */