r168: *** empty log message ***
[ctsim.git] / libctgraphics / sgp.cpp
index 4d70f8cfe965f265f99f06d723542bd7d8603883..9d3f1fc0990e1c0cfab04cffdbcbc7d1caae7611 100644 (file)
@@ -7,7 +7,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: sgp.cpp,v 1.6 2000/07/28 10:51:31 kevin Exp $
+**  $Id: sgp.cpp,v 1.9 2000/08/02 18:06:00 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
 #include "sgp.h"
 
 
+RGBColor SGP::s_aRGBColor[] =
+{
+  RGBColor (0, 0, 0),
+  RGBColor (0, 0, 128),
+  RGBColor (0, 128, 0),
+  RGBColor (0, 128, 128),
+  RGBColor (128, 0, 0),
+  RGBColor (128, 0, 128),
+  RGBColor (128, 128, 0),
+  RGBColor (80, 80, 80),
+  RGBColor (160, 160, 160),
+  RGBColor (0, 0, 255),
+  RGBColor (0, 255, 0),
+  RGBColor (0, 255, 255),
+  RGBColor (255, 0, 0),
+  RGBColor (255, 0, 255),
+  RGBColor (255, 255, 0),
+  RGBColor (255, 255, 255),
+};
+
+int SGP::s_iRGBColorCount = sizeof(s_aRGBColor) / sizeof(class RGBColor);
 
 #ifdef HAVE_WXWINDOWS
-SGPDriver::SGPDriver (wxDC* pDC, const char* szWinTitle = "", int xsize = 640, int ysize = 480)
-  : m_iPhysicalXSize(xsize), m_iPhysicalYSize(ysize), m_sWindowTitle(szWinTitle), m_idDriver(0)
+SGPDriver::SGPDriver (wxDC* pDC, int xsize = 640, int ysize = 480)
+  : m_iPhysicalXSize(xsize), m_iPhysicalYSize(ysize), m_idDriver(0)
 {
   m_pDC = pDC;
   m_idDriver |= SGPDRIVER_WXWINDOWS;
@@ -72,11 +93,11 @@ SGP::SGP (const SGPDriver& driver)
   setWindow (0., 0., 1., 1.);
   setViewport (0., 0., 1., 1.);
   moveAbs (0., 0.);
-  m_iCurrentPhysicalX = 0;
-  m_iCurrentPhysicalY = 0;
+  stylusNDC (0., 0., false);
  
   setTextAngle (0.);
   setTextSize (1. / 25.);
+  setColor (C_BLACK);
 }
 
 
@@ -89,10 +110,14 @@ SGP::stylusNDC (double x, double y, bool beam)
     yp = m_iPhysicalYSize - yp;
 
   if (beam) {
+#if HAVE_WXWINDOWS
       if (m_driver.isWX())
          m_driver.idWX()->DrawLine (m_iCurrentPhysicalX, m_iCurrentPhysicalY, xp, yp);
+#endif
+#if HAVE_G2_H
       if (m_driver.isG2())
          g2_line (m_driver.idG2(), m_iCurrentPhysicalX, m_iCurrentPhysicalY, xp, yp);
+#endif
   }
   m_iCurrentPhysicalX = xp;
   m_iCurrentPhysicalY = yp;
@@ -115,10 +140,14 @@ SGP::pointNDC (double x, double y)
 void 
 SGP::eraseWindow ()
 {
+#if HAVE_G2_H
   if (m_driver.isG2())
     g2_clear (m_driver.idG2());
+#endif
+#if HAVE_WXWINDOWS
   if (m_driver.isWX())
     m_driver.idWX()->Clear();
+#endif
 }
 
 // NAME
@@ -186,8 +215,86 @@ SGP::setTextColor (int iFGcolor, int iBGcolor)
 void 
 SGP::setColor (int icol)
 {
+  if (icol >= 0 && icol < s_iRGBColorCount) {
+#if HAVE_G2_H
+    if (m_driver.isG2()) {
+      int iInk = g2_ink (m_driver.idG2(), s_aRGBColor[icol].getRed() / 255., s_aRGBColor[icol].getGreen() / 255., s_aRGBColor[icol].getBlue() / 255.);
+      g2_pen (m_driver.idG2(), iInk);
+    }
+#endif
+#if HAVE_WXWINDOWS
+    if (m_driver.isWX()) {
+      wxColor colour (s_aRGBColor[icol].getRed(), s_aRGBColor[icol].getGreen(), s_aRGBColor[icol].getBlue());
+      wxPen pen (colour, 1, wxSOLID);
+      m_driver.idWX()->SetPen (pen);
+    }
+#endif
+  }
+}
+
+void
+SGP::setRasterOp (int ro)
+{
+#if HAVE_WXWINDOWS
+  if (m_driver.isWX()) {
+    int wxFxn = -1;
+    switch (ro) {
+    case RO_AND:
+      wxFxn = wxAND;
+      break;
+    case RO_AND_INVERT:
+      wxFxn = wxAND_INVERT;
+      break;
+    case RO_AND_REVERSE:
+      wxFxn = wxAND_REVERSE;
+      break;
+    case RO_CLEAR:
+      wxFxn = wxCLEAR;
+      break;
+    case RO_COPY:
+      wxFxn = wxCOPY;
+      break;
+    case RO_EQUIV:
+      wxFxn = wxEQUIV;
+      break;
+    case RO_INVERT:
+      wxFxn = wxINVERT;
+      break;
+    case RO_NAND:
+      wxFxn = wxNAND;
+      break;
+    case RO_NOR:
+      wxFxn = wxNOR;
+      break;
+    case RO_NO_OP:
+      wxFxn = wxNO_OP;
+      break;
+    case RO_OR:
+      wxFxn = wxOR;
+      break;
+    case RO_OR_INVERT:
+      wxFxn = wxOR_INVERT;
+      break;
+    case RO_OR_REVERSE:
+      wxFxn = wxOR_REVERSE;
+      break;
+    case RO_SET:
+      wxFxn = wxSET;
+      break;
+    case RO_SRC_INVERT:
+      wxFxn = wxSRC_INVERT;
+      break;
+    case RO_XOR:
+      wxFxn = wxXOR;
+      break;
+    }
+    if (wxFxn >= 0)
+      m_driver.idWX()->SetLogicalFunction (wxFxn);
+  }
+#endif
 }
 
+
 void
 SGP::setMarker (int idMarke, int iColor)
 {
@@ -217,7 +324,7 @@ SGP::lineAbs (double x, double y)
 
   double x2 = x;
   double y2 = y;
-  mc_to_ndc.transformPoint (&x1, &y2);
+  mc_to_ndc.transformPoint (&x2, &y2);
   
   if (clip_rect (x1, y1, x2, y2, viewNDC) == true) { // clip to viewport 
     stylusNDC (x1, y1, 0);  // move to first point
@@ -355,12 +462,17 @@ SGP::drawText (const char *pszMessage)
 
   stylusNDC (xndc, yndc, false);            // move to location 
 
+#if HAVE_G2_H
   if (m_driver.isG2()) {
-    if (m_dTextAngle == 0.)
-      g2_string (m_driver.idG2(), m_iCurrentPhysicalX, m_iCurrentPhysicalY, const_cast<char*>(pszMessage));
+    g2_string (m_driver.idG2(), m_iCurrentPhysicalX, m_iCurrentPhysicalY, const_cast<char*>(pszMessage));
   }
+#endif
+#if HAVE_WXWINDOWS
   if (m_driver.isWX()) {
+    wxString str (pszMessage);
+    m_driver.idWX()->DrawRotatedText (str, m_iCurrentPhysicalX, m_iCurrentPhysicalY, m_dTextAngle);
   }
+#endif
 }