home *** CD-ROM | disk | FTP | other *** search
- /*
- Title: watch.c
- Author: Erik Kilk
- Date: April 1985
-
- Synopsis: An analog clock desk accessory. When "watch" is started,
- it will appear just under the apple menu without a
- title bar or close box. To get the title bar and close
- box, click on the clock face (if it isn't the active
- window, you will have to click an extra time to make
- it active). To get rid of the title bar, also click
- on the clock face. In either mode, the top of the
- window will be the same (the clock face is pushed down
- when the title bar is showing.) This is so you can move
- the face all the way to the top of your desk top. This
- will increase your system file by 2k.
-
- */
-
- #define csize 16 /* half the window size */
-
- #include <stdio.h> /* type declarations and macros */
- #include <desk.h> /* these are just for the compiler */
- #include <acc.h> /* and don't generate code or data */
- #include <qd.h>
- #include <event.h>
- #include <mem.h>
- #include <misc.h>
- #include <file.h>
- #include <win.h>
- #include <device.h>
- #include <os.h>
- #include <fmath.h>
- #include <qdvars.h> /* the global quickdraw variables */
-
- ACC (0x2400, /* Responds to CNTRL call. Called
- periodically */
- 1800, /* Ticks between periodic calls (30
- seconds) */
- 0x42, /* mousedown and update events */
- 0, /* No menu items */
- 5, "Watch") /* Length and text of title */
-
- rect ringbounds; /* circle to erase before drawing hands */
- int wkind = 2; /* initial type of window (plain box) */
-
- ek () { /* my initials (only for title bar face)
- */
- move (-3, 0);
- line (0, 4);
- move (1, -4);
- line (1, 0);
- move (-1, 2);
- line (0, 0);
- move (0, 2);
- line (1, 0);
- move (2, -4);
- line (0, 4);
- move (1, -2);
- line (2, -2);
- move (-1, 3);
- line (1, 1);
- }
-
- showclock () { /* draw the entire clock face */
- datetimerec datetime; /* date gets read into here */
- int mx,
- my,
- hx,
- hy; /* hand end-points */
- double minunit,
- min,
- hr; /* time */
-
- gettime (&datetime);
- if (datetime.hour > 11)
- datetime.hour -= 12;
- minunit = (double) datetime.minute / 60.0;
- min = minunit * 6.2831; /* 2*pi */
- hr = ((double) datetime.hour + minunit) / 12.0 * 6.2831;
- mx = 0.75 * csize * sin (min);
- my = -0.75 * csize * cos (min);
- hx = 0.5 * csize * sin (hr);
- hy = -0.5 * csize * cos (hr);
- setorigin (-csize, -csize); /* make 0,0 in center */
- pennormal ();
- filloval (&ringbounds, &(qdvars.white));/* erase hands */
- moveto (0, csize - 2);
- lineto (0, csize - 2); /* draw 4 ticks */
- moveto (csize - 2, 0);
- lineto (csize - 2, 0);
- moveto (0, -csize + 1);
- lineto (0, -csize + 1);
- moveto (-csize + 1, 0);
- lineto (-csize + 1, 0);
- if (wkind == 16) { /* add my initials */
- moveto (0, 5);
- ek ();
- }
- moveto (0, 0); /* draw the hands */
- lineto (mx, my);
- moveto (0, 0);
- lineto (hx, hy);
- moveto (0, 0); /* erase the center dot */
- penpat (&(qdvars.white));
- lineto (0, 0);
- }
-
- switchwindows (dctl) /* toggle between window types */
- dctlentry *dctl; /* this gives us the window address */
- {
- windowpeek oldwp; /* the old window address */
- windowpeek newwp; /* the new window address */
- rect wr; /* the position of the new window */
- int offs; /* offset to scoot face up and down */
-
- if (wkind == 16) { /* to change regular DA to box */
- wkind = 2; /* plain box window code */
- offs = -19; /* scoot it up where title
- was */
- }
- else { /* to change box to regular DA */
- wkind = 16; /* DA window code */
- offs = 19; /* scoot it down (title bar is
- placed above window position) */
- }
- oldwp = dctl -> dctlwindow; /* get address of current window */
- wr = oldwp -> port.portrect;/* get size of the window */
- /* now position it. This took trial and error to get right. */
- offsetrect (&wr, 512 - oldwp -> port.portbits.bounds.a.right,
- 342 - oldwp -> port.portbits.bounds.a.bottom + offs);
- /* make the new window */
- newwp = newwindow (NULL, &wr, "", 1, wkind, -1L, -1, 0L);
- newwp -> windowkind = dctl -> dctlrefnum;/* Have to do this */
- dctl -> dctlwindow = newwp; /* save the window addrss */
- disposewindow (oldwp); /* dump the old window */
- }
-
-
- accopen (dctl, pb) /* open the clock for first time */
- dctlentry *dctl; /* gives window stuff */
- paramblockrec *pb; /* passed to us anyway */
- {
- windowpeek wp; /* pointer to new window */
- rect wr; /* position of new window */
-
- setrect (&ringbounds, -(csize - 2), -(csize - 2), csize - 2, csize - 2);
- if (dctl -> dctlwindow == NULL) {/* No window, so create it */
- setrect (&wr, 2, 22, (csize * 2) + 2, (csize * 2) + 22);
- wp = newwindow (NULL, &wr, "", 0, wkind, -1L, -1, 0L);
- wp -> windowkind = dctl -> dctlrefnum;
- dctl -> dctlwindow = wp;
- }
- return 0;
- }
-
- accclose (dctl, pb) /* system calls this to close up */
- dctlentry *dctl;
- paramblockrec *pb;
- {
- windowptr tmpwp; /* to keep our window address */
-
- tmpwp = dctl -> dctlwindow; /* get window address */
- dctl -> dctlwindow = NULL; /* tell system there isn't a window */
- disposewindow (tmpwp); /* dump the window */
- return 0;
- }
-
- accctl (dctl, pb) /* Called by the system when needed */
- dctlentry *dctl; /* window info is given in here */
- paramblockrec *pb; /* reason system called us is here */
- {
- eventrecord *newevent; /* address of new event record */
-
- setport (dctl -> dctlwindow);/* set to draw in our window */
- switch (pb -> paramunion.cntrlparam.cscode) {
- case accrun: /* every 30 seconds */
- showclock ();
- break;
- case accevent: /* on mousedown and updates */
- newevent = (eventrecord *) (pb -> paramunion.cntrlparam.
- csparam.asyncnbytes);
- switch (newevent -> what) {
- case mousedown: /* for mousedowns, switch windws */
- switchwindows (dctl);
- break;
- case updateevt: /* for updates, draw clock again */
- beginupdate (dctl -> dctlwindow);
- showclock ();
- endupdate (dctl -> dctlwindow);
- break;
- }
- break;
- }
- }
-
- accprime () { /* these two procedures aren't needed *//*
- but have to exist anyway */
- }
-
- accstatus () {
- }
-