From 2b16243b0aa693d18ce49a071cdae73cadc37c4f Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Thu, 3 Jan 2013 18:39:06 -0600 Subject: [PATCH] Fixed a handful of bugs related to clicking and dragging Mostly these were related to clicking and dragging with the selection arrow and the add point tool on an empty canvas. Also fixed bug that caused crashing when trying to add a poly after using the 'New' menu command. --- .gitignore | 5 ++ Makefile | 2 +- src/editwindow.cpp | 162 +++++++++++++++++++++++--------------- src/editwindow.h | 1 + src/glyphpoints.cpp | 4 + src/graphicprimitives.cpp | 14 ++++ src/graphicprimitives.h | 2 + src/mainwindow.cpp | 1 + 8 files changed, 127 insertions(+), 64 deletions(-) diff --git a/.gitignore b/.gitignore index 3841236..fdd7155 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,6 @@ +Makefile src/*~ +ttedit +debug.log +obj/* +saves/* diff --git a/Makefile b/Makefile index a8af535..81a051d 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: ttedit -# Generated by qmake (2.01a) (Qt 4.8.3) on: Tue Nov 20 15:23:38 2012 +# Generated by qmake (2.01a) (Qt 4.8.4) on: Mon Dec 31 13:07:16 2012 # Project: ttedit.pro # Template: app # Command: /usr/bin/qmake -o Makefile ttedit.pro diff --git a/src/editwindow.cpp b/src/editwindow.cpp index 192c9d2..ef3d585 100755 --- a/src/editwindow.cpp +++ b/src/editwindow.cpp @@ -117,17 +117,9 @@ void EditWindow::paintEvent(QPaintEvent * /*event*/) QPainter p(this); //hm, causes lockup (or does it???) p.setRenderHint(QPainter::Antialiasing); -//Doesn't do crap! -//dc.SetBackground(*wxWHITE_BRUSH); -// Due to the screwiness of wxWidgets coord system, the origin is ALWAYS -// the upper left corner--regardless of axis orientation, etc... -// int width, height; -// dc.GetSize(&width, &height); QSize winSize = size(); -// dc.SetDeviceOrigin(-offsetX, height - (-offsetY)); -// dc.SetAxisOrientation(true, true); p.translate(QPoint(-offsetX, winSize.height() - (-offsetY))); p.scale(1.0, -1.0); @@ -138,13 +130,10 @@ void EditWindow::paintEvent(QPaintEvent * /*event*/) // Instead, we have to scale EVERYTHING by hand. Crap! // It's not *that* bad, but not as convenient either... -// dc.SetPen(*(wxThePenList->FindOrCreatePen(wxColour(0x00, 0x00, 0xFF), 1, wxDOT))); -//// dc.DrawLine(0, 0, 10, 10); p.setPen(QPen(Qt::blue, 1.0, Qt::DotLine)); // Draw coordinate axes -// dc.CrossHair(0, 0); p.drawLine(0, -16384, 0, 16384); p.drawLine(-16384, 0, 16384, 0); @@ -237,46 +226,89 @@ void EditWindow::DrawGlyph(QPainter & p, GlyphPoints & glyph) { for(int poly=0; poly 2) - { - // Initial move... - // If it's not on curve, then move to it, otherwise move to last point... + if (glyph.GetNumPoints(poly) < 3) + continue; - int x, y; + // Initial move: If our start point is on curve, then go to it. Otherwise, + // check previous point. If it's on curve, go to it otherwise go the + // midpoint between start point and previous (since it's between two curve + // control points). + IPoint pt = (glyph.GetOnCurve(poly, 0) + ? glyph.GetPoint(poly, 0) : (glyph.GetPrevOnCurve(poly, 0) + ? glyph.GetPrevPoint(poly, 0) : glyph.GetMidpointToPrev(poly, 0))); - if (glyph.GetOnCurve(poly, glyph.GetNumPoints(poly) - 1)) - x = (int)glyph.GetX(poly, glyph.GetNumPoints(poly) - 1), y = (int)glyph.GetY(poly, glyph.GetNumPoints(poly) - 1); - else - x = (int)glyph.GetX(poly, 0), y = (int)glyph.GetY(poly, 0); +// Need to add separate color handling here for polys that are being manipulated... - for(int i=0; i 0) + QPoint pt = GetAdjustedMousePosition(event); + IPoint pointToAdd(pt.x(), pt.y(), ((event->modifiers() == Qt::ShiftModifier || event->modifiers() == Qt::ControlModifier) ? false : true)); + + if (pts.GetNumPoints() < 2) { - QPoint pt = GetAdjustedMousePosition(event); - pts.InsertPoint(pts.GetNext(ptHighlight), pt.x(), pt.y(), ((event->modifiers() == Qt::ShiftModifier || event->modifiers() == Qt::ControlModifier) ? false : true)); +// pts += IPoint(pt.x(), pt.y(), ((event->modifiers() == Qt::ShiftModifier || event->modifiers() == Qt::ControlModifier) ? false : true)); + pts += pointToAdd; + ptHighlight = pts.GetNumPoints() - 1; + } + else + { +// QPoint pt = GetAdjustedMousePosition(event); +// pts.InsertPoint(pts.GetNext(ptHighlight), pt.x(), pt.y(), ((event->modifiers() == Qt::ShiftModifier || event->modifiers() == Qt::ControlModifier) ? false : true)); + pts.InsertPoint(pts.GetNext(ptHighlight), pointToAdd); ptHighlight = ptNextHighlight; - update(); +// update(); } + + update(); } else if (tool == TOOLAddPoly) // "Add Poly" tool { @@ -384,18 +428,10 @@ WriteLogMsg(" --> [# polys: %u, # points: %u]\n", pts.GetNumPolys(), pts.GetNumP } 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(); } } @@ -432,15 +468,13 @@ void EditWindow::mouseMoveEvent(QMouseEvent * event) { if (tool == TOOLAddPt || tool == TOOLAddPoly || tool == TOOLSelect) { - if (tool != TOOLAddPt || pts.GetNumPoints() > 0)//yecch. - { -//temporary, for testing. BTW, Select drag bug is here...! -#if 1 - QPoint pt2 = GetAdjustedMousePosition(event); - pts.SetXY(ptHighlight, pt2.x(), pt2.y()); - update(); -#endif - } + // Bail out if we have the select tool and no points yet... + if (tool == TOOLSelect && pts.GetNumPoints() == 0) + return; + + QPoint pt2 = GetAdjustedMousePosition(event); + pts.SetXY(ptHighlight, pt2.x(), pt2.y()); + update(); } else if (tool == TOOLPolySelect) { @@ -449,6 +483,8 @@ void EditWindow::mouseMoveEvent(QMouseEvent * event) QPoint pt2 = GetAdjustedMousePosition(event); // Should also set onCurve here as well, depending on keystate //Or should we? +//Would be nice, but we'd need to trap the keyPressEvent() as well, otherwise pressing/releasing +//the hotkey would show no change until the user moved their mouse. pts.OffsetPoly(pts.GetPoly(ptHighlight), pt2.x() - pts.GetX(ptHighlight), pt2.y() - pts.GetY(ptHighlight)); update(); } diff --git a/src/editwindow.h b/src/editwindow.h index c60317f..98691a4 100755 --- a/src/editwindow.h +++ b/src/editwindow.h @@ -33,6 +33,7 @@ class EditWindow: public QWidget QPoint GetAdjustedMousePosition(QMouseEvent * event); QPoint GetAdjustedClientPosition(int x, int y); void DrawGlyph(QPainter & p, GlyphPoints & glyph); + void DrawGlyphPoly(QPainter & p, GlyphPoints & glyph, uint16 poly); public: QImage image; diff --git a/src/glyphpoints.cpp b/src/glyphpoints.cpp index a11b09c..2e80e38 100755 --- a/src/glyphpoints.cpp +++ b/src/glyphpoints.cpp @@ -238,6 +238,10 @@ void GlyphPoints::Clear(void) onCurve = NULL; polyEnd = NULL; numPoints = numPolys = pointsAllocated = polysAllocated = 0; + + numPolys = 1; + polyEnd = new uint16[numPolys]; + polyEnd[0] = numPoints - 1; } diff --git a/src/graphicprimitives.cpp b/src/graphicprimitives.cpp index 82e15ab..dd9b480 100755 --- a/src/graphicprimitives.cpp +++ b/src/graphicprimitives.cpp @@ -23,6 +23,7 @@ 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. @@ -49,6 +50,16 @@ void Bezier(QPainter &p, point p1, point p2, point p3) 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]) // @@ -68,6 +79,7 @@ void DrawRoundDot(QPainter &p, int32 x, int32 y) p.drawPolygon(pt, 8); } + // // Draw a sqaure dot (5x5, centered on [x, y]) // @@ -83,6 +95,7 @@ void DrawSquareDot(QPainter &p, int32 x, int32 y) p.drawPolygon(pt, 4); } + // // Draw a sqaure dot (nxn, centered on [x, y]) // @@ -99,6 +112,7 @@ void DrawSquareDotN(QPainter &p, int32 x, int32 y, uint32 n) p.drawPolygon(pt, 4); } + // // Draw a round dot (nxn, centered on [x, y]) // diff --git a/src/graphicprimitives.h b/src/graphicprimitives.h index 1513ebb..9b2de44 100755 --- a/src/graphicprimitives.h +++ b/src/graphicprimitives.h @@ -10,6 +10,7 @@ #include // For QPainter #include "types.h" // For int32 +#include "glyphpoints.h" // For IPoint struct point { @@ -19,6 +20,7 @@ struct point }; void Bezier(QPainter &, point, point, point); +void Bezier(QPainter &, IPoint, IPoint, IPoint); void DrawRoundDot(QPainter &, int32, int32); void DrawSquareDot(QPainter &, int32, int32); void DrawRoundDotN(QPainter &, int32, int32, uint32); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 378c2ee..0767695 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -191,6 +191,7 @@ void MainWindow::NewGlyph(void) editWnd->pts.Clear(); ((TTEdit *)qApp)->charWnd->MakePathFromPoints(&(editWnd->pts)); ((TTEdit *)qApp)->charWnd->update(); +// editWnd->polyFirstPoint = true; editWnd->update(); } -- 2.37.2