home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / moonclock / src / transform.c < prev    next >
Text File  |  1994-02-19  |  2KB  |  113 lines

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