transform.c revision 168023fe
1/* $Xorg: transform.c,v 1.4 2001/02/09 02:05:33 xorgcvs Exp $ */ 2/* 3 4Copyright 1993, 1998 The Open Group 5 6Permission to use, copy, modify, distribute, and sell this software and its 7documentation for any purpose is hereby granted without fee, provided that 8the above copyright notice appear in all copies and that both that 9copyright notice and this permission notice appear in supporting 10documentation. 11 12The above copyright notice and this permission notice shall be included 13in all copies or substantial portions of the Software. 14 15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 19OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21OTHER DEALINGS IN THE SOFTWARE. 22 23Except as contained in this notice, the name of The Open Group shall 24not be used in advertising or otherwise to promote the sale, use or 25other dealings in this Software without prior written authorization 26from The Open Group. 27 28*/ 29/* $XFree86: xc/programs/oclock/transform.c,v 3.4 2001/07/25 15:05:15 dawes Exp $ */ 30 31 32/* 33 * transformed coordinate system objects for X 34 */ 35 36#include <X11/Xlib.h> 37#include "transform.h" 38#include <stdlib.h> 39 40static XPoint * 41TranslatePoints(TPoint *points, int n_points, 42 Transform *t, int mode) 43{ 44 XPoint *xpoints; 45 int i; 46 double xoff = 0.0, yoff = 0.0; 47 48 xpoints = (XPoint *) malloc ((unsigned)n_points * sizeof (*xpoints)); 49 if (!xpoints) 50 return NULL; 51 for (i = 0; i < n_points; i++) { 52 xpoints[i].x = Xx(points[i].x + xoff, points[i].y + yoff, t); 53 xpoints[i].y = Xy(points[i].x + xoff, points[i].y + yoff, t); 54 if (mode == CoordModePrevious) { 55 xoff += points[i].x; 56 yoff += points[i].y; 57 } 58 } 59 return xpoints; 60} 61 62void 63TFillPolygon (register Display *dpy, Drawable d, GC gc, Transform *t, 64 TPoint *points, int n_points, int shape, int mode) 65{ 66 XPoint *xpoints; 67 68 xpoints = TranslatePoints (points, n_points, t, mode); 69 if (xpoints) { 70 XFillPolygon (dpy, d, gc, xpoints, n_points, shape, 71 CoordModeOrigin); 72 free (xpoints); 73 } 74} 75 76void 77TDrawArc (register Display *dpy, Drawable d, GC gc, Transform *t, 78 double x, double y, double width, double height, 79 int angle1, int angle2) 80{ 81 int xx, xy, xw, xh; 82 83 xx = Xx(x,y,t); 84 xy = Xy(x,y,t); 85 xw = Xwidth (width, height, t); 86 xh = Xheight (width, height, t); 87 if (xw < 0) { 88 xx += xw; 89 xw = -xw; 90 } 91 if (xh < 0) { 92 xy += xh; 93 xh = -xh; 94 } 95 XDrawArc (dpy, d, gc, xx, xy, xw, xh, angle1, angle2); 96} 97 98void 99TFillArc (register Display *dpy, Drawable d, GC gc, Transform *t, 100 double x, double y, double width, double height, 101 int angle1, int angle2) 102{ 103 int xx, xy, xw, xh; 104 105 xx = Xx(x,y,t); 106 xy = Xy(x,y,t); 107 xw = Xwidth (width, height, t); 108 xh = Xheight (width, height, t); 109 if (xw < 0) { 110 xx += xw; 111 xw = -xw; 112 } 113 if (xh < 0) { 114 xy += xh; 115 xh = -xh; 116 } 117 XFillArc (dpy, d, gc, xx, xy, xw, xh, angle1, angle2); 118} 119 120void 121SetTransform (Transform *t, int xx1, int xx2, int xy1, int xy2, 122 double tx1, double tx2, double ty1, double ty2) 123{ 124 t->mx = ((double) xx2 - xx1) / (tx2 - tx1); 125 t->bx = ((double) xx1) - t->mx * tx1; 126 t->my = ((double) xy2 - xy1) / (ty2 - ty1); 127 t->by = ((double) xy1) - t->my * ty1; 128} 129