~ubuntu-branches/ubuntu/breezy/xscreensaver/breezy

« back to all changes in this revision

Viewing changes to hacks/slip.c

  • Committer: Bazaar Package Importer
  • Author(s): Oliver Grawert
  • Date: 2005-10-11 21:00:42 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20051011210042-u7q6zslgevdxspr3
Tags: 4.21-4ubuntu17
updated pt_BR again, fixed to UTF-8 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 4 -*-
2
 
 * slip --- lots of blits.
3
 
 */
4
 
#if !defined( lint ) && !defined( SABER )
5
 
static const char sccsid[] = "@(#)slip.c        4.00 97/01/01 xlockmore";
 
1
/* -*- Mode: C; tab-width: 4 -*- */
 
2
/* slip --- lots of slipping blits */
 
3
 
 
4
#if 0
 
5
static const char sccsid[] = "@(#)slip.c        5.00 2000/11/01 xlockmore";
6
6
#endif
7
7
 
8
 
/* Copyright (c) 1992 by Scott Draves (spot@cs.cmu.edu)
 
8
/*-
 
9
 * Copyright (c) 1992 by Scott Draves <spot@cs.cmu.edu>
9
10
 *
10
11
 * Permission to use, copy, modify, and distribute this software and its
11
12
 * documentation for any purpose and without fee is hereby granted,
19
20
 * event will the author be liable for any lost revenue or profits or
20
21
 * other special, indirect and consequential damages.
21
22
 *
22
 
 * Revision History:
23
 
 * 12-May-97: jwz@jwz.org: turned into a standalone program.
24
 
 * 01-Dec-95: Patched for VMS <joukj@alpha.chem.uva.nl>.
 
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>
25
26
 */
26
27
 
27
28
#ifdef STANDALONE
28
 
# define PROGCLASS                                      "Slip"
29
 
# define HACK_INIT                                      init_slip
30
 
# define HACK_DRAW                                      draw_slip
31
 
# define slip_opts                                      xlockmore_opts
32
 
# define DEFAULTS       "*count:                35    \n"                       \
33
 
                                        "*cycles:               50    \n"                       \
34
 
                                        "*delay:                50000 \n"                       \
35
 
                                        "*ncolors:              200   \n"
36
 
# include "xlockmore.h"                         /* from the xscreensaver distribution */
37
 
#else  /* !STANDALONE */
38
 
# include "xlock.h"                                     /* from the xlockmore distribution */
39
 
#endif /* !STANDALONE */
40
 
 
41
 
ModeSpecOpt slip_opts = {
42
 
  0, NULL, 0, NULL, NULL };
 
29
#define MODE_slip
 
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" \
 
35
 "*count: 35 \n" \
 
36
 "*cycles: 50 \n" \
 
37
 "*ncolors: 200 \n"
 
38
#include "xlockmore.h"          /* in xscreensaver distribution */
 
39
#else /* STANDALONE */
 
40
#include "xlock.h"              /* in xlockmore distribution */
 
41
#endif /* STANDALONE */
 
42
 
 
43
#ifdef MODE_slip
 
44
 
 
45
ModeSpecOpt slip_opts =
 
46
{0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL};
 
47
 
 
48
#ifdef USE_MODULES
 
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};
 
54
 
 
55
#endif
43
56
 
44
57
typedef struct {
45
58
        int         width, height;
47
60
        int         blit_width, blit_height;
48
61
        int         mode;
49
62
        int         first_time;
50
 
    int         backwards;
 
63
        int         backwards;
 
64
        short       lasthalf;
 
65
        int         stage;
 
66
        unsigned long r;
51
67
} slipstruct;
52
 
static slipstruct *slips = NULL;
 
68
static slipstruct *slips = (slipstruct *) NULL;
53
69
 
54
70
static short
55
 
halfrandom(int mv)
 
71
halfrandom(slipstruct *sp, int mv)
56
72
{
57
 
        static short lasthalf = 0;
58
73
        unsigned long r;
59
74
 
60
 
        if (lasthalf) {
61
 
                r = lasthalf;
62
 
                lasthalf = 0;
 
75
        if (sp->lasthalf) {
 
76
                r = sp->lasthalf;
 
77
                sp->lasthalf = 0;
63
78
        } else {
64
79
                r = LRAND();
65
 
                lasthalf = r >> 16;
 
80
                sp->lasthalf = (short) (r >> 16);
66
81
        }
67
82
        return r % mv;
68
83
}
69
84
 
70
85
static int
71
 
erandom(int mv)
 
86
erandom(slipstruct *sp, int mv)
72
87
{
73
 
        static int  stage = 0;
74
 
        static unsigned long r;
75
88
        int         res;
76
89
 
77
 
        if (0 == stage) {
78
 
                r = LRAND();
79
 
                stage = 7;
 
90
        if (0 == sp->stage) {
 
91
                sp->r = LRAND();
 
92
                sp->stage = 7;
80
93
        }
81
 
        res = r & 0xf;
82
 
        r = r >> 4;
83
 
        stage--;
 
94
        res = (int) (sp->r & 0xf);
 
95
        sp->r = sp->r >> 4;
 
96
        sp->stage--;
84
97
        if (res & 8)
85
98
                return res & mv;
86
99
        else
88
101
}
89
102
 
90
103
static void
91
 
prepare_screen(ModeInfo * mi, slipstruct * s)
 
104
prepare_screen(ModeInfo * mi, slipstruct * sp)
92
105
{
93
106
 
94
107
        Display    *display = MI_DISPLAY(mi);
95
108
        GC          gc = MI_GC(mi);
96
 
        int         i, n, w = s->width / 20;
97
 
        int         not_solid = halfrandom(10);
 
109
        int         i, n, w = sp->width / 20;
 
110
        int         not_solid = halfrandom(sp, 10);
98
111
 
99
112
#ifdef STANDALONE                         /* jwz -- sometimes hack the desktop image! */
100
 
        if (halfrandom(2) == 0)
101
 
          {
102
 
                grab_screen_image(DefaultScreenOfDisplay (MI_DISPLAY(mi)),
103
 
                                                  MI_WINDOW(mi));
104
 
                return;
105
 
          }
 
113
        if (halfrandom(sp, 2) == 0) {
 
114
      load_random_image (DefaultScreenOfDisplay(display),
 
115
                                  MI_WINDOW(mi), MI_WINDOW(mi), NULL, NULL);
 
116
        }
106
117
#endif
107
118
 
108
 
        s->backwards = LRAND() & 1;             /* jwz: go the other way sometimes */
 
119
        sp->backwards = (int) (LRAND() & 1);    /* jwz: go the other way sometimes */
109
120
 
110
 
        if (s->first_time || (0 == halfrandom(10))) {
111
 
                XClearWindow(display, MI_WINDOW(mi));
 
121
        if (sp->first_time || !halfrandom(sp, 10)) {
 
122
                MI_CLEARWINDOW(mi);
112
123
                n = 300;
113
124
        } else {
114
 
                if (halfrandom(5))
 
125
                if (halfrandom(sp, 5))
115
126
                        return;
116
 
                if (halfrandom(5))
 
127
                if (halfrandom(sp, 5))
117
128
                        n = 100;
118
129
                else
119
130
                        n = 2000;
120
131
        }
121
132
 
122
133
        if (MI_NPIXELS(mi) > 2)
123
 
                XSetForeground(display, gc, MI_PIXEL(mi, halfrandom(MI_NPIXELS(mi))));
124
 
        else if (halfrandom(2))
125
 
                XSetForeground(display, gc, MI_WIN_WHITE_PIXEL(mi));
 
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));
126
137
        else
127
 
                XSetForeground(display, gc, MI_WIN_BLACK_PIXEL(mi));
 
138
                XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
128
139
 
129
140
        for (i = 0; i < n; i++) {
130
 
          int ww = ((w/2) + halfrandom(w));
 
141
                int         ww = ((w / 2) + halfrandom(sp, MAX(w, 1)));
 
142
 
131
143
                if (not_solid) {
132
144
                        if (MI_NPIXELS(mi) > 2)
133
 
                                XSetForeground(display, gc, MI_PIXEL(mi, halfrandom(MI_NPIXELS(mi))));
134
 
                        else if (halfrandom(2))
135
 
                                XSetForeground(display, gc, MI_WIN_WHITE_PIXEL(mi));
 
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));
136
148
                        else
137
 
                                XSetForeground(display, gc, MI_WIN_BLACK_PIXEL(mi));
 
149
                                XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
138
150
                }
139
151
                XFillRectangle(display, MI_WINDOW(mi), gc,
140
 
                               halfrandom(s->width - ww),
141
 
                               halfrandom(s->height - ww),
 
152
                               halfrandom(sp, MAX(sp->width - ww, 1)),
 
153
                               halfrandom(sp, MAX(sp->height - ww, 1)),
142
154
                               ww, ww);
143
155
        }
144
 
        s->first_time = 0;
 
156
        sp->first_time = 0;
145
157
}
146
158
 
147
159
static int
167
179
        }
168
180
        sp = &slips[MI_SCREEN(mi)];
169
181
 
170
 
        sp->width = MI_WIN_WIDTH(mi);
171
 
        sp->height = MI_WIN_HEIGHT(mi);
 
182
        sp->width = MI_WIDTH(mi);
 
183
        sp->height = MI_HEIGHT(mi);
172
184
 
173
185
        sp->blit_width = sp->width / 25;
174
186
        sp->blit_height = sp->height / 25;
186
198
        Display    *display = MI_DISPLAY(mi);
187
199
        Window      window = MI_WINDOW(mi);
188
200
        GC          gc = MI_GC(mi);
189
 
        slipstruct *s = &slips[MI_SCREEN(mi)];
190
201
        int         timer;
191
 
 
192
 
        timer = MI_BATCHCOUNT(mi) * MI_CYCLES(mi);
 
202
        slipstruct *sp;
 
203
 
 
204
        if (slips == NULL)
 
205
                return;
 
206
        sp = &slips[MI_SCREEN(mi)];
 
207
 
 
208
        timer = MI_COUNT(mi) * MI_CYCLES(mi);
 
209
 
 
210
        MI_IS_DRAWN(mi) = True;
193
211
 
194
212
        while (timer--) {
195
 
                int         xi = halfrandom(s->width - s->blit_width);
196
 
                int         yi = halfrandom(s->height - s->blit_height);
 
213
                int         xi = halfrandom(sp, MAX(sp->width - sp->blit_width, 1));
 
214
                int         yi = halfrandom(sp, MAX(sp->height - sp->blit_height, 1));
197
215
                double      x, y, dx = 0, dy = 0, t, s1, s2;
198
216
 
199
 
                if (0 == s->nblits_remaining--) {
200
 
                        static int lut[] =
 
217
                if (0 == sp->nblits_remaining--) {
 
218
                        static int  lut[] =
201
219
                        {0, 0, 0, 1, 1, 1, 2};
202
220
 
203
 
                        prepare_screen(mi, s);
204
 
                        s->nblits_remaining = MI_BATCHCOUNT(mi) *
205
 
                                (2000 + halfrandom(1000) + halfrandom(1000));
206
 
                        if (s->mode == 2)
207
 
                                s->mode = halfrandom(2);
 
221
                        prepare_screen(mi, sp);
 
222
                        sp->nblits_remaining = MI_COUNT(mi) *
 
223
                                (2000 + halfrandom(sp, 1000) + halfrandom(sp, 1000));
 
224
                        if (sp->mode == 2)
 
225
                                sp->mode = halfrandom(sp, 2);
208
226
                        else
209
 
                                s->mode = lut[halfrandom(7)];
 
227
                                sp->mode = lut[halfrandom(sp, 7)];
210
228
                }
211
 
                x = (2 * xi + s->blit_width) / (double) s->width - 1;
212
 
                y = (2 * yi + s->blit_height) / (double) s->height - 1;
 
229
                x = (2 * xi + sp->blit_width) / (double) sp->width - 1;
 
230
                y = (2 * yi + sp->blit_height) / (double) sp->height - 1;
213
231
 
214
232
                /* (x,y) is in biunit square */
215
 
                switch (s->mode) {
216
 
                        case 0:                                                         /* rotor */
 
233
                switch (sp->mode) {
 
234
                        case 0: /* rotor */
217
235
                                dx = x;
218
236
                                dy = y;
219
237
 
232
250
                                s2 = 2 * dx * dy / t;
233
251
                                dx = s1 * 5;
234
252
                                dy = s2 * 5;
235
 
                                if (s->backwards) {     /* jwz: go the other way sometimes */
 
253
 
 
254
                                if (sp->backwards) {    /* jwz: go the other way sometimes */
236
255
                                        dx = -dx;
237
256
                                        dy = -dy;
238
257
                                }
239
258
                                break;
240
 
                        case 1:                                                         /* shuffle */
241
 
                                dx = erandom(3);
242
 
                                dy = erandom(3);
 
259
                        case 1: /* shuffle */
 
260
                                dx = erandom(sp, 3);
 
261
                                dy = erandom(sp, 3);
243
262
                                break;
244
 
                        case 2:                                                         /* explode */
 
263
                        case 2: /* explode */
245
264
                                dx = x * 3;
246
265
                                dy = y * 3;
247
266
                                break;
251
270
                        int         wrap;
252
271
 
253
272
                        if (qx < 0 || qy < 0 ||
254
 
                            qx >= s->width - s->blit_width ||
255
 
                            qy >= s->height - s->blit_height)
 
273
                            qx >= sp->width - sp->blit_width ||
 
274
                            qy >= sp->height - sp->blit_height)
256
275
                                continue;
257
276
 
 
277
/*-
 
278
Seems to cause problems using Exceed
 
279
with PseudoColor
 
280
X Error of failed request:  BadGC (invalid GC parameter)
 
281
with TrueColor
 
282
X Error of failed request:  BadDrawable (invalid Pixmap or Window parameter)
 
283
  Major opcode of failed request:  62 (X_CopyArea)
 
284
 */
258
285
                        XCopyArea(display, window, window, gc, xi, yi,
259
 
                                  s->blit_width, s->blit_height,
 
286
                                  sp->blit_width, sp->blit_height,
260
287
                                  qx, qy);
261
 
 
262
 
                        switch (s->mode) {
 
288
                        switch (sp->mode) {
263
289
                                case 0:
264
290
                                        /* wrap */
265
 
                                        wrap = s->width - (2 * s->blit_width);
266
 
                                        if (qx > wrap)
 
291
                                        wrap = sp->width - (2 * sp->blit_width);
 
292
                                        if (qx > wrap ) {
267
293
                                                XCopyArea(display, window, window, gc, qx, qy,
268
 
                                                s->blit_width, s->blit_height,
 
294
                                                sp->blit_width, sp->blit_height,
269
295
                                                          qx - wrap, qy);
270
 
 
271
 
                                        if (qx < 2 * s->blit_width)
 
296
                                        }
 
297
                                        if (qx < 2 * sp->blit_width) {
272
298
                                                XCopyArea(display, window, window, gc, qx, qy,
273
 
                                                s->blit_width, s->blit_height,
 
299
                                                sp->blit_width, sp->blit_height,
274
300
                                                          qx + wrap, qy);
275
 
 
276
 
                                        wrap = s->height - (2 * s->blit_height);
277
 
                                        if (qy > wrap)
 
301
                                        }
 
302
                                        wrap = sp->height - (2 * sp->blit_height);
 
303
                                        if (qy > wrap) {
278
304
                                                XCopyArea(display, window, window, gc, qx, qy,
279
 
                                                s->blit_width, s->blit_height,
 
305
                                                sp->blit_width, sp->blit_height,
280
306
                                                          qx, qy - wrap);
281
 
 
282
 
                                        if (qy < 2 * s->blit_height)
 
307
                                        }
 
308
                                        if (qy < 2 * sp->blit_height) {
283
309
                                                XCopyArea(display, window, window, gc, qx, qy,
284
 
                                                s->blit_width, s->blit_height,
 
310
                                                sp->blit_width, sp->blit_height,
285
311
                                                          qx, qy + wrap);
 
312
                                        }
286
313
                                        break;
287
314
                                case 1:
288
315
                                case 2:
297
324
{
298
325
        if (slips != NULL) {
299
326
                (void) free((void *) slips);
300
 
                slips = NULL;
 
327
                slips = (slipstruct *) NULL;
301
328
        }
302
329
}
 
330
 
 
331
#endif /* MODE_slip */