X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fcrackberg.c;h=64e53028c6d04ca70bc211afb486fa897d5ddbe0;hb=6afd6db0ae9396cd7ff897ade597cd5483f49b0e;hp=95787ab08ab6a534f0141d2babaf3df80ececc9f;hpb=49f5b54f312fe4ac2e9bc47581a72451bd0e8439;p=xscreensaver diff --git a/hacks/glx/crackberg.c b/hacks/glx/crackberg.c index 95787ab0..64e53028 100644 --- a/hacks/glx/crackberg.c +++ b/hacks/glx/crackberg.c @@ -1,8 +1,10 @@ /*************************** ** crackberg; Matus Telgarsky [ catachresis@cmu.edu ] 2005 ** */ -#define XK_MISCELLANY -#include +#ifndef HAVE_COCOA +# define XK_MISCELLANY +# include +#endif #define DEFAULTS "*delay: 20000 \n" \ "*showFPS: False \n" \ @@ -18,9 +20,9 @@ #define DEF_NSUBDIVS "4" #define DEF_BORING "False" #define DEF_CRACK "True" -#define DEF_NOWATER "False" +#define DEF_WATER "True" #define DEF_FLAT "True" -#define DEF_COLOR "plain" +#define DEF_COLOR "random" #define DEF_LIT "True" #define DEF_VISIBILITY "0.6" #define DEF_LETTERBOX "False" @@ -129,6 +131,10 @@ struct _cberg_state { double vs0r,vs0g,vs0b, vs1r, vs1g, vs1b, vf0r,vf0g,vf0b, vf1r, vf1g, vf1b; + + Bool button_down_p; + int mouse_x, mouse_y; + struct timeval paused; }; @@ -138,7 +144,7 @@ struct _cberg_state { ** */ static unsigned int nsubdivs; -static Bool crack, boring, nowater, flat, lit, letterbox; +static Bool crack, boring, do_water, flat, lit, letterbox; static float visibility; static char *color; @@ -149,8 +155,8 @@ static XrmOptionDescRec opts[] = { {"-boring", ".boring", XrmoptionNoArg, "True"}, {"-crack", ".crack", XrmoptionNoArg, "True"}, {"-no-crack", ".crack", XrmoptionNoArg, "False"}, - {"-water", ".nowater", XrmoptionNoArg, "False"}, - {"-no-water", ".nowater", XrmoptionNoArg, "True"}, + {"-water", ".water", XrmoptionNoArg, "True"}, + {"-no-water", ".water", XrmoptionNoArg, "False"}, {"-flat", ".flat", XrmoptionNoArg, "True"}, {"-no-flat", ".flat", XrmoptionNoArg, "False"}, {"-color", ".color", XrmoptionSepArg, 0}, @@ -164,7 +170,7 @@ static argtype vars[] = { {&nsubdivs, "nsubdivs", "nsubdivs", DEF_NSUBDIVS, t_Int}, {&boring, "boring", "boring", DEF_BORING, t_Bool}, {&crack, "crack", "crack", DEF_CRACK, t_Bool}, - {&nowater, "nowater", "nowater", DEF_NOWATER, t_Bool}, + {&do_water, "water", "water", DEF_WATER, t_Bool}, {&flat, "flat", "flat", DEF_FLAT, t_Bool}, {&color, "color", "color", DEF_COLOR, t_String}, {&lit, "lit", "lit", DEF_LIT, t_Bool}, @@ -430,7 +436,7 @@ static inline void trile_draw_vertex(cberg_state *cberg, unsigned int ix, { glColor3d(0.0, 0.0, 0.0); /* don't ask. my card breaks otherwise. */ - if (!nowater && zcur <= 0.0) { + if (do_water && zcur <= 0.0) { cberg->color->water(cberg, zcur); /* XXX use average-of-3 for color when flat?*/ if (lit) glNormal3d(0.0,0.0,1.0); glVertex3d(x, y, 0.0); @@ -1205,7 +1211,9 @@ ENTRYPOINT void init_crackberg (ModeInfo *mi) glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glShadeModel((flat) ? GL_FLAT : GL_SMOOTH); +# ifndef HAVE_JWZGLES /* #### glPolygonMode other than GL_FILL unimplemented */ glPolygonMode(GL_FRONT_AND_BACK, (MI_IS_WIREFRAME(mi)) ? GL_LINE : GL_FILL); +# endif if (lit) { glEnable(GL_LIGHTING); @@ -1244,11 +1252,19 @@ ENTRYPOINT void reshape_crackberg (ModeInfo *mi, int w, int h) ENTRYPOINT Bool crackberg_handle_event (ModeInfo *mi, XEvent *ev) { cberg_state *cberg = &cbergs[MI_SCREEN(mi)]; + KeySym keysym = 0; + char c = 0; + if (ev->xany.type == KeyPress || ev->xany.type == KeyRelease) + XLookupString (&ev->xkey, &c, 1, &keysym, 0); if (ev->xany.type == KeyPress) { - switch (XKeycodeToKeysym(mi->dpy, ev->xkey.keycode, 0)) { + switch (keysym) { case XK_Left: cberg->motion_state |= MOTION_LROT; break; + case XK_Prior: cberg->motion_state |= MOTION_LROT; break; case XK_Right: cberg->motion_state |= MOTION_RROT; break; + case XK_Next: cberg->motion_state |= MOTION_RROT; break; + case XK_Down: cberg->motion_state |= MOTION_BACK; break; + case XK_Up: cberg->motion_state |= MOTION_FORW; break; case '1': cberg->motion_state |= MOTION_DEC; break; case '2': cberg->motion_state |= MOTION_INC; break; case 'a': cberg->motion_state |= MOTION_LEFT; break; @@ -1272,9 +1288,13 @@ ENTRYPOINT Bool crackberg_handle_event (ModeInfo *mi, XEvent *ev) } #endif - switch (XKeycodeToKeysym(mi->dpy, ev->xkey.keycode, 0)) { + switch (keysym) { case XK_Left: cberg->motion_state &= ~MOTION_LROT; break; + case XK_Prior: cberg->motion_state &= ~MOTION_LROT; break; case XK_Right: cberg->motion_state &= ~MOTION_RROT; break; + case XK_Next: cberg->motion_state &= ~MOTION_RROT; break; + case XK_Down: cberg->motion_state &= ~MOTION_BACK; break; + case XK_Up: cberg->motion_state &= ~MOTION_FORW; break; case '1': cberg->motion_state &= ~MOTION_DEC; break; case '2': cberg->motion_state &= ~MOTION_INC; break; case 'a': cberg->motion_state &= ~MOTION_LEFT; break; @@ -1287,6 +1307,38 @@ ENTRYPOINT Bool crackberg_handle_event (ModeInfo *mi, XEvent *ev) break; default: return False; } + } else if (ev->xany.type == ButtonPress && + ev->xbutton.button == Button1) { + cberg->button_down_p = True; + cberg->mouse_x = ev->xbutton.x; + cberg->mouse_y = ev->xbutton.y; + cberg->motion_state = MOTION_MANUAL; + cberg->paused.tv_sec = 0; + } else if (ev->xany.type == ButtonRelease && + ev->xbutton.button == Button1) { + cberg->button_down_p = False; + cberg->motion_state = MOTION_AUTO; + /* After mouse-up, don't go back into auto-motion mode for a second, so + that repeated click-and-drag gestures don't fight with auto-motion. */ + gettimeofday(&cberg->paused, NULL); + } else if (ev->xany.type == MotionNotify && + cberg->button_down_p) { + int dx = ev->xmotion.x - cberg->mouse_x; + int dy = ev->xmotion.y - cberg->mouse_y; + cberg->mouse_x = ev->xmotion.x; + cberg->mouse_y = ev->xmotion.y; + cberg->motion_state = MOTION_MANUAL; + + /* Take the larger dimension, since motion_state doesn't scale */ + if (dx > 0 && dx > dy) dy = 0; + if (dx < 0 && dx < dy) dy = 0; + if (dy > 0 && dy > dx) dx = 0; + if (dy < 0 && dy < dx) dx = 0; + + if (dx > 0) cberg->motion_state |= MOTION_LEFT; + else if (dx < 0) cberg->motion_state |= MOTION_RIGHT; + else if (dy > 0) cberg->motion_state |= MOTION_FORW; + else if (dy < 0) cberg->motion_state |= MOTION_BACK; } else return False; return True; @@ -1310,7 +1362,8 @@ ENTRYPOINT void draw_crackberg (ModeInfo *mi) cberg->elapsed = cur_frame - cberg->prev_frame; - if (cberg->motion_state == MOTION_AUTO) { + if (cberg->motion_state == MOTION_AUTO && + cberg->paused.tv_sec < cur_frame_t.tv_sec) { cberg->x += cberg->dx * cberg->elapsed; cberg->y += cberg->dy * cberg->elapsed; /* cberg->z */ @@ -1367,6 +1420,7 @@ ENTRYPOINT void draw_crackberg (ModeInfo *mi) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); + glRotatef(current_device_rotation(), 0, 0, 1); gluLookAt(0,0,0, 1,0,0, 0,0,1); glLightfv(GL_LIGHT0, GL_POSITION, lpos); /*glRotated(cberg->roll, 1,0,0); / * XXX blah broken and unused for now..* /