http://www.tienza.es/crux/src/www.jwz.org/xscreensaver/xscreensaver-5.05.tar.gz
[xscreensaver] / hacks / glx / klein.c
index 2f3e7e74d9915c92512fb5bcf5c818927436a997..e37767e89c0205eafbf28a5604ba80455e99f86e 100644 (file)
  */
 
 #ifdef STANDALONE
-# define PROGCLASS                                     "Klein"
-# define HACK_INIT                                     init_klein
-# define HACK_DRAW                                     draw_klein
-# define HACK_RESHAPE                          reshape_klein
-# define HACK_HANDLE_EVENT                     klein_handle_event
-# define EVENT_MASK                                    PointerMotionMask
-# define klein_opts                                    xlockmore_opts
-
-
-#define DEF_SPIN                               "True"
-#define DEF_WANDER                             "False"
-#define DEF_RANDOM                             "False"
-#define DEF_SPEED                              "150"
-
-# define DEFAULTS                                      "*delay:                20000   \n"                     \
-                                                                       "*showFPS:      False   \n"                     \
-                                                                       "*wireframe:    False   \n"                     \
-                                                                       "*random:          " DEF_RANDOM     "\n"        \
-                                                                       "*speed:           " DEF_SPEED     "\n" \
-                                                                       "*spin:        " DEF_SPIN      "\n" \
-                                                                       "*wander:      " DEF_WANDER    "\n" \
+# define DEFAULTS                                      "*delay:                20000   \n" \
+                                                                       "*showFPS:      False   \n"
 
+# define refresh_klein 0
 # include "xlockmore.h"                /* from the xscreensaver distribution */
 #else  /* !STANDALONE */
 # include "xlock.h"                    /* from the xlockmore distribution */
 
 #ifdef USE_GL
 
-#include <GL/glu.h>
+#define DEF_SPIN                               "True"
+#define DEF_WANDER                             "False"
+#define DEF_RANDOM                             "True"
+#define DEF_SPEED                              "150"
+
 #include "rotator.h"
 #include "gltrackball.h"
 
@@ -99,7 +85,7 @@ static argtype vars[] = {
 };
 
 
-ModeSpecOpt klein_opts = {countof(opts), opts, countof(vars), vars, NULL};
+ENTRYPOINT ModeSpecOpt klein_opts = {countof(opts), opts, countof(vars), vars, NULL};
 
 
 
@@ -122,6 +108,8 @@ typedef struct {
        float du, dv;
        float a, b, c;
 
+    float draw_step;
+
 } kleinstruct;
 
 static kleinstruct *klein = NULL;
@@ -131,7 +119,6 @@ static void
 draw(ModeInfo *mi)
 {
        kleinstruct *kp = &klein[MI_SCREEN(mi)];
-       static float step = 0.0;
        double u, v;
        float coord[3];
        
@@ -269,13 +256,13 @@ draw(ModeInfo *mi)
        glPopMatrix();
 
 
-       kp->a = sin(step+=0.01);
-       kp->b = cos(step+=0.01);
+       kp->a = sin(kp->draw_step+=0.01);
+       kp->b = cos(kp->draw_step+=0.01);
 }
 
 
 /* new window size or exposure */
-void
+ENTRYPOINT void
 reshape_klein(ModeInfo *mi, int width, int height)
 {
        GLfloat h = (GLfloat) height / (GLfloat) width;
@@ -295,19 +282,27 @@ reshape_klein(ModeInfo *mi, int width, int height)
 }
 
 
-Bool
+ENTRYPOINT Bool
 klein_handle_event (ModeInfo *mi, XEvent *event)
 {
        kleinstruct *kp = &klein[MI_SCREEN(mi)];
 
-       if (event->xany.type == ButtonPress && event->xbutton.button & Button1) {
+       if (event->xany.type == ButtonPress && event->xbutton.button == Button1) {
                        kp->button_down_p = True;
                        gltrackball_start (kp->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) {
+       } else if (event->xany.type == ButtonRelease && event->xbutton.button == Button1) {
                        kp->button_down_p = False;
                        return True;
-       } else if (event->xany.type == MotionNotify && kp->button_down_p) {
+       } else if (event->xany.type == ButtonPress &&
+               (event->xbutton.button == Button4 ||
+                event->xbutton.button == Button5 ||
+                event->xbutton.button == Button6 ||
+                event->xbutton.button == Button7)) {
+      gltrackball_mousewheel (kp->trackball, event->xbutton.button, 10,
+                              !!event->xbutton.state);
+      return True;
+    } else if (event->xany.type == MotionNotify && kp->button_down_p) {
                        gltrackball_track (kp->trackball, event->xmotion.x, event->xmotion.y, MI_WIDTH (mi), MI_HEIGHT (mi));
                        return True;
        }
@@ -316,7 +311,7 @@ klein_handle_event (ModeInfo *mi, XEvent *event)
 }
 
 
-void
+ENTRYPOINT void
 init_klein(ModeInfo *mi)
 {
        int      screen = MI_SCREEN(mi);
@@ -373,7 +368,7 @@ init_klein(ModeInfo *mi)
        }
 }
 
-void
+ENTRYPOINT void
 draw_klein(ModeInfo * mi)
 {
        kleinstruct *kp = &klein[MI_SCREEN(mi)];
@@ -391,7 +386,7 @@ draw_klein(ModeInfo * mi)
        glXSwapBuffers(display, window);
 }
 
-void
+ENTRYPOINT void
 release_klein(ModeInfo * mi)
 {
        if (klein != NULL) {
@@ -412,6 +407,8 @@ release_klein(ModeInfo * mi)
 }
 
 
+XSCREENSAVER_MODULE ("Klein", klein)
+
 /*********************************************************/
 
 #endif