-/* gears, Copyright (c) 2007 Jamie Zawinski <jwz@jwz.org>
+/* gears, Copyright (c) 2007-2014 Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
"*count: 0 \n" \
"*showFPS: False \n" \
"*wireframe: False \n" \
+ "*suppressRotationAnimation: True\n" \
-# define refresh_gears 0
+# define free_gears 0
# define release_gears 0
#undef countof
#define countof(x) (sizeof((x))/sizeof((*x)))
reshape_gears (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();
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);
- glClear(GL_COLOR_BUFFER_BIT);
-}
-
-
-ENTRYPOINT Bool
-gears_handle_event (ModeInfo *mi, XEvent *event)
-{
- gears_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))
- {
- gltrackball_mousewheel (bp->trackball, event->xbutton.button, 10,
- !!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;
- }
+# 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
- return False;
+ glClear(GL_COLOR_BUFFER_BIT);
}
-
static void
free_gear (gear *g)
{
double pix = g->tooth_h * MI_HEIGHT(mi); /* approx. tooth size in pixels */
if (pix <= 2.5) g->size = INVOLUTE_SMALL;
else if (pix <= 3.5) g->size = INVOLUTE_MEDIUM;
- else g->size = INVOLUTE_LARGE;
+ else if (pix <= 25) g->size = INVOLUTE_LARGE;
+ else g->size = INVOLUTE_HUGE;
}
g->base_p = !parent;
g4->y = 0;
g4->th = -g3->th;
+ /* rotate central gear 1/2 tooth-size if odd number of teeth */
+ if (g4->nteeth & 1)
+ g4->th -= (180.0 / g4->nteeth);
+
g0->inverted_p = True;
g0->x = 0;
g0->y = 0;
- g0->nteeth = g4->nteeth * 3;
- g0->r = g4->r * 3.05;
+ g0->nteeth = g1->nteeth * 3;
+ g0->r = g1->r * 3.05;
g0->inner_r = g0->r * 0.8;
g0->inner_r2 = 0;
g0->inner_r3 = 0;
- g0->th = -(g4->th - (180 / g0->nteeth));
- g0->ratio = g4->ratio / 3;
+ g0->th = g1->th + (180 / g0->nteeth);
+ g0->ratio = g1->ratio / 3;
g0->tooth_slope = 0;
g0->nubs = 3;
int wire = MI_IS_WIREFRAME(mi);
int i;
- if (!bps) {
- bps = (gears_configuration *)
- calloc (MI_NUM_SCREENS(mi), sizeof (gears_configuration));
- if (!bps) {
- fprintf(stderr, "%s: out of memory\n", progname);
- exit(1);
- }
-
- bp = &bps[MI_SCREEN(mi)];
- }
+ MI_INIT (mi, bps);
bp = &bps[MI_SCREEN(mi)];
glLightfv(GL_LIGHT0, GL_SPECULAR, spc);
}
- {
- double spin_speed = 0.5;
- double wander_speed = 0.01;
- double spin_accel = 0.25;
-
- bp->rot = make_rotator (do_spin ? spin_speed : 0,
- do_spin ? spin_speed : 0,
- do_spin ? spin_speed : 0,
- spin_accel,
- do_wander ? wander_speed : 0,
- True
- );
- bp->trackball = gltrackball_init ();
- }
+ if (! bp->rot)
+ {
+ double spin_speed = 0.5;
+ double wander_speed = 0.01;
+ double spin_accel = 0.25;
+
+ bp->rot = make_rotator (do_spin ? spin_speed : 0,
+ do_spin ? spin_speed : 0,
+ do_spin ? spin_speed : 0,
+ spin_accel,
+ do_wander ? wander_speed : 0,
+ True
+ );
+ bp->trackball = gltrackball_init (True);
+ }
+
+ if (bp->gears)
+ {
+ for (i = 0; i < bp->ngears; i++)
+ free_gear (bp->gears[i]);
+ free (bp->gears);
+ bp->gears = 0;
+ bp->ngears = 0;
+ }
if (!(random() % 8))
{
{
gear *g = 0;
int total_gears = MI_COUNT (mi);
- int i;
- if (total_gears <= 0)
- total_gears = 3 + abs (BELLRAND (8) - 4); /* 3 - 7, mostly 3. */
+ bp->planetary_p = False;
+
+ if (total_gears <= 0)
+ total_gears = 3 + fabs (BELLRAND (8) - 4); /* 3 - 7, mostly 3. */
bp->gears = (gear **) calloc (total_gears+2, sizeof(**bp->gears));
bp->ngears = 0;
glXSwapBuffers(dpy, window);
}
+ENTRYPOINT Bool
+gears_handle_event (ModeInfo *mi, XEvent *event)
+{
+ gears_configuration *bp = &bps[MI_SCREEN(mi)];
+
+ if (gltrackball_event_handler (event, bp->trackball,
+ MI_WIDTH (mi), MI_HEIGHT (mi),
+ &bp->button_down_p))
+ return True;
+ else if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event))
+ {
+ init_gears (mi);
+ return True;
+ }
+
+ return False;
+}
+
XSCREENSAVER_MODULE ("Gears", gears)
#endif /* USE_GL */