** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
-** $Id: sgp.cpp,v 1.5 2000/07/28 08:28:08 kevin Exp $
+** $Id: sgp.cpp,v 1.7 2000/07/29 19:50:08 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)
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);
}
void
SGP::stylusNDC (double x, double y, bool beam)
{
- int xp = static_cast<int>(x * m_iPhysicalXSize + 0.5);
- int yp = static_cast<int>(y * m_iPhysicalYSize + 0.5);
+ int xp = static_cast<int>(x * (m_iPhysicalXSize - 1) + 0.5);
+ int yp = static_cast<int>(y * (m_iPhysicalYSize - 1) + 0.5);
+ if (m_driver.isWX())
+ 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;
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
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
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
}