summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2009-07-17 19:21:39 +1000
committerSung-Jin Park <sj76.park@samsung.com>2013-09-02 23:37:55 -0400
commit221d31fb2f3b2a2989a983cb30f866f57b683f52 (patch)
treec233679e0ea81df624b8053d2674b48691d9fb73
parentf979f83baa241a896c732fdd88b782dcd99ac9ef (diff)
downloadxeyes-221d31fb2f3b2a2989a983cb30f866f57b683f52.tar.gz
xeyes-221d31fb2f3b2a2989a983cb30f866f57b683f52.tar.bz2
xeyes-221d31fb2f3b2a2989a983cb30f866f57b683f52.zip
Split drawing code into multiple functions.
Change-Id: I5d0c297a851e4e53df4f224b28f458c938461dc0
-rw-r--r--Eyes.c101
1 files changed, 60 insertions, 41 deletions
diff --git a/Eyes.c b/Eyes.c
index e0912fb..3965833 100644
--- a/Eyes.c
+++ b/Eyes.c
@@ -268,55 +268,74 @@ static void repaint_window (EyesWidget w)
}
}
+static void draw_eye(EyesWidget w, TPoint mouse, int eye1, int eye2)
+{
+ TPoint newpupil[2];
+ XPoint xnewpupil, xpupil;
+
+ 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);
+ xpupil.x = Xx(newpupil[0].x, newpupil[0].y, &w->eyes.t);
+ xpupil.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, eye1);
+ w->eyes.pupil[0] = newpupil[0];
+ eyeBall (w, w->eyes.pupGC, eye1);
+ }
+
+ w->eyes.mouse = mouse;
+ w->eyes.update = 0;
+
+ if (eye1 == eye2)
+ return;
+
+ computePupils (mouse, newpupil);
+ 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);
+ xpupil.x = Xx(newpupil[1].x, newpupil[1].y, &w->eyes.t);
+ xpupil.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, eye2);
+ w->eyes.pupil[1] = newpupil[1];
+ eyeBall (w, w->eyes.pupGC, eye2);
+ }
+ } else {
+ if (delays[w->eyes.update + 1] != 0)
+ ++w->eyes.update;
+ }
+}
+
+static void draw_it_core(EyesWidget w)
+{
+ 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);
+
+ 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);
+
+ draw_eye(w, mouse, 0, 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;
- }
+ draw_it_core(w);
}
w->eyes.interval_id =
XtAppAddTimeOut(XtWidgetToApplicationContext((Widget) w),