Пример #1
0
static void
make_eye(ModeInfo * mi, Drawable d, Eyes * e, int n, int full)
{
	EyeScrInfo *ep = &eye_info[MI_SCREEN(mi)];
	Display    *display = MI_DISPLAY(mi);
	GC          gc = ep->eyeGC;
	XRectangle *bbox = &e->bbox;
	XRectangle  tmp1, tmp2;

	if (full) {
		/* draw the outer (eyelid) oval */
		XSetForeground(display, gc, e->eyelid_pixel);
		TFillArc(display, d, gc, &e->transform,
			 EYE_X(n) - EYE_HWIDTH - EYE_THICK,
			 EYE_Y(n) - EYE_HHEIGHT - EYE_THICK,
			 EYE_WIDTH + EYE_THICK * 2.0,
			 EYE_HEIGHT + EYE_THICK * 2.0,
			 90 * 64, 360 * 64, &tmp1);

		/* draw the inner (eyeball) oval */
		XSetForeground(display, gc, e->eyeball_pixel);
		TFillArc(display, d, gc, &e->transform,
			 EYE_X(n) - EYE_HWIDTH, EYE_Y(n) - EYE_HHEIGHT,
			 EYE_WIDTH, EYE_HEIGHT, 90 * 64, 360 * 64, &tmp2);

		join_rects(&tmp1, &tmp2, &tmp1);

		/* draw the pupil on top of the eyeball oval */
		XSetForeground(display, gc, e->pupil_pixel);
		TFillArc(display, d, gc, &e->transform,
			 e->pupil[n].x - BALL_WIDTH / 2.0,
			 e->pupil[n].y - BALL_HEIGHT / 2.0,
			 BALL_WIDTH, BALL_HEIGHT, 90 * 64, 360 * 64, &tmp2);

		join_rects(&tmp1, &tmp2, bbox);
	} else {
		/* undraw the pupil */
		XSetForeground(display, gc, e->eyeball_pixel);
		TFillArc(display, d, gc, &e->transform,
			 e->last_pupil[n].x - BALL_WIDTH / 2.0,
			 e->last_pupil[n].y - BALL_HEIGHT / 2.0,
			 BALL_WIDTH, BALL_HEIGHT, 90 * 64, 360 * 64, &tmp1);

		/* draw the pupil on top of the eyeball oval */
		XSetForeground(display, gc, e->pupil_pixel);
		TFillArc(display, d, gc, &e->transform,
			 e->pupil[n].x - BALL_WIDTH / 2.0,
			 e->pupil[n].y - BALL_HEIGHT / 2.0,
			 BALL_WIDTH, BALL_HEIGHT, 90 * 64, 360 * 64, &tmp2);

		join_rects(&tmp1, &tmp2, bbox);
	}
}
Пример #2
0
static void
eyeLiner(EyesWidget	w,
	 Boolean	draw,
	 int		num)
{
    drawEllipse(w, draw ? PART_OUTLINE : PART_SHAPE,
		EYE_X(num), EYE_Y(num),
		TPOINT_NONE, TPOINT_NONE,
		EYE_DIAM + 2.0*EYE_THICK);
    if (draw) {
	drawEllipse(w, PART_CENTER, EYE_X(num), EYE_Y(num),
		    TPOINT_NONE, TPOINT_NONE,
		    EYE_DIAM);
    }
}
Пример #3
0
static  void
computePupil(int num, TPoint mouse, TPoint *ret)
{
	double      cx, cy;
	double      dist;
	double      angle;
	double      x, y;
	double      h;
	double      dx, dy;
	double      cosa, sina;

	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 {
		/* Avoid atan2: DOMAIN error message */
		if (dx == 0.0 && dy == 0.0)
			angle = 0.0;
		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;
}
Пример #4
0
Файл: Eyes.c Проект: aosm/X11
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;
}
Пример #5
0
Файл: Eyes.c Проект: aosm/X11
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);
	}
}
Пример #6
0
static TPoint
ComputePupil(int num, TPoint mouse, const TRectangle* screen)
{
   float   cx, cy;
   float   dist;
   float   angle;
   float   dx, dy;
   float   cosa, sina;
   TPoint   ret;

   cx = EYE_X(num); dx = mouse.x - cx;
   cy = EYE_Y(num); dy = mouse.y - cy;
   if (dx == 0 && dy == 0);
   else {
      angle = atan2 ((float) dy, (float) dx);
      cosa = cos (angle);
      sina = sin (angle);
      dist = BALL_DIST;
      if (screen)
      {
          /* use distance mapping */
          float x0, y0, x1, y1;
          float a[4];
          x0 = screen->x - cx;
          y0 = screen->y - cy;
          x1 = x0 + screen->width;
          y1 = y0 + screen->height;
          a[0] = atan2(y0, x0);
          a[1] = atan2(y1, x0);
          a[2] = atan2(y1, x1);
          a[3] = atan2(y0, x1);
          if (AngleBetween(angle, a[0], a[1]))
          {
              /* left */
              dist *= dx / x0;
          }
          else if (AngleBetween(angle, a[1], a[2]))
          {
              /* bottom */
              dist *= dy / y1;
          }
          else if (AngleBetween(angle, a[2], a[3]))
          {
              /* right */
              dist *= dx / x1;
          }
          else if (AngleBetween(angle, a[3], a[0]))
          {
              /* top */
              dist *= dy / y0;
          }
          if (dist > BALL_DIST)
              dist = BALL_DIST;
      }
      if (dist > hypot ((double) dx, (double) dy)) {
          cx += dx;
          cy += dy;
      } else {
          cx += dist * cosa;
          cy += dist * sina;
      }
   }
   ret.x =  cx;
   ret.y = -cy;
   return ret;
}