transform.c revision 6ea72052
16ea72052Smrg/* $Xorg: transform.c,v 1.4 2001/02/09 02:05:33 xorgcvs Exp $ */
26ea72052Smrg/*
36ea72052Smrg
46ea72052SmrgCopyright 1993, 1998  The Open Group
56ea72052Smrg
66ea72052SmrgPermission to use, copy, modify, distribute, and sell this software and its
76ea72052Smrgdocumentation for any purpose is hereby granted without fee, provided that
86ea72052Smrgthe above copyright notice appear in all copies and that both that
96ea72052Smrgcopyright notice and this permission notice appear in supporting
106ea72052Smrgdocumentation.
116ea72052Smrg
126ea72052SmrgThe above copyright notice and this permission notice shall be included
136ea72052Smrgin all copies or substantial portions of the Software.
146ea72052Smrg
156ea72052SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
166ea72052SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
176ea72052SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
186ea72052SmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
196ea72052SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
206ea72052SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
216ea72052SmrgOTHER DEALINGS IN THE SOFTWARE.
226ea72052Smrg
236ea72052SmrgExcept as contained in this notice, the name of The Open Group shall
246ea72052Smrgnot be used in advertising or otherwise to promote the sale, use or
256ea72052Smrgother dealings in this Software without prior written authorization
266ea72052Smrgfrom The Open Group.
276ea72052Smrg
286ea72052Smrg*/
296ea72052Smrg/* $XFree86: xc/programs/oclock/transform.c,v 3.4 2001/07/25 15:05:15 dawes Exp $ */
306ea72052Smrg
316ea72052Smrg
326ea72052Smrg/*
336ea72052Smrg * transformed coordinate system objects for X
346ea72052Smrg */
356ea72052Smrg
366ea72052Smrg#include	<X11/Xlib.h>
376ea72052Smrg#include	"transform.h"
386ea72052Smrg#include	<stdlib.h>
396ea72052Smrg
406ea72052Smrgstatic XPoint *
416ea72052SmrgTranslatePoints(TPoint *points, int n_points,
426ea72052Smrg		Transform *t, int mode)
436ea72052Smrg{
446ea72052Smrg	XPoint	*xpoints;
456ea72052Smrg	int	i;
466ea72052Smrg	double	xoff = 0.0, yoff = 0.0;
476ea72052Smrg
486ea72052Smrg	xpoints = (XPoint *) malloc ((unsigned)n_points * sizeof (*xpoints));
496ea72052Smrg	if (!xpoints)
506ea72052Smrg		return 0;
516ea72052Smrg	for (i = 0; i < n_points; i++) {
526ea72052Smrg		xpoints[i].x = Xx(points[i].x + xoff, points[i].y + yoff, t);
536ea72052Smrg		xpoints[i].y = Xy(points[i].x + xoff, points[i].y + yoff, t);
546ea72052Smrg		if (mode == CoordModePrevious) {
556ea72052Smrg			xoff += points[i].x;
566ea72052Smrg			yoff += points[i].y;
576ea72052Smrg		}
586ea72052Smrg	}
596ea72052Smrg	return xpoints;
606ea72052Smrg}
616ea72052Smrg
626ea72052Smrgvoid
636ea72052SmrgTFillPolygon (dpy, d, gc, t, points, n_points, shape, mode)
646ea72052Smrgregister Display	*dpy;
656ea72052SmrgDrawable		d;
666ea72052SmrgGC			gc;
676ea72052SmrgTransform		*t;
686ea72052SmrgTPoint			*points;
696ea72052Smrgint			n_points;
706ea72052Smrgint			shape;
716ea72052Smrgint			mode;
726ea72052Smrg{
736ea72052Smrg	XPoint	*xpoints;
746ea72052Smrg
756ea72052Smrg	xpoints = TranslatePoints (points, n_points, t, mode);
766ea72052Smrg	if (xpoints) {
776ea72052Smrg		XFillPolygon (dpy, d, gc, xpoints, n_points, shape,
786ea72052Smrg				CoordModeOrigin);
796ea72052Smrg		free (xpoints);
806ea72052Smrg	}
816ea72052Smrg}
826ea72052Smrg
836ea72052Smrgvoid
846ea72052SmrgTDrawArc (dpy, d, gc, t, x, y, width, height, angle1, angle2)
856ea72052Smrg	register Display	*dpy;
866ea72052Smrg	Drawable		d;
876ea72052Smrg	GC			gc;
886ea72052Smrg	Transform		*t;
896ea72052Smrg	double			x, y, width, height;
906ea72052Smrg	int			angle1, angle2;
916ea72052Smrg{
926ea72052Smrg	int	xx, xy, xw, xh;
936ea72052Smrg
946ea72052Smrg	xx = Xx(x,y,t);
956ea72052Smrg	xy = Xy(x,y,t);
966ea72052Smrg	xw = Xwidth (width, height, t);
976ea72052Smrg	xh = Xheight (width, height, t);
986ea72052Smrg	if (xw < 0) {
996ea72052Smrg		xx += xw;
1006ea72052Smrg		xw = -xw;
1016ea72052Smrg	}
1026ea72052Smrg	if (xh < 0) {
1036ea72052Smrg		xy += xh;
1046ea72052Smrg		xh = -xh;
1056ea72052Smrg	}
1066ea72052Smrg	XDrawArc (dpy, d, gc, xx, xy, xw, xh, angle1, angle2);
1076ea72052Smrg}
1086ea72052Smrg
1096ea72052Smrgvoid
1106ea72052SmrgTFillArc (dpy, d, gc, t, x, y, width, height, angle1, angle2)
1116ea72052Smrg	register Display	*dpy;
1126ea72052Smrg	Drawable		d;
1136ea72052Smrg	GC			gc;
1146ea72052Smrg	Transform		*t;
1156ea72052Smrg	double			x, y, width, height;
1166ea72052Smrg	int			angle1, angle2;
1176ea72052Smrg{
1186ea72052Smrg	int	xx, xy, xw, xh;
1196ea72052Smrg
1206ea72052Smrg	xx = Xx(x,y,t);
1216ea72052Smrg	xy = Xy(x,y,t);
1226ea72052Smrg	xw = Xwidth (width, height, t);
1236ea72052Smrg	xh = Xheight (width, height, t);
1246ea72052Smrg	if (xw < 0) {
1256ea72052Smrg		xx += xw;
1266ea72052Smrg		xw = -xw;
1276ea72052Smrg	}
1286ea72052Smrg	if (xh < 0) {
1296ea72052Smrg		xy += xh;
1306ea72052Smrg		xh = -xh;
1316ea72052Smrg	}
1326ea72052Smrg	XFillArc (dpy, d, gc, xx, xy, xw, xh, angle1, angle2);
1336ea72052Smrg}
1346ea72052Smrg
1356ea72052Smrgvoid
1366ea72052SmrgSetTransform (t, xx1, xx2, xy1, xy2, tx1, tx2, ty1, ty2)
1376ea72052SmrgTransform	*t;
1386ea72052Smrgint		xx1, xx2, xy1, xy2;
1396ea72052Smrgdouble		tx1, tx2, ty1, ty2;
1406ea72052Smrg{
1416ea72052Smrg	t->mx = ((double) xx2 - xx1) / (tx2 - tx1);
1426ea72052Smrg	t->bx = ((double) xx1) - t->mx * tx1;
1436ea72052Smrg	t->my = ((double) xy2 - xy1) / (ty2 - ty1);
1446ea72052Smrg	t->by = ((double) xy1) - t->my * ty1;
1456ea72052Smrg}
146