X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Ftangram.c;h=c250f5455ea6d7176d91fdd037c21a870f2a70c2;hb=39809ded547bdbb08207d3e514950425215b4410;hp=a7af6428f88954da8d13a1398381524ab908cdda;hpb=f8cf5ac7b2f53510f80a0eaf286a25298be17bfe;p=xscreensaver diff --git a/hacks/glx/tangram.c b/hacks/glx/tangram.c index a7af6428..c250f545 100644 --- a/hacks/glx/tangram.c +++ b/hacks/glx/tangram.c @@ -1,4 +1,4 @@ -/* tangram, Copyright (c) 2005 Jeremy English +/* tangram, Copyright (c) 2005-2014 Jeremy English * * Permission to use, copy, modify, distribute, and sell this software * and its documentation for any purpose is hereby granted without @@ -18,13 +18,12 @@ #define DEFAULTS "*delay: 10000 \n" \ "*wireframe: False \n" \ - "*titleFont: -*-helvetica-medium-r-normal-*-180-*\n" \ - "*titleFont2: -*-helvetica-medium-r-normal-*-120-*\n" \ - "*titleFont3: -*-helvetica-medium-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 free_tangram 0 # define release_tangram 0 -# define tangram_handle_event 0 #undef countof #define countof(x) (sizeof((x))/sizeof((*x))) @@ -38,7 +37,7 @@ #include #include #include "tangram_shapes.h" -#include "glxfonts.h" +#include "texfont.h" typedef struct { GLubyte r; @@ -98,17 +97,7 @@ typedef struct { XColor *colors; int ccolor; -# ifdef HAVE_GLBITMAP - XFontStruct *xfont1; - XFontStruct *xfont2; - XFontStruct *xfont3; - GLuint font1_dlist, font2_dlist, font3_dlist; -# else - texture_font_data *font1_data, *font2_data, *font3_data; -# endif - - GLuint name_list; - + texture_font_data *font1_data, *font2_data, *font3_data; GLfloat theta[3]; Bool going_down[3]; @@ -744,21 +733,24 @@ static void draw_tangram_shape(tangram_shape ts) static void load_fonts(ModeInfo * mi) { tangram_configuration *tp = &tps[MI_SCREEN(mi)]; -# ifdef HAVE_GLBITMAP - 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); -# else /* !HAVE_GLBITMAP */ 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"); -# endif /* !HAVE_GLBITMAP */ } static void draw_shapes(ModeInfo * mi) { tangram_configuration *tp = &tps[MI_SCREEN(mi)]; +# ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */ + { + GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi); + int o = (int) current_device_rotation(); + if (o != 0 && o != 180 && o != -180) + glScalef (h, 1/h, 1); + } +# endif + draw_tangram_shape(tp->tsm1); draw_tangram_shape(tp->tsm2); @@ -767,26 +759,34 @@ static void draw_shapes(ModeInfo * mi) draw_tangram_shape(tp->tlg2); draw_tangram_shape(tp->sq); draw_tangram_shape(tp->rh); - if (do_labels) glCallList(tp->name_list); -} -static void set_perspective(void) -{ - glPushMatrix(); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(60, -1, 0.1, 50); - gluLookAt(0, 5, -5, 0, 0, 0, 0, -1, 0); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); + if (do_labels) + { + texture_font_data *f; + if (MI_WIDTH(mi) >= 500 && MI_HEIGHT(mi) >= 375) + f = tp->font1_data; + else if (MI_WIDTH(mi) >= 350 && MI_HEIGHT(mi) >= 260) + f = tp->font2_data; + else + f = tp->font3_data; + glColor3f(0.8, 0.8, 0); + print_texture_label (mi->dpy, f, + mi->xgwa.width, mi->xgwa.height, + 1, tp->pn); + } } ENTRYPOINT void reshape_tangram(ModeInfo * mi, int w, int h) { - glViewport(0, 0, w, h); - set_perspective(); - glLoadIdentity(); + int y = 0; + + if (w > h * 5) { /* tiny window: show middle */ + h = w; + y = -h/2; + } + + glViewport(0, y, w, h); } static void set_camera(tangram_configuration *tp) @@ -840,13 +840,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) @@ -884,14 +884,7 @@ ENTRYPOINT void init_tangram(ModeInfo * mi) { tangram_configuration *tp; - if (!tps) { - tps = (tangram_configuration *) - calloc(MI_NUM_SCREENS(mi), sizeof(tangram_configuration)); - if (!tps) { - fprintf(stderr, "%s: out of memory\n", progname); - exit(1); - } - } + MI_INIT (mi, tps); tp = &tps[MI_SCREEN(mi)]; @@ -899,9 +892,9 @@ ENTRYPOINT void init_tangram(ModeInfo * mi) gl_init(mi); } - wire = MI_IS_WIREFRAME(mi); + reshape_tangram (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); - tp->name_list = glGenLists(1); + wire = MI_IS_WIREFRAME(mi); load_fonts(mi); init_shapes(mi); @@ -1040,43 +1033,6 @@ ENTRYPOINT void draw_tangram(ModeInfo * mi) glPushMatrix(); glLoadIdentity(); - if (do_labels) - { -# ifdef HAVE_GLBITMAP - XFontStruct *f; - GLuint fl; -# else /* !HAVE_GLBITMAP */ - texture_font_data *f; -# endif /* !HAVE_GLBITMAP */ - if (MI_WIDTH(mi) >= 500 && MI_HEIGHT(mi) >= 375) -# ifdef HAVE_GLBITMAP - f = tp->xfont1, fl = tp->font1_dlist; -# else /* !HAVE_GLBITMAP */ - f = tp->font1_data; -# endif /* !HAVE_GLBITMAP */ - else if (MI_WIDTH(mi) >= 350 && MI_HEIGHT(mi) >= 260) -# ifdef HAVE_GLBITMAP - f = tp->xfont2, fl = tp->font2_dlist; -# else /* !HAVE_GLBITMAP */ - f = tp->font2_data; -# endif /* !HAVE_GLBITMAP */ - else -# ifdef HAVE_GLBITMAP - f = tp->xfont3, fl = tp->font3_dlist; -# else /* !HAVE_GLBITMAP */ - f = tp->font3_data; -# endif /* !HAVE_GLBITMAP */ - - glNewList(tp->name_list, GL_COMPILE); - glColor3f(0.8, 0.8, 0); - print_gl_string(mi->dpy, f, -# ifdef HAVE_GLBITMAP - fl, -# endif /* !HAVE_GLBITMAP */ - mi->xgwa.width, mi->xgwa.height, - 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); @@ -1090,6 +1046,22 @@ ENTRYPOINT void draw_tangram(ModeInfo * mi) 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 */