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 double xoff = 0.0, yoff = 0.0; 446ea72052Smrg 456ea72052Smrg xpoints = (XPoint *) malloc ((unsigned)n_points * sizeof (*xpoints)); 466ea72052Smrg if (!xpoints) 47168023feSmrg return NULL; 48e32e2dabSmrg for (int i = 0; i < n_points; i++) { 496ea72052Smrg xpoints[i].x = Xx(points[i].x + xoff, points[i].y + yoff, t); 506ea72052Smrg xpoints[i].y = Xy(points[i].x + xoff, points[i].y + yoff, t); 516ea72052Smrg if (mode == CoordModePrevious) { 526ea72052Smrg xoff += points[i].x; 536ea72052Smrg yoff += points[i].y; 546ea72052Smrg } 556ea72052Smrg } 566ea72052Smrg return xpoints; 576ea72052Smrg} 586ea72052Smrg 596ea72052Smrgvoid 60168023feSmrgTFillPolygon (register Display *dpy, Drawable d, GC gc, Transform *t, 61168023feSmrg TPoint *points, int n_points, int shape, int mode) 626ea72052Smrg{ 636ea72052Smrg XPoint *xpoints; 646ea72052Smrg 656ea72052Smrg xpoints = TranslatePoints (points, n_points, t, mode); 666ea72052Smrg if (xpoints) { 676ea72052Smrg XFillPolygon (dpy, d, gc, xpoints, n_points, shape, 686ea72052Smrg CoordModeOrigin); 696ea72052Smrg free (xpoints); 706ea72052Smrg } 716ea72052Smrg} 726ea72052Smrg 736ea72052Smrgvoid 74168023feSmrgTFillArc (register Display *dpy, Drawable d, GC gc, Transform *t, 75168023feSmrg double x, double y, double width, double height, 76168023feSmrg int angle1, int angle2) 776ea72052Smrg{ 786ea72052Smrg int xx, xy, xw, xh; 796ea72052Smrg 806ea72052Smrg xx = Xx(x,y,t); 816ea72052Smrg xy = Xy(x,y,t); 826ea72052Smrg xw = Xwidth (width, height, t); 836ea72052Smrg xh = Xheight (width, height, t); 846ea72052Smrg if (xw < 0) { 856ea72052Smrg xx += xw; 866ea72052Smrg xw = -xw; 876ea72052Smrg } 886ea72052Smrg if (xh < 0) { 896ea72052Smrg xy += xh; 906ea72052Smrg xh = -xh; 916ea72052Smrg } 926ea72052Smrg XFillArc (dpy, d, gc, xx, xy, xw, xh, angle1, angle2); 936ea72052Smrg} 946ea72052Smrg 956ea72052Smrgvoid 96168023feSmrgSetTransform (Transform *t, int xx1, int xx2, int xy1, int xy2, 97168023feSmrg double tx1, double tx2, double ty1, double ty2) 986ea72052Smrg{ 996ea72052Smrg t->mx = ((double) xx2 - xx1) / (tx2 - tx1); 1006ea72052Smrg t->bx = ((double) xx1) - t->mx * tx1; 1016ea72052Smrg t->my = ((double) xy2 - xy1) / (ty2 - ty1); 1026ea72052Smrg t->by = ((double) xy1) - t->my * ty1; 1036ea72052Smrg} 104