From dfc0320568e5237fff45b3f7fb6f332d1bf5e9bf Mon Sep 17 00:00:00 2001 From: Kaleb Keithley Date: Fri, 14 Nov 2003 16:49:22 +0000 Subject: Initial revision --- Eyes.c | 455 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Eyes.h | 44 ++++++ EyesP.h | 54 +++++++ eyes.bit | 21 +++ eyesmask.bit | 21 +++ transform.c | 121 ++++++++++++++++ transform.h | 35 +++++ xeyes.c | 132 +++++++++++++++++ xeyes.man | 56 ++++++++ 9 files changed, 939 insertions(+) create mode 100644 Eyes.c create mode 100644 Eyes.h create mode 100644 EyesP.h create mode 100644 eyes.bit create mode 100644 eyesmask.bit create mode 100644 transform.c create mode 100644 transform.h create mode 100644 xeyes.c create mode 100644 xeyes.man diff --git a/Eyes.c b/Eyes.c new file mode 100644 index 0000000..71c3c26 --- /dev/null +++ b/Eyes.c @@ -0,0 +1,455 @@ +/* $XConsortium: Eyes.c,v 1.28 94/04/17 20:45:22 eswu Exp $ */ +/* $XFree86: xc/programs/xeyes/Eyes.c,v 1.4 2001/08/27 23:35:13 dawes Exp $ */ +/* + +Copyright (c) 1991 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from the X Consortium. + +*/ + +/* + * Eyes.c + * + * a widget which follows the mouse around + */ + +# include +# include +# include +# include +# include +# include "EyesP.h" +# include +# include + +#if (defined(SVR4) || defined(SYSV) && defined(i386)) +extern double hypot(double, double); +#endif + +#define offset(field) XtOffsetOf(EyesRec, eyes.field) +#define goffset(field) XtOffsetOf(WidgetRec, core.field) + +static XtResource resources[] = { + {XtNwidth, XtCWidth, XtRDimension, sizeof(Dimension), + goffset(width), XtRImmediate, (XtPointer) 150}, + {XtNheight, XtCHeight, XtRDimension, sizeof(Dimension), + goffset(height), XtRImmediate, (XtPointer) 100}, + {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), + offset(puppixel), XtRString, XtDefaultForeground}, + {XtNoutline, XtCForeground, XtRPixel, sizeof(Pixel), + offset(outline), XtRString, XtDefaultForeground}, + {XtNcenterColor, XtCBackground, XtRPixel, sizeof (Pixel), + offset(center), XtRString, XtDefaultBackground}, + {XtNreverseVideo, XtCReverseVideo, XtRBoolean, sizeof (Boolean), + offset (reverse_video), XtRImmediate, (XtPointer) FALSE}, + {XtNbackingStore, XtCBackingStore, XtRBackingStore, sizeof (int), + offset (backing_store), XtRString, "default"}, + {XtNshapeWindow, XtCShapeWindow, XtRBoolean, sizeof (Boolean), + offset (shape_window), XtRImmediate, (XtPointer) TRUE}, +}; + +#undef offset +#undef goffset + +# define NUM_EYES 2 +# define EYE_X(n) ((n) * 2.0) +# define EYE_Y(n) (0.0) +# define EYE_OFFSET (0.1) /* padding between eyes */ +# define EYE_THICK (0.175) /* thickness of eye rim */ +# define BALL_WIDTH (0.3) +# define BALL_PAD (0.05) +# define EYE_WIDTH (2.0 - (EYE_THICK + EYE_OFFSET) * 2) +# define EYE_HEIGHT EYE_WIDTH +# define EYE_HWIDTH (EYE_WIDTH / 2.0) +# define EYE_HHEIGHT (EYE_HEIGHT / 2.0) +# define BALL_HEIGHT BALL_WIDTH +# define BALL_DIST ((EYE_WIDTH - BALL_WIDTH) / 2.0 - BALL_PAD) +# define W_MIN_X (-1.0 + EYE_OFFSET) +# define W_MAX_X (3.0 - EYE_OFFSET) +# define W_MIN_Y (-1.0 + EYE_OFFSET) +# define W_MAX_Y (1.0 - EYE_OFFSET) + +# define TPointEqual(a, b) ((a).x == (b).x && (a).y == (b).y) +# define XPointEqual(a, b) ((a).x == (b).x && (a).y == (b).y) + +static int delays[] = { 50, 100, 200, 400, 0 }; + +static void ClassInitialize(void) +{ + XtAddConverter( XtRString, XtRBackingStore, XmuCvtStringToBackingStore, + NULL, 0 ); +} + +WidgetClass eyesWidgetClass = (WidgetClass) &eyesClassRec; + +/* ARGSUSED */ +static void Initialize ( + Widget greq, + Widget gnew, + ArgList args, + Cardinal *num_args) +{ + EyesWidget w = (EyesWidget)gnew; + XtGCMask valuemask; + XGCValues myXGCV; + int shape_event_base, shape_error_base; + + /* + * set the colors if reverse video; these are the colors used: + * + * background - paper white + * foreground - text, ticks black + * border - border black (foreground) + * + * This doesn't completely work since the parent has already made up a + * border. Sigh. + */ + if (w->eyes.reverse_video) { + Pixel fg = w->eyes.puppixel; + Pixel bg = w->core.background_pixel; + + if (w->core.border_pixel == fg) + w->core.border_pixel = bg; + if (w->eyes.outline == fg) + w->eyes.outline = bg; + if (w->eyes.center == bg) + w->eyes.center = fg; + w->eyes.puppixel = bg; + w->core.background_pixel = fg; + } + + myXGCV.foreground = w->eyes.puppixel; + myXGCV.background = w->core.background_pixel; + valuemask = GCForeground | GCBackground; + w->eyes.pupGC = XtGetGC(gnew, valuemask, &myXGCV); + + myXGCV.foreground = w->eyes.outline; + valuemask = GCForeground | GCBackground; + w->eyes.outGC = XtGetGC(gnew, valuemask, &myXGCV); + + myXGCV.foreground = w->eyes.center; + myXGCV.background = w->eyes.puppixel; + valuemask = GCForeground | GCBackground; + w->eyes.centerGC = XtGetGC(gnew, valuemask, &myXGCV); + + w->eyes.update = 0; + /* wait for Realize to add the timeout */ + w->eyes.interval_id = 0; + + w->eyes.pupil[0].x = w->eyes.pupil[1].x = -1000; + w->eyes.pupil[0].y = w->eyes.pupil[1].y = -1000; + + w->eyes.mouse.x = w->eyes.mouse.y = -1000; + + if (w->eyes.shape_window && !XShapeQueryExtension (XtDisplay (w), + &shape_event_base, + &shape_error_base)) + w->eyes.shape_window = False; + w->eyes.shape_mask = 0; + w->eyes.shapeGC = 0; +} + +static void eyeLiner ( + EyesWidget w, + Drawable d, + GC outgc, + GC centergc, + int num) +{ + Display *dpy = XtDisplay(w); + + TFillArc (dpy, d, outgc, &w->eyes.t, + EYE_X(num) - EYE_HWIDTH - EYE_THICK, + EYE_Y(num) - EYE_HHEIGHT - EYE_THICK, + EYE_WIDTH + EYE_THICK * 2.0, + EYE_HEIGHT + EYE_THICK * 2.0, + 90 * 64, 360 * 64); + if (centergc) { + TFillArc (dpy, d, centergc, &w->eyes.t, + EYE_X(num) - EYE_HWIDTH, + EYE_Y(num) - EYE_HHEIGHT, + EYE_WIDTH, EYE_HEIGHT, + 90 * 64, 360 * 64); + } +} + +static TPoint computePupil ( + int num, + TPoint mouse) +{ + double cx, cy; + double dist; + double angle; + double x, y; + double h; + double dx, dy; + double cosa, sina; + TPoint ret; + + dx = mouse.x - EYE_X(num); + dy = mouse.y - EYE_Y(num); + if (dx == 0 && dy == 0) { + cx = EYE_X(num); + cy = EYE_Y(num); + } else { + angle = atan2 ((double) dy, (double) dx); + cosa = cos (angle); + sina = sin (angle); + h = hypot (EYE_HHEIGHT * cosa, EYE_HWIDTH * sina); + x = (EYE_HWIDTH * EYE_HHEIGHT) * cosa / h; + y = (EYE_HWIDTH * EYE_HHEIGHT) * sina / h; + dist = BALL_DIST * hypot (x, y); + if (dist > hypot ((double) dx, (double) dy)) { + cx = dx + EYE_X(num); + cy = dy + EYE_Y(num); + } else { + cx = dist * cosa + EYE_X(num); + cy = dist * sina + EYE_Y(num); + } + } + ret.x = cx; + ret.y = cy; + return ret; +} + +static void computePupils ( + TPoint mouse, + TPoint pupils[2]) +{ + pupils[0] = computePupil (0, mouse); + pupils[1] = computePupil (1, mouse); +} + +static void eyeBall ( + EyesWidget w, + GC gc, + int num) +{ + Display *dpy = XtDisplay(w); + Window win = XtWindow(w); + + TFillArc (dpy, win, gc, &w->eyes.t, + w->eyes.pupil[num].x - BALL_WIDTH / 2.0, + w->eyes.pupil[num].y - BALL_HEIGHT / 2.0, + BALL_WIDTH, BALL_HEIGHT, + 90 * 64, 360 * 64); +} + +static void repaint_window (EyesWidget w) +{ + if (XtIsRealized ((Widget) w)) { + eyeLiner (w, XtWindow (w), w->eyes.outGC, w->eyes.centerGC, 0); + eyeLiner (w, XtWindow (w), w->eyes.outGC, w->eyes.centerGC, 1); + computePupils (w->eyes.mouse, w->eyes.pupil); + eyeBall (w, w->eyes.pupGC, 0); + eyeBall (w, w->eyes.pupGC, 1); + } +} + +/* ARGSUSED */ +static void draw_it ( + XtPointer client_data, + XtIntervalId *id) /* unused */ +{ + EyesWidget w = (EyesWidget)client_data; + Window rep_root, rep_child; + int rep_rootx, rep_rooty; + unsigned int rep_mask; + int dx, dy; + TPoint mouse; + Display *dpy = XtDisplay (w); + Window win = XtWindow (w); + TPoint newpupil[2]; + XPoint xnewpupil, xpupil; + + if (XtIsRealized((Widget)w)) { + XQueryPointer (dpy, win, &rep_root, &rep_child, + &rep_rootx, &rep_rooty, &dx, &dy, &rep_mask); + mouse.x = Tx(dx, dy, &w->eyes.t); + mouse.y = Ty(dx, dy, &w->eyes.t); + if (!TPointEqual (mouse, w->eyes.mouse)) { + computePupils (mouse, newpupil); + xpupil.x = Xx(w->eyes.pupil[0].x, w->eyes.pupil[0].y, &w->eyes.t); + xpupil.y = Xy(w->eyes.pupil[0].x, w->eyes.pupil[0].y, &w->eyes.t); + xnewpupil.x = Xx(newpupil[0].x, newpupil[0].y, &w->eyes.t); + xnewpupil.y = Xy(newpupil[0].x, newpupil[0].y, &w->eyes.t); + if (!XPointEqual (xpupil, xnewpupil)) { + if (w->eyes.pupil[0].x != -1000 || w->eyes.pupil[0].y != -1000) + eyeBall (w, w->eyes.centerGC, 0); + w->eyes.pupil[0] = newpupil[0]; + eyeBall (w, w->eyes.pupGC, 0); + } + xpupil.x = Xx(w->eyes.pupil[1].x, w->eyes.pupil[1].y, &w->eyes.t); + xpupil.y = Xy(w->eyes.pupil[1].x, w->eyes.pupil[1].y, &w->eyes.t); + xnewpupil.x = Xx(newpupil[1].x, newpupil[1].y, &w->eyes.t); + xnewpupil.y = Xy(newpupil[1].x, newpupil[1].y, &w->eyes.t); + if (!XPointEqual (xpupil, xnewpupil)) { + if (w->eyes.pupil[1].x != -1 || w->eyes.pupil[1].y != -1) + eyeBall (w, w->eyes.centerGC, 1); + w->eyes.pupil[1] = newpupil[1]; + eyeBall (w, w->eyes.pupGC, 1); + } + w->eyes.mouse = mouse; + w->eyes.update = 0; + } else { + if (delays[w->eyes.update + 1] != 0) + ++w->eyes.update; + } + } + w->eyes.interval_id = + XtAppAddTimeOut(XtWidgetToApplicationContext((Widget) w), + delays[w->eyes.update], draw_it, (XtPointer)w); +} /* draw_it */ + +static void Resize (Widget gw) +{ + EyesWidget w = (EyesWidget) gw; + XGCValues xgcv; + Widget parent; + int x, y; + + if (XtIsRealized (gw)) + { + XClearWindow (XtDisplay (w), XtWindow (w)); + SetTransform (&w->eyes.t, + 0, w->core.width, + w->core.height, 0, + W_MIN_X, W_MAX_X, + W_MIN_Y, W_MAX_Y); + if (w->eyes.shape_window) { + w->eyes.shape_mask = XCreatePixmap (XtDisplay (w), XtWindow (w), + w->core.width, w->core.height, 1); + if (!w->eyes.shapeGC) + w->eyes.shapeGC = XCreateGC (XtDisplay (w), w->eyes.shape_mask, 0, &xgcv); + XSetForeground (XtDisplay (w), w->eyes.shapeGC, 0); + XFillRectangle (XtDisplay (w), w->eyes.shape_mask, w->eyes.shapeGC, 0, 0, + w->core.width, w->core.height); + XSetForeground (XtDisplay (w), w->eyes.shapeGC, 1); + eyeLiner (w, w->eyes.shape_mask, w->eyes.shapeGC, (GC) 0, 0); + eyeLiner (w, w->eyes.shape_mask, w->eyes.shapeGC, (GC) 0, 1); + x = y = 0; + for (parent = (Widget) w; XtParent (parent); parent = XtParent (parent)) { + x += parent->core.x + parent->core.border_width; + x += parent->core.y + parent->core.border_width; + } + XShapeCombineMask (XtDisplay (parent), XtWindow (parent), ShapeBounding, + x, y, w->eyes.shape_mask, ShapeSet); + XFreePixmap (XtDisplay (w), w->eyes.shape_mask); + } + } +} + +static void Realize ( + Widget gw, + XtValueMask *valueMask, + XSetWindowAttributes *attrs) +{ + EyesWidget w = (EyesWidget)gw; + + if (w->eyes.backing_store != Always + WhenMapped + NotUseful) { + attrs->backing_store = w->eyes.backing_store; + *valueMask |= CWBackingStore; + } + XtCreateWindow( gw, (unsigned)InputOutput, (Visual *)CopyFromParent, + *valueMask, attrs ); + Resize (gw); + w->eyes.interval_id = + XtAppAddTimeOut(XtWidgetToApplicationContext(gw), + delays[w->eyes.update], draw_it, (XtPointer)gw); +} + +static void Destroy (Widget gw) +{ + EyesWidget w = (EyesWidget)gw; + + if (w->eyes.interval_id) + XtRemoveTimeOut (w->eyes.interval_id); + XtReleaseGC(gw, w->eyes.pupGC); + XtReleaseGC(gw, w->eyes.outGC); + XtReleaseGC(gw, w->eyes.centerGC); +} + +/* ARGSUSED */ +static void Redisplay( + Widget gw, + XEvent *event, + Region region) +{ + EyesWidget w; + + w = (EyesWidget) gw; + w->eyes.pupil[0].x = -1000; + w->eyes.pupil[0].y = -1000; + w->eyes.pupil[1].x = -1000; + w->eyes.pupil[1].y = -1000; + (void) repaint_window ((EyesWidget)gw); +} + +/* ARGSUSED */ +static Boolean SetValues ( + Widget current, + Widget request, + Widget new, + ArgList args, + Cardinal *num_args) +{ + return( FALSE ); +} + +EyesClassRec eyesClassRec = { + { /* core fields */ + /* superclass */ &widgetClassRec, + /* class_name */ "Eyes", + /* size */ sizeof(EyesRec), + /* class_initialize */ ClassInitialize, + /* class_part_initialize */ NULL, + /* class_inited */ FALSE, + /* initialize */ Initialize, + /* initialize_hook */ NULL, + /* realize */ Realize, + /* actions */ NULL, + /* num_actions */ 0, + /* resources */ resources, + /* num_resources */ XtNumber(resources), + /* xrm_class */ NULLQUARK, + /* compress_motion */ TRUE, + /* compress_exposure */ TRUE, + /* compress_enterleave */ TRUE, + /* visible_interest */ FALSE, + /* destroy */ Destroy, + /* resize */ Resize, + /* expose */ Redisplay, + /* set_values */ SetValues, + /* set_values_hook */ NULL, + /* set_values_almost */ NULL, + /* get_values_hook */ NULL, + /* accept_focus */ NULL, + /* version */ XtVersion, + /* callback_private */ NULL, + /* tm_table */ NULL, + /* query_geometry */ XtInheritQueryGeometry, + } +}; diff --git a/Eyes.h b/Eyes.h new file mode 100644 index 0000000..239a127 --- /dev/null +++ b/Eyes.h @@ -0,0 +1,44 @@ +/* +* $XConsortium: Eyes.h,v 1.7 90/12/01 13:04:51 rws Exp $ +*/ + +#ifndef _XtEyes_h +#define _XtEyes_h + +/*********************************************************************** + * + * Eyes Widget + * + ***********************************************************************/ + +/* Parameters: + + Name Class RepType Default Value + ---- ----- ------- ------------- + background Background pixel White + border BorderColor pixel Black + borderWidth BorderWidth int 1 + foreground Foreground Pixel Black + outline Outline Pixel Black + height Height int 120 + mappedWhenManaged MappedWhenManaged Boolean True + reverseVideo ReverseVideo Boolean False + width Width int 120 + x Position int 0 + y Position int 0 + +*/ + +#define XtNoutline "outline" +#define XtNcenterColor "center" + +#define XtNshapeWindow "shapeWindow" +#define XtCShapeWindow "ShapeWindow" + +typedef struct _EyesRec *EyesWidget; /* completely defined in EyesPrivate.h */ +typedef struct _EyesClassRec *EyesWidgetClass; /* completely defined in EyesPrivate.h */ + +extern WidgetClass eyesWidgetClass; + +#endif /* _XtEyes_h */ +/* DON'T ADD STUFF AFTER THIS #endif */ diff --git a/EyesP.h b/EyesP.h new file mode 100644 index 0000000..7dea77a --- /dev/null +++ b/EyesP.h @@ -0,0 +1,54 @@ +/* +* $XConsortium: EyesP.h,v 1.9 90/12/01 13:04:43 rws Exp $ +*/ + +#ifndef _EyesP_h +#define _EyesP_h + +#include "Eyes.h" +#include +#include "transform.h" + +#define SEG_BUFF_SIZE 128 + +/* New fields for the eyes widget instance record */ +typedef struct { + Pixel puppixel; /* foreground pixel */ + Pixel outline; /* outline pixel */ + Pixel center; /* inside pixel */ + GC outGC; /* pointer to GraphicsContext */ + GC pupGC; /* pointer to GraphicsContext */ + GC centerGC; /* pointer to GraphicsContext */ + GC shapeGC; /* pointer to GraphicsContext */ +/* start of graph stuff */ + int backing_store; /* backing store variety */ + Boolean reverse_video; /* swap fg and bg pixels */ + Boolean shape_window; /* use SetWindowShapeMask */ + int update; /* current timeout index */ + TPoint mouse; /* old mouse position */ + TPoint pupil[2]; /* pupil position */ + Transform t; + Transform maskt; + XtIntervalId interval_id; + Pixmap shape_mask; /* window shape */ + } EyesPart; + +/* Full instance record declaration */ +typedef struct _EyesRec { + CorePart core; + EyesPart eyes; + } EyesRec; + +/* New fields for the Eyes widget class record */ +typedef struct {int dummy;} EyesClassPart; + +/* Full class record declaration. */ +typedef struct _EyesClassRec { + CoreClassPart core_class; + EyesClassPart eyes_class; + } EyesClassRec; + +/* Class pointer. */ +extern EyesClassRec eyesClassRec; + +#endif /* _EyesP_h */ diff --git a/eyes.bit b/eyes.bit new file mode 100644 index 0000000..4948216 --- /dev/null +++ b/eyes.bit @@ -0,0 +1,21 @@ +#define eyes_width 48 +#define eyes_height 32 +#define eyes_x_hot 0 +#define eyes_y_hot 0 +static unsigned char eyes_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x78, 0x00, 0x00, 0x1e, 0x00, 0x00, 0xfe, 0x01, 0x80, 0x7f, 0x00, + 0x00, 0x87, 0x03, 0xc0, 0xe1, 0x00, 0x80, 0x01, 0x06, 0x60, 0x80, 0x01, + 0xc0, 0x00, 0x0c, 0x30, 0x00, 0x03, 0x60, 0x00, 0x18, 0x18, 0x00, 0x06, + 0x30, 0x00, 0x30, 0x0c, 0x00, 0x0c, 0x30, 0x00, 0x30, 0x0c, 0x00, 0x0c, + 0x10, 0x00, 0x20, 0x04, 0x00, 0x08, 0x18, 0x00, 0x60, 0x06, 0x00, 0x18, + 0x18, 0x00, 0x60, 0x06, 0x00, 0x18, 0x18, 0x00, 0x60, 0x06, 0x00, 0x18, + 0x18, 0x00, 0x60, 0x06, 0x00, 0x18, 0x18, 0x00, 0x60, 0x06, 0x00, 0x18, + 0x18, 0x00, 0x60, 0x06, 0x00, 0x18, 0x18, 0x80, 0x63, 0x06, 0x00, 0x18, + 0x18, 0x80, 0x63, 0x06, 0xe0, 0x18, 0x18, 0x80, 0x63, 0x06, 0xe0, 0x18, + 0x18, 0x00, 0x60, 0x06, 0xe0, 0x18, 0x18, 0x00, 0x20, 0x06, 0x00, 0x08, + 0x10, 0x00, 0x30, 0x04, 0x00, 0x0c, 0x10, 0x00, 0x10, 0x04, 0x00, 0x04, + 0x30, 0x00, 0x18, 0x0c, 0x00, 0x06, 0x60, 0x00, 0x08, 0x18, 0x00, 0x02, + 0x40, 0x00, 0x0c, 0x10, 0x00, 0x03, 0xc0, 0x00, 0x06, 0x30, 0x80, 0x01, + 0x80, 0x83, 0x03, 0xe0, 0xe0, 0x00, 0x00, 0xff, 0x01, 0xc0, 0x7f, 0x00, + 0x00, 0xfe, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/eyesmask.bit b/eyesmask.bit new file mode 100644 index 0000000..0e4116b --- /dev/null +++ b/eyesmask.bit @@ -0,0 +1,21 @@ +#define eyesmask_width 48 +#define eyesmask_height 32 +#define eyesmask_x_hot 0 +#define eyesmask_y_hot 0 +static unsigned char eyesmask_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x78, 0x00, 0x00, 0x1e, 0x00, 0x00, 0xfe, 0x01, 0x80, 0x7f, 0x00, + 0x00, 0xff, 0x03, 0xc0, 0xff, 0x00, 0x80, 0xff, 0x07, 0xe0, 0xff, 0x01, + 0xc0, 0xff, 0x0f, 0xf0, 0xff, 0x03, 0xe0, 0xff, 0x1f, 0xf8, 0xff, 0x07, + 0xf0, 0xff, 0x3f, 0xfc, 0xff, 0x0f, 0xf0, 0xff, 0x3f, 0xfc, 0xff, 0x0f, + 0xf0, 0xff, 0x3f, 0xfc, 0xff, 0x0f, 0xf8, 0xff, 0x7f, 0xfe, 0xff, 0x1f, + 0xf8, 0xff, 0x7f, 0xfe, 0xff, 0x1f, 0xf8, 0xff, 0x7f, 0xfe, 0xff, 0x1f, + 0xf8, 0xff, 0x7f, 0xfe, 0xff, 0x1f, 0xf8, 0xff, 0x7f, 0xfe, 0xff, 0x1f, + 0xf8, 0xff, 0x7f, 0xfe, 0xff, 0x1f, 0xf8, 0xff, 0x7f, 0xfe, 0xff, 0x1f, + 0xf8, 0xff, 0x7f, 0xfe, 0xff, 0x1f, 0xf8, 0xff, 0x7f, 0xfe, 0xff, 0x1f, + 0xf8, 0xff, 0x7f, 0xfe, 0xff, 0x1f, 0xf8, 0xff, 0x3f, 0xfe, 0xff, 0x0f, + 0xf0, 0xff, 0x3f, 0xfc, 0xff, 0x0f, 0xf0, 0xff, 0x1f, 0xfc, 0xff, 0x07, + 0xf0, 0xff, 0x1f, 0xfc, 0xff, 0x07, 0xe0, 0xff, 0x0f, 0xf8, 0xff, 0x03, + 0xc0, 0xff, 0x0f, 0xf0, 0xff, 0x03, 0xc0, 0xff, 0x07, 0xf0, 0xff, 0x01, + 0x80, 0xff, 0x03, 0xe0, 0xff, 0x00, 0x00, 0xff, 0x01, 0xc0, 0x7f, 0x00, + 0x00, 0xfe, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/transform.c b/transform.c new file mode 100644 index 0000000..9495790 --- /dev/null +++ b/transform.c @@ -0,0 +1,121 @@ +/* + * transformed coordinate system objects for X + */ +/* $XFree86: xc/programs/xeyes/transform.c,v 1.4 2001/08/27 23:35:13 dawes Exp $ */ + +# include +# include +# include +# include "transform.h" + +#if 0 +static XPoint * +TranslatePoints (TPoint *points, int n_points, Transform *t, int mode) +{ + XPoint *xpoints; + int i; + double xoff = 0.0, yoff = 0.0; + + xpoints = (XPoint *) malloc (n_points * sizeof (*xpoints)); + if (!xpoints) + return NULL; + for (i = 0; i < n_points; i++) { + xpoints[i].x = Xx(points[i].x + xoff, points[i].y + yoff, t); + xpoints[i].y = Xy(points[i].x + xoff, points[i].y + yoff, t); + if (mode == CoordModePrevious) { + xoff += points[i].x; + yoff += points[i].y; + } + } + return xpoints; +} + +static void +TFillPolygon ( + Display *dpy, + Drawable d, + GC gc, + Transform *t, + TPoint *points, + int n_points, + int shape, + int mode) +{ + XPoint *xpoints; + + xpoints = TranslatePoints (points, n_points, t, mode); + if (xpoints) { + XFillPolygon (dpy, d, gc, xpoints, n_points, shape, + CoordModeOrigin); + free (xpoints); + } +} + +static void +TDrawArc ( + Display *dpy, + Drawable d, + GC gc, + Transform *t, + double x, + double y, + double width, + double height, + int angle1, + int angle2) +{ + int xx, xy, xw, xh; + + xx = Xx(x,y,t); + xy = Xy(x,y,t); + xw = Xwidth (width, height, t); + xh = Xheight (width, height, t); + if (xw < 0) { + xx += xw; + xw = -xw; + } + if (xh < 0) { + xy += xh; + xh = -xh; + } + XDrawArc (dpy, d, gc, xx, xy, xw, xh, angle1, angle2); +} +#endif + +void +TFillArc (dpy, d, gc, t, x, y, width, height, angle1, angle2) + Display *dpy; + Drawable d; + GC gc; + Transform *t; + double x, y, width, height; + int angle1, angle2; +{ + int xx, xy, xw, xh; + + xx = Xx(x,y,t); + xy = Xy(x,y,t); + xw = Xwidth (width, height, t); + xh = Xheight (width, height, t); + if (xw < 0) { + xx += xw; + xw = -xw; + } + if (xh < 0) { + xy += xh; + xh = -xh; + } + XFillArc (dpy, d, gc, xx, xy, xw, xh, angle1, angle2); +} + +void +SetTransform (t, xx1, xx2, xy1, xy2, tx1, tx2, ty1, ty2) + Transform *t; + int xx1, xx2, xy1, xy2; + double tx1, tx2, ty1, ty2; +{ + t->mx = ((double) xx2 - xx1) / (tx2 - tx1); + t->bx = ((double) xx1) - t->mx * tx1; + t->my = ((double) xy2 - xy1) / (ty2 - ty1); + t->by = ((double) xy1) - t->my * ty1; +} diff --git a/transform.h b/transform.h new file mode 100644 index 0000000..b22620d --- /dev/null +++ b/transform.h @@ -0,0 +1,35 @@ +/* + * header file for transformed coordinate system. No rotations + * supported, as elipses cannot be rotated in X. + */ +/* $XFree86: xc/programs/xeyes/transform.h,v 1.3 2000/02/17 14:00:35 dawes Exp $ */ + +typedef struct _transform { + double mx, bx; + double my, by; +} Transform; + +typedef struct _TPoint { + double x, y; +} TPoint; + +typedef struct _TRectangle { + double x, y, width, height; +} TRectangle; + +# define Xx(x,y,t) ((int)((t)->mx * (x) + (t)->bx + 0.5)) +# define Xy(x,y,t) ((int)((t)->my * (y) + (t)->by + 0.5)) +# define Xwidth(w,h,t) ((int)((t)->mx * (w) + 0.5)) +# define Xheight(w,h,t) ((int)((t)->my * (h) + 0.5)) +# define Tx(x,y,t) ((((double) (x)) - (t)->bx) / (t)->mx) +# define Ty(x,y,t) ((((double) (y)) - (t)->by) / (t)->my) +# define Twidth(w,h,t) (((double) (w)) / (t)->mx) +# define Theight(w,h,t) (((double) (h)) / (t)->my) + +extern void TFillArc (Display *dpy, Drawable d, GC gc, + Transform *t, + double x, double y, double width, double height, + int angle1, int angle2); +extern void SetTransform (Transform *t, + int xx1, int xx2, int xy1, int xy2, + double tx1, double tx2, double ty1, double ty2); diff --git a/xeyes.c b/xeyes.c new file mode 100644 index 0000000..a78cea1 --- /dev/null +++ b/xeyes.c @@ -0,0 +1,132 @@ +/* $XConsortium: xeyes.c,v 1.16 94/04/17 20:45:23 rws Exp $ */ +/* + +Copyright (c) 1991 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from the X Consortium. + +*/ +/* $XFree86: xc/programs/xeyes/xeyes.c,v 1.4 2001/08/27 23:35:13 dawes Exp $ */ + +#include +#include +#include +#include "Eyes.h" +#include +#include +#include "eyes.bit" +#include "eyesmask.bit" + +/* Exit with message describing command line format */ + +static void +usage(void) +{ + fprintf(stderr, +"usage: xeyes\n"); + fprintf (stderr, +" [-geometry [{width}][x{height}][{+-}{xoff}[{+-}{yoff}]]] [-display [{host}]:[{vs}]]\n"); + fprintf(stderr, +" [-fg {color}] [-bg {color}] [-bd {color}] [-bw {pixels}]"); + fprintf(stderr, " [-shape | +shape]"); + fprintf(stderr, "\n"); + fprintf(stderr, +" [-outline {color}] [-center {color}] [-backing {backing-store}]\n"); + exit(1); +} + +/* Command line options table. Only resources are entered here...there is a + pass over the remaining options after XtParseCommand is let loose. */ + +static XrmOptionDescRec options[] = { +{"-outline", "*eyes.outline", XrmoptionSepArg, NULL}, +{"-center", "*eyes.center", XrmoptionSepArg, NULL}, +{"-backing", "*eyes.backingStore", XrmoptionSepArg, NULL}, +{"-shape", "*eyes.shapeWindow", XrmoptionNoArg, "TRUE"}, +{"+shape", "*eyes.shapeWindow", XrmoptionNoArg, "FALSE"}, +}; + +static Atom wm_delete_window; + +/*ARGSUSED*/ +static void +quit(Widget w, XEvent *event, String *params, Cardinal *num_params) +{ + if (event->type == ClientMessage && + event->xclient.data.l[0] != wm_delete_window) { + XBell(XtDisplay(w), 0); + } else { + XtDestroyApplicationContext(XtWidgetToApplicationContext(w)); + exit(0); + } +} + +static XtActionsRec actions[] = { + {"quit", quit} +}; + +int +main(int argc, char **argv) +{ + XtAppContext app_context; + Widget toplevel; + Arg arg[2]; + Cardinal i; + + XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL); + + toplevel = XtAppInitialize(&app_context, "XEyes", + options, XtNumber(options), &argc, argv, + NULL, arg, (Cardinal) 0); + if (argc != 1) usage(); + + wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW", + False); + XtAppAddActions(app_context, actions, XtNumber(actions)); + XtOverrideTranslations + (toplevel, XtParseTranslationTable ("WM_PROTOCOLS: quit()")); + + i = 0; + XtSetArg (arg[i], XtNiconPixmap, + XCreateBitmapFromData (XtDisplay(toplevel), + XtScreen(toplevel)->root, + (char *)eyes_bits, eyes_width, eyes_height)); + i++; + XtSetArg (arg[i], XtNiconMask, + XCreateBitmapFromData (XtDisplay(toplevel), + XtScreen(toplevel)->root, + (char *)eyesmask_bits, + eyesmask_width, eyesmask_height)); + i++; + XtSetValues (toplevel, arg, i); + + (void) XtCreateManagedWidget ("eyes", eyesWidgetClass, toplevel, NULL, 0); + XtRealizeWidget (toplevel); + (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel), + &wm_delete_window, 1); + XtAppMainLoop(app_context); + + return 0; +} diff --git a/xeyes.man b/xeyes.man new file mode 100644 index 0000000..77b170f --- /dev/null +++ b/xeyes.man @@ -0,0 +1,56 @@ +.\" $XConsortium: xeyes.man,v 1.12 94/04/17 20:45:24 gildea Exp $ +.\" +.\" $XFree86: xc/programs/xeyes/xeyes.man,v 1.3 2001/01/27 18:21:12 dawes Exp $ +.\" +.TH XEYES 1 __xorgversion__ +.SH NAME +xeyes \- a follow the mouse X demo +.SH SYNOPSIS +.B xeyes +[-option ...] +.SH DESCRIPTION +.I Xeyes +watches what you do and reports to the Boss. +.SH OPTIONS +.TP 8 +.B \-fg \fIforeground color\fB +choose a different color for the pupil of the eyes. +.TP 8 +.B \-bg \fIbackground color\fB +choose a different color for the background. +.TP 8 +.B \-outline \fIoutline color\fB +choose a different color for the outline of the eyes. +.TP 8 +.B \-center \fIcenter color\fB +choose a different color for the center of the eyes. +.TP 8 +.B \-backing \fI{ WhenMapped Always NotUseful }\fB +selects an appropriate level of backing store. +.TP 8 +.B \-geometry \fIgeometry\fB +define the initial window geometry; see \fIX(__miscmansuffix__)\fP. +.TP 8 +.B \-display \fIdisplay\fB +specify the display to use; see \fIX(__miscmansuffix__)\fP. +.TP 8 +.B \-bd \fIborder color\fB +choose a different color for the window border. +.TP 8 +.B \-bw \fIborder width\fB +choose a different width for the window border. +.TP 8 +.B \-shape +uses the SHAPE extension to shape the window. This is the default. +.TP 8 +.B \+shape +Disables uses the SHAPE extension to shape the window. +.SH "SEE ALSO" +X(__miscmansuffix__), X Toolkit documentation +.br +See \fIX(__miscmansuffix__)\fP for a full statement of rights and permissions. +.SH AUTHOR +Keith Packard, MIT X Consortium +.br +Copied from the NeWS version written (apparantly) by Jeremy Huxtable as seen +at SIGGRAPH '88 -- cgit v1.2.3