X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=hacks%2Fglx%2Fdangerball.c;h=ec39fbe34f0b59dfb9ea279453137c6481faae55;hp=32483a1dce2db772ecf470ccc30f60ca6896d85f;hb=4361b69d3178d7fc98d0388f9a223af6c2651aba;hpb=ffd8c0873576a9e3065696a624dce6b766b77062 diff --git a/hacks/glx/dangerball.c b/hacks/glx/dangerball.c index 32483a1d..ec39fbe3 100644 --- a/hacks/glx/dangerball.c +++ b/hacks/glx/dangerball.c @@ -1,4 +1,4 @@ -/* dangerball, Copyright (c) 2001-2004 Jamie Zawinski +/* dangerball, Copyright (c) 2001-2017 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 @@ -9,37 +9,14 @@ * implied warranty. */ -#include - -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))) @@ -53,7 +30,16 @@ extern XtAppContext app; #ifdef USE_GL /* whole file */ -#include + +#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; @@ -94,12 +80,12 @@ static argtype vars[] = { {&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; @@ -116,6 +102,14 @@ reshape_ball (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); } @@ -190,56 +184,27 @@ move_spikes (ModeInfo *mi) } -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; int wire = MI_IS_WIREFRAME(mi); - if (!bps) { - bps = (ball_configuration *) - calloc (MI_NUM_SCREENS(mi), sizeof (ball_configuration)); - if (!bps) { - fprintf(stderr, "%s: out of memory\n", progname); - exit(1); - } - - bp = &bps[MI_SCREEN(mi)]; - } - + MI_INIT (mi, bps, 0); bp = &bps[MI_SCREEN(mi)]; bp->glx_context = init_GL(mi); @@ -275,7 +240,7 @@ init_ball (ModeInfo *mi) spin_accel, do_wander ? wander_speed : 0, True); - bp->trackball = gltrackball_init (); + bp->trackball = gltrackball_init (True); } bp->ncolors = 128; @@ -303,7 +268,7 @@ init_ball (ModeInfo *mi) } -void +ENTRYPOINT void draw_ball (ModeInfo *mi) { ball_configuration *bp = &bps[MI_SCREEN(mi)]; @@ -311,16 +276,19 @@ draw_ball (ModeInfo *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); @@ -384,4 +352,6 @@ draw_ball (ModeInfo *mi) glXSwapBuffers(dpy, window); } +XSCREENSAVER_MODULE_2 ("DangerBall", dangerball, ball) + #endif /* USE_GL */