ftp://ftp.krokus.ru/pub/OpenBSD/distfiles/xscreensaver-5.01.tar.gz
[xscreensaver] / hacks / crystal.c
index 80bcca5b8ebb3de4841e459f80dc7894d3cef5be..5ceb91f6f2a2f29d2b1a862c8fe2703fe3d14f9e 100644 (file)
@@ -69,17 +69,13 @@ static const char sccsid[] = "@(#)crystal.c 4.12 98/09/10 xlockmore";
  */
 
 #ifdef STANDALONE
-# define PROGCLASS             "Crystal"
-# define HACK_INIT             init_crystal
-# define HACK_DRAW             draw_crystal
-# define crystal_opts  xlockmore_opts
 # define DEFAULTS              "*delay:                60000   \n" \
                                                 "*count:                -500   \n" \
                                                 "*cycles:                200   \n" \
                                                 "*size:                  -15   \n" \
-                                                "*ncolors:               100   \n" \
-                                                "*fullrandom:   True   \n" \
-                                                "*verbose:             False   \n"
+                                                "*ncolors:               100   \n"
+# define reshape_crystal 0
+# define crystal_handle_event 0
 # include "xlockmore.h"                /* in xscreensaver distribution */
 #else /* STANDALONE */
 # include "xlock.h"                    /* in xlockmore distribution */
@@ -96,11 +92,10 @@ static const char sccsid[] = "@(#)crystal.c 4.12 98/09/10 xlockmore";
 #define DEF_MAXSIZE "False"
 #define DEF_CYCLE "True"
 
-#define min(a,b) ((a) <= (b) ? (a) : (b))
+#undef NRAND
+#define NRAND(n)           ( (n) ? (int) (LRAND() % (n)) : 0)
 
-#ifdef STANDALONE
-void release_crystal(ModeInfo * mi);
-#endif
+#define min(a,b) ((a) <= (b) ? (a) : (b))
 
 static int  nx, ny;
 
@@ -108,29 +103,29 @@ static Bool unit_cell, grid_cell, centre, maxsize, cycle_p;
 
 static XrmOptionDescRec opts[] =
 {
-       {"-nx", "crystal.nx", XrmoptionSepArg, (caddr_t) NULL},
-       {"-ny", "crystal.ny", XrmoptionSepArg, (caddr_t) NULL},
-       {"-centre", ".crystal.centre", XrmoptionNoArg, (caddr_t) "on"},
-       {"+centre", ".crystal.centre", XrmoptionNoArg, (caddr_t) "off"},
-       {"-maxsize", ".crystal.maxsize", XrmoptionNoArg, (caddr_t) "on"},
-       {"+maxsize", ".crystal.maxsize", XrmoptionNoArg, (caddr_t) "off"},
-       {"-cell", ".crystal.cell", XrmoptionNoArg, (caddr_t) "on"},
-       {"+cell", ".crystal.cell", XrmoptionNoArg, (caddr_t) "off"},
-       {"-grid", ".crystal.grid", XrmoptionNoArg, (caddr_t) "on"},
-       {"+grid", ".crystal.grid", XrmoptionNoArg, (caddr_t) "off"},
-       {"-shift", ".crystal.shift", XrmoptionNoArg, (caddr_t) "on"},
-       {"+shift", ".crystal.shift", XrmoptionNoArg, (caddr_t) "off"}
+       {"-nx", "crystal.nx", XrmoptionSepArg, 0},
+       {"-ny", "crystal.ny", XrmoptionSepArg, 0},
+       {"-centre", ".crystal.centre", XrmoptionNoArg, "on"},
+       {"+centre", ".crystal.centre", XrmoptionNoArg, "off"},
+       {"-maxsize", ".crystal.maxsize", XrmoptionNoArg, "on"},
+       {"+maxsize", ".crystal.maxsize", XrmoptionNoArg, "off"},
+       {"-cell", ".crystal.cell", XrmoptionNoArg, "on"},
+       {"+cell", ".crystal.cell", XrmoptionNoArg, "off"},
+       {"-grid", ".crystal.grid", XrmoptionNoArg, "on"},
+       {"+grid", ".crystal.grid", XrmoptionNoArg, "off"},
+       {"-shift", ".crystal.shift", XrmoptionNoArg, "on"},
+       {"+shift", ".crystal.shift", XrmoptionNoArg, "off"}
 };
 
 static argtype vars[] =
 {
-       {(caddr_t *) & nx, "nx", "nx", DEF_NX, t_Int},
-       {(caddr_t *) & ny, "ny", "ny", DEF_NY, t_Int},
-       {(caddr_t *) & centre, "centre", "Centre", DEF_CENTRE, t_Bool},
-       {(caddr_t *) & maxsize, "maxsize", "Maxsize", DEF_MAXSIZE, t_Bool},
-       {(caddr_t *) & unit_cell, "cell", "Cell", DEF_CELL, t_Bool},
-       {(caddr_t *) & grid_cell, "grid", "Grid", DEF_GRID, t_Bool},
-       {(caddr_t *) & cycle_p, "shift", "Shift", DEF_CYCLE, t_Bool}
+       {&nx, "nx", "nx", DEF_NX, t_Int},
+       {&ny, "ny", "ny", DEF_NY, t_Int},
+       {&centre, "centre", "Centre", DEF_CENTRE, t_Bool},
+       {&maxsize, "maxsize", "Maxsize", DEF_MAXSIZE, t_Bool},
+       {&unit_cell, "cell", "Cell", DEF_CELL, t_Bool},
+       {&grid_cell, "grid", "Grid", DEF_GRID, t_Bool},
+       {&cycle_p, "shift", "Shift", DEF_CYCLE, t_Bool}
 };
 static OptionStruct desc[] =
 {
@@ -143,7 +138,7 @@ static OptionStruct desc[] =
        {"-/+shift", "turn on/off colour cycling"}
 };
 
-ModeSpecOpt crystal_opts =
+ENTRYPOINT ModeSpecOpt crystal_opts =
 {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc};
 
 #ifdef USE_MODULES
@@ -560,13 +555,21 @@ crystal_drawatom(ModeInfo * mi, crystalatom * atom0)
        }
 }
 
-void
+ENTRYPOINT void init_crystal(ModeInfo * mi);
+ENTRYPOINT void release_crystal(ModeInfo * mi);
+
+
+ENTRYPOINT void
 draw_crystal(ModeInfo * mi)
 {
        Display    *display = MI_DISPLAY(mi);
        crystalstruct *cryst = &crystals[MI_SCREEN(mi)];
        int         i;
 
+#ifdef HAVE_COCOA      /* Don't second-guess Quartz's double-buffering */
+    XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi));
+#endif
+
        if (cryst->no_colors) {
                release_crystal(mi);
                init_crystal(mi);
@@ -618,7 +621,7 @@ draw_crystal(ModeInfo * mi)
        XSetFunction(display, cryst->gc, GXcopy);
 }
 
-void
+ENTRYPOINT void
 refresh_crystal(ModeInfo * mi)
 {
        Display    *display = MI_DISPLAY(mi);
@@ -785,7 +788,7 @@ refresh_crystal(ModeInfo * mi)
        XSetFunction(display, cryst->gc, GXcopy);
 }
 
-void
+ENTRYPOINT void
 release_crystal(ModeInfo * mi)
 {
        Display    *display = MI_DISPLAY(mi);
@@ -821,7 +824,7 @@ release_crystal(ModeInfo * mi)
        }
 }
 
-void
+ENTRYPOINT void
 init_crystal(ModeInfo * mi)
 {
        Display    *display = MI_DISPLAY(mi);
@@ -980,9 +983,12 @@ init_crystal(ModeInfo * mi)
                        cryst->offset_w = (int) (cryst->b * 0.5);
                }
        } else {
+               int max_repeat = 10;
                cryst->offset_w = -1;
-               while (cryst->offset_w < 4 || (int) (cryst->offset_w - cryst->b *
-                                   sin((cryst->gamma - 90) * PI_RAD)) < 4) {
+               while (max_repeat-- && 
+                 (cryst->offset_w < 4 || (int) (cryst->offset_w - cryst->b *
+                                   sin((cryst->gamma - 90) * PI_RAD)) < 4)
+                          ) {
                        cryst->b = NRAND((int) (cryst->win_height / (cos((cryst->gamma - 90) *
                                            PI_RAD))) - cell_min) + cell_min;
                        if (cryst->planegroup > 8)
@@ -1259,6 +1265,7 @@ init_crystal(ModeInfo * mi)
                crystal_setupatom(atom0, cryst->gamma);
                crystal_drawatom(mi, atom0);
        }
-       XSync(display, False);
        XSetFunction(display, cryst->gc, GXcopy);
 }
+
+XSCREENSAVER_MODULE ("Crystal", crystal)