dcpsg.cpp
来自「A*算法 A*算法 A*算法 A*算法A*算法A*算法」· C++ 代码 · 共 2,062 行 · 第 1/5 页
CPP
2,062 行
alpha1 = alpha2 = 0.0;
}
else
{
alpha1 = (x1 - xc == 0) ?
(y1 - yc < 0) ? 90.0 : -90.0 :
-atan2(double(y1-yc), double(x1-xc)) * RAD2DEG;
alpha2 = (x2 - xc == 0) ?
(y2 - yc < 0) ? 90.0 : -90.0 :
-atan2(double(y2-yc), double(x2-xc)) * RAD2DEG;
}
while (alpha1 <= 0) alpha1 += 360;
while (alpha2 <= 0) alpha2 += 360; // adjust angles to be between
while (alpha1 > 360) alpha1 -= 360; // 0 and 360 degree
while (alpha2 > 360) alpha2 -= 360;
if (m_brush.GetStyle() != wxTRANSPARENT)
{
SetBrush( m_brush );
PsPrintf( wxT("newpath\n")
wxT("%d %d %d %d %d %d ellipse\n")
wxT("%d %d lineto\n")
wxT("closepath\n")
wxT("fill\n"),
LogicalToDeviceX(xc), LogicalToDeviceY(yc), LogicalToDeviceXRel(radius), LogicalToDeviceYRel(radius), (wxCoord)alpha1, (wxCoord) alpha2,
LogicalToDeviceX(xc), LogicalToDeviceY(yc) );
CalcBoundingBox( xc-radius, yc-radius );
CalcBoundingBox( xc+radius, yc+radius );
}
if (m_pen.GetStyle() != wxTRANSPARENT)
{
SetPen( m_pen );
PsPrintf( wxT("newpath\n")
wxT("%d %d %d %d %d %d ellipse\n")
wxT("%d %d lineto\n")
wxT("stroke\n")
wxT("fill\n"),
LogicalToDeviceX(xc), LogicalToDeviceY(yc), LogicalToDeviceXRel(radius), LogicalToDeviceYRel(radius), (wxCoord)alpha1, (wxCoord) alpha2,
LogicalToDeviceX(xc), LogicalToDeviceY(yc) );
CalcBoundingBox( xc-radius, yc-radius );
CalcBoundingBox( xc+radius, yc+radius );
}
}
void wxPostScriptDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
{
wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
if (sa>=360 || sa<=-360) sa=sa-int(sa/360)*360;
if (ea>=360 || ea<=-360) ea=ea-int(ea/360)*360;
if (sa<0) sa+=360;
if (ea<0) ea+=360;
if (sa==ea)
{
DrawEllipse(x,y,w,h);
return;
}
if (m_brush.GetStyle () != wxTRANSPARENT)
{
SetBrush( m_brush );
PsPrintf( wxT("newpath\n")
wxT("%d %d %d %d %d %d true ellipticarc\n"),
LogicalToDeviceX(x+w/2), LogicalToDeviceY(y+h/2),
LogicalToDeviceXRel(w/2), LogicalToDeviceYRel(h/2),
(wxCoord)sa, (wxCoord)ea );
CalcBoundingBox( x ,y );
CalcBoundingBox( x+w, y+h );
}
if (m_pen.GetStyle () != wxTRANSPARENT)
{
SetPen( m_pen );
PsPrintf( wxT("newpath\n")
wxT("%d %d %d %d %d %d false ellipticarc\n"),
LogicalToDeviceX(x+w/2), LogicalToDeviceY(y+h/2),
LogicalToDeviceXRel(w/2), LogicalToDeviceYRel(h/2),
(wxCoord)sa, (wxCoord)ea );
CalcBoundingBox( x ,y );
CalcBoundingBox( x+w, y+h );
}
}
void wxPostScriptDC::DoDrawPoint (wxCoord x, wxCoord y)
{
wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
if (m_pen.GetStyle() == wxTRANSPARENT) return;
SetPen (m_pen);
PsPrintf( wxT("newpath\n")
wxT("%d %d moveto\n")
wxT("%d %d lineto\n")
wxT("stroke\n"),
LogicalToDeviceX(x), LogicalToDeviceY(y),
LogicalToDeviceX(x+1), LogicalToDeviceY(y) );
CalcBoundingBox( x, y );
}
void wxPostScriptDC::DoDrawPolygon (int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
{
wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
if (n <= 0) return;
if (m_brush.GetStyle () != wxTRANSPARENT)
{
SetBrush( m_brush );
PsPrint( "newpath\n" );
wxCoord xx = LogicalToDeviceX(points[0].x + xoffset);
wxCoord yy = LogicalToDeviceY(points[0].y + yoffset);
PsPrintf( wxT("%d %d moveto\n"), xx, yy );
CalcBoundingBox( points[0].x + xoffset, points[0].y + yoffset );
for (int i = 1; i < n; i++)
{
xx = LogicalToDeviceX(points[i].x + xoffset);
yy = LogicalToDeviceY(points[i].y + yoffset);
PsPrintf( wxT("%d %d lineto\n"), xx, yy );
CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset);
}
PsPrint( (fillStyle == wxODDEVEN_RULE ? "eofill\n" : "fill\n") );
}
if (m_pen.GetStyle () != wxTRANSPARENT)
{
SetPen( m_pen );
PsPrint( "newpath\n" );
wxCoord xx = LogicalToDeviceX(points[0].x + xoffset);
wxCoord yy = LogicalToDeviceY(points[0].y + yoffset);
PsPrintf( wxT("%d %d moveto\n"), xx, yy );
CalcBoundingBox( points[0].x + xoffset, points[0].y + yoffset );
for (int i = 1; i < n; i++)
{
xx = LogicalToDeviceX(points[i].x + xoffset);
yy = LogicalToDeviceY(points[i].y + yoffset);
PsPrintf( wxT("%d %d lineto\n"), xx, yy );
CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset);
}
PsPrint( "closepath\n" );
PsPrint( "stroke\n" );
}
}
void wxPostScriptDC::DoDrawPolyPolygon (int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
{
wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
if (n <= 0) return;
if (m_brush.GetStyle () != wxTRANSPARENT)
{
SetBrush( m_brush );
PsPrint( "newpath\n" );
int ofs = 0;
for (int i = 0; i < n; ofs += count[i++])
{
wxCoord xx = LogicalToDeviceX(points[ofs].x + xoffset);
wxCoord yy = LogicalToDeviceY(points[ofs].y + yoffset);
PsPrintf( wxT("%d %d moveto\n"), xx, yy );
CalcBoundingBox( points[ofs].x + xoffset, points[ofs].y + yoffset );
for (int j = 1; j < count[i]; j++)
{
xx = LogicalToDeviceX(points[ofs+j].x + xoffset);
yy = LogicalToDeviceY(points[ofs+j].y + yoffset);
PsPrintf( wxT("%d %d lineto\n"), xx, yy );
CalcBoundingBox( points[ofs+j].x + xoffset, points[ofs+j].y + yoffset);
}
}
PsPrint( (fillStyle == wxODDEVEN_RULE ? "eofill\n" : "fill\n") );
}
if (m_pen.GetStyle () != wxTRANSPARENT)
{
SetPen( m_pen );
PsPrint( "newpath\n" );
int ofs = 0;
for (int i = 0; i < n; ofs += count[i++])
{
wxCoord xx = LogicalToDeviceX(points[ofs].x + xoffset);
wxCoord yy = LogicalToDeviceY(points[ofs].y + yoffset);
PsPrintf( wxT("%d %d moveto\n"), xx, yy );
CalcBoundingBox( points[ofs].x + xoffset, points[ofs].y + yoffset );
for (int j = 1; j < count[i]; j++)
{
xx = LogicalToDeviceX(points[ofs+j].x + xoffset);
yy = LogicalToDeviceY(points[ofs+j].y + yoffset);
PsPrintf( wxT("%d %d lineto\n"), xx, yy );
CalcBoundingBox( points[ofs+j].x + xoffset, points[ofs+j].y + yoffset);
}
}
PsPrint( "closepath\n" );
PsPrint( "stroke\n" );
}
}
void wxPostScriptDC::DoDrawLines (int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
{
wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
if (m_pen.GetStyle() == wxTRANSPARENT) return;
if (n <= 0) return;
SetPen (m_pen);
int i;
for ( i =0; i<n ; i++ )
{
CalcBoundingBox( LogicalToDeviceX(points[i].x+xoffset), LogicalToDeviceY(points[i].y+yoffset));
}
PsPrintf( wxT("newpath\n")
wxT("%d %d moveto\n"),
LogicalToDeviceX(points[0].x+xoffset),
LogicalToDeviceY(points[0].y+yoffset) );
for (i = 1; i < n; i++)
{
PsPrintf( wxT("%d %d lineto\n"),
LogicalToDeviceX(points[i].x+xoffset),
LogicalToDeviceY(points[i].y+yoffset) );
}
PsPrint( "stroke\n" );
}
void wxPostScriptDC::DoDrawRectangle (wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
if (m_brush.GetStyle () != wxTRANSPARENT)
{
SetBrush( m_brush );
PsPrintf( wxT("newpath\n")
wxT("%d %d moveto\n")
wxT("%d %d lineto\n")
wxT("%d %d lineto\n")
wxT("%d %d lineto\n")
wxT("closepath\n")
wxT("fill\n"),
LogicalToDeviceX(x), LogicalToDeviceY(y),
LogicalToDeviceX(x + width), LogicalToDeviceY(y),
LogicalToDeviceX(x + width), LogicalToDeviceY(y + height),
LogicalToDeviceX(x), LogicalToDeviceY(y + height) );
CalcBoundingBox( x, y );
CalcBoundingBox( x + width, y + height );
}
if (m_pen.GetStyle () != wxTRANSPARENT)
{
SetPen (m_pen);
PsPrintf( wxT("newpath\n")
wxT("%d %d moveto\n")
wxT("%d %d lineto\n")
wxT("%d %d lineto\n")
wxT("%d %d lineto\n")
wxT("closepath\n")
wxT("stroke\n"),
LogicalToDeviceX(x), LogicalToDeviceY(y),
LogicalToDeviceX(x + width), LogicalToDeviceY(y),
LogicalToDeviceX(x + width), LogicalToDeviceY(y + height),
LogicalToDeviceX(x), LogicalToDeviceY(y + height) );
CalcBoundingBox( x, y );
CalcBoundingBox( x + width, y + height );
}
}
void wxPostScriptDC::DoDrawRoundedRectangle (wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
{
wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
if (radius < 0.0)
{
// Now, a negative radius is interpreted to mean
// 'the proportion of the smallest X or Y dimension'
double smallest = width < height ? width : height;
radius = (-radius * smallest);
}
wxCoord rad = (wxCoord) radius;
if (m_brush.GetStyle () != wxTRANSPARENT)
{
SetBrush( m_brush );
/* Draw rectangle anticlockwise */
PsPrintf( wxT("newpath\n")
wxT("%d %d %d 90 180 arc\n")
wxT("%d %d lineto\n")
wxT("%d %d %d 180 270 arc\n")
wxT("%d %d lineto\n")
wxT("%d %d %d 270 0 arc\n")
wxT("%d %d lineto\n")
wxT("%d %d %d 0 90 arc\n")
wxT("%d %d lineto\n")
wxT("closepath\n")
wxT("fill\n"),
LogicalToDeviceX(x + rad), LogicalToDeviceY(y + rad), LogicalToDeviceXRel(rad),
LogicalToDeviceX(x), LogicalToDeviceY(y + height - rad),
LogicalToDeviceX(x + rad), LogicalToDeviceY(y + height - rad), LogicalToDeviceXRel(rad),
LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + height),
LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + height - rad), LogicalToDeviceXRel(rad),
LogicalToDeviceX(x + width), LogicalToDeviceY(y + rad),
LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + rad), LogicalToDeviceXRel(rad),
LogicalToDeviceX(x + rad), LogicalToDeviceY(y) );
CalcBoundingBox( x, y );
CalcBoundingBox( x + width, y + height );
}
if (m_pen.GetStyle () != wxTRANSPARENT)
{
SetPen (m_pen);
/* Draw rectangle anticlockwise */
PsPrintf( wxT("newpath\n")
wxT("%d %d %d 90 180 arc\n")
wxT("%d %d lineto\n")
wxT("%d %d %d 180 270 arc\n")
wxT("%d %d lineto\n")
wxT("%d %d %d 270 0 arc\n")
wxT("%d %d lineto\n")
wxT("%d %d %d 0 90 arc\n")
wxT("%d %d lineto\n")
wxT("closepath\n")
wxT("stroke\n"),
LogicalToDeviceX(x + rad), LogicalToDeviceY(y + rad), LogicalToDeviceXRel(rad),
LogicalToDeviceX(x), LogicalToDeviceY(y + height - rad),
LogicalToDeviceX(x + rad), LogicalToDeviceY(y + height - rad), LogicalToDeviceXRel(rad),
LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + height),
LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + height - rad), LogicalToDeviceXRel(rad),
LogicalToDeviceX(x + width), LogicalToDeviceY(y + rad),
LogicalToDeviceX(x + width - rad), LogicalToDeviceY(y + rad), LogicalToDeviceXRel(rad),
LogicalToDeviceX(x + rad), LogicalToDeviceY(y) );
CalcBoundingBox( x, y );
CalcBoundingBox( x + width, y + height );
}
}
void wxPostScriptDC::DoDrawEllipse (wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
if (m_brush.GetStyle () != wxTRANSPARENT)
{
SetBrush (m_brush);
PsPrintf( wxT("newpath\n")
wxT("%d %d %d %d 0 360 ellipse\n")
wxT("fill\n"),
LogicalToDeviceX(x + width / 2), LogicalToDeviceY(y + height / 2),
LogicalToDeviceXRel(width / 2), LogicalToDeviceYRel(height / 2) );
CalcBoundingBox( x - width, y - height );
CalcBoundingBox( x + width, y + height );
}
if (m_pen.GetStyle () != wxTRANSPARENT)
{
SetPen (m_pen);
PsPrintf( wxT("newpath\n")
wxT("%d %d %d %d 0 360 ellipse\n")
wxT("stroke\n"),
LogicalToDeviceX(x + width / 2), LogicalToDeviceY(y + height / 2),
LogicalToDeviceXRel(width / 2), LogicalToDeviceYRel(height / 2) );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?