transform.c revision 2ddb6cf1
1/*
2 * transformed coordinate system objects for X
3 */
4/* $XFree86: xc/programs/xeyes/transform.c,v 1.3 2000/02/17 14:00:35 dawes Exp $ */
5
6# include	<X11/Xos.h>
7# include	<stdlib.h>
8# include	<X11/Xlib.h>
9# include	"transform.h"
10
11#if 0
12static XPoint *
13TranslatePoints (TPoint *points, int n_points, Transform *t, int mode)
14{
15	XPoint	*xpoints;
16	int	i;
17	double	xoff = 0.0, yoff = 0.0;
18
19	xpoints = (XPoint *) malloc (n_points * sizeof (*xpoints));
20	if (!xpoints)
21		return NULL;
22	for (i = 0; i < n_points; i++) {
23		xpoints[i].x = Xx(points[i].x + xoff, points[i].y + yoff, t);
24		xpoints[i].y = Xy(points[i].x + xoff, points[i].y + yoff, t);
25		if (mode == CoordModePrevious) {
26			xoff += points[i].x;
27			yoff += points[i].y;
28		}
29	}
30	return xpoints;
31}
32
33static void
34TFillPolygon (
35    Display	*dpy,
36    Drawable	d,
37    GC		gc,
38    Transform	*t,
39    TPoint	*points,
40    int		n_points,
41    int		shape,
42    int		mode)
43{
44	XPoint	*xpoints;
45
46	xpoints = TranslatePoints (points, n_points, t, mode);
47	if (xpoints) {
48		XFillPolygon (dpy, d, gc, xpoints, n_points, shape,
49				CoordModeOrigin);
50		free (xpoints);
51	}
52}
53
54static void
55TDrawArc (
56    Display	*dpy,
57    Drawable	d,
58    GC		gc,
59    Transform	*t,
60    double	x,
61    double	y,
62    double	width,
63    double	height,
64    int		angle1,
65    int		angle2)
66{
67	int	xx, xy, xw, xh;
68
69	xx = Xx(x,y,t);
70	xy = Xy(x,y,t);
71	xw = Xwidth (width, height, t);
72	xh = Xheight (width, height, t);
73	if (xw < 0) {
74		xx += xw;
75		xw = -xw;
76	}
77	if (xh < 0) {
78		xy += xh;
79		xh = -xh;
80	}
81	XDrawArc (dpy, d, gc, xx, xy, xw, xh, angle1, angle2);
82}
83#endif
84
85void
86Trectangle(const Transform *t, const TRectangle *i, TRectangle *o)
87{
88    o->x = t->mx * i->x + t->bx;
89    o->y = t->my * i->y + t->by;
90    o->width = t->mx * i->width;
91    o->height = t->my * i->height;
92    if (o->width < 0) {
93	o->x += o->width;
94	o->width = -o->width;
95    }
96    if (o->height < 0) {
97	o->y += o->height;
98	o->height = -o->height;
99    }
100}
101
102void
103SetTransform (Transform *t,
104	      int xx1, int xx2, int xy1, int xy2,
105	      double tx1, double tx2, double ty1, double ty2)
106{
107	t->mx = ((double) xx2 - xx1) / (tx2 - tx1);
108	t->bx = ((double) xx1) - t->mx * tx1;
109	t->my = ((double) xy2 - xy1) / (ty2 - ty1);
110	t->by = ((double) xy1) - t->my * ty1;
111}
112