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

« back to all changes in this revision

Viewing changes to hacks/mountain.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
1
/* -*- Mode: C; tab-width: 4 -*- */
2
2
/* mountain -- square grid mountains */
3
3
 
4
 
#if !defined( lint ) && !defined( SABER )
5
 
static const char sccsid[] = "@(#)mountain.c    4.04 97/07/28 xlockmore";
6
 
 
 
4
#if 0
 
5
static const char sccsid[] = "@(#)mountain.c    5.00 2000/11/01 xlockmore";
7
6
#endif
8
7
 
9
8
/*-
22
21
 * other special, indirect and consequential damages.
23
22
 *
24
23
 * Revision History:
25
 
 * 10-May-97: Compatible with xscreensaver
 
24
 * 01-Nov-2000: Allocation checks
 
25
 * 10-May-1997: Compatible with xscreensaver
 
26
 * 1995: Written
26
27
 */
27
28
 
28
29
#ifdef STANDALONE
29
 
# define PROGCLASS "Mountain"
30
 
# define HACK_INIT init_mountain
31
 
# define HACK_DRAW draw_mountain
32
 
# define mountain_opts xlockmore_opts
33
 
# define DEFAULTS       "*delay: 0 \n"          \
34
 
                                        "*count: 30 \n"         \
35
 
                                        "*cycles: 100 \n"       \
36
 
                                        "*ncolors: 64 \n"
37
 
# define SMOOTH_COLORS
 
30
#define MODE_mountain
 
31
#define PROGCLASS "Mountain"
 
32
#define HACK_INIT init_mountain
 
33
#define HACK_DRAW draw_mountain
 
34
#define mountain_opts xlockmore_opts
 
35
#define DEFAULTS "*delay: 1000 \n" \
 
36
 "*count: 30 \n" \
 
37
 "*cycles: 4000 \n" \
 
38
 "*ncolors: 64 \n"
 
39
#define SMOOTH_COLORS
38
40
#include "xlockmore.h"          /* in xscreensaver distribution */
39
41
#else /* STANDALONE */
40
42
#include "xlock.h"              /* in xlockmore distribution */
41
43
#endif /* STANDALONE */
42
44
 
 
45
#ifdef MODE_mountain
 
46
 
43
47
ModeSpecOpt mountain_opts =
44
 
{0, NULL, 0, NULL, NULL};
 
48
{0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL};
 
49
 
 
50
#ifdef USE_MODULES
 
51
ModStruct   mountain_description =
 
52
{"mountain", "init_mountain", "draw_mountain", "release_mountain",
 
53
 "refresh_mountain", "init_mountain", (char *) NULL, &mountain_opts,
 
54
 1000, 30, 4000, 1, 64, 1.0, "",
 
55
 "Shows Papo's mountain range", 0, NULL};
 
56
 
 
57
#endif
45
58
 
46
59
/* ~ 5000 Max mountain height (1000 - 10000) */
47
60
#define MAXHEIGHT  (3 * (mp->width + mp->height))
58
71
        int         offset;
59
72
        int         stage;
60
73
        int         h[WORLDWIDTH][WORLDWIDTH];
61
 
        int         time;       /* up time */
62
 
        int         first;
63
 
        GC          stippled_GC;
 
74
        long        time;       /* up time */
 
75
        Bool        wireframe;
 
76
        Bool        joke;
 
77
        GC          stippledGC;
64
78
} mountainstruct;
65
79
 
66
 
static mountainstruct *mountains = NULL;
 
80
static mountainstruct *mountains = (mountainstruct *) NULL;
67
81
 
68
82
static void
69
83
spread(int  (*m)[50], int x, int y)
116
130
        if (MI_NPIXELS(mi) > 2)
117
131
                XSetForeground(display, gc, MI_PIXEL(mi, c));
118
132
        else
119
 
                XSetForeground(display, gc, MI_WIN_WHITE_PIXEL(mi));
120
 
        XFillPolygon(display, window, gc, p, 4, Complex, CoordModeOrigin);
121
 
 
122
 
        if (!mp->pixelmode) {
123
 
                XSetForeground(display, gc, MI_WIN_BLACK_PIXEL(mi));
124
 
                XDrawLines(display, window, gc, p, 5, CoordModeOrigin);
 
133
                XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
 
134
 
 
135
        if (mp->joke) {
 
136
                if ((Bool) (LRAND() & 1))
 
137
                        XDrawLines(display, window, gc, p, 5, CoordModeOrigin);
 
138
                else {
 
139
                        XFillPolygon(display, window, gc, p, 4, Complex, CoordModeOrigin);
 
140
                        if (!mp->pixelmode) {
 
141
                                XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
 
142
                                XDrawLines(display, window, gc, p, 5, CoordModeOrigin);
 
143
                        }
 
144
                }
 
145
        } else {
 
146
                if (mp->wireframe) {
 
147
                        XDrawLines(display, window, gc, p, 5, CoordModeOrigin);
 
148
                } else {
 
149
                        XFillPolygon(display, window, gc, p, 4, Complex, CoordModeOrigin);
 
150
 
 
151
                        if (!mp->pixelmode) {
 
152
                                XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
 
153
                                XDrawLines(display, window, gc, p, 5, CoordModeOrigin);
 
154
                        }
 
155
                }
125
156
        }
126
157
        mp->x++;
127
158
        if (mp->x == WORLDWIDTH - 1) {
135
166
void
136
167
init_mountain(ModeInfo * mi)
137
168
{
138
 
        mountainstruct *mp;
139
169
        int         i, j, x, y;
140
170
        XGCValues   gcv;
 
171
        mountainstruct *mp;
141
172
 
142
173
        if (mountains == NULL) {
143
174
                if ((mountains = (mountainstruct *) calloc(MI_NUM_SCREENS(mi),
145
176
                        return;
146
177
        }
147
178
        mp = &mountains[MI_SCREEN(mi)];
148
 
        mp->width = MI_WIN_WIDTH(mi);
149
 
        mp->height = MI_WIN_HEIGHT(mi);
 
179
 
 
180
        mp->width = MI_WIDTH(mi);
 
181
        mp->height = MI_HEIGHT(mi);
150
182
        mp->pixelmode = (mp->width + mp->height < 200);
151
183
        mp->stage = 0;
152
184
        mp->time = 0;
153
185
        mp->x = mp->y = 0;
154
 
        if (!mp->first) {
155
 
                mp->first = 1;
156
 
                gcv.foreground = MI_WIN_WHITE_PIXEL(mi);
157
 
                gcv.background = MI_WIN_BLACK_PIXEL(mi);
158
 
 
159
 
                mp->stippled_GC = XCreateGC(MI_DISPLAY(mi), MI_WINDOW(mi),
160
 
                                          GCForeground | GCBackground, &gcv);
161
 
        }
162
 
        XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi));
163
 
 
164
 
        for (y = 0; y < WORLDWIDTH; y++)
165
 
                for (x = 0; x < WORLDWIDTH; x++)
 
186
        if (MI_IS_FULLRANDOM(mi)) {
 
187
                mp->joke = (Bool) (NRAND(10) == 0);
 
188
                mp->wireframe = (Bool) (LRAND() & 1);
 
189
        } else {
 
190
                mp->joke = False;
 
191
                mp->wireframe = MI_IS_WIREFRAME(mi);
 
192
        }
 
193
 
 
194
        if (mp->stippledGC == None) {
 
195
                gcv.foreground = MI_WHITE_PIXEL(mi);
 
196
                gcv.background = MI_BLACK_PIXEL(mi);
 
197
                if ((mp->stippledGC = XCreateGC(MI_DISPLAY(mi), MI_WINDOW(mi),
 
198
                                          GCForeground | GCBackground, &gcv)) == None)
 
199
                        return;
 
200
        }
 
201
        MI_CLEARWINDOW(mi);
 
202
 
 
203
        for (y = 0; y < (int) WORLDWIDTH; y++)
 
204
                for (x = 0; x < (int) WORLDWIDTH; x++)
166
205
                        mp->h[x][y] = 0;
167
206
 
168
 
        j = MI_BATCHCOUNT(mi);
 
207
        j = MI_COUNT(mi);
169
208
        if (j < 0)
170
209
                j = NRAND(-j) + 1;
171
210
        for (i = 0; i < j; i++)
192
231
void
193
232
draw_mountain(ModeInfo * mi)
194
233
{
195
 
        mountainstruct *mp = &mountains[MI_SCREEN(mi)];
 
234
        mountainstruct *mp;
 
235
 
 
236
        if (mountains == NULL)
 
237
                        return;
 
238
        mp = &mountains[MI_SCREEN(mi)];
 
239
        if (mp->stippledGC == NULL)
 
240
                        return;
 
241
 
 
242
        MI_IS_DRAWN(mi) = True;
196
243
 
197
244
        switch (mp->stage) {
198
245
                case 0:
199
246
                        drawamountain(mi);
200
247
                        break;
201
248
                case 1:
202
 
                        MI_PAUSE(mi) = 2000000;
203
 
                        /*if (++mp->time > MI_CYCLES(mi)); */
204
 
                        mp->stage++;
 
249
                        if (++mp->time > MI_CYCLES(mi))
 
250
                                mp->stage++;
205
251
                        break;
206
252
                case 2:
207
253
                        init_mountain(mi);
218
264
                for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
219
265
                        mountainstruct *mp = &mountains[screen];
220
266
 
221
 
                        XFreeGC(MI_DISPLAY(mi), mp->stippled_GC);
 
267
                        if (mp->stippledGC)
 
268
                                XFreeGC(MI_DISPLAY(mi), mp->stippledGC);
222
269
                }
223
270
                (void) free((void *) mountains);
224
 
                mountains = NULL;
 
271
                mountains = (mountainstruct *) NULL;
225
272
        }
226
273
}
227
274
 
228
275
void
229
276
refresh_mountain(ModeInfo * mi)
230
277
{
231
 
        mountainstruct *mp = &mountains[MI_SCREEN(mi)];
232
 
 
 
278
        mountainstruct *mp;
 
279
 
 
280
        if (mountains == NULL)
 
281
                        return;
 
282
        mp = &mountains[MI_SCREEN(mi)];
 
283
 
 
284
        MI_CLEARWINDOW(mi);
233
285
        mp->x = 0;
234
286
        mp->y = 0;
235
287
}
 
288
 
 
289
#endif /* MODE_mountain */