-/* dangerball, Copyright (c) 2001, 2002, 2003 Jamie Zawinski <jwz@jwz.org>
+/* dangerball, Copyright (c) 2001-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
* implied warranty.
*/
-#include <X11/Intrinsic.h>
-
-extern XtAppContext app;
-
-#define PROGCLASS "DangerBall"
-#define HACK_INIT init_ball
-#define HACK_DRAW draw_ball
-#define HACK_RESHAPE reshape_ball
-#define HACK_HANDLE_EVENT ball_handle_event
-#define EVENT_MASK PointerMotionMask
-#define sws_opts xlockmore_opts
-
-#define DEF_SPIN "True"
-#define DEF_WANDER "True"
-#define DEF_SPEED "0.05"
-
#define DEFAULTS "*delay: 30000 \n" \
"*count: 30 \n" \
"*showFPS: False \n" \
"*wireframe: False \n" \
- "*speed: " DEF_SPEED " \n" \
- "*spin: " DEF_SPIN "\n" \
- "*wander: " DEF_WANDER "\n" \
-
-
-#define SPIKE_FACES 12 /* how densely to render spikes */
-#define SMOOTH_SPIKES True
-#define SPHERE_SLICES 32 /* how densely to render spheres */
-#define SPHERE_STACKS 16
-
+ "*suppressRotationAnimation: True\n" \
+# define refresh_ball 0
+# define release_ball 0
#undef countof
#define countof(x) (sizeof((x))/sizeof((*x)))
#ifdef USE_GL /* whole file */
-#include <GL/glu.h>
+
+#define DEF_SPIN "True"
+#define DEF_WANDER "True"
+#define DEF_SPEED "0.05"
+
+#define SPIKE_FACES 12 /* how densely to render spikes */
+#define SMOOTH_SPIKES True
+#define SPHERE_SLICES 32 /* how densely to render spheres */
+#define SPHERE_STACKS 16
+
typedef struct {
GLXContext *glx_context;
{&speed, "speed", "Speed", DEF_SPEED, t_Float},
};
-ModeSpecOpt sws_opts = {countof(opts), opts, countof(vars), vars, NULL};
+ENTRYPOINT ModeSpecOpt ball_opts = {countof(opts), opts, countof(vars), vars, NULL};
/* Window management, etc
*/
-void
+ENTRYPOINT void
reshape_ball (ModeInfo *mi, int width, int height)
{
GLfloat h = (GLfloat) height / (GLfloat) width;
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);
}
}
-Bool
+ENTRYPOINT Bool
ball_handle_event (ModeInfo *mi, XEvent *event)
{
ball_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 == 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;
return False;
}
-void
+ENTRYPOINT void
init_ball (ModeInfo *mi)
{
ball_configuration *bp;
fprintf(stderr, "%s: out of memory\n", progname);
exit(1);
}
-
- bp = &bps[MI_SCREEN(mi)];
}
bp = &bps[MI_SCREEN(mi)];
{
double spin_speed = 10.0;
- double wander_speed = 0.15;
+ double wander_speed = 0.12;
double spin_accel = 2.0;
bp->rot = make_rotator (do_spin ? spin_speed : 0,
spin_accel,
do_wander ? wander_speed : 0,
True);
- bp->trackball = gltrackball_init ();
+ bp->trackball = gltrackball_init (True);
}
bp->ncolors = 128;
}
-void
+ENTRYPOINT void
draw_ball (ModeInfo *mi)
{
ball_configuration *bp = &bps[MI_SCREEN(mi)];
Window window = MI_WINDOW(mi);
int c2;
- static GLfloat bcolor[4] = {0.0, 0.0, 0.0, 1.0};
- static GLfloat scolor[4] = {0.0, 0.0, 0.0, 1.0};
- static GLfloat bspec[4] = {1.0, 1.0, 1.0, 1.0};
- static GLfloat sspec[4] = {0.0, 0.0, 0.0, 1.0};
- static GLfloat bshiny = 128.0;
- static GLfloat sshiny = 0.0;
+ static const GLfloat bspec[4] = {1.0, 1.0, 1.0, 1.0};
+ static const GLfloat sspec[4] = {0.0, 0.0, 0.0, 1.0};
+ static const GLfloat bshiny = 128.0;
+ static const GLfloat sshiny = 0.0;
+
+ GLfloat bcolor[4] = {0.0, 0.0, 0.0, 1.0};
+ GLfloat scolor[4] = {0.0, 0.0, 0.0, 1.0};
if (!bp->glx_context)
return;
+ glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(bp->glx_context));
+
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glXSwapBuffers(dpy, window);
}
+XSCREENSAVER_MODULE_2 ("DangerBall", dangerball, ball)
+
#endif /* USE_GL */