From: Shamus Hammons Date: Wed, 9 Mar 2016 04:18:08 +0000 (-0600) Subject: First stab at showing effect of added points on a given poly. X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=ttedit;a=commitdiff_plain;h=3fe885b75511c9fbfe18a5c509260e83bb7ac136 First stab at showing effect of added points on a given poly. Right now, it only works with the AddPoly tool, and not 100% well. More work needs to be done to really polish it so it fits in with the rest of the tools. --- diff --git a/src/editwindow.cpp b/src/editwindow.cpp index 4a3d43f..e4f7d7b 100644 --- a/src/editwindow.cpp +++ b/src/editwindow.cpp @@ -269,46 +269,68 @@ void EditWindow::DrawGlyph(Painter & p, GlyphPoints & glyph) } +/* +So, to make it draw the point the pointer is pointing at, we need to do something. Either patch the GlyphPoints to handle it, or insert the point into the GlyphPoints and delete it if the user changes tools. Either way, need +to change the color of the line(s) drawn to the point to signal to the user +that it isn't finalized until they click the button. +*/ void EditWindow::DrawGlyphPoly(Painter & p, GlyphPoints & glyph, uint16_t poly) { // Sanity check if (glyph.GetNumPoints(poly) < 3) return; - // 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))); + IPoint p1 = glyph.GetPrevPoint(poly, 0); + IPoint p2 = glyph.GetPoint(poly, 0); + + // Inject the new poly point into the current polygon + if ((tool == TOOLAddPoly) && (poly == (glyph.GetNumPolys() - 1))) + { + p1 = IPoint(addPoint.x, addPoint.y, addPointOnCurve); + } for(int i=0; ix(), event->y())); - pts.SetXY(ptHighlight, pt2.x, pt2.y); + + if (tool != TOOLSelect) + { + addPoint = pt2; + // Prolly should move this to the key handlers below... + addPointOnCurve = ((event->modifiers() == Qt::ShiftModifier) || (event->modifiers() == Qt::ControlModifier) ? false : true); + } + else + pts.SetXY(ptHighlight, pt2.x, pt2.y); + update(); } else if (tool == TOOLPolySelect) @@ -667,6 +698,11 @@ void EditWindow::mouseMoveEvent(QMouseEvent * event) } ptPrevious = Vector(event->x(), event->y()); + addPoint = Painter::QtToCartesianCoords(Vector(event->x(), event->y())); +// addPointOnCurve = ((event->modifiers() == Qt::ShiftModifier) || (event->modifiers() == Qt::ControlModifier) ? false : true); + + if (tool == TOOLAddPoly) + update(); } event->accept(); @@ -753,17 +789,29 @@ void EditWindow::keyPressEvent(QKeyEvent * event) pts.SetXY(ptHighlight, pts.GetX(ptHighlight) + 1, pts.GetY(ptHighlight)); else if (event->key() == Qt::Key_Left) pts.SetXY(ptHighlight, pts.GetX(ptHighlight) - 1, pts.GetY(ptHighlight)); + else if ((event->key() == Qt::Key_Shift) || (event->key() == Qt::Key_Control)) + { + addPointOnCurve = false; + } else return; - event->accept(); +// event->accept(); update(); ((TTEdit *)qApp)->charWnd->MakePathFromPoints(&pts); ((TTEdit *)qApp)->charWnd->update(); } -void EditWindow::keyReleaseEvent(QKeyEvent * /*event*/) +void EditWindow::keyReleaseEvent(QKeyEvent * event) { + if ((event->key() == Qt::Key_Shift) || (event->key() == Qt::Key_Control)) + { + addPointOnCurve = true; + } + else + return; + + update(); } diff --git a/src/editwindow.h b/src/editwindow.h index f1518e9..77104bd 100644 --- a/src/editwindow.h +++ b/src/editwindow.h @@ -36,11 +36,13 @@ class EditWindow: public QWidget void CreateCursors(void); void DrawGlyph(Painter & p, GlyphPoints & glyph); void DrawGlyphPoly(Painter & p, GlyphPoints & glyph, uint16_t poly); + void DrawGlyphSegment(Painter & p, IPoint p1, IPoint p2, IPoint p3); void ClearSelection(void); public: QImage image; - Vector pt, ptOffset, ptPrevious; + Vector pt, ptOffset, ptPrevious, addPoint; + bool addPointOnCurve; ToolType tool; // Current tool GlyphPoints pts; // Glyph point structure int32_t ptHighlight, oldPtHighlight, ptNextHighlight, oldPtNextHighlight; diff --git a/src/glyphpoints.cpp b/src/glyphpoints.cpp index 4ae01e5..856b859 100644 --- a/src/glyphpoints.cpp +++ b/src/glyphpoints.cpp @@ -74,19 +74,6 @@ WriteLogMsg("GlyphPoints: Copy constructor. %u points, %u polys.\n", numPoints, GlyphPoints::~GlyphPoints() { FreeAllocatedMemory(); -#if 0 - if (x) - delete[] x; - - if (y) - delete[] y; - - if (onCurve) - delete[] onCurve; - - if (polyEnd) - delete[] polyEnd; -#endif } @@ -751,7 +738,7 @@ IPoint GlyphPoints::GetPrevPoint(uint16_t poly, uint16_t pt) { uint16_t prevPt = GetPrev(poly, pt); - return IPoint(GetX(poly, prevPt), GetY(poly, prevPt)); + return IPoint(GetX(poly, prevPt), GetY(poly, prevPt), GetOnCurve(poly, prevPt)); } @@ -759,7 +746,7 @@ IPoint GlyphPoints::GetNextPoint(uint16_t poly, uint16_t pt) { uint16_t nextPt = GetNext(poly, pt); - return IPoint(GetX(poly, nextPt), GetY(poly, nextPt)); + return IPoint(GetX(poly, nextPt), GetY(poly, nextPt), GetOnCurve(poly, nextPt)); } diff --git a/src/painter.cpp b/src/painter.cpp index 16268e7..e2a457a 100644 --- a/src/painter.cpp +++ b/src/painter.cpp @@ -279,6 +279,17 @@ void Painter::DrawLine(int x1, int y1, int x2, int y2) } +void Painter::DrawLine(IPoint p1, IPoint p2) +{ + if (!painter) + return; + + Vector v1 = CartesianToQtCoords(Vector(p1.x, p1.y)); + Vector v2 = CartesianToQtCoords(Vector(p2.x, p2.y)); + painter->drawLine(v1.x, v1.y, v2.x, v2.y); +} + + void Painter::DrawLine(Vector v1, Vector v2) { if (!painter) diff --git a/src/painter.h b/src/painter.h index c95b84a..d136f23 100644 --- a/src/painter.h +++ b/src/painter.h @@ -30,6 +30,7 @@ class Painter void DrawArrowHandle(Vector, double); void DrawArrowToLineHandle(Vector, double); void DrawLine(int, int, int, int); + void DrawLine(IPoint, IPoint); void DrawLine(Vector, Vector); void DrawPoint(int, int); void DrawRoundedRect(QRectF, double, double);