1
/* -*- Mode: C; tab-width: 4 -*-
2
* laser --- draws swinging laser beams.
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 */
5
static const char sccsid[] = "@(#)laser.c 5.00 2000/11/01 xlockmore";
8
/* Copyright (c) 1995 Pascal Pensa <pensa@aurora.unice.fr>
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
9
* Copyright (c) 1995 Pascal Pensa <pensa@aurora.unice.fr>
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.
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
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" \
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 */
37
ModeSpecOpt laser_opts = {
38
0, NULL, 0, NULL, NULL };
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" \
40
#include "xlockmore.h" /* in xscreensaver distribution */
41
#else /* STANDALONE */
42
#include "xlock.h" /* in xlockmore distribution */
43
#endif /* STANDALONE */
47
ModeSpecOpt laser_opts =
48
{0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL};
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};
40
59
#define MINREDRAW 3 /* Number of redrawn on each frame */
41
60
#define MAXREDRAW 8
102
134
lp = &lasers[MI_SCREEN(mi)];
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);
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);
145
lp->laser = (laserstruct *) NULL;
115
147
lp->ln = NRAND(-lp->ln - MINLASER + 1) + MINLASER;
116
148
} else if (lp->ln < MINLASER)
117
149
lp->ln = MINLASER;
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);
122
if (lp->stippledGC == NULL) {
158
if (lp->stippledGC == None) {
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);
131
XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi));
133
172
if (MINDIST < lp->width - MINDIST)
134
173
lp->cx = RANGE_RAND(MINDIST, lp->width - MINDIST);
299
345
if (lasers != NULL) {
302
for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
303
lasersstruct *lp = &lasers[screen];
305
if (lp->laser != NULL)
306
(void) free((void *) lp->laser);
307
if (lp->stippledGC != NULL)
308
XFreeGC(MI_DISPLAY(mi), lp->stippledGC);
348
for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++)
349
free_laser(MI_DISPLAY(mi), &lasers[screen]);
310
350
(void) free((void *) lasers);
351
lasers = (lasersstruct *) NULL;
316
356
refresh_laser(ModeInfo * mi)
318
/* Do nothing, it will refresh by itself */
361
#endif /* MODE_laser */