X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fflipflop.c;h=bb21b9600a6d55a6113c8108c4df561018236a29;hb=49f5b54f312fe4ac2e9bc47581a72451bd0e8439;hp=6e1593d9b106b72e61848091620f6e3df3afd44e;hpb=6a1da724858673ac40aa13a9612340d8bed8c7b9;p=xscreensaver diff --git a/hacks/glx/flipflop.c b/hacks/glx/flipflop.c index 6e1593d9..bb21b960 100644 --- a/hacks/glx/flipflop.c +++ b/hacks/glx/flipflop.c @@ -9,30 +9,16 @@ * implied warranty. */ -#include - -#include -#include -#include -#include - #define BOARDSIZE 9 #define NUMSQUARES 76 #define HALFTHICK 0.04 #ifdef STANDALONE -# define PROGCLASS "Flipflop" -# define HACK_INIT init_flipflop -# define HACK_DRAW draw_flipflop -# define HACK_RESHAPE reshape_flipflop -# define HACK_HANDLE_EVENT flipflop_handle_event -# define EVENT_MASK PointerMotionMask -# define flipflop_opts xlockmore_opts - #define DEFAULTS "*delay: 20000 \n" \ "*showFPS: False \n" \ "*wireframe: False \n" +# define refresh_flipflop 0 # include "xlockmore.h" #else @@ -41,15 +27,14 @@ #ifdef USE_GL -#include #include "gltrackball.h" #undef countof #define countof(x) (sizeof((x))/sizeof((*x))) static XrmOptionDescRec opts[] = { - {"+rotate", ".flipflop.rotate", XrmoptionNoArg, (caddr_t) "false" }, - {"-rotate", ".flipflop.rotate", XrmoptionNoArg, (caddr_t) "true" }, + {"+rotate", ".flipflop.rotate", XrmoptionNoArg, "false" }, + {"-rotate", ".flipflop.rotate", XrmoptionNoArg, "true" }, }; @@ -57,10 +42,10 @@ static XrmOptionDescRec opts[] = { static int rotate, wire, clearbits; static argtype vars[] = { - {(caddr_t *) &rotate, "rotate", "Rotate", "True", t_Bool}, + { &rotate, "rotate", "Rotate", "True", t_Bool}, }; -ModeSpecOpt flipflop_opts = {countof(opts), opts, countof(vars), vars, NULL}; +ENTRYPOINT ModeSpecOpt flipflop_opts = {countof(opts), opts, countof(vars), vars, NULL}; #ifdef USE_MODULES ModStruct flipflop_description = @@ -71,15 +56,6 @@ ModStruct flipflop_description = #endif -typedef struct { - GLXContext *glx_context; - Window window; - trackball_state *trackball; - Bool button_down_p; -} Flipflopcreen; - -static Flipflopcreen *qs = NULL; - typedef struct{ /* 2D array specifying which squares are where (to avoid collisions) */ /* -1 means empty otherwise integer represents square index 0 - n-1 */ @@ -100,17 +76,22 @@ typedef struct{ } randsheet; -/*** ADDED RANDSHEET VARS ***/ +typedef struct { + GLXContext *glx_context; + Window window; + trackball_state *trackball; + Bool button_down_p; + + randsheet sheet; -static randsheet MyRandSheet; + double theta; + float flipspeed; /* amount of flip. 1 is a entire flip */ + float reldist; /* relative distace of camera from center */ + float energy; /* likelehood a square will attempt a move */ -static double theta = 0.0; -/* amount which the square flips. 1 is a entire flip */ -static float flipspeed = 0.03; -/* relative distace of camera from center */ -static float reldist = 1; -/* likelehood a square will attempt a move */ -static float energy = 40; +} Flipflopcreen; + +static Flipflopcreen *qs = NULL; static void randsheet_initialize( randsheet *rs ); @@ -119,7 +100,7 @@ static int randsheet_new_move( randsheet* rs ); static void randsheet_move( randsheet *rs, float rot ); static void randsheet_draw( randsheet *rs ); static void setup_lights(void); -static void drawBoard(void); +static void drawBoard(Flipflopcreen *); static void display(Flipflopcreen *c); static void draw_sheet(void); @@ -140,13 +121,13 @@ setup_lights(void) glEnable(GL_LIGHT0); } -Bool +ENTRYPOINT Bool flipflop_handle_event (ModeInfo *mi, XEvent *event) { Flipflopcreen *c = &qs[MI_SCREEN(mi)]; if (event->xany.type == ButtonPress && - event->xbutton.button & Button1) + event->xbutton.button == Button1) { c->button_down_p = True; gltrackball_start (c->trackball, @@ -155,11 +136,19 @@ flipflop_handle_event (ModeInfo *mi, XEvent *event) return True; } else if (event->xany.type == ButtonRelease && - event->xbutton.button & Button1) + event->xbutton.button == Button1) { c->button_down_p = False; return True; } + else if (event->xany.type == ButtonPress && + (event->xbutton.button == Button4 || + event->xbutton.button == Button5)) + { + gltrackball_mousewheel (c->trackball, event->xbutton.button, 5, + !event->xbutton.state); + return True; + } else if (event->xany.type == MotionNotify && c->button_down_p) { @@ -174,13 +163,13 @@ flipflop_handle_event (ModeInfo *mi, XEvent *event) /* draw board */ static void -drawBoard(void) +drawBoard(Flipflopcreen *c) { int i; - for( i=0; i < (energy) ; i++ ) - randsheet_new_move( &MyRandSheet ); - randsheet_move( &MyRandSheet, flipspeed * 3.14159 ); - randsheet_draw( &MyRandSheet ); + for( i=0; i < (c->energy) ; i++ ) + randsheet_new_move( &c->sheet ); + randsheet_move( &c->sheet, c->flipspeed * 3.14159 ); + randsheet_draw( &c->sheet ); } @@ -201,20 +190,20 @@ display(Flipflopcreen *c) /** setup perspectif */ - glTranslatef(0.0, 0.0, -reldist*BOARDSIZE); + glTranslatef(0.0, 0.0, -c->reldist*BOARDSIZE); glRotatef(22.5, 1.0, 0.0, 0.0); gltrackball_rotate (c->trackball); - glRotatef(theta*100, 0.0, 1.0, 0.0); + glRotatef(c->theta*100, 0.0, 1.0, 0.0); glTranslatef(-0.5*BOARDSIZE, 0.0, -0.5*BOARDSIZE); - drawBoard(); + drawBoard(c); if (!c->button_down_p) - theta += .001; + c->theta += .001; } -void +ENTRYPOINT void reshape_flipflop(ModeInfo *mi, int width, int height) { GLfloat h = (GLfloat) height / (GLfloat) width; @@ -225,7 +214,7 @@ reshape_flipflop(ModeInfo *mi, int width, int height) glMatrixMode(GL_MODELVIEW); } -void +ENTRYPOINT void init_flipflop(ModeInfo *mi) { int screen = MI_SCREEN(mi); @@ -240,6 +229,10 @@ init_flipflop(ModeInfo *mi) c->window = MI_WINDOW(mi); c->trackball = gltrackball_init (); + c->flipspeed = 0.03; + c->reldist = 1; + c->energy = 40; + if((c->glx_context = init_GL(mi))) reshape_flipflop(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); else @@ -257,12 +250,12 @@ init_flipflop(ModeInfo *mi) clearbits |= GL_DEPTH_BUFFER_BIT; glEnable(GL_CULL_FACE); glCullFace(GL_BACK); - randsheet_initialize( &MyRandSheet ); + randsheet_initialize( &c->sheet ); } -void +ENTRYPOINT void draw_flipflop(ModeInfo *mi) { Flipflopcreen *c = &qs[MI_SCREEN(mi)]; @@ -286,13 +279,14 @@ draw_flipflop(ModeInfo *mi) } -void +ENTRYPOINT void release_flipflop(ModeInfo *mi) { if(qs) free((void *) qs); + qs = 0; - FreeAllGL(MI); + FreeAllGL(mi); } /*** ADDED RANDSHEET FUNCTIONS ***/ @@ -585,4 +579,6 @@ randsheet_draw( randsheet *rs ) /**** END RANDSHEET FUNCTIONS ***/ +XSCREENSAVER_MODULE ("Flipflop", flipflop) + #endif