From http://www.jwz.org/xscreensaver/xscreensaver-5.30.tar.gz
[xscreensaver] / hacks / glx / tangram.c
index 187c3a712ff1a2493660c4973fa525020c52bcb6..e05a80438e88b046d14471056a848de8c7585bdd 100644 (file)
 
 #define DEFAULTS       "*delay:        10000            \n" \
                        "*wireframe:    False         \n" \
-                       "*titleFont:  -*-times-bold-r-normal-*-180-*\n" \
-                       "*titleFont2: -*-times-bold-r-normal-*-120-*\n" \
-                       "*titleFont3: -*-times-bold-r-normal-*-80-*\n"  \
+                       "*titleFont:  -*-helvetica-medium-r-normal-*-180-*\n" \
+                       "*titleFont2: -*-helvetica-medium-r-normal-*-120-*\n" \
+                       "*titleFont3: -*-helvetica-medium-r-normal-*-80-*\n"  \
 
 # define refresh_tangram 0
 # define release_tangram 0
-# define tangram_handle_event 0
 #undef countof
 #define countof(x) (sizeof((x))/sizeof((*x)))
 
@@ -98,10 +97,8 @@ typedef struct {
     XColor *colors;
     int ccolor;
 
-    XFontStruct *xfont1;
-    XFontStruct *xfont2;
-    XFontStruct *xfont3;
-    GLuint font1_dlist, font2_dlist, font3_dlist;
+    texture_font_data *font1_data, *font2_data, *font3_data;
+
     GLuint name_list;
 
     GLfloat theta[3];
@@ -115,34 +112,38 @@ typedef struct {
 static tangram_configuration *tps = NULL;
 
 #define DEF_VIEWING_TIME "5"
-#define DEF_ROTATE_CAMERA "True"
+#define DEF_ROTATE "True"
 #define DEF_X_CAMERA_ROTATE "0.2"
 #define DEF_Y_CAMERA_ROTATE "0.5"
 #define DEF_Z_CAMERA_ROTATE "0"
-
+#define DEF_LABELS "True"
 
 static GLuint viewing_time;
 static Bool do_rotate;
+static Bool do_labels;
 static GLfloat x_camera_rotate;
 static GLfloat y_camera_rotate;
 static GLfloat z_camera_rotate;
 static int wire;
 
 static XrmOptionDescRec opts[] = {
-    {"-viewing_time", ".viewing_time", XrmoptionSepArg, 0},
+    {"-viewing_time", ".viewingTime", XrmoptionSepArg, 0},
     {"-rotate", ".rotate", XrmoptionNoArg, "True"},
     {"+rotate", ".rotate", XrmoptionNoArg, "False"},
-    {"-x_camera_rotate", ".x_camera_rotate", XrmoptionSepArg, 0},
-    {"-y_camera_rotate", ".y_camera_rotate", XrmoptionSepArg, 0},
-    {"-z_camera_rotate", ".z_camera_rotate", XrmoptionSepArg, 0}
+    {"-labels", ".labels", XrmoptionNoArg, "True"},
+    {"+labels", ".labels", XrmoptionNoArg, "False"},
+    {"-x_camera_rotate", ".xCameraRotate", XrmoptionSepArg, 0},
+    {"-y_camera_rotate", ".yCameraRotate", XrmoptionSepArg, 0},
+    {"-z_camera_rotate", ".zCameraRotate", XrmoptionSepArg, 0}
 };
 
 static argtype vars[] = {
-    {&viewing_time, "viewing_time", "Viewing Time", DEF_VIEWING_TIME, t_Int},
-    {&do_rotate, "rotate", "Rotate", DEF_ROTATE_CAMERA, t_Bool},
-    {&x_camera_rotate, "x_camera_rotate", "X Camera Rotate", DEF_X_CAMERA_ROTATE, t_Float},
-    {&y_camera_rotate, "y_camera_rotate", "Y Camera Rotate", DEF_Y_CAMERA_ROTATE, t_Float},
-    {&z_camera_rotate, "z_camera_rotate", "Z Camera Rotate", DEF_Z_CAMERA_ROTATE, t_Float}
+    {&viewing_time, "viewingTime", "ViewingTime", DEF_VIEWING_TIME, t_Int},
+    {&do_rotate, "rotate", "Rotate", DEF_ROTATE, t_Bool},
+    {&do_labels, "labels", "Labels", DEF_LABELS, t_Bool},
+    {&x_camera_rotate, "xCameraRotate", "XCameraRotate", DEF_X_CAMERA_ROTATE, t_Float},
+    {&y_camera_rotate, "yCameraRotate", "YCameraRotate", DEF_Y_CAMERA_ROTATE, t_Float},
+    {&z_camera_rotate, "zCameraRotate", "ZCameraRotate", DEF_Z_CAMERA_ROTATE, t_Float}
 };
 
 ENTRYPOINT ModeSpecOpt tangram_opts = { countof(opts), opts, countof(vars), vars, NULL };
@@ -735,9 +736,9 @@ static void draw_tangram_shape(tangram_shape ts)
 static void load_fonts(ModeInfo * mi)
 {
     tangram_configuration *tp = &tps[MI_SCREEN(mi)];
-    load_font(mi->dpy, "titleFont", &tp->xfont1, &tp->font1_dlist);
-    load_font(mi->dpy, "titleFont2", &tp->xfont2, &tp->font2_dlist);
-    load_font(mi->dpy, "titleFont3", &tp->xfont3, &tp->font3_dlist);
+    tp->font1_data = load_texture_font (mi->dpy, "titleFont");
+    tp->font2_data = load_texture_font (mi->dpy, "titleFont2");
+    tp->font3_data = load_texture_font (mi->dpy, "titleFont3");
 }
 
 static void draw_shapes(ModeInfo * mi)
@@ -752,7 +753,7 @@ static void draw_shapes(ModeInfo * mi)
     draw_tangram_shape(tp->tlg2);
     draw_tangram_shape(tp->sq);
     draw_tangram_shape(tp->rh);
-    glCallList(tp->name_list);
+    if (do_labels) glCallList(tp->name_list);
 }
 
 static void set_perspective(void)
@@ -825,13 +826,13 @@ static void init_shapes(ModeInfo * mi)
                       &tp->tlg2, &tp->sq, &tp->rh);
     get_solved_puzzle(mi, &tp->n_tsm1, &tp->n_tsm2, &tp->n_tm, &tp->n_tlg1,
                       &tp->n_tlg2, &tp->n_sq, &tp->n_rh);
-    tp->tsm1.dl = get_sm_tri_dl(wire);
-    tp->tsm2.dl = get_sm_tri_dl(wire);
-    tp->tm.dl = get_md_tri_dl(wire);
-    tp->tlg1.dl = get_lg_tri_dl(wire);
-    tp->tlg2.dl = get_lg_tri_dl(wire);
-    tp->sq.dl = get_square_dl(wire);
-    tp->rh.dl = get_rhomboid_dl(wire);
+    tp->tsm1.dl = tangram_get_sm_tri_dl(wire);
+    tp->tsm2.dl = tangram_get_sm_tri_dl(wire);
+    tp->tm.dl = tangram_get_md_tri_dl(wire);
+    tp->tlg1.dl = tangram_get_lg_tri_dl(wire);
+    tp->tlg2.dl = tangram_get_lg_tri_dl(wire);
+    tp->sq.dl = tangram_get_square_dl(wire);
+    tp->rh.dl = tangram_get_rhomboid_dl(wire);
 }
 
 static void gl_init(ModeInfo * mi)
@@ -876,8 +877,6 @@ ENTRYPOINT void init_tangram(ModeInfo * mi)
             fprintf(stderr, "%s: out of memory\n", progname);
             exit(1);
         }
-
-        tp = &tps[MI_SCREEN(mi)];
     }
 
     tp = &tps[MI_SCREEN(mi)];
@@ -886,8 +885,12 @@ ENTRYPOINT void init_tangram(ModeInfo * mi)
         gl_init(mi);
     }
 
+    reshape_tangram (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
+
     wire = MI_IS_WIREFRAME(mi);
 
+    tp->name_list = glGenLists(1);
+
     load_fonts(mi);
     init_shapes(mi);
 
@@ -1025,34 +1028,52 @@ ENTRYPOINT void draw_tangram(ModeInfo * mi)
     glPushMatrix();
 
     glLoadIdentity();
-    glNewList(tp->name_list, GL_COMPILE);
-    {
-        XFontStruct *f;
-        GLuint fl;
+    if (do_labels)
+      {
+        texture_font_data *f;
         if (MI_WIDTH(mi) >= 500 && MI_HEIGHT(mi) >= 375)
-            f = tp->xfont1, fl = tp->font1_dlist;
+            f = tp->font1_data;
         else if (MI_WIDTH(mi) >= 350 && MI_HEIGHT(mi) >= 260)
-            f = tp->xfont2, fl = tp->font2_dlist;
+            f = tp->font2_data;
         else
-            f = tp->xfont3, fl = tp->font3_dlist;
+            f = tp->font3_data;
 
+        glNewList(tp->name_list, GL_COMPILE);
         glColor3f(0.8, 0.8, 0);
-        print_gl_string(mi->dpy, f, fl,
+        print_gl_string(mi->dpy, f,
                         mi->xgwa.width, mi->xgwa.height,
-                        10, mi->xgwa.height - 10, tp->pn);
-    }
-    glEndList();
+                        10, mi->xgwa.height - 10, tp->pn, False);
+        glEndList();
+      }
 
     glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
     glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 128);
 
     draw_shapes(mi);
 
+    if (mi->fps_p) do_fps (mi);
+
     glFlush();
     glPopMatrix();
     glXSwapBuffers(dpy, window);
 }
 
+ENTRYPOINT Bool
+tangram_handle_event (ModeInfo *mi, XEvent *event)
+{
+  tangram_configuration *tp = &tps[MI_SCREEN(mi)];
+
+  if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event))
+    {
+      tp->display_counter = 0;
+      return True;
+    }
+
+  return False;
+}
+
+
+
 XSCREENSAVER_MODULE ("Tangram", tangram)
 
 #endif                          /* USE_GL */