X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fcrystal.c;h=9dfa5ea266873d9e953c57d41732aeaf993d6724;hb=aa75c7476aeaa84cf3abc192b376a8b03c325213;hp=be090c2efc0a8fa076da55596a8e3116d9468a5d;hpb=49f5b54f312fe4ac2e9bc47581a72451bd0e8439;p=xscreensaver diff --git a/hacks/crystal.c b/hacks/crystal.c index be090c2e..9dfa5ea2 100644 --- a/hacks/crystal.c +++ b/hacks/crystal.c @@ -73,9 +73,10 @@ static const char sccsid[] = "@(#)crystal.c 4.12 98/09/10 xlockmore"; "*count: -500 \n" \ "*cycles: 200 \n" \ "*size: -15 \n" \ - "*ncolors: 100 \n" -# define reshape_crystal 0 -# define crystal_handle_event 0 + "*ncolors: 100 \n" \ + "*fpsSolid: True \n" \ + "*ignoreRotation: True \n" \ + # include "xlockmore.h" /* in xscreensaver distribution */ #else /* STANDALONE */ # include "xlock.h" /* in xlockmore distribution */ @@ -92,6 +93,9 @@ static const char sccsid[] = "@(#)crystal.c 4.12 98/09/10 xlockmore"; #define DEF_MAXSIZE "False" #define DEF_CYCLE "True" +#undef NRAND +#define NRAND(n) ( (n) ? (int) (LRAND() % (n)) : 0) + #define min(a,b) ((a) <= (b) ? (a) : (b)) static int nx, ny; @@ -563,7 +567,7 @@ draw_crystal(ModeInfo * mi) crystalstruct *cryst = &crystals[MI_SCREEN(mi)]; int i; -#ifdef HAVE_COCOA /* Don't second-guess Quartz's double-buffering */ +#ifdef HAVE_JWXYZ /* Don't second-guess Quartz's double-buffering */ XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi)); #endif @@ -578,7 +582,8 @@ draw_crystal(ModeInfo * mi) /* Rotate colours */ if (cryst->cycle_p) { - rotate_colors(display, cryst->cmap, cryst->colors, cryst->ncolors, + rotate_colors(mi->xgwa.screen, cryst->cmap, + cryst->colors, cryst->ncolors, cryst->direction); if (!(LRAND() % 1000)) cryst->direction = -cryst->direction; @@ -804,7 +809,8 @@ release_crystal(ModeInfo * mi) MI_BG_PIXEL(mi) = cryst->bg; #endif if (cryst->colors && cryst->ncolors && !cryst->no_colors) - free_colors(display, cryst->cmap, cryst->colors, cryst->ncolors); + free_colors(mi->xgwa.screen, cryst->cmap, cryst->colors, + cryst->ncolors); if (cryst->colors) (void) free((void *) cryst->colors); #if 0 /* #### wrong! -jwz */ @@ -980,9 +986,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) @@ -1168,7 +1177,8 @@ init_crystal(ModeInfo * mi) if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { /* Set up colour map */ if (cryst->colors && cryst->ncolors && !cryst->no_colors) - free_colors(display, cryst->cmap, cryst->colors, cryst->ncolors); + free_colors(mi->xgwa.screen, cryst->cmap, + cryst->colors, cryst->ncolors); if (cryst->colors) (void) free((void *) cryst->colors); cryst->colors = 0; @@ -1197,14 +1207,20 @@ init_crystal(ModeInfo * mi) } if (!cryst->mono_p) { if (!(LRAND() % 10)) - make_random_colormap(MI_DISPLAY(mi), MI_VISUAL(mi), cryst->cmap, cryst->colors, &cryst->ncolors, - True, True, &cryst->cycle_p, True); + make_random_colormap(mi->xgwa.screen, MI_VISUAL(mi), + cryst->cmap, cryst->colors, + &cryst->ncolors, + True, True, &cryst->cycle_p, True); else if (!(LRAND() % 2)) - make_uniform_colormap(MI_DISPLAY(mi), MI_VISUAL(mi), cryst->cmap, cryst->colors, &cryst->ncolors, - True, &cryst->cycle_p, True); + make_uniform_colormap(mi->xgwa.screen, MI_VISUAL(mi), + cryst->cmap, cryst->colors, + &cryst->ncolors, True, + &cryst->cycle_p, True); else - make_smooth_colormap(MI_DISPLAY(mi), MI_VISUAL(mi), cryst->cmap, cryst->colors, &cryst->ncolors, - True, &cryst->cycle_p, True); + make_smooth_colormap(mi->xgwa.screen, MI_VISUAL(mi), + cryst->cmap, cryst->colors, + &cryst->ncolors, + True, &cryst->cycle_p, True); } #if 0 /* #### wrong! -jwz */ XInstallColormap(display, cryst->cmap); @@ -1262,4 +1278,22 @@ init_crystal(ModeInfo * mi) XSetFunction(display, cryst->gc, GXcopy); } +ENTRYPOINT void +reshape_crystal(ModeInfo * mi, int width, int height) +{ + release_crystal(mi); + init_crystal(mi); +} + +ENTRYPOINT Bool +crystal_handle_event (ModeInfo *mi, XEvent *event) +{ + if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event)) + { + reshape_crystal (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); + return True; + } + return False; +} + XSCREENSAVER_MODULE ("Crystal", crystal)