From http://www.jwz.org/xscreensaver/xscreensaver-5.40.tar.gz
[xscreensaver] / hacks / testx11.c
index 554c704e4e1bfd87b5407d10482e91bc4e30d39a..cc2162111171ff5bdef371fb0248fc62c15d1bb8 100644 (file)
 
 #include "screenhack.h"
 #include "glx/rotator.h"
+#include "colorbars.h"
+#include "erase.h"
+
+#include "ximage-loader.h"
+#include "images/gen/logo-180_png.h"
 
 #include <assert.h>
 #include <errno.h>
@@ -50,6 +55,7 @@ enum
   mode_images,
   mode_copy,
   mode_preserve,
+  mode_erase,
 
   mode_count
 };
@@ -95,6 +101,8 @@ struct testx11 {
 
   Pixmap preserve[2];
 
+  eraser_state *erase;
+
   rotator *rot;
 };
 
@@ -211,6 +219,21 @@ make_clip_mask (struct testx11 *st)
 }
 
 
+static void
+colorbars (struct testx11 *st)
+{
+  Pixmap logo_mask = 0;
+  Pixmap logo = image_data_to_pixmap (st->dpy, st->win,
+                                      logo_180_png, sizeof(logo_180_png),
+                                      0, 0, &logo_mask);
+  draw_colorbars (st->xgwa.screen, st->xgwa.visual, st->win,
+                  st->xgwa.colormap, 0, 0, st->xgwa.width, st->xgwa.height,
+                  logo, logo_mask);
+  XFreePixmap (st->dpy, logo);
+  XFreePixmap (st->dpy, logo_mask);
+}
+
+
 static void *
 testx11_init (Display *dpy, Window win)
 {
@@ -315,7 +338,7 @@ testx11_init (Display *dpy, Window win)
 
   {
     static const char text[] = "Welcome from testx11_init().";
-    XClearWindow (dpy, win);
+    colorbars (st);
     XDrawString (dpy, win, st->copy_gc, 16, 16, text, countof (text) - 1);
   }
 
@@ -328,6 +351,8 @@ testx11_init (Display *dpy, Window win)
 
   toggle_antialiasing (st);
 
+  st->erase = NULL;
+
   jwxyz_assert_display (dpy);
 
   st->rot = make_rotator (2, 2, 2, 2, 0.01, False);
@@ -345,7 +370,8 @@ backdrop (struct testx11 *st, Drawable t)
     const float s0 = 2 * M_PI / tile_count;
     float y_fac = sin ((y + st->frame / 16.0) * s0);
     for (x = 0; x != tile_count; ++x) {
-      unsigned c = ((sin ((x + st->frame / 8.0) * s0) * y_fac) - 1) / 2 * st->backdrop_ncolors / 2;
+      int c = ((sin ((x + st->frame / 8.0) * s0) * y_fac) - 1) / 2 *
+              st->backdrop_ncolors / 2;
       c = (c + st->frame) % st->backdrop_ncolors;
       XSetBackground (st->dpy, st->backdrop_black_gc,
                       st->backdrop_colors[c].pixel);
@@ -840,6 +866,12 @@ testx11_draw (Display *dpy, Window win, void *st_raw)
                preserve_size, preserve_size,
                w - preserve_size / 2, preserve_size);
     break;
+
+  case mode_erase:
+    if (!st->erase)
+      colorbars (st);
+    st->erase = erase_window(st->dpy, st->win, st->erase);
+    break;
   }
 
   /* Mode toggle buttons */