]> Shamusworld >> Repos - ttedit/commitdiff
Added implementation of Polygon Rotate and Flip Winding tools.
authorShamus Hammons <jlhamm@acm.org>
Mon, 3 Dec 2012 03:47:56 +0000 (21:47 -0600)
committerShamus Hammons <jlhamm@acm.org>
Mon, 3 Dec 2012 03:47:56 +0000 (21:47 -0600)
src/editwindow.cpp
src/editwindow.h
src/glyphpoints.cpp
src/glyphpoints.h
src/toolwindow.cpp
src/toolwindow.h

index 242d237bb14a877b1038e5af334fd137e641a5a2..192c9d2ee30b5bb5736588544af24895a504718c 100755 (executable)
@@ -71,12 +71,12 @@ QSize EditWindow::sizeHint() const
 
 void EditWindow::CreateCursors(void)
 {
-       int hotx[10] = {  1,  1, 11, 15,  1,  1,  1,  1,  1,  1 };
-       int hoty[10] = {  1,  1, 11, 13,  1,  1,  1,  1,  1,  1 };
-       char cursorName[10][48] = { "select", "select-poly", "scroll", "zoom", "add-point",
-               "add-poly", "del-point", "del-poly", "rotate", "rotate" };
+       int hotx[11] = {  1,  1, 11, 15,  1,  1,  1,  1,  1,  1,  1 };
+       int hoty[11] = {  1,  1, 11, 13,  1,  1,  1,  1,  1,  1,  1 };
+       char cursorName[11][48] = { "select", "select-poly", "scroll", "zoom", "add-point",
+               "add-poly", "del-point", "del-poly", "rotate", "rotate", "select" };
 
-       for(int i=0; i<10; i++)
+       for(int i=0; i<11; i++)
        {
                QString s;
                s.sprintf(":/res/cursor-%s.png", cursorName[i]);
@@ -382,6 +382,21 @@ WriteLogMsg(" --> [# polys: %u, # points: %u]\n", pts.GetNumPolys(), pts.GetNumP
                        rotationAngle = 0;
                        update();
                }
+               else if (tool == TOOLFlipWinding)
+               {
+//                     IPoint centroid = pts.GetPolyCentroid(pts.GetPolyForPointNumber(ptHighlight));
+//                     rotationCenter = QPoint(centroid.x, centroid.y);
+//                     showRotationCenter = true;
+                       pts.InvertPolyDrawSequence(pts.GetPolyForPointNumber(ptHighlight));
+                       pt = GetAdjustedClientPosition(pts.GetX(ptHighlight), pts.GetY(ptHighlight));
+                       QCursor::setPos(mapToGlobal(pt));
+//                     rotationZeroPoint = QPoint(pts.GetX(ptHighlight), pts.GetY(ptHighlight));
+//                     haveZeroPoint = true;
+//                     rotationAngle = 0;
+                       update();
+//                     ((TTEdit *)qApp)->charWnd->MakePathFromPoints(&pts);
+//                     ((TTEdit *)qApp)->charWnd->update();
+               }
        }
 
        event->accept();
@@ -472,7 +487,7 @@ void EditWindow::mouseMoveEvent(QMouseEvent * event)
        {
                // Moving, not dragging...
                if (tool == TOOLSelect || tool == TOOLDelPt || tool == TOOLAddPt
-                       || tool == TOOLPolySelect || tool == TOOLRotatePoly)
+                       || tool == TOOLPolySelect || tool == TOOLRotatePoly || tool == TOOLFlipWinding)
                {
                        QPoint pt2 = GetAdjustedMousePosition(event);
                        double closest = 1.0e+99;
index d6f2acbffc6d189d59e187b79eedd724b2c2dcdd..c60317fbcb5344d52be6bf292c24c39695ea9afa 100755 (executable)
@@ -42,13 +42,14 @@ class EditWindow: public QWidget
                ToolType tool;                                                  // Current tool
                GlyphPoints pts;                                                // Glyph point structure
                int32 ptHighlight, oldPtHighlight, ptNextHighlight, oldPtNextHighlight;
+               int16 polyHighlight, oldPolyHighlight;
                bool polyFirstPoint;
                bool showRotationCenter, haveZeroPoint;
                QPoint rotationCenter, rotationZeroPoint, rotationCurrentPoint;
                double rotationAngle;
 
                ToolWindow * toolPalette;
-               QCursor cur[10];
+               QCursor cur[11];
 };
 
 #endif // __EDITWINDOW_H__
index 05edc828d791d44bba987e683b0ed935f1c1b858..a11b09ca3c5b82ba0221a832ab3052eefefda0cd 100755 (executable)
@@ -437,7 +437,7 @@ int GlyphPoints::GetNextY(uint16 poly, uint16 pt)
 
 IPoint GlyphPoints::GetPoint(uint16 poly, uint16 pt)
 {
-       return IPoint(GetX(poly, pt), GetY(poly, pt));
+       return IPoint(GetX(poly, pt), GetY(poly, pt), GetOnCurve(poly, pt));
 }
 
 
@@ -446,7 +446,7 @@ IPoint GlyphPoints::GetPoint(uint16 pointNumber)
        if (pointNumber > numPoints)
                throw GP_OUT_OF_RANGE;
 
-       return IPoint(x[pointNumber], y[pointNumber]);
+       return IPoint(x[pointNumber], y[pointNumber], onCurve[pointNumber]);
 }
 
 
@@ -580,6 +580,22 @@ WriteLogMsg("Exception: SetOnCurve(uint16, bool). pt=%u, numPoints=%u\xD\xA", pt
 }
 
 
+void GlyphPoints::SetPoint(const uint16 pointNum, const IPoint point)
+{
+       if (pointNum >= numPoints)
+#ifdef DEBUG
+{
+WriteLogMsg("Exception: SetPoint(uint16, IPoint). pt=%u, numPoints=%u\xD\xA", pointNum, numPoints);
+#endif
+               throw GP_OUT_OF_RANGE;
+#ifdef DEBUG
+}
+#endif
+
+       x[pointNum] = point.x, y[pointNum] = point.y, onCurve[pointNum] = point.onCurve;
+}
+
+
 uint16 GlyphPoints::GetPrev(uint16 pt)
 {
 // pt = 7, polyEnd = 4, 9, 15
@@ -808,8 +824,10 @@ IPoint GlyphPoints::GetPolyCentroid(const int16 poly)
 {
        // We should throw an exception here, but meh
        // (this actually short circuits the exception handling in all the GetPolyXXX() functions)
+       // [now we do!]
        if (poly >= numPolys)
-               return IPoint(0, 0);
+               throw GP_OUT_OF_RANGE;
+//             return IPoint(0, 0);
 
 //     if (poly >= numPolys)
 //#ifdef DEBUG
@@ -853,6 +871,27 @@ void GlyphPoints::RotatePolyAroundCentroid(const int16 poly, const double angle)
 }
 
 
+void GlyphPoints::InvertPolyDrawSequence(const uint16 poly)
+{
+       if (poly >= numPolys)
+               throw GP_OUT_OF_RANGE;
+
+       uint16 pointNum1 = GetPolyStart(poly);
+       uint16 pointNum2 = GetPolyEnd(poly);
+
+       // Algorithm: Step through points in the polygon, swapping 1st and last, then
+       // 2nd and (last - 1), 3rd and (last - 2), etc. We only do this for half the
+       // points, as doing it for all would undo the swapping we did in the 1st half.
+       for(uint16 i=0; i<GetNumPoints(poly)/2; i++)
+       {
+               IPoint point1 = GetPoint(pointNum1 + i);
+               IPoint point2 = GetPoint(pointNum2 - i);
+               SetPoint(pointNum2 - i, point1);
+               SetPoint(pointNum1 + i, point2);
+       }
+}
+
+
 // really need to do checking on the results from fscanf...
 bool GlyphPoints::LoadGlyphFromFile(FILE * file)
 {
@@ -869,7 +908,7 @@ bool GlyphPoints::LoadGlyphFromFile(FILE * file)
 
        for(int i=0; i<numPoints; i++)
        {
-               fscanf(file, "%d %d %s", &x[i], &y[i], &line);
+               fscanf(file, "%d %d %s", &x[i], &y[i], (char *)&line);
                onCurve[i] = (line[0] == 'T' ? true : false);
        }
 
index fc0dd2b40fd17d1d56909c8c39bff35c79aba19e..ce82ec9e9407e53c269bb47cdfbd19da2a045dcd 100755 (executable)
@@ -75,6 +75,7 @@ class GlyphPoints
                void ScalePoints(float);
                void SetXY(uint16, int, int);
                void SetOnCurve(uint16, bool);
+               void SetPoint(const uint16 pointNum, const IPoint point);
                uint16 GetPrev(uint16);
                uint16 GetNext(uint16);
                uint16 GetPrev(uint16, uint16);
@@ -92,6 +93,7 @@ class GlyphPoints
                void RotatePoints(const double angle, const IPoint point);
                IPoint GetPolyCentroid(const int16 poly);
                void RotatePolyAroundCentroid(const int16 poly, const double angle);
+               void InvertPolyDrawSequence(const uint16 poly);
 
                bool LoadGlyphFromFile(FILE *);
                bool SaveGlyphToFile(FILE *);
index 1cc41e3a8882a17bdf963b5276faaace36b9f6c4..5fd774c1498430542df30b7ec84403e2afaf2041 100755 (executable)
@@ -82,7 +82,7 @@ ToolType ToolWindow::FindSelectedTool(void)
                newTool = (ToolType)((y * 4) + x);
 
        // We don't have 11 yet, so fix this if the user selected the blank space
-       if (newTool > 9)
+       if (newTool > 10)
                newTool = TOOLNone;
 
        return newTool;
index f9134bc2f0392ecde8ec627f544f2e2abcb504ad..bb10b15187a3726913f4ee1b1e2e514cacf3ef7f 100755 (executable)
@@ -23,7 +23,8 @@ enum ToolType {
        TOOLDelPt,                                                              // Delete point tool
        TOOLDelPoly,                                                    // Delete polygon tool
        TOOLRotate,                                                             // Rotate tool
-       TOOLRotatePoly                                                  // Rotate polygon around centroid tool
+       TOOLRotatePoly,                                                 // Rotate polygon around centroid tool
+       TOOLFlipWinding                                                 // Change polygon's winding direction tool
 };
 
 class ToolWindow: public QWidget