+/* update the model for one iteration.
+ This one draws a clock. By jwz. */
+static void updateClock (void)
+{
+ Barcode *b = &barcodes[0];
+ int BW = 76 /* BARCODE_WIDTH */;
+ int BH = BARCODE_HEIGHT;
+ int mag_x, mag_y;
+ int i;
+ time_t now = time ((time_t *) 0);
+ struct tm *tm = localtime (&now);
+ XWindowAttributes xgwa;
+ int ow = windowWidth;
+ int oh = windowHeight;
+
+ XGetWindowAttributes (display, window, &xgwa);
+ windowWidth = xgwa.width;
+ windowHeight = xgwa.height;
+
+ mag_x = windowWidth / BW;
+ mag_y = windowHeight / BH;
+
+ barcode_count = 1;
+
+ b->mag = (mag_x < mag_y ? mag_x : mag_y);
+
+ if (b->mag > MAX_MAG) b->mag = MAX_MAG;
+ if (b->mag < 1) b->mag = 1;
+
+ b->x = (windowWidth - (b->mag * BW )) / 2;
+ b->y = (windowHeight - (b->mag * (BH + 9))) / 2;
+ b->pixel = fg_pixel;
+
+ if (!button_down_p)
+ sprintf (b->code, "0%02d%02d%02d?:",
+ (mode == BC_CLOCK24
+ ? tm->tm_hour
+ : (tm->tm_hour > 12
+ ? tm->tm_hour - 12
+ : (tm->tm_hour == 0
+ ? 12
+ : tm->tm_hour))),
+ tm->tm_min,
+ tm->tm_sec);
+ else
+ sprintf (b->code, "0%02d%02d%02d?:",
+ tm->tm_year % 100, tm->tm_mon+1, tm->tm_mday);
+
+ {
+ int vstart = 9;
+ int hh = BH + vstart;
+ char expandedDigits[13];
+
+ expandedDigits[0] = '\0';
+
+ expandToUpcADigits (b->code, expandedDigits);
+ if (expandedDigits[0] != '\0')
+ b->code[7] = expandedDigits[11];
+
+ bitmapClear (theBitmap);
+ drawUpcEBars (theBitmap, b->code, 6, 9, 59, 65);
+ for (i = 0; i < 6; i++)
+ {
+ int off = (i < 2 ? 0 :
+ i < 4 ? 4 :
+ 8);
+ drawDigitChar (theBitmap, 11 + i*7 + off, hh - 16, b->code[i+1]);
+ }
+
+ if (!button_down_p)
+ {
+#if 0
+ char *days[] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
+ char *s = days[tm->tm_wday];
+ bitmapDrawString5x8 (theBitmap, (BW - strlen (s)*5) / 2, 0, s);
+#endif
+ drawDigitChar (theBitmap, 0, hh - 23, (tm->tm_hour < 12 ? 'A' : 'P'));
+ drawDigitChar (theBitmap, 68, hh - 23, 'M');
+ }
+ else
+ {
+ char s[20];
+ sprintf (s, "%03d", tm->tm_yday);
+ bitmapDrawString5x8 (theBitmap, (BW - strlen (s)*5) / 2, 0, s);
+ }
+ }
+
+ bitmapScale (b->bitmap, theBitmap, b->mag);
+
+ if (ow != windowWidth || oh != windowHeight)
+ XClearWindow (display, window);
+}
+
+