X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fgears.c;h=bd0bb4e6092528a04d35a806a56d6a367e28e0fd;hb=49f5b54f312fe4ac2e9bc47581a72451bd0e8439;hp=e1c08bdc35b39d64b243dbd4b66fd4011b170a06;hpb=96a411663168b0ba5432b407a83be55f3df0c802;p=xscreensaver diff --git a/hacks/glx/gears.c b/hacks/glx/gears.c index e1c08bdc..bd0bb4e6 100644 --- a/hacks/glx/gears.c +++ b/hacks/glx/gears.c @@ -34,28 +34,14 @@ static const char sccsid[] = "@(#)gears.c 4.07 97/11/24 xlockmore"; * been fixed in MesaGL 2.2 and later releases. */ -/*- - * due to a Bug/feature in VMS X11/Intrinsic.h has to be placed before xlock. - * otherwise caddr_t is not defined correctly - */ - -#include - #ifdef STANDALONE -# define PROGCLASS "Gears" -# define HACK_INIT init_gears -# define HACK_DRAW draw_gears -# define HACK_RESHAPE reshape_gears -# define HACK_HANDLE_EVENT gears_handle_event -# define EVENT_MASK PointerMotionMask -# define gears_opts xlockmore_opts -# define DEFAULTS "*count: 1 \n" \ +# define DEFAULTS "*count: 1000000 \n" \ "*cycles: 2 \n" \ "*delay: 20000 \n" \ - "*planetary: False \n" \ "*showFPS: False \n" \ "*wireframe: False \n" # include "xlockmore.h" /* from the xscreensaver distribution */ +# define refresh_gears 0 #else /* !STANDALONE */ # include "xlock.h" /* from the xlockmore distribution */ #endif /* !STANDALONE */ @@ -68,20 +54,26 @@ static const char sccsid[] = "@(#)gears.c 4.07 97/11/24 xlockmore"; #undef countof #define countof(x) (sizeof((x))/sizeof((*x))) -#define DEF_PLANETARY "False" +#define DEF_MODE "random" +#define DEF_SPIN "True" -static int planetary; +static char *mode_str; +static int spin; static XrmOptionDescRec opts[] = { - {"-planetary", ".gears.planetary", XrmoptionNoArg, (caddr_t) "true" }, - {"+planetary", ".gears.planetary", XrmoptionNoArg, (caddr_t) "false" }, + {"-mode", ".gears.mode", XrmoptionSepArg, 0 }, + {"-planetary", ".gears.mode", XrmoptionNoArg, "planetary" }, + {"-simple", ".gears.mode", XrmoptionNoArg, "simple" }, + {"-spin", ".gears.spin", XrmoptionNoArg, "true" }, + {"+spin", ".gears.spin", XrmoptionNoArg, "false" }, }; static argtype vars[] = { - {(caddr_t *) &planetary, "planetary", "Planetary", DEF_PLANETARY, t_Bool}, + {&mode_str, "mode", "Mode", DEF_MODE, t_String}, + {&spin, "spin", "Spin", DEF_SPIN, t_Bool}, }; -ModeSpecOpt gears_opts = {countof(opts), opts, countof(vars), vars, NULL}; +ENTRYPOINT ModeSpecOpt gears_opts = {countof(opts), opts, countof(vars), vars, NULL}; #ifdef USE_MODULES ModStruct gears_description = @@ -111,6 +103,7 @@ typedef struct { rotator *rot; trackball_state *trackball; Bool button_down_p; + int planetary_p; } gearsstruct; static gearsstruct *gears = NULL; @@ -543,15 +536,16 @@ draw(ModeInfo * mi) gltrackball_rotate (gp->trackball); - { - double x, y, z; - get_rotation (gp->rot, &x, &y, &z, !gp->button_down_p); - glRotatef (x * 360, 1.0, 0.0, 0.0); - glRotatef (y * 360, 0.0, 1.0, 0.0); - glRotatef (z * 360, 0.0, 0.0, 1.0); - } + if (spin) + { + double x, y, z; + get_rotation (gp->rot, &x, &y, &z, !gp->button_down_p); + glRotatef (x * 360, 1.0, 0.0, 0.0); + glRotatef (y * 360, 0.0, 1.0, 0.0); + glRotatef (z * 360, 0.0, 0.0, 1.0); + } - if (!planetary) { + if (!gp->planetary_p) { glPushMatrix(); glTranslatef(-3.0, -2.0, 0.0); glRotatef(gp->angle, 0.0, 0.0, 1.0); @@ -572,7 +566,7 @@ draw(ModeInfo * mi) glCallList(gp->gear3); glPopMatrix(); - } else { /* planetary */ + } else { /* gp->planetary_p */ glScalef(0.8, 0.8, 0.8); @@ -620,8 +614,8 @@ draw(ModeInfo * mi) /* new window size or exposure */ -void -reshape_gears(ModeInfo *mi, int width, int height) +ENTRYPOINT void +reshape_gears (ModeInfo *mi, int width, int height) { GLfloat h = (GLfloat) height / (GLfloat) width; @@ -645,18 +639,12 @@ static void pinit(ModeInfo * mi) { gearsstruct *gp = &gears[MI_SCREEN(mi)]; - static GLfloat pos[4] = - {5.0, 5.0, 10.0, 1.0}; - static GLfloat red[4] = - {0.8, 0.1, 0.0, 1.0}; - static GLfloat green[4] = - {0.0, 0.8, 0.2, 1.0}; - static GLfloat blue[4] = - {0.2, 0.2, 1.0, 1.0}; - static GLfloat gray[4] = - {0.5, 0.5, 0.5, 1.0}; - static GLfloat white[4] = - {1.0, 1.0, 1.0, 1.0}; + static const GLfloat pos[4] = {5.0, 5.0, 10.0, 1.0}; + static const GLfloat red[4] = {0.8, 0.1, 0.0, 1.0}; + static const GLfloat green[4] = {0.0, 0.8, 0.2, 1.0}; + static const GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0}; + static const GLfloat gray[4] = {0.5, 0.5, 0.5, 1.0}; + static const GLfloat white[4] = {1.0, 1.0, 1.0, 1.0}; int wire = MI_IS_WIREFRAME(mi); int mono = MI_IS_MONO(mi); @@ -682,7 +670,7 @@ pinit(ModeInfo * mi) /* make the gears */ - if (! planetary) { + if (! gp->planetary_p) { gp->gear1 = glGenLists(1); glNewList(gp->gear1, GL_COMPILE); @@ -735,7 +723,7 @@ pinit(ModeInfo * mi) if (!wire) glEnable(GL_NORMALIZE); - } else { /* planetary */ + } else { /* gp->planetary_p */ gp->gear1 = glGenLists(1); glNewList(gp->gear1, GL_COMPILE); @@ -920,13 +908,13 @@ pinit(ModeInfo * mi) } -Bool +ENTRYPOINT Bool gears_handle_event (ModeInfo *mi, XEvent *event) { gearsstruct *gp = &gears[MI_SCREEN(mi)]; if (event->xany.type == ButtonPress && - event->xbutton.button & Button1) + event->xbutton.button == Button1) { gp->button_down_p = True; gltrackball_start (gp->trackball, @@ -935,11 +923,19 @@ gears_handle_event (ModeInfo *mi, XEvent *event) return True; } else if (event->xany.type == ButtonRelease && - event->xbutton.button & Button1) + event->xbutton.button == Button1) { gp->button_down_p = False; return True; } + else if (event->xany.type == ButtonPress && + (event->xbutton.button == Button4 || + event->xbutton.button == Button5)) + { + gltrackball_mousewheel (gp->trackball, event->xbutton.button, 10, + !!event->xbutton.state); + return True; + } else if (event->xany.type == MotionNotify && gp->button_down_p) { @@ -953,8 +949,8 @@ gears_handle_event (ModeInfo *mi, XEvent *event) } -void -init_gears(ModeInfo * mi) +ENTRYPOINT void +init_gears (ModeInfo * mi) { int screen = MI_SCREEN(mi); @@ -969,6 +965,16 @@ init_gears(ModeInfo * mi) } gp = &gears[screen]; + if (mode_str && !strcasecmp (mode_str, "planetary")) + gp->planetary_p = True; + else if (mode_str && !strcasecmp (mode_str, "simple")) + gp->planetary_p = False; + else if (!mode_str || !*mode_str || !strcasecmp (mode_str, "random")) + gp->planetary_p = !(random() % 2); + else + fprintf (stderr, "%s: mode must be planetary, simple, or random", + progname); + gp->window = MI_WINDOW(mi); gp->rot = make_rotator (1, 1, 1, 1, 0, True); @@ -982,15 +988,15 @@ init_gears(ModeInfo * mi) } } -void -draw_gears(ModeInfo * mi) +ENTRYPOINT void +draw_gears (ModeInfo * mi) { gearsstruct *gp = &gears[MI_SCREEN(mi)]; Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int angle_incr = MI_CYCLES(mi) ? MI_CYCLES(mi) : 2; - if (planetary) + if (gp->planetary_p) angle_incr *= 3; if (!gp->glx_context) @@ -1009,8 +1015,8 @@ draw_gears(ModeInfo * mi) glXSwapBuffers(display, window); } -void -release_gears(ModeInfo * mi) +ENTRYPOINT void +release_gears (ModeInfo * mi) { if (gears != NULL) { int screen; @@ -1042,6 +1048,8 @@ release_gears(ModeInfo * mi) } +XSCREENSAVER_MODULE ("Gears", gears) + /*********************************************************/ #endif