"Michael_Powers.Henr801M"@XEROX.COM (11/01/88)
Note: Here is a see through clock implementation which consists of two files (glass.c and glass.cps). Mike Powers powers.henr801m@xerox.com %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Glass Clock by Michael Powers (powers.henr801m@xerox.com) % Copyright (C) 1988 Xerox Corp. % % Back end disclaimer: % % This program is provided free for unrestricted use and % redistribution provided that this header is included. % No author (that be me), company (that be Xerox), or % distributor (that be me again) accepts % liability for any problems, lost revenues, or damages. % % glass.c % cc -o glass glass.c -I /usr/NeWS/include /usr/NeWS/lib/libcps.a % % notes: % Glass is an implementation of a NeWS clock that I wrote to % experiment with shaped canvases. The clock is shaped like the % the hands and tick marks thereby allowing you to "see through' % the face to whatever lies behind. Because of the bug concerning % stroking a canvas path the face must redraw every time it is % updated (gross). % One note on the use of glass. I would not suggest using the % -s option (second hand) since the updating chews up lots of time. % Perhaps a few more pauses would help here but I doubt it. % Enjoy! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #include <stdio.h> #ifdef SYSVREF #include <stropts.h> #include <poll.h> #include <sys/types.h> #include <time.h> #else #include <sys/time.h> #endif #include <sys/ioctl.h> #include "glass.h" #include <signal.h> #include "psio.h" main (argc, argv) char **argv; { int show_seconds = 0; int lmin = -1, lhour = -1, lsec = -1; while (--argc > 0) { if ((++argv)[0][0] == '-') switch (argv[0][1]) { case 's': show_seconds = 1; break; default: fprintf (stderr, "glassclock: illegal option: %s\n", argv[0]); exit (-1); } else { fprintf (stderr, "glassclock: illegal option: %s\n", argv[0]); exit (-1); } } if (ps_open_PostScript () == 0) { fprintf (stderr, "No NeWS server\n"); exit (-1); } ps_createclock (); /* initialize glass clock window */ while (1) { register struct tm *tm; #ifdef SYSVREF time_t now; #else long now; #endif now = time (0); tm = localtime (&now); tm->tm_hour = tm->tm_hour * 5 + tm->tm_min / 12; if (tm->tm_min != lmin || (show_seconds && tm->tm_sec != lsec) || tm->tm_hour != lhour) ps_update (tm->tm_hour,tm->tm_min,tm->tm_sec,show_seconds); lsec = tm->tm_sec; lmin = tm->tm_min; lhour = tm->tm_hour; ps_flush_PostScript (); { int n; #ifdef SYSVREF struct pollfd msk[1]; static int t = 0; #else int msk = 1 << psio_fileno (PostScriptInput); static struct timeval t; #endif #ifdef SYSVREF msk[0].fd = psio_fileno (PostScriptInput); msk[0].events = POLLIN; #endif #ifdef SYSVREF now = (show_seconds ? 1 : 60 - tm->tm_sec) * 1000; t = now > 60000 ? 60000 : now; if (poll(msk, 1, t) > 0) #else now = show_seconds ? 1 : 60 - tm->tm_sec; t.tv_sec = now > 60 ? 60 : now; if (select (32, &msk, 0, 0, &t) > 0) #endif { char buf[1000]; n = read (psio_fileno (PostScriptInput), buf, sizeof buf); if (n == 0) exit (0); else perror ("read"); } } } } cut here 8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8< %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Glass Clock by Michael Powers (powers.henr801m@xerox.com) % Copyright (C) 1988 Xerox Corp. % % Back end disclaimer: % % This program is provided free for unrestricted use and % redistribution provided that this header is included. % No author (that be me), company (that be Xerox), or % distributor (that be me again) accepts % liability for any problems, lost revenue, or damages. % % Misc disclaimer: % % The postscript isn't pretty, the clock face isn't pretty, % and the author isn't pretty. % % glass.cps % just run it through cps to generate glass.h % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% cdef ps_createclock() /Hour 0 def /Min 0 def /Sec 0 def /ShowSeconds? 0 def /HourLength 25 def /HourWidth 6 def /MinLength 38 def /MinWidth 4 def /SecLength 38 def /SecWidth 2 def /draw_hand { % rad wid rot => dup rotate 3 1 roll dup 2 div neg 3 moveto dup 0 rlineto exch dup 0 exch rlineto exch neg 0 rlineto neg 0 exch rlineto neg rotate } def /draw_face { 50 50 translate ShowSeconds? 1 eq {SecLength SecWidth Sec draw_hand} if MinLength MinWidth Min draw_hand HourLength HourWidth Hour draw_hand 12 {-2 42 moveto 4 0 rlineto 0 6 rlineto -4 0 rlineto 0 -6 rlineto 30 rotate} repeat } def /window framebuffer /new DefaultWindow send def { /IconLabel (Clock) def /PaintClient { gsave ClientCanvas setcanvas 1 fillcanvas FrameWidth 100 div FrameHeight 100 div scale 48 52 translate 0 setgray 2 setlinewidth gsave HourLength HourWidth Hour draw_hand gsave 1 setgray fill grestore stroke pause MinLength MinWidth Min draw_hand gsave 1 setgray fill grestore stroke pause ShowSeconds? 1 eq {SecLength SecWidth Sec draw_hand . gsave 1 setgray fill grestore stroke} if 12 {-2 42 moveto 4 0 rlineto 0 6 rlineto -4 0 rlineto 0 -6 rlineto 30 rotate} repeat gsave 1 setgray fill grestore stroke grestore } def /ShapeFrameCanvas { gsave ParentCanvas setcanvas FrameX FrameY translate FrameWidth 100 div FrameHeight 100 div scale draw_face FrameCanvas setcanvasshape grestore } def /ShapeClientCanvas { gsave FrameCanvas setcanvas 0 0 FrameWidth FrameHeight rectpath ClientCanvas setcanvasshape grestore } def /PaintFrame { } def /PaintFocus { gsave FrameCanvas setcanvas FrameWidth 100 div FrameHeight 100 div scale KeyFocus? {1} {0} ifelse setgray 1 setlinewidth 48 48 43 0 360 arc stroke grestore } def } window send /reshapefromuser window send % Shape it. /map window send % Map the window. (Damage causes PaintClient to be called) window /ClientCanvas get setcanvas cdef ps_update(hour,min,sec,show) gsave /Hour hour 6 neg mul store /Min min 6 neg mul store /Sec sec 6 neg mul store /ShowSeconds? show store /ShapeFrameCanvas window send grestore