X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Ftronbit.c;h=832d329d1d65cec4f7f2e2fd75df03aa601c7b08;hb=4361b69d3178d7fc98d0388f9a223af6c2651aba;hp=261aca3c2f214263ea111e8c05ebc4af9bea97ec;hpb=f8cf5ac7b2f53510f80a0eaf286a25298be17bfe;p=xscreensaver diff --git a/hacks/glx/tronbit.c b/hacks/glx/tronbit.c index 261aca3c..832d329d 100644 --- a/hacks/glx/tronbit.c +++ b/hacks/glx/tronbit.c @@ -1,4 +1,4 @@ -/* tronbit, Copyright (c) 2011-2012 Jamie Zawinski +/* tronbit, Copyright (c) 2011-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 @@ -301,7 +301,7 @@ draw_histogram (ModeInfo *mi, GLfloat ratio) glPushMatrix(); glLoadIdentity(); - glRotatef(current_device_rotation(), 0, 0, 1); + /* glRotatef(current_device_rotation(), 0, 0, 1); */ glOrtho (0, mi->xgwa.width, 0, mi->xgwa.height, -1, 1); for (k = 0; k < overlays; k++) @@ -316,9 +316,11 @@ draw_histogram (ModeInfo *mi, GLfloat ratio) j = bp->histogram_fp + 1; for (i = 0; i < samples; i++) { - GLfloat x = i; - GLfloat y = bp->histogram[j]; - GLfloat z = 0; + GLfloat x, y, z; + if (j >= samples) j = 0; + x = i; + y = bp->histogram[j]; + z = 0; y += (int) ((random() % 16) - 8); y += 16; /* margin at bottom of screen */ @@ -327,7 +329,7 @@ draw_histogram (ModeInfo *mi, GLfloat ratio) y *= scaley; glVertex3f (x, y, z); - if (++j >= samples) j = 0; + ++j; polys++; } glEnd(); @@ -373,45 +375,22 @@ bit_handle_event (ModeInfo *mi, XEvent *event) { bit_configuration *bp = &bps[MI_SCREEN(mi)]; - if (event->xany.type == ButtonPress && - event->xbutton.button == Button1) - { - 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, 3, - !!event->xbutton.state); - return True; - } - else if (event->xany.type == MotionNotify && - bp->button_down_p) - { - gltrackball_track (bp->trackball, - event->xmotion.x, event->xmotion.y, - MI_WIDTH (mi), MI_HEIGHT (mi)); - return True; - } + 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) { KeySym keysym; char c = 0; XLookupString (&event->xkey, &c, 1, &keysym, 0); - if (c == ' ' || c == '1' || c == '0') + + if (keysym == XK_Up || keysym == XK_Left || keysym == XK_Prior) + c = '1'; + else if (keysym == XK_Down || keysym == XK_Right || keysym == XK_Next) + c = '0'; + + if (c == ' ' || c == '\t' || c == '\n' || c == '1' || c == '0') { bp->kbd = c; return True; @@ -428,14 +407,7 @@ init_bit (ModeInfo *mi) bit_configuration *bp; int i; - if (!bps) { - bps = (bit_configuration *) - calloc (MI_NUM_SCREENS(mi), sizeof (bit_configuration)); - if (!bps) { - fprintf(stderr, "%s: out of memory\n", progname); - exit(1); - } - } + MI_INIT (mi, bps, NULL); bp = &bps[MI_SCREEN(mi)]; @@ -454,7 +426,7 @@ init_bit (ModeInfo *mi) spin_accel, do_wander ? wander_speed : 0, False); - bp->trackball = gltrackball_init (); + bp->trackball = gltrackball_init (False); } for (i = 0; i < countof(bp->dlists); i++) @@ -504,20 +476,25 @@ draw_bit (ModeInfo *mi) } glPushMatrix (); - glRotatef(current_device_rotation(), 0, 0, 1); - glScalef(1.1, 1.1, 1.1); +# ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */ + { + GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi); + int o = (int) current_device_rotation(); + if (o != 0 && o != 180 && o != -180) + glScalef (1/h, 1/h, 1/h); + glRotatef(o, 0, 0, 1); + } +# endif + { double x, y, z; get_position (bp->rot, &x, &y, &z, !bp->button_down_p); glTranslatef((x - 0.5) * 11, (y - 0.5) * 5, (z - 0.5) * 3); - - 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.0, 0.0);