Index: /trunk/Ohana/src/kapa2/src/bDrawOverlay.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/bDrawOverlay.c	(revision 19837)
+++ /trunk/Ohana/src/kapa2/src/bDrawOverlay.c	(revision 19838)
@@ -7,7 +7,7 @@
 
   int i;
-  int dX, dY, dx, dy;
-  int X, Y, Xmin, Ymin, Xmax, Ymax, Xrange, Yrange;
-  double expand, X0, Y0;
+  int dx, dy;
+  int Xmin, Ymin, Xmax, Ymax, Xrange, Yrange;
+  double expand, X, Y, dX, dY, pX, pY;
   bDrawColor color;
  
@@ -18,13 +18,9 @@
   expand = 1.0;
   if (image[0].picture.expand > 0) {
-    expand = 1 / (1.0*image[0].picture.expand);
+    expand = image[0].picture.expand;
   }
   if (image[0].picture.expand < 0) {
-    expand = fabs((double)image[0].picture.expand);
+    expand = 1.0 / fabs((double)image[0].picture.expand);
   }
-
-  Image_to_Screen (&X0, &Y0, 0.0, 0.0, &image[0].picture);
-  X0 -= image[0].picture.x;
-  Y0 -= image[0].picture.y;
 
   Xmin = 0;
@@ -35,20 +31,23 @@
   Yrange = image[0].picture.dy;
 
+  if (N == INFRONT) {
+    fprintf (stderr, "INFRONT deprecated\n");
+    return;
+  } 
+
   for (i = 0; i < image[0].overlay[N].Nobjects; i++) {
-    if (N == INFRONT) {
-      X  = image[0].overlay[N].objects[i].x * Xrange;
-      Y  = image[0].overlay[N].objects[i].y * Yrange;
-      dX = image[0].overlay[N].objects[i].dx * Xrange;
-      dY = image[0].overlay[N].objects[i].dy * Yrange;
-    } else {
-      X  = image[0].overlay[N].objects[i].x/expand + X0;
-      Y =  image[0].overlay[N].objects[i].y/expand + Y0;
-      dX = image[0].overlay[N].objects[i].dx/expand;
-      dY = image[0].overlay[N].objects[i].dy/expand;
-    }
-    if ((X + dX < Xmin) || (X - dX > Xmax) ||
-	(Y + dY < Ymin) || (Y - dY > Ymax)) {
-      continue;
-    }
+    Image_to_Picture (&X, &Y, image[0].overlay[N].objects[i].x, image[0].overlay[N].objects[i].y, &image[0].picture);
+    dX = image[0].overlay[N].objects[i].dx * expand;
+    dY = image[0].overlay[N].objects[i].dy * expand;
+    if (image[0].picture.flipx) dX *= -1;
+    if (image[0].picture.flipy) dY *= -1;
+
+    if (X + dX < Xmin) continue;
+    if (X - dX > Xmax) continue;
+    if (Y + dY < Ymin) continue; 
+    if (Y - dY > Ymax);
+
+    pX = (image[0].picture.flipx) ? -1.0 : +1.0;
+    pY = (image[0].picture.flipy) ? -1.0 : +1.0;
 
     /* for a LINE, (x, y) is the start, (dx, dy) is the distance to end
@@ -75,14 +74,21 @@
 	  bDrawArc (X, Y, dx, dy, 0, 360);
 	} else {
-	  // very stupid rotate ellipse drawing:
-	  double x, y, t;
+	  // moderately-stupid rotated ellipse drawing:
+	  // ANGLE is distance ccw from the x-axis to the major axis
+	  double x0, y0, x1, y1, t;
 	  double angle = image[0].overlay[N].objects[i].angle * RAD_DEG;
 	  double cs = cos(angle);
 	  double sn = sin(angle);
+	  x0 = X + pX*dx*cs;
+	  y0 = Y - pY*dx*sn;
 	  // XXX dt should be based on the size of the ellipse...
-	  for (t = 0; t < 2*M_PI; t+=0.05) {
-	    x = X + dx*cos(t)*cs + dy*sin(t)*sn;
-	    y = Y - dx*cos(t)*sn + dy*sin(t)*cs;
-	    bDrawPoint (x, y);
+	  // 0.10 -> 60 segments on the ellipse
+	  # define DT 0.1
+	  for (t = DT; t < 2*M_PI + DT; t+=DT) {
+	    x1 = X + pX*dx*cos(t)*cs + pX*dy*sin(t)*sn;
+	    y1 = Y - pY*dx*cos(t)*sn + pY*dy*sin(t)*cs;
+	    bDrawLine (x0, y0, x1, y1);
+	    x0 = x1;
+	    y0 = y1;
 	  }
 	}
