X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fslidescreen.c;h=22c7fe28cc7982368ca3f7128006516cce4deef3;hb=3f438031d610c7e15fd33876a879b97e290e05fb;hp=9415ac22049aaccd5842e29d0b1784558e8aee97;hpb=ce3185de9d9705e259f2b60dd4b5509007fa17d4;p=xscreensaver diff --git a/hacks/slidescreen.c b/hacks/slidescreen.c index 9415ac22..22c7fe28 100644 --- a/hacks/slidescreen.c +++ b/hacks/slidescreen.c @@ -1,5 +1,4 @@ -/* xscreensaver, Copyright (c) 1992, 1993, 1994, 1996, 1997 - * Jamie Zawinski +/* xscreensaver, Copyright (c) 1992-2005 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -12,6 +11,9 @@ #include "screenhack.h" +enum { DOWN = 0, LEFT, UP, RIGHT }; +enum { VERTICAL, HORIZONTAL }; + static int grid_size; static int pix_inc; static int hole_x, hole_y; @@ -36,9 +38,7 @@ init_slide (Display *dpy, Window window) Visual *visual; XGetWindowAttributes (dpy, window, &xgwa); - grab_screen_image (xgwa.screen, window); - - XGetWindowAttributes (dpy, window, &xgwa); /* re-retrieve colormap */ + load_random_image (xgwa.screen, window, window, NULL, NULL); cmap = xgwa.colormap; visual = xgwa.visual; max_width = xgwa.width; @@ -50,6 +50,12 @@ init_slide (Display *dpy, Window window) pix_inc = get_integer_resource ("pixelIncrement", "Integer"); border = get_integer_resource ("internalBorderWidth", "InternalBorderWidth"); + /* Don't let the grid be smaller than 3x3 */ + if (grid_size > xgwa.width / 3) + grid_size = xgwa.width / 3; + if (grid_size > xgwa.height / 3) + grid_size = xgwa.height / 3; + { XColor fgc, bgc; char *fgs = get_string_resource("background", "Background"); @@ -94,7 +100,7 @@ init_slide (Display *dpy, Window window) for(i = 0; i < max; i++) { long rd, gd, bd; - unsigned long d; + unsigned long dd; if (!fg_ok) { rd = (all[i].red >> 8) - (fgc.red >> 8); @@ -103,12 +109,12 @@ init_slide (Display *dpy, Window window) if (rd < 0) rd = -rd; if (gd < 0) gd = -gd; if (bd < 0) bd = -bd; - d = (rd << 1) + (gd << 2) + bd; - if (d < fgd) + dd = (rd << 1) + (gd << 2) + bd; + if (dd < fgd) { - fgd = d; + fgd = dd; fg = all[i].pixel; - if (d == 0) + if (dd == 0) fg_ok = True; } } @@ -121,12 +127,12 @@ init_slide (Display *dpy, Window window) if (rd < 0) rd = -rd; if (gd < 0) gd = -gd; if (bd < 0) bd = -bd; - d = (rd << 1) + (gd << 2) + bd; - if (d < bgd) + dd = (rd << 1) + (gd << 2) + bd; + if (dd < bgd) { - bgd = d; + bgd = dd; bg = all[i].pixel; - if (d == 0) + if (dd == 0) bg_ok = True; } } @@ -197,8 +203,8 @@ init_slide (Display *dpy, Window window) XFillRectangle (dpy, d, gc, 0, bitmap_h - yoff, bitmap_w, yoff); } - XSync (dpy, True); - if (delay2) usleep (delay2 * 2); + XSync (dpy, False); + if (delay2) usleep (delay2); for (i = 0; i < grid_size; i += pix_inc) { XPoint points [3]; @@ -228,7 +234,7 @@ init_slide (Display *dpy, Window window) points[2].y = points[1].y; XFillPolygon (dpy, window, gc, points, 3, Convex, CoordModeOrigin); - XSync (dpy, True); + XSync (dpy, False); if (delay) usleep (delay); } @@ -236,42 +242,40 @@ init_slide (Display *dpy, Window window) xoff + grid_size * hole_x, yoff + grid_size * hole_y, grid_size, grid_size); + + XSync (dpy, False); + if (delay2) usleep (delay2); } static void slide1 (Display *dpy, Window window) { /* this code is a total kludge, but who cares, it works... */ - int i, x, y, ix, iy, dx, dy, dir, w, h, size, inc; + int rnd, i, x, y, ix, iy, dx, dy, dir, w, h, size, inc; static int last = -1; - do { - dir = random () % 4; - switch (dir) - { - case 0: dx = 0, dy = 1; break; - case 1: dx = -1, dy = 0; break; - case 2: dx = 0, dy = -1; break; - case 3: dx = 1, dy = 0; break; - default: abort (); - } - } while (dir == last || - hole_x + dx < 0 || hole_x + dx >= grid_w || - hole_y + dy < 0 || hole_y + dy >= grid_h); - if (grid_w > 1 && grid_h > 1) - last = (dir == 0 ? 2 : dir == 2 ? 0 : dir == 1 ? 3 : 1); - - switch (dir) - { - case 0: size = 1 + (random()%(grid_h - hole_y - 1)); h = size; w = 1; break; - case 1: size = 1 + (random()%hole_x); w = size; h = 1; break; - case 2: size = 1 + (random()%hole_y); h = size; w = 1; break; - case 3: size = 1 + (random()%(grid_w - hole_x - 1)); w = size; h = 1; break; - default: abort (); - } - if (dx == -1) hole_x -= (size - 1); - else if (dy == -1) hole_y -= (size - 1); + if (last == -1) last = random () % 2; +/* alternate between horizontal and vertical slides */ +/* note that dir specifies the direction the _hole_ moves, not the tiles */ + if (last == VERTICAL) { + if ((rnd = random () % (grid_w - 1)) < hole_x) { + dx = -1; dir = LEFT; hole_x -= rnd; + } else { + dx = 1; dir = RIGHT; rnd -= hole_x; + } + dy = 0; w = size = rnd + 1; h = 1; + last = HORIZONTAL; + } else { + if ((rnd = random () % (grid_h - 1)) < hole_y) { + dy = -1; dir = UP; hole_y -= rnd; + } else { + dy = 1; dir = DOWN; rnd -= hole_y; + } + dx = 0; h = size = rnd + 1; w = 1; + last = VERTICAL; + } + ix = x = xoff + (hole_x + dx) * grid_size; iy = y = yoff + (hole_y + dy) * grid_size; inc = pix_inc; @@ -297,27 +301,27 @@ slide1 (Display *dpy, Window window) y -= dy * inc; switch (dir) { - case 0: XFillRectangle (dpy, window, gc, + case DOWN: XFillRectangle (dpy, window, gc, ix, y + grid_size * h, grid_size * w, iy - y); break; - case 1: XFillRectangle (dpy, window, gc, ix, iy, x - ix, grid_size * h); + case LEFT: XFillRectangle (dpy, window, gc, ix, iy, x - ix, grid_size * h); break; - case 2: XFillRectangle (dpy, window, gc, ix, iy, grid_size * w, y - iy); + case UP: XFillRectangle (dpy, window, gc, ix, iy, grid_size * w, y - iy); break; - case 3: XFillRectangle (dpy, window, gc, + case RIGHT: XFillRectangle (dpy, window, gc, x + grid_size * w, iy, ix - x, grid_size * h); break; } - XSync (dpy, True); + XSync (dpy, False); if (delay) usleep (delay); } switch (dir) { - case 0: hole_y += size; break; - case 1: hole_x--; break; - case 2: hole_y--; break; - case 3: hole_x += size; break; + case DOWN: hole_y += size; break; + case LEFT: hole_x--; break; + case UP: hole_y--; break; + case RIGHT: hole_x += size; break; } } @@ -357,6 +361,7 @@ screenhack (Display *dpy, Window window) while (1) { slide1 (dpy, window); + screenhack_handle_events (dpy); if (delay2) usleep (delay2); } }