]> Shamusworld >> Repos - ttedit/blobdiff - src/graphicprimitives.cpp
Set the eol style on the project to native, to avoid line ending chaos.
[ttedit] / src / graphicprimitives.cpp
index 9802347b713ae289496f3a2eb9ab7e8a3f14d4b4..6eb84a23770a39552862be9d63b6ee8e6283daa7 100755 (executable)
-//\r
-// Graphics primitives\r
-//\r
-// Various graphic functions that are slightly more complex than those that\r
-// come with various widget libraries.\r
-//\r
-// by James L. Hammons\r
-// (C) 2005 Underground Software\r
-//\r
-// JLH = James L. Hammons <jlhamm@acm.org>\r
-//\r
-// Who  When        What\r
-// ---  ----------  -------------------------------------------------------------\r
-// JLH  03/14/1998  Created this file\r
-// JLH  01/20/2005  Converted to use wxWidgets\r
-// JLH  08/30/2008  Repurposed file to handle more than just bezier curves\r
-//\r
-\r
-#include "graphicprimitives.h"\r
-\r
-double abs(double n)                                                   // Helper function\r
-{\r
-       return (n < 0 ? -n : n);\r
-}\r
-\r
-//\r
-// This function takes three points and draws a curve using a second order\r
-// Bezier function.\r
-//\r
-void Bezier(wxDC &dc, point p1, point p2, point p3)\r
-{\r
-       double step = abs(p1.x - p3.x), tmp = abs(p1.y - p3.y);\r
-       step = (tmp > step ? tmp : step);                       // Get the larger of the two...\r
-       step = (step > 0 ? 1/step : 1);                         // & convert to valid step value\r
-\r
-       wxCoord prevX = (wxCoord)p1.x, prevY = (wxCoord)p1.y;\r
-\r
-       for(double u=0; u<=1; u+=step)\r
-       {\r
-               double _2u = 2*u, _uu = u*u, _2uu = 2*_uu;\r
-               double x = (p1.x * (1 - _2u + _uu)) + (p2.x * (_2u - _2uu)) + (p3.x * _uu);\r
-               double y = (p1.y * (1 - _2u + _uu)) + (p2.y * (_2u - _2uu)) + (p3.y * _uu);\r
-\r
-               dc.DrawLine(prevX, prevY, (wxCoord)x, (wxCoord)y);\r
-               prevX = (wxCoord)x, prevY = (wxCoord)y;\r
-       }\r
-\r
-       dc.DrawLine(prevX, prevY, (wxCoord)p3.x, (wxCoord)p3.y);\r
-}\r
-\r
-//\r
-// Draw a round dot (5x5, centered on [x, y])\r
-//\r
-void DrawRoundDot(wxDC &dc, int32 x, int32 y)\r
-{\r
-       wxPoint pt[8];\r
-\r
-       pt[0].x = x - 1, pt[0].y = y - 2;\r
-       pt[1].x = x + 1, pt[1].y = y - 2;\r
-       pt[2].x = x + 2, pt[2].y = y - 1;\r
-       pt[3].x = x + 2, pt[3].y = y + 1;\r
-       pt[4].x = x + 1, pt[4].y = y + 2;\r
-       pt[5].x = x - 1, pt[5].y = y + 2;\r
-       pt[6].x = x - 2, pt[6].y = y + 1;\r
-       pt[7].x = x - 2, pt[7].y = y - 1;\r
-\r
-       dc.DrawPolygon(8, pt);\r
-}\r
-\r
-//\r
-// Draw a sqaure dot (5x5, centered on [x, y])\r
-//\r
-void DrawSquareDot(wxDC &dc, int32 x, int32 y)\r
-{\r
-       wxPoint pt[4];\r
-\r
-       pt[0].x = x - 2, pt[0].y = y - 2;\r
-       pt[1].x = x + 2, pt[1].y = y - 2;\r
-       pt[2].x = x + 2, pt[2].y = y + 2;\r
-       pt[3].x = x - 2, pt[3].y = y + 2;\r
-\r
-       dc.DrawPolygon(4, pt);\r
-}\r
-\r
-//\r
-// Draw a sqaure dot (nxn, centered on [x, y])\r
-//\r
-void DrawSquareDotN(wxDC &dc, int32 x, int32 y, uint32 n)\r
-{\r
-       wxPoint pt[4];\r
-       uint32 offset = (n - 1) / 2;\r
-\r
-       pt[0].x = x - offset, pt[0].y = y - offset;\r
-       pt[1].x = x + offset, pt[1].y = y - offset;\r
-       pt[2].x = x + offset, pt[2].y = y + offset;\r
-       pt[3].x = x - offset, pt[3].y = y + offset;\r
-\r
-       dc.DrawPolygon(4, pt);\r
-}\r
-\r
-//\r
-// Draw a round dot (nxn, centered on [x, y])\r
-//\r
-void DrawRoundDotN(wxDC &dc, int32 x, int32 y, uint32 n)\r
-{\r
-       dc.DrawCircle(x, y, (n / 2) + 1);\r
-}\r
+//
+// Graphics primitives
+//
+// Various graphic functions that are slightly more complex than those that
+// come with various widget libraries.
+//
+// by James L. Hammons
+// (C) 2005 Underground Software
+//
+// JLH = James L. Hammons <jlhamm@acm.org>
+//
+// Who  When        What
+// ---  ----------  -------------------------------------------------------------
+// JLH  03/14/1998  Created this file
+// JLH  01/20/2005  Converted to use wxWidgets
+// JLH  08/30/2008  Repurposed file to handle more than just bezier curves
+//
+
+#include "graphicprimitives.h"
+
+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)
+{
+       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
+
+       wxCoord prevX = (wxCoord)p1.x, prevY = (wxCoord)p1.y;
+
+       for(double u=0; u<=1; u+=step)
+       {
+               double _2u = 2*u, _uu = u*u, _2uu = 2*_uu;
+               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;
+       }
+
+       dc.DrawLine(prevX, prevY, (wxCoord)p3.x, (wxCoord)p3.y);
+}
+
+//
+// Draw a round dot (5x5, centered on [x, y])
+//
+void DrawRoundDot(wxDC &dc, 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);
+}
+
+//
+// Draw a sqaure dot (5x5, centered on [x, y])
+//
+void DrawSquareDot(wxDC &dc, int32 x, int32 y)
+{
+       wxPoint 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;
+
+       dc.DrawPolygon(4, pt);
+}
+
+//
+// Draw a sqaure dot (nxn, centered on [x, y])
+//
+void DrawSquareDotN(wxDC &dc, int32 x, int32 y, uint32 n)
+{
+       wxPoint 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;
+
+       dc.DrawPolygon(4, pt);
+}
+
+//
+// Draw a round dot (nxn, centered on [x, y])
+//
+void DrawRoundDotN(wxDC &dc, int32 x, int32 y, uint32 n)
+{
+       dc.DrawCircle(x, y, (n / 2) + 1);
+}