http://packetstormsecurity.org/UNIX/admin/xscreensaver-4.01.tar.gz
[xscreensaver] / hacks / forest.c
index 54fe80739b9e4f62c8b3f83e614bbea1558c42eb..ce57b7b93002416a1352e57b0d51b49473129fe1 100644 (file)
@@ -1,11 +1,13 @@
-/* -*- Mode: C; tab-width: 4 -*-
- * forest.c --- draw a fractal forest.
- */
+/* -*- Mode: C; tab-width: 4 -*- */
+/* forest --- binary trees in a fractal forest */
+
 #if !defined( lint ) && !defined( SABER )
-static const char sccsid[] = "@(#)forest.c     4.03 97/05/10 xlockmore";
+static const char sccsid[] = "@(#)forest.c     5.00 2000/11/01 xlockmore";
+
 #endif
 
-/* Copyright (c) 1995 Pascal Pensa <pensa@aurora.unice.fr>
+/*-
+ * Copyright (c) 1995 Pascal Pensa <pensa@aurora.unice.fr>
  *
  * Original idea : Guillaume Ramey <ramey@aurora.unice.fr>
  *
@@ -22,28 +24,41 @@ static const char sccsid[] = "@(#)forest.c  4.03 97/05/10 xlockmore";
  * other special, indirect and consequential damages.
  *
  * Revision History:
- * 10-May-97: Compatible with xscreensaver
+ * 01-Nov-2000: Allocation checks
+ * 10-May-1997: Compatible with xscreensaver
+ *
  */
 
 #ifdef STANDALONE
-# define PROGCLASS                                     "Forest"
-# define HACK_INIT                                     init_forest
-# define HACK_DRAW                                     draw_forest
-# define forest_opts                           xlockmore_opts
-# define DEFAULTS      "*count:                100     \n"                     \
-                                       "*cycles:               200     \n"                     \
-                                       "*delay:                400000  \n"                     \
-                                       "*ncolors:              100     \n"
-# define UNIFORM_COLORS
-# include "xlockmore.h"                                /* from the xscreensaver distribution */
-# include "erase.h"
-#else  /* !STANDALONE */
-# include "xlock.h"                                    /* from the xlockmore distribution */
-#endif /* !STANDALONE */
-
-ModeSpecOpt forest_opts = {
-  0, NULL, 0, NULL, NULL };
+#define MODE_forest
+#define PROGCLASS "Forest"
+#define HACK_INIT init_forest
+#define HACK_DRAW draw_forest
+#define forest_opts xlockmore_opts
+#define DEFAULTS "*delay: 500000 \n" \
+ "*count: 100 \n" \
+ "*cycles: 200 \n" \
+ "*ncolors: 20 \n"
+#define UNIFORM_COLORS
+#include "xlockmore.h"         /* in xscreensaver distribution */
+#else /* STANDALONE */
+#include "xlock.h"             /* in xlockmore distribution */
+
+#endif /* STANDALONE */
+
+#ifdef MODE_forest
+
+ModeSpecOpt forest_opts =
+{0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL};
 
+#ifdef USE_MODULES
+ModStruct   forest_description =
+{"forest", "init_forest", "draw_forest", "release_forest",
+ "refresh_forest", "init_forest", (char *) NULL, &forest_opts,
+ 400000, 100, 200, 1, 64, 1.0, "",
+ "Shows binary trees of a fractal forest", 0, NULL};
+
+#endif
 
 #define MINTREES   1
 
@@ -72,7 +87,7 @@ typedef struct {
        int         ntrees;
 } foreststruct;
 
-static foreststruct *forests = NULL;
+static foreststruct *forests = (foreststruct *) NULL;
 
 static void
 draw_tree(ModeInfo * mi,
@@ -109,7 +124,7 @@ draw_tree(ModeInfo * mi,
                XSetForeground(display, gc, MI_PIXEL(mi, c));
                c = (c + COLORSPEED) % MI_NPIXELS(mi);
        } else
-               XSetForeground(display, gc, MI_WIN_WHITE_PIXEL(mi));
+               XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
 
        XDrawLine(display, window, gc, x, y, x_1, y_1);
        XDrawLine(display, window, gc, x, y, x_2, y_2);
@@ -138,16 +153,17 @@ init_forest(ModeInfo * mi)
        }
        fp = &forests[MI_SCREEN(mi)];
 
-       fp->width = MI_WIN_WIDTH(mi);
-       fp->height = MI_WIN_HEIGHT(mi);
+       fp->width = MI_WIDTH(mi);
+       fp->height = MI_HEIGHT(mi);
        fp->time = 0;
 
-       fp->ntrees = MI_BATCHCOUNT(mi);
+       fp->ntrees = MI_COUNT(mi);
        if (fp->ntrees < -MINTREES)
                fp->ntrees = NRAND(-fp->ntrees - MINTREES + 1) + MINTREES;
        else if (fp->ntrees < MINTREES)
                fp->ntrees = MINTREES;
-       XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi));
+
+       MI_CLEARWINDOW(mi);
 }
 
 void
@@ -155,10 +171,15 @@ draw_forest(ModeInfo * mi)
 {
        Display    *display = MI_DISPLAY(mi);
        GC          gc = MI_GC(mi);
-       foreststruct *fp = &forests[MI_SCREEN(mi)];
        short       x, y, x_2, y_2, len, c = 0;
        float       a, as;
+       foreststruct *fp;
 
+       if (forests == NULL)
+               return;
+       fp = &forests[MI_SCREEN(mi)];
+
+       MI_IS_DRAWN(mi) = True;
        if (fp->time < fp->ntrees) {
 
                x = RANGE_RAND(0, fp->width);
@@ -172,7 +193,7 @@ draw_forest(ModeInfo * mi)
                        XSetForeground(display, gc, MI_PIXEL(mi, c));
                        c = (c + COLORSPEED) % MI_NPIXELS(mi);
                } else
-                       XSetForeground(display, gc, MI_WIN_WHITE_PIXEL(mi));
+                       XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
 
                x_2 = x + (short) (COSF(a) * ((float) len));
                y_2 = y + (short) (SINF(a) * ((float) len));
@@ -183,10 +204,7 @@ draw_forest(ModeInfo * mi)
                draw_tree(mi, x_2, y_2, (len * REDUCE) / 100, a, as, c, 1);
        }
        if (++fp->time > MI_CYCLES(mi)) {
-#ifdef STANDALONE
-         erase_full_window(MI_DISPLAY(mi), MI_WINDOW(mi));
-#endif /* STANDALONE */
-         init_forest(mi);
+               init_forest(mi);
        }
 }
 
@@ -195,17 +213,14 @@ release_forest(ModeInfo * mi)
 {
        if (forests != NULL) {
                (void) free((void *) forests);
-               forests = NULL;
+               forests = (foreststruct *) NULL;
        }
 }
 
 void
 refresh_forest(ModeInfo * mi)
 {
-       foreststruct *fp = &forests[MI_SCREEN(mi)];
-
-       if (fp->time < fp->ntrees)
-               XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi));
-       else
-               init_forest(mi);
+       MI_CLEARWINDOW(mi);
 }
+
+#endif /* MODE_forest */