~ubuntu-branches/ubuntu/dapper/xscreensaver/dapper

« back to all changes in this revision

Viewing changes to hacks/laser.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
 
 * laser --- draws swinging laser beams.
3
 
 */
4
 
#if !defined( lint ) && !defined( SABER )
5
 
static const char sccsid[] = "@(#)laser.c       4.00 97/01/01 xlockmore";
 
1
/* -*- Mode: C; tab-width: 4 -*- */
 
2
/* laser --- spinning lasers */
 
3
 
 
4
#if 0
 
5
static const char sccsid[] = "@(#)laser.c       5.00 2000/11/01 xlockmore";
6
6
#endif
7
7
 
8
 
/* Copyright (c) 1995 Pascal Pensa <pensa@aurora.unice.fr>
9
 
 *
10
 
 * Permission to use, copy, modify, distribute, and sell this software and its
11
 
 * documentation for any purpose is hereby granted without fee, provided that
12
 
 * the above copyright notice appear in all copies and that both that
13
 
 * copyright notice and this permission notice appear in supporting
14
 
 * documentation.  No representations are made about the suitability of this
15
 
 * software for any purpose.  It is provided "as is" without express or
16
 
 * implied warranty.
 
8
/*-
 
9
 * Copyright (c) 1995 Pascal Pensa <pensa@aurora.unice.fr>
 
10
 *
 
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.
 
16
 *
 
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.
17
22
 *
18
23
 * Revision History:
19
 
 * 10-May-97: jwz@jwz.org: turned into a standalone program.
 
24
 * 01-Nov-2000: Allocation checks
 
25
 * 10-May-1997: Compatible with xscreensaver
 
26
 * 1995: Written.
20
27
 */
21
28
 
22
29
#ifdef STANDALONE
23
 
# define PROGCLASS                                      "Laser"
24
 
# define HACK_INIT                                      init_laser
25
 
# define HACK_DRAW                                      draw_laser
26
 
# define laser_opts                                     xlockmore_opts
27
 
# define DEFAULTS       "*count:                10    \n"                       \
28
 
                                        "*cycles:               200   \n"                       \
29
 
                                        "*delay:                40000 \n"                       \
30
 
                                        "*ncolors:              64   \n"
31
 
# define SMOOTH_COLORS
32
 
# include "xlockmore.h"                         /* from the xscreensaver distribution */
33
 
#else  /* !STANDALONE */
34
 
# include "xlock.h"                                     /* from the xlockmore distribution */
35
 
#endif /* !STANDALONE */
36
 
 
37
 
ModeSpecOpt laser_opts = {
38
 
  0, NULL, 0, NULL, NULL };
 
30
#define MODE_laser
 
31
#define PROGCLASS "Laser"
 
32
#define HACK_INIT init_laser
 
33
#define HACK_DRAW draw_laser
 
34
#define laser_opts xlockmore_opts
 
35
#define DEFAULTS "*delay: 40000 \n" \
 
36
 "*count: 10 \n" \
 
37
 "*cycles: 200 \n" \
 
38
 "*ncolors: 64 \n"
 
39
#define BRIGHT_COLORS
 
40
#include "xlockmore.h"          /* in xscreensaver distribution */
 
41
#else /* STANDALONE */
 
42
#include "xlock.h"              /* in xlockmore distribution */
 
43
#endif /* STANDALONE */
 
44
 
 
45
#ifdef MODE_laser
 
46
 
 
47
ModeSpecOpt laser_opts =
 
48
{0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL};
 
49
 
 
50
#ifdef USE_MODULES
 
51
ModStruct   laser_description =
 
52
{"laser", "init_laser", "draw_laser", "release_laser",
 
53
 "refresh_laser", "init_laser", (char *) NULL, &laser_opts,
 
54
 20000, -10, 200, 1, 64, 1.0, "",
 
55
 "Shows spinning lasers", 0, NULL};
 
56
 
 
57
#endif
39
58
 
40
59
#define MINREDRAW 3             /* Number of redrawn on each frame */
41
60
#define MAXREDRAW 8
52
71
 
53
72
#define COLORSTEP 2             /* Laser color step */
54
73
 
55
 
#define RANGE_RAND(min,max) ((min) + LRAND() % ((max) - (min)))
 
74
#define RANGE_RAND(min,max) (int) ((min) + LRAND() % ((max) - (min)))
56
75
 
57
76
typedef enum {
58
77
        TOP, RIGHT, BOTTOM, LEFT
85
104
        laserstruct *laser;
86
105
} lasersstruct;
87
106
 
88
 
static lasersstruct *lasers = NULL;
 
107
static lasersstruct *lasers = (lasersstruct *) NULL;
89
108
 
 
109
static void
 
110
free_laser(Display *display, lasersstruct *lp)
 
111
{
 
112
        if (lp->laser != NULL) {
 
113
                (void) free((void *) lp->laser);
 
114
                lp->laser = (laserstruct *) NULL;
 
115
        }
 
116
        if (lp->stippledGC != None) {
 
117
                XFreeGC(display, lp->stippledGC);
 
118
                lp->stippledGC = None;
 
119
        }
 
120
}
90
121
 
91
122
void
92
123
init_laser(ModeInfo * mi)
93
124
{
 
125
        Display *display = MI_DISPLAY(mi);
94
126
        int         i, c = 0;
95
127
        lasersstruct *lp;
96
128
 
101
133
        }
102
134
        lp = &lasers[MI_SCREEN(mi)];
103
135
 
104
 
        lp->width = MI_WIN_WIDTH(mi);
105
 
        lp->height = MI_WIN_HEIGHT(mi);
 
136
        lp->width = MI_WIDTH(mi);
 
137
        lp->height = MI_HEIGHT(mi);
106
138
        lp->time = 0;
107
139
 
108
 
        lp->ln = MI_BATCHCOUNT(mi);
 
140
        lp->ln = MI_COUNT(mi);
109
141
        if (lp->ln < -MINLASER) {
110
142
                /* if lp->ln is random ... the size can change */
111
143
                if (lp->laser != NULL) {
112
144
                        (void) free((void *) lp->laser);
113
 
                        lp->laser = NULL;
 
145
                        lp->laser = (laserstruct *) NULL;
114
146
                }
115
147
                lp->ln = NRAND(-lp->ln - MINLASER + 1) + MINLASER;
116
148
        } else if (lp->ln < MINLASER)
117
149
                lp->ln = MINLASER;
118
150
 
119
 
        if (!lp->laser) {
120
 
                lp->laser = (laserstruct *) malloc(lp->ln * sizeof (laserstruct));
 
151
        if (lp->laser == NULL) {
 
152
                if ((lp->laser = (laserstruct *) malloc(lp->ln *
 
153
                                sizeof (laserstruct))) == NULL) {
 
154
                        free_laser(display, lp);
 
155
                        return;
 
156
                }
121
157
        }
122
 
        if (lp->stippledGC == NULL) {
 
158
        if (lp->stippledGC == None) {
123
159
                XGCValues   gcv;
124
160
 
125
 
                gcv.foreground = MI_WIN_WHITE_PIXEL(mi);
126
 
                gcv.background = MI_WIN_BLACK_PIXEL(mi);
127
 
                lp->gcv_black.foreground = MI_WIN_BLACK_PIXEL(mi);
128
 
                lp->stippledGC = XCreateGC(MI_DISPLAY(mi), MI_WINDOW(mi),
129
 
                                           GCForeground | GCBackground, &gcv);
 
161
                gcv.foreground = MI_WHITE_PIXEL(mi);
 
162
                gcv.background = MI_BLACK_PIXEL(mi);
 
163
                lp->gcv_black.foreground = MI_BLACK_PIXEL(mi);
 
164
                if ((lp->stippledGC = XCreateGC(display, MI_WINDOW(mi),
 
165
                                GCForeground | GCBackground, &gcv)) == None) {
 
166
                        free_laser(display, lp);
 
167
                        return;
 
168
                }
130
169
        }
131
 
        XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi));
 
170
        MI_CLEARWINDOW(mi);
132
171
 
133
172
        if (MINDIST < lp->width - MINDIST)
134
173
                lp->cx = RANGE_RAND(MINDIST, lp->width - MINDIST);
169
208
                                l->by = NRAND(lp->height);
170
209
                }
171
210
 
172
 
                l->dir = LRAND() & 1;
 
211
                l->dir = (int) (LRAND() & 1);
173
212
                l->speed = ((RANGE_RAND(MINSPEED, MAXSPEED) * lp->width) / 1000) + 1;
174
213
                if (MI_NPIXELS(mi) > 2) {
175
214
                        l->gcv.foreground = MI_PIXEL(mi, c);
176
215
                        c = (c + COLORSTEP) % MI_NPIXELS(mi);
177
216
                } else
178
 
                        l->gcv.foreground = MI_WIN_WHITE_PIXEL(mi);
 
217
                        l->gcv.foreground = MI_WHITE_PIXEL(mi);
179
218
        }
180
219
}
181
220
 
283
322
void
284
323
draw_laser(ModeInfo * mi)
285
324
{
286
 
        lasersstruct *lp = &lasers[MI_SCREEN(mi)];
287
325
        int         i;
288
 
 
 
326
        lasersstruct *lp;
 
327
 
 
328
        if (lasers == NULL)
 
329
                return;
 
330
        lp = &lasers[MI_SCREEN(mi)];
 
331
        if (lp->laser == NULL)
 
332
                return;
 
333
 
 
334
        MI_IS_DRAWN(mi) = True;
289
335
        for (i = 0; i < lp->lr; i++)
290
336
                draw_laser_once(mi);
291
337
 
299
345
        if (lasers != NULL) {
300
346
                int         screen;
301
347
 
302
 
                for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
303
 
                        lasersstruct *lp = &lasers[screen];
304
 
 
305
 
                        if (lp->laser != NULL)
306
 
                                (void) free((void *) lp->laser);
307
 
                        if (lp->stippledGC != NULL)
308
 
                                XFreeGC(MI_DISPLAY(mi), lp->stippledGC);
309
 
                }
 
348
                for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++)
 
349
                        free_laser(MI_DISPLAY(mi), &lasers[screen]);
310
350
                (void) free((void *) lasers);
311
 
                lasers = NULL;
 
351
                lasers = (lasersstruct *) NULL;
312
352
        }
313
353
}
314
354
 
315
355
void
316
356
refresh_laser(ModeInfo * mi)
317
357
{
318
 
        /* Do nothing, it will refresh by itself */
 
358
        MI_CLEARWINDOW(mi);
319
359
}
 
360
 
 
361
#endif /* MODE_laser */