http://packetstormsecurity.org/UNIX/admin/xscreensaver-4.14.tar.gz
[xscreensaver] / hacks / flag.c
index 1c2c5054ed12096558eadc2181f5cfa80f8e39fe..8d1ab15503ed094bb375cf00d0cab4700773a970 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- Mode: C; tab-width: 4 -*-
  * flag --- a waving flag
  */
-#if !defined( lint ) && !defined( SABER )
+#if 0
 static const char sccsid[] = "@(#)flag.c       4.02 97/04/01 xlockmore";
 #endif
 
@@ -24,7 +24,10 @@ static const char sccsid[] = "@(#)flag.c     4.02 97/04/01 xlockmore";
  * other special, indirect and consequential damages.
  *
  * Revision History: 
- * 13-May-97: jwz@netscape.com: turned into a standalone program.
+ * 22-Jan-98: jwz: made the flag wigglier; added xpm support.
+ *            (I tried to do this by re-porting from xlockmore, but the
+ *            current xlockmore version is completely inscrutable.)
+ * 13-May-97: jwz@jwz.org: turned into a standalone program.
  *                       Made it able to animate arbitrary (runtime) text or bitmaps.
  * 01-May-96: written.
  */
@@ -45,15 +48,9 @@ static const char sccsid[] = "@(#)flag.c     4.02 97/04/01 xlockmore";
 # define DEF_TEXT                                      ""
 # include "xlockmore.h"                                /* from the xscreensaver distribution */
 
-#ifdef HAVE_XMU
-# ifndef VMS
-#  include <X11/Xmu/Drawing.h>
-# else  /* VMS */
-#  include <Xmu/Drawing.h>
-# endif /* VMS */
-#endif /* HAVE_XMU */
+#include "xpm-pixmap.h"
 
-#include "bob.xbm"
+#include "images/bob.xbm"
 
 #else  /* !STANDALONE */
 # include "xlock.h"                                    /* from the xlockmore distribution */
@@ -61,16 +58,26 @@ static const char sccsid[] = "@(#)flag.c    4.02 97/04/01 xlockmore";
 #endif /* !STANDALONE */
 
 
-#if defined(VMS) && !defined(HAVE_UNAME) && (__VMS_VER >= 70000000)
-# define HAVE_UNAME 1
-#endif
-
 #ifdef HAVE_UNAME
 # include <sys/utsname.h>
 #endif /* HAVE_UNAME */
 
+#ifdef STANDALONE
+static XrmOptionDescRec opts[] =
+{
+  { "-bitmap", ".flag.bitmap", XrmoptionSepArg, 0 },
+  { "-text",   ".flag.text",   XrmoptionSepArg, 0 }
+};
+
+#endif /* STANDALONE */
+
 ModeSpecOpt flag_opts = {
-  0, NULL, 0, NULL, NULL };
+#ifdef STANDALONE
+  2, opts, 0, NULL, NULL
+#else  /* !STANDALONE */
+  0, NULL, 0, NULL, NULL
+#endif /* STANDALONE */
+};
 
 #include <string.h>
 #include <X11/Xutil.h>
@@ -119,8 +126,18 @@ initSintab(ModeInfo * mi)
        flagstruct *fp = &flags[MI_SCREEN(mi)];
        int         i;
 
+  /*-
+   * change the periodicity of the sin formula : the maximum of the
+   * periocity seem to be 16 ( 2^4 ), after the drawing isn't good looking
+   */
+       int         periodicity = random_num(4);
+       int         puissance = 1;
+
+       /* for (i=0;i<periodicity;i++) puissance*=2; */
+       puissance <<= periodicity;
        for (i = 0; i < ANGLES; i++)
-               fp->stab[i] = (int) (SINF(i * 4 * M_PI / ANGLES) * fp->samp) + fp->sofs;
+               fp->stab[i] = (int) (SINF(i * puissance * M_PI / ANGLES) * fp->samp) +
+                       fp->sofs;
 }
 
 static void
@@ -136,13 +153,18 @@ affiche(ModeInfo * mi)
                                fp->stab[(fp->sidx + x + y) % ANGLES];
                        yp = (int) (fp->size * (float) y) +
                                fp->stab[(fp->sidx + 4 * x + y + y) % ANGLES];
-                       if (XGetPixel(fp->image, x, y))
+
+                       if (fp->image->depth > 1)
+                         XSetForeground(display, MI_GC(mi),
+                                                        XGetPixel(fp->image, x, y));
+                       else if (XGetPixel(fp->image, x, y))
                                XSetForeground(display, MI_GC(mi), MI_WIN_BLACK_PIXEL(mi));
                        else if (MI_NPIXELS(mi) <= 2)
                                XSetForeground(display, MI_GC(mi), MI_WIN_WHITE_PIXEL(mi));
                        else
                                XSetForeground(display, MI_GC(mi),
                                               MI_PIXEL(mi, (y + x + fp->sidx + fp->startcolor) % MI_NPIXELS(mi)));
+
                        if (fp->pointsize <= 1)
                                XDrawPoint(display, fp->cache, MI_GC(mi), xp, yp);
                        else if (fp->pointsize < 6)
@@ -184,29 +206,18 @@ make_flag_bits(ModeInfo *mi)
          *bitmap_name &&
          !!strcmp(bitmap_name, "(default)"))
        {
-#ifdef HAVE_XMU
-         int width, height, xh, yh;
-         Pixmap bitmap =
-               XmuLocateBitmapFile (DefaultScreenOfDisplay (dpy),
-                                                        bitmap_name, 0, 0, &width, &height, &xh, &yh);
-         if (!bitmap)
+         Pixmap bitmap = 0;
+      int width = 0;
+      int height = 0;
+
+      bitmap = xpm_file_to_pixmap (dpy, MI_WINDOW (mi), bitmap_name,
+                                   &width, &height, 0);
+         if (bitmap)
                {
-                 fprintf(stderr, "%s: unable to load bitmap file %s\n",
-                                 progname, bitmap_name);
-                 exit (1);
+                 fp->image = XGetImage(dpy, bitmap, 0, 0, width, height, ~0L,
+                                                               ZPixmap);
+                 XFreePixmap(dpy, bitmap);
                }
-         fp->image = XGetImage(dpy, bitmap, 0, 0, width, height,
-                                                       1L, XYPixmap);
-         XFreePixmap(dpy, bitmap);
-
-#else  /* !XMU */
-      fprintf (stderr,
-                          "%s: your vendor doesn't ship the standard Xmu library.\n",
-                          progname);
-      fprintf (stderr, "\tWe can't load XBM files without it.\n");
-      exit (1);
-#endif /* !XMU */
-
        }
   else if (text && *text)
        {
@@ -240,9 +251,15 @@ make_flag_bits(ModeInfo *mi)
                                *s = 0;
                          text = (char *) malloc(strlen(uts.nodename) +
                                                                         strlen(uts.sysname) +
+                                                                        strlen(uts.version) +
                                                                         strlen(uts.release) + 10);
+# ifdef _AIX
+                         sprintf(text, "%s\n%s %s.%s",
+                                         uts.nodename, uts.sysname, uts.version, uts.release);
+# else  /* !_AIX */
                          sprintf(text, "%s\n%s %s",
                                          uts.nodename, uts.sysname, uts.release);
+# endif /* !_AIX */
                        }
 #else  /* !HAVE_UNAME */
 # ifdef VMS
@@ -326,8 +343,10 @@ make_flag_bits(ModeInfo *mi)
        }
   else
        {
+      char *bits = (char *) malloc (sizeof(bob_bits));
+      memcpy (bits, bob_bits, sizeof(bob_bits));
          fp->image = XCreateImage (dpy, MI_VISUAL(mi), 1, XYBitmap, 0,
-                                                               (char *) bob_bits, bob_width, bob_height,
+                                                               bits, bob_width, bob_height,
                                                                8, 0);
          fp->image->byte_order = LSBFirst;
          fp->image->bitmap_bit_order = LSBFirst;
@@ -429,6 +448,9 @@ init_flag(ModeInfo * mi)
        XClearWindow(display, MI_WINDOW(mi));
 }
 
+void release_flag(ModeInfo * mi);
+
+
 void
 draw_flag(ModeInfo * mi)
 {
@@ -460,7 +482,10 @@ draw_flag(ModeInfo * mi)
        XFlush(display);
        fp->timer++;
        if ((MI_CYCLES(mi) > 0) && (fp->timer >= MI_CYCLES(mi)))
+      {
+        release_flag(mi);
                init_flag(mi);
+      }
 }
 
 void