From cc0c50cea6f15bf422b94936af816a2897c187ff Mon Sep 17 00:00:00 2001 From: Sofian Date: Sun, 8 Apr 2018 16:29:49 -0400 Subject: [PATCH] Do not display scale/rotation icons on internal vertices --- src/core/Util.cpp | 51 +++++++++++++++++++++++-------------------- src/core/Util.h | 2 +- src/shape/Ellipse.cpp | 6 +++++ src/shape/Ellipse.h | 3 +++ src/shape/Mesh.cpp | 9 ++++++++ src/shape/Mesh.h | 3 +++ src/shape/Shape.h | 3 +++ 7 files changed, 52 insertions(+), 25 deletions(-) diff --git a/src/core/Util.cpp b/src/core/Util.cpp index 825e2cb..29f880b 100644 --- a/src/core/Util.cpp +++ b/src/core/Util.cpp @@ -150,7 +150,7 @@ Ellipse* createEllipseForColor(int frameWidth, int frameHeight) ); } -void drawControlsVertex(QPainter* painter, const QPointF& vertex, bool selected, bool locked, MShape::ShapeMode shapeMode, qreal radius, qreal strokeWidth) +void drawControlsVertex(QPainter* painter, const QPointF& vertex, bool major, bool selected, bool locked, MShape::ShapeMode shapeMode, qreal radius, qreal strokeWidth) { // Init colors and stroke. if (locked) @@ -164,32 +164,35 @@ void drawControlsVertex(QPainter* painter, const QPointF& vertex, bool selected, (vertex.y() - radius) - 1, radius * 2, radius * 2); - if (locked) { - // Draw loccked ellipse. + if (locked) + { + // Draw ellipse. painter->drawEllipse(vertex, radius, radius); - } else { - switch (shapeMode) { - case MShape::ScaleMode: - // Draw scale icons - painter->drawEllipse(vertex, radius, radius); - painter->drawPixmap(target, QPixmap(":/vertex-scale")); - break; - case MShape::RotateMode: - // Draw rotate icons - painter->drawEllipse(vertex, radius, radius); - painter->drawPixmap(target, QPixmap(":/vertex-rotate")); - break; - default: - // Draw ellipse. - painter->drawEllipse(vertex, radius, radius); - break; - } + } + else if (shapeMode == MShape::DefaultMode) + { + // Draw ellipse. + painter->drawEllipse(vertex, radius, radius); + + // Draw cross. + qreal offset = sin(M_PI/4) * radius; + painter->drawLine( vertex + QPointF(offset, offset), vertex + QPointF(-offset, -offset) ); + painter->drawLine( vertex + QPointF(offset, -offset), vertex + QPointF(-offset, offset) ); + } + else if (!major) + { + painter->drawEllipse(vertex, radius, radius); + } + else if (shapeMode == MShape::ScaleMode) + { + painter->drawPixmap(target, QPixmap(":/vertex-scale")); + } + else // RotateMode + { + // Draw rotate icons + painter->drawPixmap(target, QPixmap(":/vertex-rotate")); } - // Draw cross. - // qreal offset = sin(M_PI/4) * radius; - // painter->drawLine( vertex + QPointF(offset, offset), vertex + QPointF(-offset, -offset) ); - // painter->drawLine( vertex + QPointF(offset, -offset), vertex + QPointF(-offset, offset) ); } bool fileExists(const QString& filename) diff --git a/src/core/Util.h b/src/core/Util.h index d9e91b8..6fd29ab 100644 --- a/src/core/Util.h +++ b/src/core/Util.h @@ -68,7 +68,7 @@ Mesh* createMeshForColor(int frameWidth, int frameHeight); Triangle* createTriangleForColor(int frameWidth, int frameHeight); Ellipse* createEllipseForColor(int frameWidth, int frameHeight); -void drawControlsVertex(QPainter* painter, const QPointF& vertex, bool selected, bool locked, MShape::ShapeMode shapeMode, qreal radius = MM::VERTEX_SELECT_RADIUS, qreal strokeWidth = MM::VERTEX_SELECT_STROKE_WIDTH); +void drawControlsVertex(QPainter* painter, const QPointF& vertex, bool major, bool selected, bool locked, MShape::ShapeMode shapeMode, qreal radius = MM::VERTEX_SELECT_RADIUS, qreal strokeWidth = MM::VERTEX_SELECT_STROKE_WIDTH); /** * Checks if a file exists or not. diff --git a/src/shape/Ellipse.cpp b/src/shape/Ellipse.cpp index aca9f22..e60ccb6 100644 --- a/src/shape/Ellipse.cpp +++ b/src/shape/Ellipse.cpp @@ -149,4 +149,10 @@ void Ellipse::setVertex(int i, const QPointF& v) sanitize(); } +// Returns true iff vertex index is considered a major (external) control point. +bool Ellipse::isMajorVertex(int idx) const +{ + return !hasCenterControl() || idx != 4; +} + } diff --git a/src/shape/Ellipse.h b/src/shape/Ellipse.h index 1f50e17..9816ad4 100644 --- a/src/shape/Ellipse.h +++ b/src/shape/Ellipse.h @@ -132,6 +132,9 @@ public: // Override the parent, checking to make sure the vertices are displaced correctly. virtual void setVertex(int i, const QPointF& v); + // Returns true iff vertex index is considered a major (external) control point. + virtual bool isMajorVertex(int idx) const; + protected: /// Returns a new MShape (using default constructor). virtual MShape* _create() const { return new Ellipse(); } diff --git a/src/shape/Mesh.cpp b/src/shape/Mesh.cpp index cc48e92..cab48b7 100644 --- a/src/shape/Mesh.cpp +++ b/src/shape/Mesh.cpp @@ -131,6 +131,15 @@ void Mesh::setVertex(int i, const QPointF& v) _rawSetVertex(i, realV); } +bool Mesh::isMajorVertex(int idx) const +{ + return (idx == 0 || + idx == nColumns()-1 || + idx == nVertices()-1 || + idx == nVertices()-nColumns()); +} + + void Mesh::resizeVertices2d(IndexVector2d& vertices2d, int nColumns, int nRows) { vertices2d.resize(nColumns); diff --git a/src/shape/Mesh.h b/src/shape/Mesh.h index 25f3d84..de5de88 100644 --- a/src/shape/Mesh.h +++ b/src/shape/Mesh.h @@ -59,6 +59,9 @@ public: // Override the parent, checking to make sure the vertices are displaced correctly. virtual void setVertex(int i, const QPointF& v); + // Returns true iff vertex index is considered a major (external) control point. + virtual bool isMajorVertex(int idx) const; + QPointF getVertex2d(int i, int j) const { return vertices[_vertices2d[i][j]]; diff --git a/src/shape/Shape.h b/src/shape/Shape.h index 5fdb4c6..2dde372 100644 --- a/src/shape/Shape.h +++ b/src/shape/Shape.h @@ -132,6 +132,9 @@ public: qCopy(vertices_.begin(), vertices_.end(), vertices.begin()); } + // Returns true iff vertex index is considered a major (external) control point. + virtual bool isMajorVertex(int idx) const { Q_UNUSED(idx); return true; } + // Returns center of object. virtual QPointF getCenter() const;