/* 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 drawEyes(EyesWidget w, TPoint mouse) { TPoint newpupil[2]; int num; if (TPointEqual (mouse, w->eyes.mouse)) { if (delays[w->eyes.update + 1] != 0) ++w->eyes.update; return; } computePupils (w, mouse, newpupil); for (num = 0; num < 2; num ++) { drawEye(w, newpupil[num], num); } w->eyes.mouse = mouse; w->eyes.update = 0; }
static void paint_eyes(ModeInfo * mi, Eyes * e, Fly * f, Eyes * eyes, int num_eyes) { EyeScrInfo *ep = &eye_info[MI_SCREEN(mi)]; Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = ep->eyeGC; Bool iconic = MI_IS_ICONIC(mi); int focusx = (f->x + (f->width / 2)) - e->x; int focusy = (f->y + (f->height / 2)) - e->y; Pixmap pix = e->pixmap; TPoint point; int i; if (pix == None) { e->time_to_die = 0; /* "should not happen" */ } if (ep->time >= e->time_to_die) { /* Sorry Bud, your time is up */ if (e->painted) { /* only unpaint it if previously painted */ XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XFillRectangle(display, window, gc, e->x, e->y, e->width, e->height); } /* randomly place the eyes elsewhere */ create_eyes(mi, e, eyes, num_eyes); pix = e->pixmap; /* pixmap may have changed */ } /* If the bouncer would intersect this pair of eyes, force the * eyes to move. This simplifies the code, because we do not * have to deal with drawing the bouncer on top of the eyes. * When trying to do so, there was too much annoying flashing * and ghost images from the undraw. I decided to observe the * KISS principle and keep it simple. I think the effect is * better also. * We must draw the flyer on the eyes when iconic, but that is * easy because the eyes repaint the whole box each time. */ if ((!iconic) && (fly_touches_eye(f, e))) { e->time_to_die = 0; } if (e->time_to_die == 0) { return; /* collides with something */ } /* set the point to look at and compute the pupil position */ point.x = Tx(focusx, focusy, &e->transform); point.y = Ty(focusx, focusy, &e->transform); computePupil(0, point, &(e->pupil[0])); computePupil(1, point, &(e->pupil[1])); if (e->painted) { /* if still looking at the same point, do nothing further */ if (TPointEqual(e->pupil[0], e->last_pupil[0]) && TPointEqual(e->pupil[1], e->last_pupil[1])) { return; } } for (i = 0; i < 2; i++) { /* update the eye, calculates the changed rectangle */ make_eye(mi, pix, e, i, False); /* Only blit the change if the full image has been painted */ if (e->painted) { /* copy the changed rectangle out to the screen */ XCopyArea(display, pix, window, gc, e->bbox.x, e->bbox.y, (int) e->bbox.width, (int) e->bbox.height, e->x + e->bbox.x, e->y + e->bbox.y); } /* remember where we're looking, for the next time around */ e->last_pupil[i] = e->pupil[i]; } /* always do full paint when iconic, eliminates need to track fly */ if (iconic || (!e->painted)) { XCopyArea(display, pix, window, gc, 0, 0, e->width, e->height, e->x, e->y); } /* when iconic, pretend to never paint, causes full paint each time */ if (!iconic) { e->painted++; /* note that a paint has been done */ } }