From http://www.jwz.org/xscreensaver/xscreensaver-5.39.tar.gz
[xscreensaver] / hacks / bubbles.c
index 50b54dac073e24339b80687d503723739c2e8554..9cb2678d2bed0c1d6efe4194702b9f10947e29c1 100644 (file)
@@ -1,6 +1,6 @@
 /* bubbles.c - frying pan / soft drink in a glass simulation */
 
-/*$Id: bubbles.c,v 1.28 2006/03/13 11:41:31 jwz Exp $*/
+/*$Id: bubbles.c,v 1.30 2008/07/31 19:27:48 jwz Exp $*/
 
 /*
  *  Copyright (C) 1995-1996 James Macnicol
@@ -43,6 +43,8 @@
 # include "config.h"
 #endif
 
+#undef DEBUG /* doesn't compile */
+
 #include <math.h>
 #include <limits.h>
 
 #include "screenhack.h"
 #include "yarandom.h"
 #include "bubbles.h"
-#include "xpm-pixmap.h"
+#include "ximage-loader.h"
 
-#if defined(HAVE_GDK_PIXBUF) || defined(HAVE_XPM)
-# define FANCY_BUBBLES
-#endif
+#define FANCY_BUBBLES
 
 /* 
  * Public variables 
 static const char *bubbles_defaults [] = {
   ".background:                black",
   ".foreground:                white",
+  "*fpsSolid:          true",
   "*simple:            false",
   "*broken:            false",
-  "*delay:             800",
+  "*delay:             10000",
   "*quiet:             false", 
-  "*nodelay:           false",
   "*mode:              float",
   "*trails:            false",
   "*3D:                        false",
@@ -91,7 +91,6 @@ static XrmOptionDescRec bubbles_options [] = {
   { "-broken",          ".broken",      XrmoptionNoArg, "true" },
 #endif
   { "-quiet",           ".quiet",       XrmoptionNoArg, "true" },
-  { "-nodelay",         ".nodelay",     XrmoptionNoArg, "true" },
   { "-3D",          ".3D",      XrmoptionNoArg, "true" },
   { "-delay",           ".delay",       XrmoptionSepArg, 0 },
   { "-mode",            ".mode",        XrmoptionSepArg, 0 },
@@ -1160,7 +1159,10 @@ make_pixmap_array(struct state *st, Bubble_Step *list)
 }
 
 static void
-make_pixmap_from_default(struct state *st, char **pixmap_data, Bubble_Step *bl)
+make_pixmap_from_default(struct state *st,
+                         const unsigned char *png_data,
+                         unsigned long data_size,
+                         Bubble_Step *bl)
 /* Read pixmap data which has been compiled into the program and a pointer
  to which has been passed. 
 
@@ -1184,8 +1186,8 @@ changes made to either should be propagated onwards! */
 #ifdef FANCY_BUBBLES
   {
     int w, h;
-    bl->ball = xpm_data_to_pixmap (st->dpy, st->window, (char **) pixmap_data,
-                                   &w, &h, &bl->shape_mask);
+    bl->ball = image_data_to_pixmap (st->dpy, st->window, png_data, data_size,
+                                     &w, &h, &bl->shape_mask);
     bl->radius = MAX(w, h) / 2;
     bl->area = calc_bubble_area(st, bl->radius);
   }
@@ -1209,14 +1211,15 @@ default_to_pixmaps (struct state *st)
   int i;
   Bubble_Step *pixmap_list = (Bubble_Step *)NULL;
   Bubble_Step *newpix, *tmppix;
-  char **pixpt;
 
   init_default_bubbles();
 
   for (i = 0; i < num_default_bubbles; i++) {
-    pixpt = default_bubbles[i];
     newpix = (Bubble_Step *)xmalloc(sizeof(Bubble_Step));
-    make_pixmap_from_default(st, pixpt, newpix);
+    make_pixmap_from_default(st,
+                             default_bubbles[i].png, 
+                             default_bubbles[i].size,
+                             newpix);
     /* Now add to list */
     if (pixmap_list == (Bubble_Step *)NULL) {
       pixmap_list = newpix;
@@ -1245,7 +1248,7 @@ static void
 get_resources(struct state *st)
 /* Get the appropriate X resources and warn about any inconsistencies. */
 {
-  Bool nodelay, rise;
+  Bool rise;
   XWindowAttributes xgwa;
   Colormap cmap;
   char *s;
@@ -1263,11 +1266,6 @@ get_resources(struct state *st)
     st->simple = True;
   }
   st->delay = get_integer_resource(st->dpy, "delay", "Integer");
-  nodelay = get_boolean_resource(st->dpy, "nodelay", "Boolean");
-  if (nodelay)
-    st->delay = 0;
-  if (st->delay < 0)
-    st->delay = 0;
 
   s = get_string_resource (st->dpy, "mode", "Mode");
   rise = False;
@@ -1406,11 +1404,13 @@ static unsigned long
 bubbles_draw (Display *dpy, Window window, void *closure)
 {
   struct state *st = (struct state *) closure;
-  Bubble *tmp;
-
-  tmp = new_bubble(st);
-  add_to_mesh(st, tmp);
-  insert_new_bubble(st, tmp);
+  int i;
+  for (i = 0; i < 5; i++)
+    {
+      Bubble *tmp = new_bubble(st);
+      add_to_mesh(st, tmp);
+      insert_new_bubble(st, tmp);
+    }
   return st->delay;
 }