]> Shamusworld >> Repos - ttedit/commitdiff
Repurposed code in bezier.h/cpp, added middle button scrolling
authorShamus Hammons <jlhamm@acm.org>
Sat, 30 Aug 2008 18:35:28 +0000 (18:35 +0000)
committerShamus Hammons <jlhamm@acm.org>
Sat, 30 Aug 2008 18:35:28 +0000 (18:35 +0000)
Makefile
src/bezier.cpp [deleted file]
src/bezier.h [deleted file]
src/editwindow.cpp
src/editwindow.h
src/graphicprimitives.cpp [new file with mode: 0755]
src/graphicprimitives.h [new file with mode: 0755]

index a9a0602cb2f087cb8ac7c6917c3954263f15b30f..59b61f9a968e892e99f777272b0fd6003aeaf665 100755 (executable)
--- a/Makefile
+++ b/Makefile
@@ -59,18 +59,18 @@ PROGRAM = ttedit
 
 # KO si sihT
 
-OBJECTS  =            \
-       obj/bezier.o      \
-       obj/charnames.o   \
-       obj/charwindow.o  \
-       obj/debug.o       \
-       obj/editwindow.o  \
-       obj/glyphpoints.o \
-       obj/registry.o    \
-       obj/toolwindow.o  \
-       obj/ttf.o         \
-       obj/vector.o      \
-       obj/$(PROGRAM).o  \
+OBJECTS  =                  \
+       obj/charnames.o         \
+       obj/charwindow.o        \
+       obj/debug.o             \
+       obj/editwindow.o        \
+       obj/glyphpoints.o       \
+       obj/graphicprimitives.o \
+       obj/registry.o          \
+       obj/toolwindow.o        \
+       obj/ttf.o               \
+       obj/vector.o            \
+       obj/$(PROGRAM).o        \
        $(ICON)
 
 BIN_PROGRAM = $(PROGRAM)$(EXESUFFIX)
diff --git a/src/bezier.cpp b/src/bezier.cpp
deleted file mode 100755 (executable)
index 415f381..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-//\r
-// Bezier curve fitter\r
-// by James L. Hammons\r
-// (C) 2005 Underground Software\r
-//\r
-// This function takes three points and draws a curve using a\r
-// second order Bezier function.\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
-//\r
-\r
-#include "bezier.h"\r
-\r
-double abs(double n)                                                   // Helper function\r
-{\r
-       return (n < 0 ? -n : n);\r
-}\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
-//     MoveToEx(hdc, (int)p1.x, (int)p1.y, NULL);\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
-                       x = (p1.x * (1 - _2u + _uu)) + (p2.x * (_2u - _2uu)) + (p3.x * _uu),\r
-                       y = (p1.y * (1 - _2u + _uu)) + (p2.y * (_2u - _2uu)) + (p3.y * _uu);\r
-//             LineTo(hdc, (int)x, (int)y);\r
-               dc.DrawLine(prevX, prevY, (wxCoord)x, (wxCoord)y);\r
-               prevX = (wxCoord)x, prevY = (wxCoord)y;\r
-       }\r
-\r
-//     LineTo(hdc, (int)p3.x, (int)p3.y);\r
-       dc.DrawLine(prevX, prevY, (wxCoord)p3.x, (wxCoord)p3.y);\r
-}\r
diff --git a/src/bezier.h b/src/bezier.h
deleted file mode 100755 (executable)
index 4a5c5ee..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-// True Type Hack\r
-//\r
-// Bezier Curve fitter header\r
-//\r
-// This function takes three points and draws a curve using a\r
-// second order Bezier function.\r
-\r
-#ifndef __BEZIER_H__\r
-#define __BEZIER_H__\r
-\r
-#include <wx/wx.h>                                                             // For device context\r
-\r
-struct point\r
-{\r
-       float x, y;\r
-\r
-       point(float xx = 0, float yy = 0): x(xx), y(yy) {}\r
-};\r
-\r
-void Bezier(wxDC &, point, point, point);\r
-\r
-#endif // __BEZIER_H__\r
index 63e8b3f4a9e2e1674a804fdac3b627fbb52b49d4..e16cee9a5be37a6726e562fa1d476b6bcd906817 100755 (executable)
@@ -24,7 +24,7 @@
 #define DEBUGTP                                // Toolpalette debugging...\r
 \r
 #include "editwindow.h"\r
-#include "bezier.h"\r
+#include "graphicprimitives.h"\r
 #include "toolwindow.h"\r
 #include "debug.h"\r
 #include "vector.h"\r
@@ -321,16 +321,33 @@ WriteLogMsg(" --> [# polys: %u, # points: %u]\n", pts.GetNumPolys(), pts.GetNumP
                        return;\r
                }\r
 \r
-           // Extract current point from lParam/calc offset from previous point\r
+               if (e.MiddleIsDown())\r
+               {\r
+                   // Calc offset from previous point\r
+                       pt = e.GetPosition();\r
+                       ptOffset.x = pt.x - ptPrevious.x,\r
+                       ptOffset.y = pt.y - ptPrevious.y;\r
 \r
-               pt = e.GetPosition();\r
-               ptOffset.x = pt.x - ptPrevious.x,\r
-               ptOffset.y = pt.y - ptPrevious.y;\r
+// Then multiply it by the scaling factor. Whee!\r
+                       // This looks wacky because we're using screen coords for the offset...\r
+                       // Otherwise, we would subtract both offsets!\r
+                       offsetX -= ptOffset.x, offsetY += ptOffset.y;\r
+                       Refresh();\r
+\r
+                       return;\r
+               }\r
 \r
 //             if (e.LeftIsDown())\r
 //             {\r
+#if 0\r
                        if (tool == TOOLScroll)\r
                        {\r
+                           // Extract current point from lParam/calc offset from previous point\r
+\r
+                               pt = e.GetPosition();\r
+                               ptOffset.x = pt.x - ptPrevious.x,\r
+                               ptOffset.y = pt.y - ptPrevious.y;\r
+\r
                                // NOTE: OffsetViewportOrg operates in DEVICE UNITS...\r
 \r
 //Seems there's no equivalent for this in wxWidgets...!\r
@@ -348,7 +365,9 @@ WriteLogMsg(" --> [# polys: %u, # points: %u]\n", pts.GetNumPolys(), pts.GetNumP
                                offsetX -= ptOffset.x, offsetY += ptOffset.y;\r
                                Refresh();\r
                        }\r
-                       else if (tool == TOOLAddPt || tool == TOOLAddPoly || tool == TOOLSelect)\r
+                       else\r
+#endif\r
+ if (tool == TOOLAddPt || tool == TOOLAddPoly || tool == TOOLSelect)\r
                        {\r
                                if (tool != TOOLAddPt || pts.GetNumPoints() > 0)//yecch.\r
                                {\r
@@ -504,64 +523,6 @@ wxPoint TTEditWindow::GetAdjustedClientPosition(wxCoord x, wxCoord y)
        return wxPoint(dc.LogicalToDeviceX(x), dc.LogicalToDeviceY(y));\r
 }\r
 \r
-//\r
-// Draw a round dot (5x5, centered on [x, y])\r
-//\r
-void TTEditWindow::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 TTEditWindow::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 TTEditWindow::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 TTEditWindow::DrawRoundDotN(wxDC &dc, int32 x, int32 y, uint32 n)\r
-{\r
-       dc.DrawCircle(x, y, (n / 2) + 1);\r
-}\r
-\r
 \r
 #if 0\r
 \r
index 8034d7e27245aa1e2829240417008370be30fea8..4d0a9319725a316d11a0a294d04004b1630fe889 100755 (executable)
@@ -41,10 +41,6 @@ class TTEditWindow: public wxWindow
        protected:\r
                wxPoint GetAdjustedMousePosition(wxMouseEvent &e);\r
                wxPoint GetAdjustedClientPosition(wxCoord x, wxCoord y);\r
-               void DrawRoundDot(wxDC &, int32, int32);\r
-               void DrawSquareDot(wxDC &, int32, int32);\r
-               void DrawRoundDotN(wxDC &, int32, int32, uint32);\r
-               void DrawSquareDotN(wxDC &, int32, int32, uint32);\r
 \r
        DECLARE_EVENT_TABLE()\r
 };\r
diff --git a/src/graphicprimitives.cpp b/src/graphicprimitives.cpp
new file mode 100755 (executable)
index 0000000..9802347
--- /dev/null
@@ -0,0 +1,107 @@
+//\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
diff --git a/src/graphicprimitives.h b/src/graphicprimitives.h
new file mode 100755 (executable)
index 0000000..dbc7a11
--- /dev/null
@@ -0,0 +1,27 @@
+//\r
+// Graphics primitives\r
+//\r
+// Various graphic functions that are slightly more complex than those that\r
+// come with various widget libraries.\r
+//\r
+\r
+#ifndef __GRAPHICPRIMITIVES_H__\r
+#define __GRAPHICPRIMITIVES_H__\r
+\r
+#include <wx/wx.h>                                                             // For device context\r
+#include "types.h"                                                             // For int32\r
+\r
+struct point\r
+{\r
+       float x, y;\r
+\r
+       point(float xx = 0, float yy = 0): x(xx), y(yy) {}\r
+};\r
+\r
+void Bezier(wxDC &, point, point, point);\r
+void DrawRoundDot(wxDC &, int32, int32);\r
+void DrawSquareDot(wxDC &, int32, int32);\r
+void DrawRoundDotN(wxDC &, int32, int32, uint32);\r
+void DrawSquareDotN(wxDC &, int32, int32, uint32);\r
+\r
+#endif // __GRAPHICPRIMITIVES_H__\r