r186: *** empty log message ***
[ctsim.git] / libctgraphics / sgp.cpp
index 52a2430ad942d98d0f63d2b934a671db10b5f6d0..c1004d699bc2a720b9c2e4e1ab80c16d8a53a0ca 100644 (file)
@@ -7,7 +7,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: sgp.cpp,v 1.11 2000/08/27 20:32:55 kevin Exp $
+**  $Id: sgp.cpp,v 1.12 2000/08/31 08:38:58 kevin Exp $
 **
 **  This program is free software; you can redistribute it and/or modify
 **  it under the terms of the GNU General Public License (version 2) as
@@ -53,9 +53,8 @@ int SGP::s_iRGBColorCount = sizeof(s_aRGBColor) / sizeof(class RGBColor);
 
 #ifdef HAVE_WXWINDOWS
 SGPDriver::SGPDriver (wxDC* pDC, int xsize = 640, int ysize = 480)
-  : m_iPhysicalXSize(xsize), m_iPhysicalYSize(ysize), m_idDriver(0)
+  : m_iPhysicalXSize(xsize), m_iPhysicalYSize(ysize), m_idDriver(0), m_pDC(pDC)
 {
-  m_pDC = pDC;
   m_idDriver |= SGPDRIVER_WXWINDOWS;
 }
 #endif
@@ -103,7 +102,6 @@ SGP::SGP (const SGPDriver& driver)
   setTextAngle (0.);
   setTextSize (1. / 25.);
   setColor (C_BLACK);
-
 }
 
 
@@ -199,6 +197,15 @@ SGP::setViewport (double xmin, double ymin, double xmax, double ymax)
   viewNDC[3] = ymax;
 }
 
+void
+SGP::getViewport (double& xmin, double& ymin, double& xmax, double& ymax)
+{
+    xmin = xv_min;
+    ymin = yv_min;
+    xmax = xv_max;
+    ymax = yv_max;
+}
+
 
 // NAME
 //     frameViewport           draw box around viewport
@@ -566,47 +573,46 @@ SGP::drawRect (double xmin, double ymin, double xmax, double ymax)
 void 
 SGP::drawCircle (const double r)
 {
-       drawArc (r, 0.0, 7.0);
+       drawArc (r, 0.0, TWOPI);
 }
 
-// =============================================================
-// draw arc around current center.  pass angles and radius     
+//==============================================================
+// draw arc around current center.  angles in radius   
 //==============================================================
 
 void 
 SGP::drawArc (const double r, double start, double stop)
 {
-  if ((stop-start) > 2 * PI)
-    stop = start + 2 * PI;
-  if ((start-stop) > 2 * PI)
-    stop = start + 2 * PI;
-  while (start >= stop)
-    stop += 2*PI;
+  if (start > stop) {
+    double temp = start;
+    start = stop;
+    stop = temp;
+  }
 
   double x = r * cos ((double) start);
   double y = r * sin ((double) start);
   moveRel (x, y);          // move from center to start of arc 
 
-  double theta = 5 * PI / 180;
-  double c = cos(theta);
-  double s = sin(theta);
+  const double thetaIncrement = (5 * (TWOPI / 360)); 
+  double cosTheta = cos(thetaIncrement);
+  double sinTheta = sin(thetaIncrement);
 
   double angle, xp, yp;
-  for (angle = start; angle < stop - theta; angle += theta) {
-    xp = c * x - s * y;
-    yp = s * x + c * y;
-    lineRel (xp - x, yp - y);
+  for (angle = start; angle < stop - thetaIncrement; angle += thetaIncrement) {
+    xp = cosTheta * x - sinTheta * y; // translate point by thetaIncrement
+    yp = sinTheta * x + cosTheta * y;
+    lineAbs (xp, yp);
     x = xp; y = yp;
   }
 
-  c = cos (stop - angle);
-  s = sin (stop - angle);
+  double c = cos (stop - angle);
+  double s = sin (stop - angle);
   xp = c * x - s * y;
   yp = s * x + c * y;
-  lineRel (xp - x, yp - y);
+  lineAbs (xp, yp);
 
-  x = r * cos ((double) stop);
-  y = r * sin ((double) stop);
+  x = r * cos (stop);
+  y = r * sin (stop);
   moveRel (-x, -y);            // move back to center of circle 
 }
 
@@ -783,3 +789,13 @@ const unsigned char SGP::MARKER_BITMAP[MARK_COUNT][5] =
     {'\076', '\042', '\042', '\042', '\076'},    // big open square 
     {'\010', '\024', '\042', '\024', '\010'},    // big open diamond 
 };
+
+
+#if HAVE_WXWINDOWS
+void
+SGP::setDC (wxDC* pDC)
+{
+  if (m_driver.isWX())
+    m_driver.setDC(pDC);
+}
+#endif