X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgraphicprimitives.cpp;h=dd9b480e54650eca6ce7553d3326276da7de3511;hb=3ef71393f70213eb53db552605ae3c93f1303ee9;hp=6eb84a23770a39552862be9d63b6ee8e6283daa7;hpb=c84263bb8b0d16e4c6da49aa0b7d0bc904ae02b1;p=ttedit diff --git a/src/graphicprimitives.cpp b/src/graphicprimitives.cpp index 6eb84a2..dd9b480 100755 --- a/src/graphicprimitives.cpp +++ b/src/graphicprimitives.cpp @@ -23,17 +23,19 @@ double abs(double n) // Helper function return (n < 0 ? -n : n); } + // // This function takes three points and draws a curve using a second order // Bezier function. // -void Bezier(wxDC &dc, point p1, point p2, point p3) +void Bezier(QPainter &p, point p1, point p2, point p3) { double step = abs(p1.x - p3.x), tmp = abs(p1.y - p3.y); step = (tmp > step ? tmp : step); // Get the larger of the two... step = (step > 0 ? 1/step : 1); // & convert to valid step value + step *= 2.0; // (double it to draw less...) - wxCoord prevX = (wxCoord)p1.x, prevY = (wxCoord)p1.y; + int prevX = (int)p1.x, prevY = (int)p1.y; for(double u=0; u<=1; u+=step) { @@ -41,67 +43,81 @@ void Bezier(wxDC &dc, point p1, point p2, point p3) double x = (p1.x * (1 - _2u + _uu)) + (p2.x * (_2u - _2uu)) + (p3.x * _uu); double y = (p1.y * (1 - _2u + _uu)) + (p2.y * (_2u - _2uu)) + (p3.y * _uu); - dc.DrawLine(prevX, prevY, (wxCoord)x, (wxCoord)y); - prevX = (wxCoord)x, prevY = (wxCoord)y; + p.drawLine(prevX, prevY, (int)x, (int)y); + prevX = (int)x, prevY = (int)y; } - dc.DrawLine(prevX, prevY, (wxCoord)p3.x, (wxCoord)p3.y); + p.drawLine(prevX, prevY, (int)p3.x, (int)p3.y); } + +// +// This is a convenience funtion, using IPoints :-) +// +void Bezier(QPainter &p, IPoint p1, IPoint p2, IPoint p3) +{ + Bezier(p, point(p1.x, p1.y), point(p2.x, p2.y), point(p3.x, p3.y)); +} + + // // Draw a round dot (5x5, centered on [x, y]) // -void DrawRoundDot(wxDC &dc, int32 x, int32 y) +void DrawRoundDot(QPainter &p, int32 x, int32 y) { - wxPoint pt[8]; - - pt[0].x = x - 1, pt[0].y = y - 2; - pt[1].x = x + 1, pt[1].y = y - 2; - pt[2].x = x + 2, pt[2].y = y - 1; - pt[3].x = x + 2, pt[3].y = y + 1; - pt[4].x = x + 1, pt[4].y = y + 2; - pt[5].x = x - 1, pt[5].y = y + 2; - pt[6].x = x - 2, pt[6].y = y + 1; - pt[7].x = x - 2, pt[7].y = y - 1; - - dc.DrawPolygon(8, pt); + QPoint pt[8]; + + pt[0] = QPoint(x - 1, y - 2); + pt[1] = QPoint(x + 1, y - 2); + pt[2] = QPoint(x + 2, y - 1); + pt[3] = QPoint(x + 2, y + 1); + pt[4] = QPoint(x + 1, y + 2); + pt[5] = QPoint(x - 1, y + 2); + pt[6] = QPoint(x - 2, y + 1); + pt[7] = QPoint(x - 2, y - 1); + + p.drawPolygon(pt, 8); } + // // Draw a sqaure dot (5x5, centered on [x, y]) // -void DrawSquareDot(wxDC &dc, int32 x, int32 y) +void DrawSquareDot(QPainter &p, int32 x, int32 y) { - wxPoint pt[4]; + QPoint pt[4]; - pt[0].x = x - 2, pt[0].y = y - 2; - pt[1].x = x + 2, pt[1].y = y - 2; - pt[2].x = x + 2, pt[2].y = y + 2; - pt[3].x = x - 2, pt[3].y = y + 2; + pt[0] = QPoint(x - 2, y - 2); + pt[1] = QPoint(x + 2, y - 2); + pt[2] = QPoint(x + 2, y + 2); + pt[3] = QPoint(x - 2, y + 2); - dc.DrawPolygon(4, pt); + p.drawPolygon(pt, 4); } + // // Draw a sqaure dot (nxn, centered on [x, y]) // -void DrawSquareDotN(wxDC &dc, int32 x, int32 y, uint32 n) +void DrawSquareDotN(QPainter &p, int32 x, int32 y, uint32 n) { - wxPoint pt[4]; + QPoint pt[4]; uint32 offset = (n - 1) / 2; - pt[0].x = x - offset, pt[0].y = y - offset; - pt[1].x = x + offset, pt[1].y = y - offset; - pt[2].x = x + offset, pt[2].y = y + offset; - pt[3].x = x - offset, pt[3].y = y + offset; + pt[0] = QPoint(x - offset, y - offset); + pt[1] = QPoint(x + offset, y - offset); + pt[2] = QPoint(x + offset, y + offset); + pt[3] = QPoint(x - offset, y + offset); - dc.DrawPolygon(4, pt); + p.drawPolygon(pt, 4); } + // // Draw a round dot (nxn, centered on [x, y]) // -void DrawRoundDotN(wxDC &dc, int32 x, int32 y, uint32 n) +void DrawRoundDotN(QPainter &p, int32 x, int32 y, uint32 n) { - dc.DrawCircle(x, y, (n / 2) + 1); + int radius = (n / 2) + 1; + p.drawEllipse(x - radius, y - radius, n, n); }