v06i031: lclock -- clock with a logo face, Part01/01

Dave Lemke lupine!lemke at uunet.UU.NET
Thu Mar 15 15:41:47 AEST 1990


Submitted-by: Dave Lemke <lupine!lemke at uunet.UU.NET>
Posting-number: Volume 6, Issue 31
Archive-name: xclock/part01

this is yet another clock, this time using the SHAPE extension
with the X logo as the face.

Dave
lemke at ncd.com

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  README Imakefile makefile Clock.c ClockP.h Clock.h
#   lclock.c transform.c transform.h lclock.man
# Wrapped by lemke at hansen on Fri Mar  9 11:00:11 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(732 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
Xlclock -- Logo clock -- yet another clock demo
X
Xthis one requires R4 libraries and a server that supports SHAPE.
X
Xits been tested with uwm, twm, olwm and swm (including swm's virtual
Xdesktop), and is happiest with those WM in that order:  uwm & twm don't
Xget in its way at all, and olwm and swm (at least the versions i have)
Xdon't understand SHAPE, so things don't look right.
X
Xit shouldn't be too difficult to modify Clock.c to use any
Xlogo as the clock face.  just replace the calls to XmuDrawLogo()
Xwith another drawing routine.
X
XBugs:
XTwo of the inner sides have no border.  This is due to the
Xway XmuDrawLogo() calculates its polygons.
X
XDave Lemke				ARPA: lemke at ncd.com
XNetwork Computing Devices, Inc. 	UUCP: uunet!ncd!lemke
END_OF_FILE
if test 732 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'Imakefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Imakefile'\"
else
echo shar: Extracting \"'Imakefile'\" \(371 characters\)
sed "s/^X//" >'Imakefile' <<'END_OF_FILE'
X#ifdef BandAidCompiler
X#include BandAidCompiler
X#endif
X
XDEFINES = ExtensionDefines
XINCLUDES = -I$(TOP) -I$(TOP)/X11
XSYS_LIBRARIES = -lm
XDEPLIBS = $(DEPXTOOLLIB) $(DEPXMULIB) $(DEPEXTENSIONLIB) $(DEPXLIB)
XLOCAL_LIBRARIES = $(XTOOLLIB) $(XMULIB) $(EXTENSIONLIB) $(XLIB)
X
XSRCS = lclock.c Clock.c transform.c
XOBJS = lclock.o Clock.o transform.o
X
XComplexProgramTarget(lclock)
END_OF_FILE
if test 371 -ne `wc -c <'Imakefile'`; then
    echo shar: \"'Imakefile'\" unpacked with wrong size!
fi
# end of 'Imakefile'
fi
if test -f 'makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'makefile'\"
else
echo shar: Extracting \"'makefile'\" \(408 characters\)
sed "s/^X//" >'makefile' <<'END_OF_FILE'
XCFLAGS = -O
XLDFLAGS =
XLIBS = -lXt -lXmu -lXext -lX11 -lm
X
X.KEEP_STATE:
X
XOBJS = Clock.o lclock.o transform.o
XSRCS = Clock.c lclock.c transform.c
X
XHEADERS = CLock.h CLockP.h transform.h
X
Xall:	lclock
X
Xlclock:	$(OBJS)
X	cc -o $@ $(OBJS) $(LDFLAGS) $(LIBS)
X
Xshar:
X	shar README Imakefile makefile Clock.c ClockP.h Clock.h \
X		lclock.c transform.c transform.h lclock.man > lclock.shar
X
Xclean:
X	rm -f *.o core lclock
END_OF_FILE
if test 408 -ne `wc -c <'makefile'`; then
    echo shar: \"'makefile'\" unpacked with wrong size!
fi
# end of 'makefile'
fi
if test -f 'Clock.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Clock.c'\"
else
echo shar: Extracting \"'Clock.c'\" \(11473 characters\)
sed "s/^X//" >'Clock.c' <<'END_OF_FILE'
X/*
X * Clock.c
X *
X * a NeWS clone clock
X *
X * Dave Lemke
X * lemke at ncd.com
X * Wed Feb 28 16:42:39 PST 1990
X *
X * idea from the NeWS sunclock demo by Stuart Marks and Greg McLaughlin.
X * code is whacked over 'oclock' by Keith Packard
X */
X
X#include <X11/Xos.h>
X#include <stdio.h>
X#include <X11/IntrinsicP.h>
X#include <X11/StringDefs.h>
X#include <X11/Xmu/Converters.h>
X#include "ClockP.h"
X#include <math.h>
X#include <X11/extensions/shape.h>
X
X#define offset(field) XtOffset(ClockWidget,clock.field)
X#define goffset(field) XtOffset(Widget,core.field)
X
Xstatic XtResource resources[] = {
X    {XtNwidth, XtCWidth, XtRDimension, sizeof(Dimension),
X    goffset(width), XtRString, "120"},
X    {XtNheight, XtCHeight, XtRDimension, sizeof(Dimension),
X    goffset(height), XtRString, "120"},
X    {XtNminute, XtCForeground, XtRPixel, sizeof(Pixel),
X    offset(minute), XtRString, XtDefaultBackground},
X    {XtNhour, XtCForeground, XtRPixel, sizeof(Pixel),
X    offset(hour), XtRString, XtDefaultBackground},
X    {XtNborder, XtCForeground, XtRPixel, sizeof(Pixel),
X    offset(border), XtRString, XtDefaultBackground},
X    {XtNreverseVideo, XtCReverseVideo, XtRBoolean, sizeof(Boolean),
X    offset(reverse_video), XtRString, "FALSE"},
X    {XtNbackingStore, XtCBackingStore, XtRBackingStore, sizeof(int),
X    offset(backing_store), XtRString, "default"},
X};
X
X#undef offset
X#undef goffset
X
Xstatic void Initialize(), Realize(), Destroy(), Resize(), Redisplay();
X
X#define BORDER_WIDTH	(0.1)
X#define WINDOW_WIDTH	(2.0 - BORDER_WIDTH*2)
X#define WINDOW_HEIGHT	(2.0 - BORDER_WIDTH*2)
X#define MINUTE_WIDTH	(BORDER_WIDTH / 2.0)
X#define HOUR_WIDTH	(BORDER_WIDTH / 2.0)
X#define JEWEL_SIZE	(BORDER_WIDTH * 0.75)
X#define MINUTE_LENGTH	(0.8)
X#define HOUR_LENGTH	(0.5)
X
X#define HAND_BORDER_WIDTH	(0.02)
X
X#define LOGO_BORDER_WIDTH	(w->core.width/20)
X#define LOGO_BORDER_HEIGHT	(w->core.height/20)
X#define LOGO_WINDOW_WIDTH	(w->core.width - LOGO_BORDER_WIDTH*2)
X#define LOGO_WINDOW_HEIGHT	(w->core.height - LOGO_BORDER_HEIGHT*2)
X
X#define	HOUR_HAND	1
X#define	MINUTE_HAND	2
X
X
Xstatic void ClassInitialize();
X
XClockClassRec clockClassRec = {
X    {				/* core fields */
X	 /* superclass		 	 */ &widgetClassRec,
X	 /* class_name			 */ "LogoClock",
X	 /* size			 */ sizeof(ClockRec),
X	 /* class_initialize		 */ ClassInitialize,
X	 /* class_part_initialize	 */ NULL,
X	 /* class_inited		 */ FALSE,
X	 /* initialize			 */ Initialize,
X	 /* initialize_hook		 */ NULL,
X	 /* realize			 */ Realize,
X	 /* actions			 */ NULL,
X	 /* num_actions			 */ 0,
X	 /* resources			 */ resources,
X	 /* num_resources		 */ XtNumber(resources),
X	 /* xrm_class			 */ NULL,
X	 /* compress_motion		 */ TRUE,
X	 /* compress_exposure		 */ TRUE,
X	 /* compress_enterleave		 */ TRUE,
X	 /* visible_interest		 */ FALSE,
X	 /* destroy			 */ Destroy,
X	 /* resize			 */ Resize,
X	 /* expose			 */ Redisplay,
X	 /* set_values			 */ NULL,
X	 /* set_values_hook		 */ NULL,
X	 /* set_values_almost		 */ NULL,
X	 /* get_values_hook		 */ NULL,
X	 /* accept_focus		 */ NULL,
X	 /* version			 */ XtVersion,
X	 /* callback_private		 */ NULL,
X	 /* tm_table			 */ NULL,
X	 /* query_geometry		 */ XtInheritQueryGeometry,
X    }
X};
X
Xstatic void
XClassInitialize()
X{
X    XtAddConverter(XtRString, XtRBackingStore, XmuCvtStringToBackingStore,
X		   NULL, 0);
X}
X
XWidgetClass clockWidgetClass = (WidgetClass) & clockClassRec;
X
X/* ARGSUSED */
Xstatic void
XInitialize(greq, gnew)
X    Widget      greq,
X                gnew;
X{
X    ClockWidget w = (ClockWidget) gnew;
X    int         shape_event_base,
X                shape_error_base;
X
X    /* wait for Realize to add the timeout */
X    w->clock.interval_id = 0;
X
X    if (!XShapeQueryExtension(XtDisplay(w), &shape_event_base,
X			      &shape_error_base)) {
X	fprintf(stderr, "sorry, lclock needs the SHAPE extension to run\n");
X    }
X    w->clock.shape_mask = 0;
X    w->clock.shapeGC = 0;
X    w->clock.shapebackGC = 0;
X    w->clock.handGC = 0;
X    w->clock.shape_width = 0;
X    w->clock.shape_height = 0;
X}
X
Xstatic void
XResize(w)
X    ClockWidget w;
X{
X    int         face_width,
X                face_height;
X
X    if (!XtIsRealized(w))
X	return;
X
X    /*
X     * compute desired border size
X     */
X
X    SetTransform(&w->clock.maskt,
X		 0, w->core.width,
X		 w->core.height, 0,
X		 -1.0, 1.0,
X		 -1.0, 1.0);
X
X    face_width = abs(Xwidth(BORDER_WIDTH, BORDER_WIDTH, &w->clock.maskt));
X    face_height = abs(Xheight(BORDER_WIDTH, BORDER_WIDTH, &w->clock.maskt));
X
X    /*
X     * shape the windows and borders
X     */
X
X    SetTransform(&w->clock.t,
X		 face_width, w->core.width - face_width,
X		 w->core.height - face_height, face_height,
X		 -WINDOW_WIDTH / 2, WINDOW_WIDTH / 2,
X		 -WINDOW_HEIGHT / 2, WINDOW_HEIGHT / 2);
X
X    draw_clock(w);
X}
X
X
Xdraw_clock(w)
X    ClockWidget w;
X{
X    XGCValues   xgcv;
X    Widget      parent;
X    int         x,
X                y;
X    Pixmap      shape_mask;
X
X    /*
X     * allocate a pixmap to draw shapes in
X     */
X
X    shape_mask = XCreatePixmap(XtDisplay(w), XtWindow(w),
X			       w->core.width, w->core.height, 1);
X    if (!w->clock.shapeGC) {
X	w->clock.shapeGC = XCreateGC(XtDisplay(w), shape_mask, 0, &xgcv);
X	xgcv.foreground = 0;
X	w->clock.shapebackGC = XCreateGC(XtDisplay(w), shape_mask,
X					 GCForeground, &xgcv);
X    }
X    /* erase the pixmap */
X    XSetForeground(XtDisplay(w), w->clock.shapeGC, 0);
X    XFillRectangle(XtDisplay(w), shape_mask, w->clock.shapeGC,
X		   0, 0, w->core.width, w->core.height);
X    XSetForeground(XtDisplay(w), w->clock.shapeGC, 1);
X
X    /*
X     * draw the bounding shape.  Doing this first eliminates extra exposure
X     * events.
X     */
X
X    XmuDrawLogo(XtDisplay(w), shape_mask, w->clock.shapeGC,
X		w->clock.shapebackGC,
X		0, 0,
X		w->core.width, w->core.height);
X
X    draw_hands(w, shape_mask, True);
X    /*
X     * Find the highest enclosing widget and shape it
X     */
X
X    x = 0;
X    y = 0;
X    for (parent = (Widget) w; XtParent(parent); parent = XtParent(parent)) {
X	x = x + parent->core.x + parent->core.border_width;
X	y = y + parent->core.y + parent->core.border_width;
X    }
X
X    XShapeCombineMask(XtDisplay(parent), XtWindow(parent), ShapeBounding,
X		      x, y, shape_mask, ShapeSet);
X
X    /* erase the pixmap */
X    XSetForeground(XtDisplay(w), w->clock.shapeGC, 0);
X    XFillRectangle(XtDisplay(w), shape_mask, w->clock.shapeGC,
X		   0, 0, w->core.width, w->core.height);
X    XSetForeground(XtDisplay(w), w->clock.shapeGC, 1);
X
X    /*
X     * draw the clip shape
X     */
X
X    XmuDrawLogo(XtDisplay(w), shape_mask, w->clock.shapeGC,
X		w->clock.shapebackGC,
X		LOGO_BORDER_WIDTH, LOGO_BORDER_HEIGHT,
X		LOGO_WINDOW_WIDTH, LOGO_WINDOW_HEIGHT);
X
X    draw_hands(w, shape_mask, False);
X
X    XShapeCombineMask(XtDisplay(w), XtWindow(w), ShapeClip,
X		      0, 0, shape_mask, ShapeSet);
X
X    XFreePixmap(XtDisplay(w), shape_mask);
X}
X
Xdraw_hands(w, mask, border)
X    ClockWidget w;
X    Pixmap      mask;
X    Bool        border;
X{
X    draw_hand(w, mask, MINUTE_HAND, border, w->clock.shapeGC);
X    draw_hand(w, mask, HOUR_HAND, border, w->clock.shapeGC);
X}
X
Xdraw_hand(w, drawable, hand, border, gc)
X    ClockWidget w;
X    Drawable    drawable;
X    int         hand;
X    Bool        border;
X    GC          gc;
X{
X    TPoint      poly[POLY_SIZE];
X    double      angle,
X                width,
X                length;
X
X    switch (hand) {
X    case HOUR_HAND:
X	angle = w->clock.hour_angle;
X	width = HOUR_WIDTH;
X	length = HOUR_LENGTH;
X	break;
X    case MINUTE_HAND:
X	angle = w->clock.minute_angle;
X	width = MINUTE_WIDTH;
X	length = MINUTE_LENGTH;
X	break;
X    }
X
X    if (border)
X	compute_hand(angle, length, width, poly);
X    else
X	compute_hand(angle,
X		     length - 2 * HAND_BORDER_WIDTH,
X		     width - 2 * HAND_BORDER_WIDTH,
X		     poly);
X
X    TFillPolygon(XtDisplay(w), drawable, gc,
X		 &w->clock.t, poly, POLY_SIZE,
X		 Convex, CoordModeOrigin);
X}
X
X/* ARGSUSED */
Xstatic void
XRedisplay(gw, event, region)
X    Widget gw;
X    XEvent *event;
X    Region region;
X{
X    ClockWidget w;
X
X    w = (ClockWidget) gw;
X    XClearWindow(XtDisplay(w), XtWindow(w));	/* erase the old hands */
X    if (!w->clock.handGC)
X	w->clock.handGC = XCreateGC(XtDisplay(w), XtWindow(w), 0, NULL);
X    paint_hands(w);
X}
X
Xstatic void
XRealize(gw, valueMask, attrs)
X    Widget      gw;
X    XtValueMask *valueMask;
X    XSetWindowAttributes *attrs;
X{
X    ClockWidget w = (ClockWidget) gw;
X    static int  new_time();
X
X    if (w->clock.backing_store != Always + WhenMapped + NotUseful) {
X	attrs->backing_store = w->clock.backing_store;
X	*valueMask |= CWBackingStore;
X    }
X    XtCreateWindow(gw, (unsigned) InputOutput, (Visual *) CopyFromParent,
X		   *valueMask, attrs);
X
X    Resize(w);
X    new_time((caddr_t) gw, 0);
X}
X
Xstatic void
XDestroy(gw)
X    Widget      gw;
X{
X    ClockWidget w = (ClockWidget) gw;
X
X    if (w->clock.interval_id)
X	XtRemoveTimeOut(w->clock.interval_id);
X    if (w->clock.shapeGC)
X	XtDestroyGC(w->clock.shapeGC);
X    if (w->clock.shapebackGC)
X	XtDestroyGC(w->clock.shapebackGC);
X    if (w->clock.handGC)
X	XtDestroyGC(w->clock.handGC);
X}
X
X
X/*
X * routines to draw the hands
X */
X
X#define PI (3.14159265358979323846)
X
X/*
X * converts a number from 0..1 representing a clockwise radial distance
X * from the 12 oclock position to a radian measure of the counter-clockwise
X * distance from the 3 oclock position
X */
X
Xstatic double
Xclock_to_angle(clock)
X    double      clock;
X{
X    if (clock >= .75)
X	clock -= 1.0;
X    return -2.0 * PI * clock + PI / 2.0;
X}
X
X/* ARGSUSED */
Xstatic int
Xnew_time(client_data, id)
X    caddr_t     client_data;
X    XtIntervalId id;		/* unused */
X{
X    ClockWidget w = (ClockWidget) client_data;
X    long        now;
X    struct tm  *localtime(),
X               *tm;
X
X    (void) time(&now);
X    tm = localtime(&now);
X    if (tm->tm_hour >= 12)
X	tm->tm_hour -= 12;
X    w->clock.hour_angle = clock_to_angle((((double) tm->tm_hour) +
X				       ((double) tm->tm_min) / 60.0) / 12.0);
X    w->clock.minute_angle =
X	clock_to_angle(((double) tm->tm_min) / 60.0);
X    /*
X     * add the timeout before painting the hands, that may take a while and
X     * we'd like the clock to keep up with time changes.
X     */
X    w->clock.interval_id = XtAddTimeOut((60 - tm->tm_sec) * 1000, new_time,
X					client_data);
X    draw_clock(w);
X}				/* new_time */
X
X
X/*
X * A hand is a rectangle with a triangular cap at the far end.
X * This is represented with a five sided polygon.
X */
X
Xcompute_hand(a, l, width, poly)
X    double      a,
X                l,
X                width;
X    TPoint      poly[POLY_SIZE];
X{
X    double      c,
X                s;
X
X    c = cos(a);
X    s = sin(a);
X    poly[0].x = c * l;
X    poly[0].y = s * l;
X    poly[1].x = (l - width) * c - s * width;
X    poly[1].y = (l - width) * s + c * width;
X    poly[2].x = (-width) * c - s * width;
X    poly[2].y = (-width) * s + c * width;
X    poly[3].x = (-width) * c + s * width;
X    poly[3].y = (-width) * s - c * width;
X    poly[4].x = (l - width) * c + s * width;
X    poly[4].y = (l - width) * s - c * width;
X    poly[5].x = poly[0].x;
X    poly[5].y = poly[0].y;
X}
X
Xpaint_hands(w)
X    ClockWidget w;
X{
X    GC          gc = w->clock.handGC;
X    Display    *dpy = XtDisplay(w);
X
X    /* draw the hands, border first, hour hand on top */
X    XSetForeground(dpy, gc, w->clock.border);
X    draw_hand(w, XtWindow(w), MINUTE_HAND, True, gc);
X    XSetForeground(dpy, gc, w->clock.minute);
X    draw_hand(w, XtWindow(w), MINUTE_HAND, False, gc);
X
X    XSetForeground(dpy, gc, w->clock.border);
X    draw_hand(w, XtWindow(w), HOUR_HAND, True, gc);
X    XSetForeground(dpy, gc, w->clock.hour);
X    draw_hand(w, XtWindow(w), HOUR_HAND, False, gc);
X}
END_OF_FILE
if test 11473 -ne `wc -c <'Clock.c'`; then
    echo shar: \"'Clock.c'\" unpacked with wrong size!
fi
# end of 'Clock.c'
fi
if test -f 'ClockP.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ClockP.h'\"
else
echo shar: Extracting \"'ClockP.h'\" \(1379 characters\)
sed "s/^X//" >'ClockP.h' <<'END_OF_FILE'
X/*
X * $XConsortium: ClockP.h,v 1.5 89/07/21 13:44:45 jim Exp $
X */
X
X#ifndef _ClockP_h
X#define _ClockP_h
X
X#include "Clock.h"
X#include <X11/CoreP.h>
X#include "transform.h"
X
X#define POLY_SIZE	6
X
X/* New fields for the clock widget instance record */
Xtypedef struct {
X	Pixel		minute;		/* minute hand pixel */
X	Pixel		hour;		/* hour hand pixel */
X	Pixel		border;		/* border pixel */
X	GC		shapeGC;	/* pointer to GraphicsContext */
X	GC		shapebackGC;	/* pointer to GraphicsContext */
X/* start of graph stuff */
X	int		backing_store;	/* backing store variety */
X	Boolean		reverse_video;	/* swap fg and bg pixels */
X	XtIntervalId	interval_id;
X	Transform	t;
X	Transform	maskt;
X	Pixmap		shape_mask;	/* window shape */
X	int		shape_width;	/* window width when shape last made */
X	int		shape_height;	/* window height when shape last made */
X	GC		handGC;
X	double		hour_angle;	/* hour hand position */
X	double		minute_angle;	/* minute hand position */
X} ClockPart;
X
X/* Full instance record declaration */
Xtypedef struct _ClockRec {
X	CorePart core;
X	ClockPart clock;
X} ClockRec;
X
X/* New fields for the Clock widget class record */
Xtypedef struct {int dummy;} ClockClassPart;
X
X/* Full class record declaration. */
Xtypedef struct _ClockClassRec {
X	CoreClassPart core_class;
X	ClockClassPart clock_class;
X} ClockClassRec;
X
X/* Class pointer. */
Xextern ClockClassRec clockClassRec;
X
X#endif /* _ClockP_h */
END_OF_FILE
if test 1379 -ne `wc -c <'ClockP.h'`; then
    echo shar: \"'ClockP.h'\" unpacked with wrong size!
fi
# end of 'ClockP.h'
fi
if test -f 'Clock.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Clock.h'\"
else
echo shar: Extracting \"'Clock.h'\" \(1230 characters\)
sed "s/^X//" >'Clock.h' <<'END_OF_FILE'
X/*
X * $XConsortium: Clock.h,v 1.4 89/07/21 13:44:44 jim Exp $
X */
X
X#ifndef _XtClock_h
X#define _XtClock_h
X
X/***********************************************************************
X *
X * Clock Widget
X *
X ***********************************************************************/
X
X/* Parameters:
X
X Name		     Class		RepType		Default Value
X ----		     -----		-------		-------------
X background	     Background		pixel		White
X border		     BorderColor	pixel		Black
X borderWidth	     BorderWidth	int		1
X minute		     Foreground		Pixel		Black
X hour		     Foreground		Pixel		Black
X height		     Height		int		120
X mappedWhenManaged   MappedWhenManaged	Boolean		True
X reverseVideo	     ReverseVideo	Boolean		False
X width		     Width		int		120
X x		     Position		int		0
X y		     Position		int		0
X
X*/
X
X#define XtNminute	"minute"
X#define XtNhour		"hour"
X
X#define XtNshapeWindow	"shapeWindow"
X#define XtCShapeWindow	"ShapeWindow"
X
Xtypedef struct _ClockRec *ClockWidget;  /* completely defined in ClockPrivate.h */
Xtypedef struct _ClockClassRec *ClockWidgetClass;    /* completely defined in ClockPrivate.h */
X
Xextern WidgetClass clockWidgetClass;
X
XXtEventHandler	structure_event();
X
X#endif /* _XtClock_h */
X/* DON'T ADD STUFF AFTER THIS #endif */
END_OF_FILE
if test 1230 -ne `wc -c <'Clock.h'`; then
    echo shar: \"'Clock.h'\" unpacked with wrong size!
fi
# end of 'Clock.h'
fi
if test -f 'lclock.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'lclock.c'\"
else
echo shar: Extracting \"'lclock.c'\" \(1515 characters\)
sed "s/^X//" >'lclock.c' <<'END_OF_FILE'
X#include <X11/Intrinsic.h>
X#include <X11/Xatom.h>
X#include <X11/StringDefs.h>
X#include <X11/Shell.h>
X#include "Clock.h"
X#include <stdio.h> 
X
Xextern void exit();
X
X/* Command line options table.  Only resources are entered here...there is a
X   pass over the remaining options after XtParseCommand is let loose. */
X
X/* Exit with message describing command line format */
X
Xvoid usage()
X{
X    fprintf(stderr,
X"usage: oclock\n");
X    fprintf (stderr, 
X"       [-geometry [{width}][x{height}][{+-}{xoff}[{+-}{yoff}]]] [-display [{host}]:[{vs}]]\n");
X    fprintf(stderr,
X"       [-fg {color}] [-bg {color}] [-bd {color}] [-bw {pixels}]\n");
X    fprintf(stderr,
X"       [-minute {color}] [-hour {color}]\n");
X    fprintf(stderr,
X"       [-backing {backing-store}]\n");
X    exit(1);
X}
X
Xstatic XrmOptionDescRec options[] = {
X{"-bg",		"*Background",		XrmoptionSepArg,	NULL},
X{"-foreground",	"*Foreground",		XrmoptionSepArg,	NULL},
X{"-background",	"*Background",		XrmoptionSepArg,	NULL},
X{"-minute",	"*clock.minute",	XrmoptionSepArg,	NULL},
X{"-hour",	"*clock.hour",		XrmoptionSepArg,	NULL},
X{"-backing",	"*clock.backingStore",	XrmoptionSepArg,	NULL},
X};
X
Xvoid main(argc, argv)
X    int argc;
X    char **argv;
X{
X    Widget toplevel;
X    Widget clock;
X    
X    toplevel = XtInitialize(NULL, "LogoClock", options, XtNumber (options),
X				    &argc, argv);
X      
X    if (argc != 1) usage();
X
X    clock = XtCreateManagedWidget ("lclock", clockWidgetClass, toplevel, 
X				NULL, 0);
X    XtRealizeWidget (toplevel);
X    XtMainLoop();
X}
END_OF_FILE
if test 1515 -ne `wc -c <'lclock.c'`; then
    echo shar: \"'lclock.c'\" unpacked with wrong size!
fi
# end of 'lclock.c'
fi
if test -f 'transform.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'transform.c'\"
else
echo shar: Extracting \"'transform.c'\" \(2202 characters\)
sed "s/^X//" >'transform.c' <<'END_OF_FILE'
X/*
X * transformed coordinate system objects for X
X */
X
X# include	<X11/Xlib.h>
X# include	"transform.h"
X
Xstatic XPoint *
XTranslatePoints (points, n_points, t, mode)
XTPoint	*points;
Xint	n_points;
XTransform	*t;
Xint	mode;
X{
X	XPoint	*xpoints;
X	int	i;
X	double	xoff = 0.0, yoff = 0.0;
X
X	xpoints = (XPoint *) malloc (n_points * sizeof (*xpoints));
X	if (!xpoints)
X		return 0;
X	for (i = 0; i < n_points; i++) {
X		xpoints[i].x = Xx(points[i].x + xoff, points[i].y + yoff, t);
X		xpoints[i].y = Xy(points[i].x + xoff, points[i].y + yoff, t);
X		if (mode == CoordModePrevious) {
X			xoff += points[i].x;
X			yoff += points[i].y;
X		}
X	}
X	return xpoints;
X}
X
XTFillPolygon (dpy, d, gc, t, points, n_points, shape, mode)
Xregister Display	*dpy;
XDrawable		d;
XGC			gc;
XTransform		*t;
XTPoint			*points;
Xint			n_points;
Xint			shape;
Xint			mode;
X{
X	XPoint	*xpoints;
X
X	xpoints = TranslatePoints (points, n_points, t, mode);
X	if (xpoints) {
X		XFillPolygon (dpy, d, gc, xpoints, n_points, shape,
X				CoordModeOrigin);
X		free (xpoints);
X	}
X}
X
XTDrawArc (dpy, d, gc, t, x, y, width, height, angle1, angle2)
X	register Display	*dpy;
X	Drawable		d;
X	GC			gc;
X	Transform		*t;
X	double			x, y, width, height;
X	int			angle1, angle2;
X{
X	int	xx, xy, xw, xh;
X
X	xx = Xx(x,y,t);
X	xy = Xy(x,y,t);
X	xw = Xwidth (width, height, t);
X	xh = Xheight (width, height, t);
X	if (xw < 0) {
X		xx += xw;
X		xw = -xw;
X	}
X	if (xh < 0) {
X		xy += xh;
X		xh = -xh;
X	}
X	XDrawArc (dpy, d, gc, xx, xy, xw, xh, angle1, angle2);
X}
X
XTFillArc (dpy, d, gc, t, x, y, width, height, angle1, angle2)
X	register Display	*dpy;
X	Drawable		d;
X	GC			gc;
X	Transform		*t;
X	double			x, y, width, height;
X	int			angle1, angle2;
X{
X	int	xx, xy, xw, xh;
X
X	xx = Xx(x,y,t);
X	xy = Xy(x,y,t);
X	xw = Xwidth (width, height, t);
X	xh = Xheight (width, height, t);
X	if (xw < 0) {
X		xx += xw;
X		xw = -xw;
X	}
X	if (xh < 0) {
X		xy += xh;
X		xh = -xh;
X	}
X	XFillArc (dpy, d, gc, xx, xy, xw, xh, angle1, angle2);
X}
X
XSetTransform (t, xx1, xx2, xy1, xy2, tx1, tx2, ty1, ty2)
XTransform	*t;
Xint		xx1, xx2, xy1, xy2;
Xdouble		tx1, tx2, ty1, ty2;
X{
X	t->mx = ((double) xx2 - xx1) / (tx2 - tx1);
X	t->bx = ((double) xx1) - t->mx * tx1;
X	t->my = ((double) xy2 - xy1) / (ty2 - ty1);
X	t->by = ((double) xy1) - t->my * ty1;
X}
END_OF_FILE
if test 2202 -ne `wc -c <'transform.c'`; then
    echo shar: \"'transform.c'\" unpacked with wrong size!
fi
# end of 'transform.c'
fi
if test -f 'transform.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'transform.h'\"
else
echo shar: Extracting \"'transform.h'\" \(756 characters\)
sed "s/^X//" >'transform.h' <<'END_OF_FILE'
X/*
X * header file for transformed coordinate system.  No rotations
X * supported, as elipses cannot be rotated in X.
X */
X
Xtypedef struct _transform {
X	double	mx, bx;
X	double	my, by;
X} Transform;
X
Xtypedef struct _TPoint {
X	double	x, y;
X} TPoint;
X
Xtypedef struct _TRectangle {
X	double	x, y, width, height;
X} TRectangle;
X
X# define Xx(x,y,t)	((int)((t)->mx * (x) + (t)->bx + 0.5))
X# define Xy(x,y,t)	((int)((t)->my * (y) + (t)->by + 0.5))
X# define Xwidth(w,h,t)	((int)((t)->mx * (w) + 0.5))
X# define Xheight(w,h,t)	((int)((t)->my * (h) + 0.5))
X# define Tx(x,y,t)	((((double) (x)) - (t)->bx) / (t)->mx)
X# define Ty(x,y,t)	((((double) (y)) - (t)->by) / (t)->my)
X# define Twidth(w,h,t)	(((double) (w)) / (t)->mx)
X# define Theight(w,h,t)	(((double) (h)) / (t)->my)
END_OF_FILE
if test 756 -ne `wc -c <'transform.h'`; then
    echo shar: \"'transform.h'\" unpacked with wrong size!
fi
# end of 'transform.h'
fi
if test -f 'lclock.man' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'lclock.man'\"
else
echo shar: Extracting \"'lclock.man'\" \(1807 characters\)
sed "s/^X//" >'lclock.man' <<'END_OF_FILE'
X.TH LCLOCK 1 "Release 4" "X Version 11"
X.SH NAME
Xlclock \- display time of day
X.SH SYNOPSIS
X.B lclock
X[-option ...]
X.SH DESCRIPTION
X.I Clock
Xsimply displays the current time on an analog display
X.SH OPTIONS
X.TP 8
X.B \-bg \fIbackground color\fB
Xchoose a different color for the background.
X.TP 8
X.B \-minute \fIminute color\fB
Xchoose a different color for the minute hand of the clock.
X.TP 8
X.B \-hour \fIhour color\fB
Xchoose a different color for the hour hand of the clock.
X.TP 8
X.B \-backing \fI{ WhenMapped Always NotUseful }\fB
Xselects an appropriate level of backing store.
X.TP 8
X.B \-geometry \fIgeometry\fB
Xdefine the initial window geometry; see \fIX(1)\fP.
X.TP 8
X.B \-display \fIdisplay\fB
Xspecify the display to use; see \fIX(1)\fP.
X.TP 8
X.B \-bd \fIborder color\fB
Xchoose a different color for the window border.
X.TP 8
X.B \-bw \fIborder width\fB
Xchoose a different width for the window border.  As the Clock widget changes
Xits border around quite a bit, this is most usefully set to zero.
X.SH COLORS
XAlthough the default colors for the Clock widget are black and white, the
Xwidget was designed in color; unfortunately, the toolkit makes specifying
Xthese colors in a device-independent manner difficult.  If you want to
Xsee the correct colors, add the following lines to your resource file:
X.sp 1
XClock*Background: grey
X.br
XClock*BorderColor: light blue
X.br
XClock*hour: yellow
X.br
XClock*minute: yellow
X.SH BUGS
XShould really be called \fBxclock\fR, but that name was already taken.
X.SH "SEE ALSO"
XX(1), X Toolkit documentation
X.SH COPYRIGHT
XCopyright 1989, Massachusetts Institute of Technology.
XCopyright 1990, Network Computing Devices, Inc.
X.br
XSee \fIX(1)\fP for a full statement of rights and permissions.
X.SH AUTHOR
XKeith Packard, MIT X Consortium
XDave Lemke, Network Computing Devices, Inc
END_OF_FILE
if test 1807 -ne `wc -c <'lclock.man'`; then
    echo shar: \"'lclock.man'\" unpacked with wrong size!
fi
# end of 'lclock.man'
fi
echo shar: End of shell archive.
exit 0

------- End of Forwarded Message


dan
-----------------------------------------------------------
		    O'Reilly && Associates
		argv at sun.com / argv at ora.com
	   632 Petaluma Ave, Sebastopol, CA 95472 
     800-338-NUTS, in CA: 800-533-NUTS, FAX 707-829-0104
    Opinions expressed reflect those of the author only.



More information about the Comp.sources.x mailing list