1a1d141d5Smrg/* 2a1d141d5Smrg * transformed coordinate system objects for X 3a1d141d5Smrg */ 4a1d141d5Smrg 5a1d141d5Smrg# include <X11/Xos.h> 6a1d141d5Smrg# include <stdlib.h> 7a1d141d5Smrg# include <X11/Xlib.h> 8a1d141d5Smrg# include "transform.h" 9a1d141d5Smrg 10a1d141d5Smrg#if 0 11a1d141d5Smrgstatic XPoint * 12a1d141d5SmrgTranslatePoints (TPoint *points, int n_points, Transform *t, int mode) 13a1d141d5Smrg{ 14a1d141d5Smrg XPoint *xpoints; 15a1d141d5Smrg int i; 16a1d141d5Smrg double xoff = 0.0, yoff = 0.0; 17a1d141d5Smrg 18a1d141d5Smrg xpoints = (XPoint *) malloc (n_points * sizeof (*xpoints)); 19a1d141d5Smrg if (!xpoints) 20a1d141d5Smrg return NULL; 21a1d141d5Smrg for (i = 0; i < n_points; i++) { 22a1d141d5Smrg xpoints[i].x = Xx(points[i].x + xoff, points[i].y + yoff, t); 23a1d141d5Smrg xpoints[i].y = Xy(points[i].x + xoff, points[i].y + yoff, t); 24a1d141d5Smrg if (mode == CoordModePrevious) { 25a1d141d5Smrg xoff += points[i].x; 26a1d141d5Smrg yoff += points[i].y; 27a1d141d5Smrg } 28a1d141d5Smrg } 29a1d141d5Smrg return xpoints; 30a1d141d5Smrg} 31a1d141d5Smrg 32a1d141d5Smrgstatic void 33a1d141d5SmrgTFillPolygon ( 34a1d141d5Smrg Display *dpy, 35a1d141d5Smrg Drawable d, 36a1d141d5Smrg GC gc, 37a1d141d5Smrg Transform *t, 38a1d141d5Smrg TPoint *points, 39a1d141d5Smrg int n_points, 40a1d141d5Smrg int shape, 41a1d141d5Smrg int mode) 42a1d141d5Smrg{ 43a1d141d5Smrg XPoint *xpoints; 44a1d141d5Smrg 45a1d141d5Smrg xpoints = TranslatePoints (points, n_points, t, mode); 46a1d141d5Smrg if (xpoints) { 47a1d141d5Smrg XFillPolygon (dpy, d, gc, xpoints, n_points, shape, 48a1d141d5Smrg CoordModeOrigin); 49a1d141d5Smrg free (xpoints); 50a1d141d5Smrg } 51a1d141d5Smrg} 52a1d141d5Smrg 53a1d141d5Smrgstatic void 54a1d141d5SmrgTDrawArc ( 55a1d141d5Smrg Display *dpy, 56a1d141d5Smrg Drawable d, 57a1d141d5Smrg GC gc, 58a1d141d5Smrg Transform *t, 59a1d141d5Smrg double x, 60a1d141d5Smrg double y, 61a1d141d5Smrg double width, 62a1d141d5Smrg double height, 63a1d141d5Smrg int angle1, 64a1d141d5Smrg int angle2) 65a1d141d5Smrg{ 66a1d141d5Smrg int xx, xy, xw, xh; 67a1d141d5Smrg 68a1d141d5Smrg xx = Xx(x,y,t); 69a1d141d5Smrg xy = Xy(x,y,t); 70a1d141d5Smrg xw = Xwidth (width, height, t); 71a1d141d5Smrg xh = Xheight (width, height, t); 72a1d141d5Smrg if (xw < 0) { 73a1d141d5Smrg xx += xw; 74a1d141d5Smrg xw = -xw; 75a1d141d5Smrg } 76a1d141d5Smrg if (xh < 0) { 77a1d141d5Smrg xy += xh; 78a1d141d5Smrg xh = -xh; 79a1d141d5Smrg } 80a1d141d5Smrg XDrawArc (dpy, d, gc, xx, xy, xw, xh, angle1, angle2); 81a1d141d5Smrg} 82a1d141d5Smrg#endif 83a1d141d5Smrg 84a1d141d5Smrgvoid 852ddb6cf1SmrgTrectangle(const Transform *t, const TRectangle *i, TRectangle *o) 86a1d141d5Smrg{ 872ddb6cf1Smrg o->x = t->mx * i->x + t->bx; 882ddb6cf1Smrg o->y = t->my * i->y + t->by; 892ddb6cf1Smrg o->width = t->mx * i->width; 902ddb6cf1Smrg o->height = t->my * i->height; 912ddb6cf1Smrg if (o->width < 0) { 922ddb6cf1Smrg o->x += o->width; 932ddb6cf1Smrg o->width = -o->width; 942ddb6cf1Smrg } 952ddb6cf1Smrg if (o->height < 0) { 962ddb6cf1Smrg o->y += o->height; 972ddb6cf1Smrg o->height = -o->height; 982ddb6cf1Smrg } 99a1d141d5Smrg} 100a1d141d5Smrg 101a1d141d5Smrgvoid 1022ddb6cf1SmrgSetTransform (Transform *t, 1032ddb6cf1Smrg int xx1, int xx2, int xy1, int xy2, 1042ddb6cf1Smrg double tx1, double tx2, double ty1, double ty2) 105a1d141d5Smrg{ 106a1d141d5Smrg t->mx = ((double) xx2 - xx1) / (tx2 - tx1); 107a1d141d5Smrg t->bx = ((double) xx1) - t->mx * tx1; 108a1d141d5Smrg t->my = ((double) xy2 - xy1) / (ty2 - ty1); 109a1d141d5Smrg t->by = ((double) xy1) - t->my * ty1; 110a1d141d5Smrg} 111