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