|
1 /* |
|
2 * Copyright (c) 1988-91 by Patrick J. Naughton. |
|
3 * |
|
4 * Permission to use, copy, modify, and distribute this software and its |
|
5 * documentation for any purpose and without fee is hereby granted, |
|
6 * provided that the above copyright notice appear in all copies and that |
|
7 * both that copyright notice and this permission notice appear in |
|
8 * supporting documentation. |
|
9 * |
|
10 * This file is provided AS IS with no warranties of any kind. The author |
|
11 * shall have no liability with respect to the infringement of copyrights, |
|
12 * trade secrets or any patents by this file or any part thereof. In no |
|
13 * event will the author be liable for any lost revenue or profits or |
|
14 * other special, indirect and consequential damages. |
|
15 */ |
|
16 |
|
17 /* |
|
18 * Copyright 1994 Sun Microsystems, Inc. All rights reserved. |
|
19 * Use is subject to license terms. |
|
20 * |
|
21 * Permission is hereby granted, free of charge, to any person obtaining a |
|
22 * copy of this software and associated documentation files (the |
|
23 * "Software"), to deal in the Software without restriction, including |
|
24 * without limitation the rights to use, copy, modify, merge, publish, |
|
25 * distribute, and/or sell copies of the Software, and to permit persons |
|
26 * to whom the Software is furnished to do so, provided that the above |
|
27 * copyright notice(s) and this permission notice appear in all copies of |
|
28 * the Software and that both the above copyright notice(s) and this |
|
29 * permission notice appear in supporting documentation. |
|
30 * |
|
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
|
32 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT |
|
34 * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
|
35 * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL |
|
36 * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING |
|
37 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
|
38 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION |
|
39 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
40 * |
|
41 * Except as contained in this notice, the name of a copyright holder |
|
42 * shall not be used in advertising or otherwise to promote the sale, use |
|
43 * or other dealings in this Software without prior written authorization |
|
44 * of the copyright holder. |
|
45 */ |
|
46 |
|
47 #ifndef lint |
|
48 static char sccsid[] = "@(#)image.c 35.3 08/09/18 XLOCK"; |
|
49 #endif |
|
50 /*- |
|
51 * image.c - image bouncer for xlock, the X Window System lockscreen. |
|
52 * |
|
53 * Copyright (c) 1991 by Patrick J. Naughton. |
|
54 * |
|
55 * See xlock.c for copying information. |
|
56 * |
|
57 * Revision History: |
|
58 * 29-Jul-90: Written. |
|
59 */ |
|
60 |
|
61 #include "xlock.h" |
|
62 #include "sunlogo.bit" |
|
63 |
|
64 static XImage logo = { |
|
65 0, 0, /* width, height */ |
|
66 0, XYBitmap, 0, /* xoffset, format, data */ |
|
67 LSBFirst, 8, /* byte-order, bitmap-unit */ |
|
68 LSBFirst, 8, 1 /* bitmap-bit-order, bitmap-pad, depth */ |
|
69 }; |
|
70 |
|
71 #define MAXICONS 1024 |
|
72 |
|
73 typedef struct { |
|
74 int x; |
|
75 int y; |
|
76 } point; |
|
77 |
|
78 typedef struct { |
|
79 int width; |
|
80 int height; |
|
81 int nrows; |
|
82 int ncols; |
|
83 int xb; |
|
84 int yb; |
|
85 int iconmode; |
|
86 int iconcount; |
|
87 point icons[MAXICONS]; |
|
88 long startTime; |
|
89 } imagestruct; |
|
90 |
|
91 extern XColor ssblack[]; |
|
92 extern XColor sswhite[]; |
|
93 |
|
94 static imagestruct ims[MAXSCREENS]; |
|
95 |
|
96 void |
|
97 drawimage(win) |
|
98 Window win; |
|
99 { |
|
100 imagestruct *ip = &ims[screen]; |
|
101 int i; |
|
102 |
|
103 XSetForeground(dsp, Scr[screen].gc, ssblack[screen].pixel); |
|
104 for (i = 0; i < ip->iconcount; i++) { |
|
105 if (!ip->iconmode) |
|
106 XFillRectangle(dsp, win, Scr[screen].gc, |
|
107 ip->xb + sunlogo_width * ip->icons[i].x, |
|
108 ip->yb + sunlogo_height * ip->icons[i].y, |
|
109 sunlogo_width, sunlogo_height); |
|
110 |
|
111 ip->icons[i].x = random() % ip->ncols; |
|
112 ip->icons[i].y = random() % ip->nrows; |
|
113 } |
|
114 if (Scr[screen].npixels == 2) |
|
115 XSetForeground(dsp, Scr[screen].gc, sswhite[screen].pixel); |
|
116 for (i = 0; i < ip->iconcount; i++) { |
|
117 if (Scr[screen].npixels > 2) |
|
118 XSetForeground(dsp, Scr[screen].gc, |
|
119 Scr[screen].pixels[random() % Scr[screen].npixels]); |
|
120 |
|
121 XPutImage(dsp, win, Scr[screen].gc, &logo, |
|
122 0, 0, |
|
123 ip->xb + sunlogo_width * ip->icons[i].x, |
|
124 ip->yb + sunlogo_height * ip->icons[i].y, |
|
125 sunlogo_width, sunlogo_height); |
|
126 } |
|
127 } |
|
128 |
|
129 void |
|
130 initimage(win) |
|
131 Window win; |
|
132 { |
|
133 XWindowAttributes xgwa; |
|
134 imagestruct *ip = &ims[screen]; |
|
135 |
|
136 ip->startTime = seconds(); |
|
137 |
|
138 logo.data = (char *) sunlogo_bits; |
|
139 logo.width = sunlogo_width; |
|
140 logo.height = sunlogo_height; |
|
141 logo.bytes_per_line = (sunlogo_width + 7) / 8; |
|
142 |
|
143 XGetWindowAttributes(dsp, win, &xgwa); |
|
144 ip->width = xgwa.width; |
|
145 ip->height = xgwa.height; |
|
146 ip->ncols = ip->width / sunlogo_width; |
|
147 ip->nrows = ip->height / sunlogo_height; |
|
148 ip->iconmode = (ip->ncols < 2 || ip->nrows < 2); |
|
149 if (ip->iconmode) { |
|
150 ip->xb = 0; |
|
151 ip->yb = 0; |
|
152 ip->iconcount = 1; /* icon mode */ |
|
153 } else { |
|
154 ip->xb = (ip->width - sunlogo_width * ip->ncols) / 2; |
|
155 ip->yb = (ip->height - sunlogo_height * ip->nrows) / 2; |
|
156 ip->iconcount = batchcount; |
|
157 if ((ip->iconcount) > MAXICONS) |
|
158 ip->iconcount = MAXICONS; |
|
159 } |
|
160 XSetForeground(dsp, Scr[screen].gc, ssblack[screen].pixel); |
|
161 XFillRectangle(dsp, win, Scr[screen].gc, 0, 0, ip->width, ip->height); |
|
162 } |