/* bubbles.c - frying pan / soft drink in a glass simulation */
-/*$Id: bubbles.c,v 1.17 2000/07/19 06:38:42 jwz Exp $*/
+/*$Id: bubbles.c,v 1.18 2002/01/17 02:16:04 jwz Exp $*/
/*
* Copyright (C) 1995-1996 James Macnicol
#include <math.h>
#include "screenhack.h"
-#include "bubbles.h"
#include <limits.h>
# include <unistd.h>
#endif
#include "yarandom.h"
+#include "bubbles.h"
+#include "xpm-pixmap.h"
-#ifdef HAVE_XPM
-# include <X11/xpm.h>
+#if defined(HAVE_GDK_PIXBUF) || defined(HAVE_XPM)
+# define FANCY_BUBBLES
#endif
/*
XrmOptionDescRec options [] = {
{ "-simple", ".simple", XrmoptionNoArg, "true" },
-#ifdef HAVE_XPM
+#ifdef FANCY_BUBBLES
{ "-broken", ".broken", XrmoptionNoArg, "true" },
-#endif /* HAVE_XPM */
+#endif
{ "-quiet", ".quiet", XrmoptionNoArg, "true" },
{ "-nodelay", ".nodelay", XrmoptionNoArg, "true" },
{ "-3D", ".3D", XrmoptionNoArg, "true" },
static int *bubble_droppages;
static GC draw_gc, erase_gc;
-#ifdef HAVE_XPM
+#ifdef FANCY_BUBBLES
static int num_bubble_pixmaps;
static Bubble_Step **step_pixmaps;
-#endif /* HAVE_XPM */
+#endif
/* Options stuff */
-#ifdef HAVE_XPM
+#ifdef FANCY_BUBBLES
static Bool simple = False;
#else
static Bool simple = True;
bb->radius, bb->x, bb->y, bb->magic, bb->cell_index);
die_bad_bubble(bb);
}
-#ifdef HAVE_XPM
+#ifdef FANCY_BUBBLES
} else {
if ((bb->x < 0) || (bb->x > screen_width) ||
(bb->y < 0) || (bb->y > screen_height) ||
bb->radius, bb->x, bb->y, bb->magic, bb->cell_index);
die_bad_bubble(bb);
}
-#endif /* HAVE_XPM */
+#endif
}
#endif /* DEBUG */
return 0;
long factor;
int i;
-#ifdef HAVE_XPM
+#ifdef FANCY_BUBBLES
if (simple)
maxarea = bubble_areas[bubble_max_radius+1];
else
maxarea = step_pixmaps[num_bubble_pixmaps]->area;
-#else
+#else /* !FANCY_BUBBLES */
maxarea = bubble_areas[bubble_max_radius+1];
-#endif /* HAVE_XPM */
+#endif /* !FANCY_BUBBLES */
maxvalue = (double)screen_width * 2.0 * (double)maxarea;
factor = (long)ceil(maxvalue / (double)LONG_MAX);
if (factor > 1) {
/* Overflow will occur in weighted_mean(). We must divide areas
each by factor so it will never do so. */
-#ifdef HAVE_XPM
+#ifdef FANCY_BUBBLES
if (simple) {
for (i = bubble_min_radius; i <= bubble_max_radius+1; i++) {
bubble_areas[i] /= factor;
#endif /* DEBUG */
}
}
-#else
+#else /* !FANCY_BUBBLES */
for (i = bubble_min_radius; i <= bubble_max_radius+1; i++) {
bubble_areas[i] /= factor;
if (bubble_areas[i] == 0)
bubble_areas[i] = 1;
}
-#endif /* HAVE_XPM */
+#endif /* !FANCY_BUBBLES */
}
#ifdef DEBUG
printf("maxarea = %ld\n", maxarea);
if (simple) {
rv->radius = bubble_min_radius;
rv->area = bubble_areas[bubble_min_radius];
-#ifdef HAVE_XPM
+#ifdef FANCY_BUBBLES
} else {
rv->step = 0;
rv->radius = step_pixmaps[0]->radius;
rv->area = step_pixmaps[0]->area;
-#endif /* HAVE_XPM */
+#endif /* FANCY_BUBBLES */
}
rv->visible = 0;
rv->magic = BUBBLE_MAGIC;
(bb->y - bb->radius), bb->radius*2, bb->radius*2, 0,
360*64);
} else {
-#ifdef HAVE_XPM
+#ifdef FANCY_BUBBLES
XSetClipOrigin(defdsp, step_pixmaps[bb->step]->draw_gc,
(bb->x - bb->radius),
(bb->y - bb->radius));
(bb->radius * 2),
(bb->x - bb->radius),
(bb->y - bb->radius));
-#endif /* HAVE_XPM */
+#endif /* FANCY_BUBBLES */
}
}
}
(bb->y - bb->radius), bb->radius*2, bb->radius*2, 0,
360*64);
} else {
-#ifdef HAVE_XPM
+#ifdef FANCY_BUBBLES
if (! broken) {
XSetClipOrigin(defdsp, step_pixmaps[bb->step]->erase_gc,
(bb->x - bb->radius), (bb->y - bb->radius));
(bb->radius * 2),
(bb->radius * 2));
}
-#endif /* HAVE_XPM */
+#endif /* FANCY_BUBBLES */
}
}
}
if ((simple) && (diner->area > bubble_areas[bubble_max_radius])) {
diner->area = bubble_areas[bubble_max_radius];
}
-#ifdef HAVE_XPM
+#ifdef FANCY_BUBBLES
if ((! simple) && (diner->area > step_pixmaps[num_bubble_pixmaps]->area)) {
diner->area = step_pixmaps[num_bubble_pixmaps]->area;
}
-#endif /* HAVE_XPM */
+#endif /* FANCY_BUBBLES */
}
else {
if ((simple) && (diner->area > bubble_areas[bubble_max_radius])) {
delete_bubble_in_mesh(diner, DELETE_BUBBLE);
return 0;
}
-#ifdef HAVE_XPM
+#ifdef FANCY_BUBBLES
if ((! simple) && (diner->area >
step_pixmaps[num_bubble_pixmaps]->area)) {
delete_bubble_in_mesh(diner, DELETE_BUBBLE);
return 0;
}
-#endif /* HAVE_XPM */
+#endif /* FANCY_BUBBLES */
}
if (simple) {
diner->radius = i;
}
show_bubble(diner);
-#ifdef HAVE_XPM
+#ifdef FANCY_BUBBLES
} else {
if (diner->area > step_pixmaps[diner->step+1]->area) {
i = diner->step;
diner->radius = step_pixmaps[diner->step]->radius;
}
show_bubble(diner);
-#endif /* HAVE_XPM */
+#endif /* FANCY_BUBBLES */
}
/* Now adjust locations and cells if need be */
if ((nextbub->area >= bubble_areas[bubble_max_radius - 1]) && (random() % 2 == 0))
continue;
}
-#ifdef HAVE_XPM
+#ifdef FANCY_BUBBLES
else {
if ((nextbub->step >= num_bubble_pixmaps - 1) && (random() % 2 == 0))
continue;
}
-#endif /* HAVE_XPM */
+#endif /* FANCY_BUBBLES */
}
break;
}
if (simple)
(bb->y) += (bubble_droppages[bb->radius] * drop_dir);
-#ifdef HAVE_XPM
+#ifdef FANCY_BUBBLES
else
(bb->y) += (step_pixmaps[bb->step]->droppage * drop_dir);
-#endif /* HAVE_XPM */
+#endif /* FANCY_BUBBLES */
if ((bb->y < 0) || (bb->y > screen_height)) {
delete_bubble_in_mesh( bb, DELETE_BUBBLE );
return -1;
if ((bb->area >= bubble_areas[bubble_max_radius - 1]) && (random() % 2 == 0))
leave_trail( bb );
}
-#ifdef HAVE_XPM
+#ifdef FANCY_BUBBLES
else {
if ((bb->step >= num_bubble_pixmaps - 1) && (random() % 2 == 0))
leave_trail( bb );
}
-#endif /* HAVE_XPM */
+#endif /* FANCY_BUBBLES */
}
return 0;
* still check for XPM, though!
*/
-#ifdef HAVE_XPM
+#ifdef FANCY_BUBBLES
/*
* Pixmaps without file I/O (but do have XPM)
This is virtually copied verbatim from make_pixmap_from_file() above and
changes made to either should be propagated onwards! */
{
- int result;
XGCValues gcv;
#ifdef DEBUG
exit(1);
}
- bl->xpmattrs.valuemask = 0;
-
-#ifdef XpmCloseness
- bl->xpmattrs.valuemask |= XpmCloseness;
- bl->xpmattrs.closeness = 40000;
-#endif
-#ifdef XpmVisual
- bl->xpmattrs.valuemask |= XpmVisual;
- bl->xpmattrs.visual = defvisual;
-#endif
-#ifdef XpmDepth
- bl->xpmattrs.valuemask |= XpmDepth;
- bl->xpmattrs.depth = screen_depth;
-#endif
-#ifdef XpmColormap
- bl->xpmattrs.valuemask |= XpmColormap;
- bl->xpmattrs.colormap = defcmap;
-#endif
-
-
- /* This is the only line which is different from make_pixmap_from_file() */
- result = XpmCreatePixmapFromData(defdsp, defwin, pixmap_data, &bl->ball,
- &bl->shape_mask, &bl->xpmattrs);
-
- switch(result) {
- case XpmColorError:
- fprintf(stderr, "xpm: color substitution performed\n");
- /* fall through */
- case XpmSuccess:
- bl->radius = MAX(bl->xpmattrs.width, bl->xpmattrs.height) / 2;
+#ifdef FANCY_BUBBLES
+ {
+ int w, h;
+ bl->ball = xpm_data_to_pixmap (defdsp, defwin, (char **) pixmap_data,
+ &w, &h, &bl->shape_mask);
+ bl->radius = MAX(w, h) / 2;
bl->area = calc_bubble_area(bl->radius);
- break;
- case XpmColorFailed:
- fprintf(stderr, "xpm: color allocation failed\n");
- exit(1);
- case XpmNoMemory:
- fprintf(stderr, "xpm: out of memory\n");
- exit(1);
- default:
- fprintf(stderr, "xpm: unknown error code %d\n", result);
- exit(1);
}
-
+#endif /* FANCY_BUBBLES */
+
gcv.plane_mask = AllPlanes;
gcv.foreground = default_fg_pixel;
gcv.function = GXcopy;
make_pixmap_array(pixmap_list);
}
-#endif /* HAVE_XPM */
+#endif /* FANCY_BUBBLES */
/*
if (! quiet)
fprintf(stderr, "-broken not available in simple mode\n");
} else {
-#ifndef HAVE_XPM
+#ifndef FANCY_BUBBLES
simple = 1;
-#else
+#else /* FANCY_BUBBLES */
broken = get_boolean_resource("broken", "Boolean");
-#endif /* HAVE_XPM */
+#endif /* FANCY_BUBBLES */
}
}
mesh_length = (2 * bubble_max_radius) + 3;
} else {
-#ifndef HAVE_XPM
+#ifndef FANCY_BUBBLES
fprintf(stderr,
- "Bug: simple mode code not set but HAVE_XPM not defined\n");
+ "Bug: simple mode code not set but FANCY_BUBBLES not defined\n");
exit(1);
-#else
+#else /* FANCY_BUBBLES */
/* Make sure all #ifdef sort of things have been taken care of in
get_resources(). */
default_to_pixmaps();
/* Set mesh length */
mesh_length = (2 * step_pixmaps[num_bubble_pixmaps-1]->radius) + 3;
-#endif /* HAVE_XPM */
+#endif /* FANCY_BUBBLES */
/* Am I missing something in here??? */
}