transform.c revision 49e82ceb
16ea72052Smrg/*
26ea72052Smrg
36ea72052SmrgCopyright 1993, 1998  The Open Group
46ea72052Smrg
56ea72052SmrgPermission to use, copy, modify, distribute, and sell this software and its
66ea72052Smrgdocumentation for any purpose is hereby granted without fee, provided that
76ea72052Smrgthe above copyright notice appear in all copies and that both that
86ea72052Smrgcopyright notice and this permission notice appear in supporting
96ea72052Smrgdocumentation.
106ea72052Smrg
116ea72052SmrgThe above copyright notice and this permission notice shall be included
126ea72052Smrgin all copies or substantial portions of the Software.
136ea72052Smrg
146ea72052SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
156ea72052SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
166ea72052SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
176ea72052SmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
186ea72052SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
196ea72052SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
206ea72052SmrgOTHER DEALINGS IN THE SOFTWARE.
216ea72052Smrg
226ea72052SmrgExcept as contained in this notice, the name of The Open Group shall
236ea72052Smrgnot be used in advertising or otherwise to promote the sale, use or
246ea72052Smrgother dealings in this Software without prior written authorization
256ea72052Smrgfrom The Open Group.
266ea72052Smrg
276ea72052Smrg*/
286ea72052Smrg
296ea72052Smrg
306ea72052Smrg/*
316ea72052Smrg * transformed coordinate system objects for X
326ea72052Smrg */
336ea72052Smrg
346ea72052Smrg#include	<X11/Xlib.h>
356ea72052Smrg#include	"transform.h"
366ea72052Smrg#include	<stdlib.h>
376ea72052Smrg
3849e82cebSmrgstatic XPoint *
3949e82cebSmrgTranslatePoints(TPoint *points, int n_points,
406ea72052Smrg		Transform *t, int mode)
416ea72052Smrg{
426ea72052Smrg	XPoint	*xpoints;
436ea72052Smrg	int	i;
446ea72052Smrg	double	xoff = 0.0, yoff = 0.0;
456ea72052Smrg
466ea72052Smrg	xpoints = (XPoint *) malloc ((unsigned)n_points * sizeof (*xpoints));
476ea72052Smrg	if (!xpoints)
48168023feSmrg		return NULL;
496ea72052Smrg	for (i = 0; i < n_points; i++) {
506ea72052Smrg		xpoints[i].x = Xx(points[i].x + xoff, points[i].y + yoff, t);
516ea72052Smrg		xpoints[i].y = Xy(points[i].x + xoff, points[i].y + yoff, t);
526ea72052Smrg		if (mode == CoordModePrevious) {
536ea72052Smrg			xoff += points[i].x;
546ea72052Smrg			yoff += points[i].y;
556ea72052Smrg		}
566ea72052Smrg	}
576ea72052Smrg	return xpoints;
586ea72052Smrg}
596ea72052Smrg
606ea72052Smrgvoid
61168023feSmrgTFillPolygon (register Display *dpy, Drawable d, GC gc, Transform *t,
62168023feSmrg	      TPoint *points, int n_points, int shape, int mode)
636ea72052Smrg{
646ea72052Smrg	XPoint	*xpoints;
656ea72052Smrg
666ea72052Smrg	xpoints = TranslatePoints (points, n_points, t, mode);
676ea72052Smrg	if (xpoints) {
686ea72052Smrg		XFillPolygon (dpy, d, gc, xpoints, n_points, shape,
696ea72052Smrg				CoordModeOrigin);
706ea72052Smrg		free (xpoints);
716ea72052Smrg	}
726ea72052Smrg}
736ea72052Smrg
746ea72052Smrgvoid
75168023feSmrgTDrawArc (register Display *dpy, Drawable d, GC gc, Transform *t,
76168023feSmrg	  double x, double y, double width, double height,
77168023feSmrg	  int angle1, int angle2)
786ea72052Smrg{
796ea72052Smrg	int	xx, xy, xw, xh;
806ea72052Smrg
816ea72052Smrg	xx = Xx(x,y,t);
826ea72052Smrg	xy = Xy(x,y,t);
836ea72052Smrg	xw = Xwidth (width, height, t);
846ea72052Smrg	xh = Xheight (width, height, t);
856ea72052Smrg	if (xw < 0) {
866ea72052Smrg		xx += xw;
876ea72052Smrg		xw = -xw;
886ea72052Smrg	}
896ea72052Smrg	if (xh < 0) {
906ea72052Smrg		xy += xh;
916ea72052Smrg		xh = -xh;
926ea72052Smrg	}
936ea72052Smrg	XDrawArc (dpy, d, gc, xx, xy, xw, xh, angle1, angle2);
946ea72052Smrg}
956ea72052Smrg
966ea72052Smrgvoid
97168023feSmrgTFillArc (register Display *dpy, Drawable d, GC gc, Transform *t,
98168023feSmrg	  double x, double y, double width, double height,
99168023feSmrg	  int angle1, int angle2)
1006ea72052Smrg{
1016ea72052Smrg	int	xx, xy, xw, xh;
1026ea72052Smrg
1036ea72052Smrg	xx = Xx(x,y,t);
1046ea72052Smrg	xy = Xy(x,y,t);
1056ea72052Smrg	xw = Xwidth (width, height, t);
1066ea72052Smrg	xh = Xheight (width, height, t);
1076ea72052Smrg	if (xw < 0) {
1086ea72052Smrg		xx += xw;
1096ea72052Smrg		xw = -xw;
1106ea72052Smrg	}
1116ea72052Smrg	if (xh < 0) {
1126ea72052Smrg		xy += xh;
1136ea72052Smrg		xh = -xh;
1146ea72052Smrg	}
1156ea72052Smrg	XFillArc (dpy, d, gc, xx, xy, xw, xh, angle1, angle2);
1166ea72052Smrg}
1176ea72052Smrg
1186ea72052Smrgvoid
119168023feSmrgSetTransform (Transform *t, int xx1, int xx2, int xy1, int xy2,
120168023feSmrg	      double tx1, double tx2, double ty1, double ty2)
1216ea72052Smrg{
1226ea72052Smrg	t->mx = ((double) xx2 - xx1) / (tx2 - tx1);
1236ea72052Smrg	t->bx = ((double) xx1) - t->mx * tx1;
1246ea72052Smrg	t->my = ((double) xy2 - xy1) / (ty2 - ty1);
1256ea72052Smrg	t->by = ((double) xy1) - t->my * ty1;
1266ea72052Smrg}
127