1 /* -*- Mode: C; tab-width: 4 -*- */
2 /* slip --- lots of slipping blits */
5 static const char sccsid[] = "@(#)slip.c 5.00 2000/11/01 xlockmore";
9 * Copyright (c) 1992 by Scott Draves <spot@cs.cmu.edu>
11 * Permission to use, copy, modify, and distribute this software and its
12 * documentation for any purpose and without fee is hereby granted,
13 * provided that the above copyright notice appear in all copies and that
14 * both that copyright notice and this permission notice appear in
15 * supporting documentation.
17 * This file is provided AS IS with no warranties of any kind. The author
18 * shall have no liability with respect to the infringement of copyrights,
19 * trade secrets or any patents by this file or any part thereof. In no
20 * event will the author be liable for any lost revenue or profits or
21 * other special, indirect and consequential damages.
23 * 01-Nov-2000: Allocation checks
24 * 10-May-1997: Jamie Zawinski <jwz@jwz.org> compatible with xscreensaver
25 * 01-Dec-1995: Patched for VMS <joukj@hrem.stm.tudelft.nl>
30 #define PROGCLASS "Slip"
31 #define HACK_INIT init_slip
32 #define HACK_DRAW draw_slip
33 #define slip_opts xlockmore_opts
34 #define DEFAULTS "*delay: 50000 \n" \
38 #include "xlockmore.h" /* in xscreensaver distribution */
39 #else /* STANDALONE */
40 #include "xlock.h" /* in xlockmore distribution */
41 #endif /* STANDALONE */
45 ModeSpecOpt slip_opts =
46 {0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL};
49 ModStruct slip_description =
50 {"slip", "init_slip", "draw_slip", "release_slip",
51 "init_slip", "init_slip", (char *) NULL, &slip_opts,
52 50000, 35, 50, 1, 64, 1.0, "",
53 "Shows slipping blits", 0, NULL};
60 int blit_width, blit_height;
68 static slipstruct *slips = (slipstruct *) NULL;
71 halfrandom(slipstruct *sp, int mv)
80 sp->lasthalf = (short) (r >> 16);
86 erandom(slipstruct *sp, int mv)
94 res = (int) (sp->r & 0xf);
104 prepare_screen(ModeInfo * mi, slipstruct * sp)
107 Display *display = MI_DISPLAY(mi);
109 int i, n, w = sp->width / 20;
110 int not_solid = halfrandom(sp, 10);
112 #ifdef STANDALONE /* jwz -- sometimes hack the desktop image! */
113 if (halfrandom(sp, 2) == 0) {
114 load_random_image (DefaultScreenOfDisplay(display),
115 MI_WINDOW(mi), MI_WINDOW(mi), NULL);
119 sp->backwards = (int) (LRAND() & 1); /* jwz: go the other way sometimes */
121 if (sp->first_time || !halfrandom(sp, 10)) {
125 if (halfrandom(sp, 5))
127 if (halfrandom(sp, 5))
133 if (MI_NPIXELS(mi) > 2)
134 XSetForeground(display, gc, MI_PIXEL(mi, halfrandom(sp, MI_NPIXELS(mi))));
135 else if (halfrandom(sp, 2))
136 XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
138 XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
140 for (i = 0; i < n; i++) {
141 int ww = ((w / 2) + halfrandom(sp, MAX(w, 1)));
144 if (MI_NPIXELS(mi) > 2)
145 XSetForeground(display, gc, MI_PIXEL(mi, halfrandom(sp, MI_NPIXELS(mi))));
146 else if (halfrandom(sp, 2))
147 XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
149 XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
151 XFillRectangle(display, MI_WINDOW(mi), gc,
152 halfrandom(sp, MAX(sp->width - ww, 1)),
153 halfrandom(sp, MAX(sp->height - ww, 1)),
162 int i = (int) floor(d);
165 if ((LRAND() & 0xff) < f * 0xff)
171 init_slip(ModeInfo * mi)
176 if ((slips = (slipstruct *) calloc(MI_NUM_SCREENS(mi),
177 sizeof (slipstruct))) == NULL)
180 sp = &slips[MI_SCREEN(mi)];
182 sp->width = MI_WIDTH(mi);
183 sp->height = MI_HEIGHT(mi);
185 sp->blit_width = sp->width / 25;
186 sp->blit_height = sp->height / 25;
187 sp->nblits_remaining = 0;
191 /* no "NoExpose" events from XCopyArea wanted */
192 XSetGraphicsExposures(MI_DISPLAY(mi), MI_GC(mi), False);
196 draw_slip(ModeInfo * mi)
198 Display *display = MI_DISPLAY(mi);
199 Window window = MI_WINDOW(mi);
206 sp = &slips[MI_SCREEN(mi)];
208 timer = MI_COUNT(mi) * MI_CYCLES(mi);
210 MI_IS_DRAWN(mi) = True;
213 int xi = halfrandom(sp, MAX(sp->width - sp->blit_width, 1));
214 int yi = halfrandom(sp, MAX(sp->height - sp->blit_height, 1));
215 double x, y, dx = 0, dy = 0, t, s1, s2;
217 if (0 == sp->nblits_remaining--) {
219 {0, 0, 0, 1, 1, 1, 2};
221 prepare_screen(mi, sp);
222 sp->nblits_remaining = MI_COUNT(mi) *
223 (2000 + halfrandom(sp, 1000) + halfrandom(sp, 1000));
225 sp->mode = halfrandom(sp, 2);
227 sp->mode = lut[halfrandom(sp, 7)];
229 x = (2 * xi + sp->blit_width) / (double) sp->width - 1;
230 y = (2 * yi + sp->blit_height) / (double) sp->height - 1;
232 /* (x,y) is in biunit square */
248 t = dx * dx + dy * dy + 1e-10;
249 s1 = 2 * dx * dx / t - 1;
250 s2 = 2 * dx * dy / t;
254 if (sp->backwards) { /* jwz: go the other way sometimes */
259 case 1: /* shuffle */
263 case 2: /* explode */
269 int qx = xi + quantize(dx), qy = yi + quantize(dy);
272 if (qx < 0 || qy < 0 ||
273 qx >= sp->width - sp->blit_width ||
274 qy >= sp->height - sp->blit_height)
278 Seems to cause problems using Exceed
280 X Error of failed request: BadGC (invalid GC parameter)
282 X Error of failed request: BadDrawable (invalid Pixmap or Window parameter)
283 Major opcode of failed request: 62 (X_CopyArea)
285 XCopyArea(display, window, window, gc, xi, yi,
286 sp->blit_width, sp->blit_height,
291 wrap = sp->width - (2 * sp->blit_width);
293 XCopyArea(display, window, window, gc, qx, qy,
294 sp->blit_width, sp->blit_height,
297 if (qx < 2 * sp->blit_width) {
298 XCopyArea(display, window, window, gc, qx, qy,
299 sp->blit_width, sp->blit_height,
302 wrap = sp->height - (2 * sp->blit_height);
304 XCopyArea(display, window, window, gc, qx, qy,
305 sp->blit_width, sp->blit_height,
308 if (qy < 2 * sp->blit_height) {
309 XCopyArea(display, window, window, gc, qx, qy,
310 sp->blit_width, sp->blit_height,
323 release_slip(ModeInfo * mi)
326 (void) free((void *) slips);
327 slips = (slipstruct *) NULL;
331 #endif /* MODE_slip */