X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fkaleidocycle.c;h=884400f8c65256554ac7fb0419b59fc3dc25be5d;hb=39809ded547bdbb08207d3e514950425215b4410;hp=025e45b40f284c9cca869b59e8c535adc1dda79f;hpb=4ade52359b6eba3621566dac79793a33aa4c915f;p=xscreensaver diff --git a/hacks/glx/kaleidocycle.c b/hacks/glx/kaleidocycle.c index 025e45b4..884400f8 100644 --- a/hacks/glx/kaleidocycle.c +++ b/hacks/glx/kaleidocycle.c @@ -1,4 +1,4 @@ -/* kaleidocycle, Copyright (c) 2013 Jamie Zawinski +/* kaleidocycle, Copyright (c) 2013-2014 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -19,8 +19,9 @@ "*count: 16 \n" \ "*showFPS: False \n" \ "*wireframe: False \n" \ + "*suppressRotationAnimation: True\n" \ -# define refresh_kaleidocycle 0 +# define free_kaleidocycle 0 # define release_kaleidocycle 0 #undef countof #define countof(x) (sizeof((x))/sizeof((*x))) @@ -31,6 +32,7 @@ #include "rotator.h" #include "gltrackball.h" #include +#include #ifdef USE_GL /* whole file */ @@ -88,8 +90,15 @@ ENTRYPOINT void reshape_kaleidocycle (ModeInfo *mi, int width, int height) { GLfloat h = (GLfloat) height / (GLfloat) width; + int y = 0; - glViewport (0, 0, (GLint) width, (GLint) height); + if (width > height * 5) { /* tiny window: show middle */ + height = width * 9/16; + y = -height/2; + h = height / (GLfloat) width; + } + + glViewport (0, y, (GLint) width, (GLint) height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -101,6 +110,14 @@ reshape_kaleidocycle (ModeInfo *mi, int width, int height) 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); +# ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */ + { + int o = (int) current_device_rotation(); + if (o != 0 && o != 180 && o != -180) + glScalef (1/h, 1/h, 1/h); + } +# endif + glClear(GL_COLOR_BUFFER_BIT); } @@ -110,37 +127,38 @@ kaleidocycle_handle_event (ModeInfo *mi, XEvent *event) { kaleidocycle_configuration *bp = &bps[MI_SCREEN(mi)]; - if (event->xany.type == ButtonPress && - event->xbutton.button == Button1) + if (gltrackball_event_handler (event, bp->trackball, + MI_WIDTH (mi), MI_HEIGHT (mi), + &bp->button_down_p)) + return True; + else if (event->xany.type == KeyPress) { - bp->button_down_p = True; - gltrackball_start (bp->trackball, - event->xbutton.x, event->xbutton.y, - MI_WIDTH (mi), MI_HEIGHT (mi)); - return True; - } - else if (event->xany.type == ButtonRelease && - event->xbutton.button == Button1) - { - bp->button_down_p = False; - return True; - } - else if (event->xany.type == ButtonPress && - (event->xbutton.button == Button4 || - event->xbutton.button == Button5 || - event->xbutton.button == Button6 || - event->xbutton.button == Button7)) - { - gltrackball_mousewheel (bp->trackball, event->xbutton.button, 5, - !!event->xbutton.state); - return True; + KeySym keysym; + char c = 0; + XLookupString (&event->xkey, &c, 1, &keysym, 0); + if (c == '+' || c == '.' || c == '>' || c == '=' || c == '+' || + keysym == XK_Right || keysym == XK_Up || keysym == XK_Next) + { + bp->mode = IN; + return True; + } + else if ((c == '-' || c == ',' || c == '<' || c == '-' || c == '_' || + keysym == XK_Left || keysym == XK_Down || keysym == XK_Prior) && + bp->count > bp->min_count) + { + bp->mode = OUT; + return True; + } + else if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event)) + goto DEF; } - else if (event->xany.type == MotionNotify && - bp->button_down_p) + else if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event)) { - gltrackball_track (bp->trackball, - event->xmotion.x, event->xmotion.y, - MI_WIDTH (mi), MI_HEIGHT (mi)); + DEF: + if (bp->count <= bp->min_count) + bp->mode = IN; + else + bp->mode = (random() & 1) ? IN : OUT; return True; } @@ -156,14 +174,7 @@ init_kaleidocycle (ModeInfo *mi) int wire = MI_IS_WIREFRAME(mi); int i; - if (!bps) { - bps = (kaleidocycle_configuration *) - calloc (MI_NUM_SCREENS(mi), sizeof (kaleidocycle_configuration)); - if (!bps) { - fprintf(stderr, "%s: out of memory\n", progname); - exit(1); - } - } + MI_INIT (mi, bps); bp = &bps[MI_SCREEN(mi)]; @@ -227,7 +238,7 @@ init_kaleidocycle (ModeInfo *mi) False); bp->rot2 = make_rotator (twist_speed, 0, 0, twist_accel, 0, True); - bp->trackball = gltrackball_init (); + bp->trackball = gltrackball_init (True); } if (MI_COUNT(mi) < 8) MI_COUNT(mi) = 8; @@ -423,10 +434,7 @@ draw_kaleidocycle (ModeInfo *mi) (y - 0.5) * 5, (z - 0.5) * 10); - /* Do it twice because we don't track the device's orientation. */ - glRotatef( current_device_rotation(), 0, 0, 1); gltrackball_rotate (bp->trackball); - glRotatef(-current_device_rotation(), 0, 0, 1); get_rotation (bp->rot, &x, &y, &z, !bp->button_down_p); glRotatef (x * 360, 1, 0, 0);