X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fcircuit.c;h=744e4b68a341cf58e64078928078055608bd8e60;hb=39809ded547bdbb08207d3e514950425215b4410;hp=9cce87d5e530e2527b719e87d12d5f6867176aa8;hpb=d5186197bc394e10a4402f7f6d23fbb14103bc50;p=xscreensaver diff --git a/hacks/glx/circuit.c b/hacks/glx/circuit.c index 9cce87d5..744e4b68 100644 --- a/hacks/glx/circuit.c +++ b/hacks/glx/circuit.c @@ -11,7 +11,7 @@ * surface mount, to-92 markings. Fixed ~5min crash. * Better LED illumination. Other minor changes. * - * Copyright (C) 2001,2002 Ben Buxton (bb@cactii.net) + * Copyright (C) 2001-2015 Ben Buxton (bb@cactii.net) * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -32,10 +32,11 @@ #ifdef STANDALONE #define DEFAULTS "*delay: 20000 \n" \ "*showFPS: False \n" \ + "*suppressRotationAnimation: True\n" \ "*componentFont: -*-courier-bold-r-normal-*-*-140-*-*-*-*-*-*" -# define refresh_circuit 0 -# define circuit_handle_event 0 +# define release_circuit 0 +# define circuit_handle_event xlockmore_no_events # include "xlockmore.h" /* from the xscreensaver distribution */ #else /* !STANDALONE */ # include "xlock.h" /* from the xlockmore distribution */ @@ -91,8 +92,8 @@ ENTRYPOINT ModeSpecOpt circuit_opts = {countof(opts), opts, countof(vars), vars, #ifdef USE_MODULES ModStruct circuit_description = -{"circuit", "init_circuit", "draw_circuit", "release_circuit", - "draw_circuit", "init_circuit", NULL, &circuit_opts, +{"circuit", "init_circuit", "draw_circuit", NULL, + "draw_circuit", "init_circuit", "free_circuit", &circuit_opts, 1000, 1, 2, 1, 4, 1.0, "", "Flying electronic components", 0, NULL}; @@ -1037,7 +1038,6 @@ static int DrawIC(Circuit *ci, IC *c) GLfloat lspec[] = {0.6, 0.6, 0.6, 0}; GLfloat lcol[] = {0.4, 0.4, 0.4, 0}; GLfloat lshine = 40; - float th, size; glPushMatrix(); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, col); @@ -1103,17 +1103,12 @@ static int DrawIC(Circuit *ci, IC *c) glDisable(GL_POLYGON_OFFSET_FILL); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); - if (c->pins == 8) - size = 0.4; - else - size = 0.6; - th = size*2/3; { GLfloat texfg[] = {0.7, 0.7, 0.7, 1.0}; GLfloat s = 0.015; - int w, h; - w = texture_string_width (ci->font, c->text, &h); + XCharStruct e; + texture_string_metrics (ci->font, c->text, &e, 0, 0); glPushMatrix(); glTranslatef (0, 0, 0.1); @@ -1352,9 +1347,10 @@ static int DrawTransistor(Circuit *ci, Transistor *t) { GLfloat texfg[] = {0.7, 0.7, 0.7, 1.0}; GLfloat s = 0.015; - int w, h; - w = texture_string_width (ci->font, t->text, &h); - + XCharStruct e; + int w; + texture_string_metrics (ci->font, t->text, &e, 0, 0); + w = e.width; glPushMatrix(); glRotatef (90, 1, 0, 0); glTranslatef (0.5, -0.05, 0.21); @@ -1379,9 +1375,10 @@ static int DrawTransistor(Circuit *ci, Transistor *t) { GLfloat texfg[] = {0.7, 0.7, 0.7, 1.0}; GLfloat s = 0.015; - int w, h; - w = texture_string_width (ci->font, t->text, &h); - + XCharStruct e; + int w; + texture_string_metrics (ci->font, t->text, &e, 0, 0); + w = e.width; glPushMatrix(); glTranslatef (0.75, 0.75, 0.01); glScalef (s, s, s); @@ -1911,7 +1908,6 @@ static void display(ModeInfo *mi) glEnable(GL_LIGHTING); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glLoadIdentity(); - /* glRotatef(current_device_rotation(), 0, 0, 1); */ gluLookAt(ci->viewer[0], ci->viewer[1], ci->viewer[2], 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); @@ -1926,6 +1922,18 @@ static void display(ModeInfo *mi) glLighti(GL_LIGHT0, GL_CONSTANT_ATTENUATION, (GLfloat)1); glLighti(GL_LIGHT0, GL_LINEAR_ATTENUATION, (GLfloat)0.5); glLighti(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, (GLfloat)0); + +# 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, h, h); + h = 2; + glScalef (h, h, h); + } +# endif + mi->polygon_count += drawgrid(ci); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, light_sp); if (f_rand() < 0.05) { @@ -1991,8 +1999,16 @@ static void reorder(Component *c[]) ENTRYPOINT void reshape_circuit(ModeInfo *mi, int width, int height) { Circuit *ci = &circuit[MI_SCREEN(mi)]; + int y = 0; GLfloat h = (GLfloat) height / (GLfloat) width; - glViewport(0,0,(GLint)width, (GLint) height); + + if (width > height * 5) { /* tiny window: show middle */ + height = width * 9/16; + y = -height/2; + h = height / (GLfloat) width; + } + + glViewport(0,y,(GLint)width, (GLint) height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1.0,1.0,-h,h,1.5,35.0); @@ -2008,11 +2024,7 @@ ENTRYPOINT void init_circuit(ModeInfo *mi) int screen = MI_SCREEN(mi); Circuit *ci; - if (circuit == NULL) { - if ((circuit = (Circuit *) calloc(MI_NUM_SCREENS(mi), - sizeof(Circuit))) == NULL) - return; - } + MI_INIT(mi, circuit); ci = &circuit[screen]; ci->window = MI_WINDOW(mi); @@ -2069,7 +2081,7 @@ ENTRYPOINT void draw_circuit(ModeInfo *mi) glXSwapBuffers(disp, w); } -ENTRYPOINT void release_circuit(ModeInfo *mi) +ENTRYPOINT void free_circuit(ModeInfo *mi) { Circuit *ci = &circuit[MI_SCREEN(mi)]; if (ci->font)