Changeset 19835
- Timestamp:
- Oct 2, 2008, 10:44:40 AM (18 years ago)
- Location:
- trunk/Ohana/src/kapa2/src
- Files:
-
- 2 edited
-
PSOverlay.c (modified) (4 diffs)
-
PaintOverlay.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/kapa2/src/PSOverlay.c
r16255 r19835 1 1 # include "Ximage.h" 2 3 static char name[4][16] = {"red", "green", "blue", "yellow"}; 2 4 3 5 void PSOverlay (KapaImageWidget *image, int N, FILE *f, int extra) { … … 6 8 double X, Y, dX, dY; 7 9 int Xmin, Ymin, Xmax, Ymax; 8 double expand, X0, Y0; 10 double expand, pX, pY; 11 bDrawColor color; 9 12 13 /* translate color to bDrawColors : image[0].overlay[N].color */ 14 color = KapaColorByName (name[N]); 15 fprintf (f, "%s setrgbcolor\n", KapaColorRGBString(color)); 16 10 17 expand = 1.0; 11 18 if (image[0].picture.expand > 0) { 12 expand = 1 / (1.0*image[0].picture.expand);19 expand = image[0].picture.expand; 13 20 } 14 21 if (image[0].picture.expand < 0) { 15 expand = fabs((double)image[0].picture.expand);22 expand = 1.0 / fabs((double)image[0].picture.expand); 16 23 } 17 18 Image_to_Screen (&X0, &Y0, 0.0, 0.0, &image[0].picture);19 X0 -= image[0].picture.x;20 Y0 -= image[0].picture.y;21 24 22 25 Xmin = 0; … … 26 29 27 30 for (i = 0; i < image[0].overlay[N].Nobjects; i++) { 28 X = (image[0].overlay[N].objects[i].x)/expand + X0; 29 Y = Ymax - (image[0].overlay[N].objects[i].y)/expand - Y0; 30 dX = (image[0].overlay[N].objects[i].dx)/expand; 31 dY = (image[0].overlay[N].objects[i].dy)/expand; 32 31 32 Image_to_Screen (&X, &Y, image[0].overlay[N].objects[i].x, image[0].overlay[N].objects[i].y, &image[0].picture); 33 dX = image[0].overlay[N].objects[i].dx * expand; 34 dY = image[0].overlay[N].objects[i].dy * expand; 35 if (image[0].picture.flipx) dX *= -1; 36 if (image[0].picture.flipy) dY *= -1; 37 38 // PS coord system is flipped relative to screen 39 Y = Ymax - Y; 40 41 pX = (image[0].picture.flipx) ? -1.0 : +1.0; 42 pY = (image[0].picture.flipy) ? -1.0 : +1.0; 43 33 44 switch (image[0].overlay[N].objects[i].type) { 34 45 case KII_OVERLAY_LINE: … … 58 69 break; 59 70 } 60 // XXX add in the rotated ellipse version (rotate in PS space) 61 fprintf (f, " %6.1f %6.1f %6.1f C\n", X, Y, fabs(dX + extra)); 71 // is this a true circle, or is it an ellipse? 72 if (fabs(dX - dY) < 0.01) { 73 fprintf (f, " %6.1f %6.1f %6.1f C\n", X, Y, fabs(dX + extra)); 74 } else { 75 // moderately-stupid rotated ellipse drawing: 76 // ANGLE is distance ccw from the x-axis to the major axis 77 double x0, y0, x1, y1, t; 78 double angle = image[0].overlay[N].objects[i].angle * RAD_DEG; 79 double cs = cos(angle); 80 double sn = sin(angle); 81 x0 = X + pX*dX*cs; 82 y0 = Y + pY*dX*sn; 83 // XXX dt should be based on the size of the ellipse... 84 // 0.10 -> 60 segments on the ellipse 85 # define DT 0.1 86 for (t = DT; t < 2*M_PI + DT; t+=DT) { 87 x1 = X + pX*dX*cos(t)*cs - pX*dY*sin(t)*sn; 88 y1 = Y + pY*dX*cos(t)*sn + pY*dY*sin(t)*cs; 89 fprintf (f, " %6.1f %6.1f %6.1f %6.1f L\n", x0 + extra, y0 + extra, x1 + extra, y1 + extra); 90 x0 = x1; 91 y0 = y1; 92 } 93 } 62 94 break; 63 95 default: -
trunk/Ohana/src/kapa2/src/PaintOverlay.c
r17120 r19835 6 6 int dX, dY, dx, dy; 7 7 int x, y, Xmin, Ymin, Xmax, Ymax, Xrange, Yrange; 8 double t, expand, X, Y ;8 double t, expand, X, Y, pX, pY; 9 9 10 10 XSetForeground (graphic[0].display, graphic[0].gc, image[0].overlay[N].color); … … 37 37 if (Y - dY > Ymax); 38 38 39 pX = (image[0].picture.flipx) ? -1.0 : +1.0; 40 pY = (image[0].picture.flipy) ? -1.0 : +1.0; 41 39 42 /* for a LINE, (x, y) is the start, (dx, dy) is the distance to end 40 43 for a CIRCLE (x, y) is the center, (dx, dy) is the radius … … 62 65 XDrawArc (graphic[0].display, graphic[0].window, graphic[0].gc, (X - dx), (Y - dy), 2*dx, 2*dy, 0, 23040); 63 66 } else { 64 // very stupid rotate ellipse drawing: 67 // very stupid rotated ellipse drawing: 68 double x0, y0, x1, y1; 65 69 double angle = image[0].overlay[N].objects[i].angle * RAD_DEG; 66 70 double cs = cos(angle); 67 71 double sn = sin(angle); 72 x0 = X + pX*dx*cs; 73 y0 = Y - pY*dx*sn; 68 74 // XXX dt should be based on the size of the ellipse... 69 for (t = 0; t < 2*M_PI; t+=0.05) { 70 x = X + dx*cos(t)*cs + dy*sin(t)*sn; 71 y = Y - dx*cos(t)*sn + dy*sin(t)*cs; 72 XDrawPoint (graphic[0].display, graphic[0].window, graphic[0].gc, x, y); 75 // 0.10 -> 60 segments on the ellipse 76 # define DT 0.1 77 for (t = DT; t < 2*M_PI + DT; t+=DT) { 78 x1 = X + pX*dx*cos(t)*cs + pX*dy*sin(t)*sn; 79 y1 = Y - pY*dx*cos(t)*sn + pY*dy*sin(t)*cs; 80 XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, x0, y0, x1, y1); 81 x0 = x1; 82 y0 = y1; 73 83 } 74 84 }
Note:
See TracChangeset
for help on using the changeset viewer.
