bool MgCmdDrawFreeLines::touchEnded(const MgMotion* sender) { MgBaseLines* lines = (MgBaseLines*)dynshape()->shape(); float closelen = mgLineHalfWidthModel(dynshape(), sender) + mgDisplayMmToModel(5, sender); float closedist = sender->pointM.distanceTo(dynshape()->shape()->getPoint(0)); bool closed = (m_step > 2 && closedist < closelen && dynshape()->shape()->getExtent().width() > closedist * 1.5f && dynshape()->shape()->getExtent().height() > closedist * 1.5f); if (m_step > 2 && dynshape()->shape()->isClosed() != closed) { lines->setClosed(closed); if (closed) lines->removePoint(m_step); else lines->addPoint(sender->pointM); } if (!closed) { dynshape()->shape()->setPoint(m_step, sender->pointM); if (m_step > 0 && !canAddPoint(sender, true)) lines->removePoint(m_step); } dynshape()->shape()->update(); if (m_step > 1) { _addshape(sender); } else { click(sender); // add a point } _delayClear(); return _touchEnded(sender); }
bool MgCmdDrawLines::touchEnded(const MgMotion* sender) { Point2d pnt(snapPoint(sender)); dynshape()->shape()->setPoint(m_index, pnt); bool closed = checkClosed(sender, pnt); MgBaseLines* lines = (MgBaseLines*)dynshape()->shape(); dynshape()->shape()->update(); if (canAddPoint(sender, pnt)) { if (closed || needEnded()) { if (closed) { lines->removePoint(m_step); } addShape(sender); m_step = 0; _lastClicked = false; } else if (m_step <= dynshape()->shape()->getPointCount()) { m_step++; } } else if (m_step > 1) { if (m_step >= dynshape()->shape()->getPointCount()) { m_step--; } lines->removePoint(m_index); } return MgCommandDraw::touchEnded(sender); }
bool MgCmdDrawFreeLines::touchMoved(const MgMotion* sender) { MgBaseLines* lines = (MgBaseLines*)dynshape()->shape(); float closelen = mgLineHalfWidthModel(dynshape(), sender) + mgDisplayMmToModel(5, sender); float closedist = sender->pointM.distanceTo(dynshape()->shape()->getPoint(0)); bool closed = (m_step > 2 && closedist < closelen && dynshape()->shape()->getExtent().width() > closedist * 1.5f && dynshape()->shape()->getExtent().height() > closedist * 1.5f); if (m_step > 2 && dynshape()->shape()->isClosed() != closed) { lines->setClosed(closed); if (closed) lines->removePoint(m_step); else lines->addPoint(sender->pointM); } if (!closed) { dynshape()->shape()->setPoint(m_step, sender->pointM); if (m_step > 0 && canAddPoint(sender, false)) { m_step++; if (m_step >= dynshape()->shape()->getPointCount()) { ((MgBaseLines*)dynshape()->shape())->addPoint(sender->pointM); } } } dynshape()->shape()->update(); return _touchMoved(sender); }
bool MgCmdDrawSplines::touchBegan(const MgMotion* sender) { MgBaseLines* lines = (MgBaseLines*)dynshape()->shape(); Point2d pnt(m_freehand ? sender->startPtM : snapPoint(sender, true)); if (m_step > 0 && !m_freehand) { m_step++; if (m_step >= dynshape()->shape()->getPointCount()) { lines->addPoint(pnt); dynshape()->shape()->update(); } return MgCommandDraw::touchMoved(sender); } else { lines->resize(m_freehand ? 1 : 2); lines->setClosed(false); m_step = 1; dynshape()->shape()->setPoint(0, pnt); if (!m_freehand) dynshape()->shape()->setPoint(1, pnt); dynshape()->shape()->update(); return MgCommandDraw::touchBegan(sender); } }
bool MgCmdDrawLines::touchBegan(const MgMotion* sender) { Point2d pnt(snapPoint(sender, true)); MgBaseLines* lines = (MgBaseLines*)dynshape()->shape(); if (0 == m_step) { m_step = 1; m_index = 1; lines->resize(2); dynshape()->shape()->setPoint(0, pnt); dynshape()->shape()->setPoint(1, pnt); } else { if (m_step >= dynshape()->shape()->getPointCount()) { if (m_step > 2) { lines->addPoint(pnt); m_step = mgMin(m_step, lines->getPointCount() - 1); m_index = m_step; } else { lines->addPoint(pnt); m_index = m_step; } } dynshape()->shape()->setPoint(m_index, pnt); } dynshape()->shape()->update(); _lastClicked = true; return MgCommandDraw::touchBegan(sender); }
bool MgCmdDrawSplines::cancel(const MgMotion* sender) { if (!m_freehand && m_step > 1) { MgBaseLines* lines = (MgBaseLines*)dynshape()->shape(); lines->removePoint(m_step--); addShape(sender); } return MgCommandDraw::cancel(sender); }
bool MgCmdDrawLines::cancel(const MgMotion* sender) { MgBaseLines* lines = (MgBaseLines*)dynshape()->shape(); if (m_step > (lines->isClosed() ? 2 : 1)) { addShape(sender); m_step = 0; return true; } return MgCommandDraw::cancel(sender); }
bool MgCmdDrawSplines::canAddPoint(const MgMotion* sender, bool ended) { if (!m_freehand && !ended) return false; if (m_step > 0) { MgBaseLines* lines = (MgBaseLines*)dynshape()->shape(); float dist = sender->pointM.distanceTo(lines->endPoint()); if (dist < sender->displayMmToModel(ended ? 0.3f : 0.5f)) return false; } return true; }
bool MgCmdDrawLines::checkClosed(const MgMotion* sender, const Point2d& pnt) { bool closed = false; MgBaseLines* lines = (MgBaseLines*)dynshape()->shape(); if ((m_index == 0 || m_index == m_step) && needCheckClosed()) { float distmin = sender->displayMmToModel(2.f); closed = m_step > 2 && pnt.distanceTo(m_index == 0 ? lines->endPoint() : lines->getPoint(0)) < distmin; lines->setClosed(closed); } return closed; }
bool MgCmdDrawSplines::touchMoved(const MgMotion* sender) { MgBaseLines* lines = (MgBaseLines*)dynshape()->shape(); dynshape()->shape()->setPoint(m_step, sender->pointM); if (m_step > 0 && canAddPoint(sender, false)) { m_step++; if (m_step >= dynshape()->shape()->getPointCount()) { lines->addPoint(sender->pointM); } } dynshape()->shape()->update(); return _touchMoved(sender); }
bool MgCmdDrawTriangle::touchBegan(const MgMotion* sender) { MgBaseLines* lines = (MgBaseLines*)dynshape()->shape(); if (0 == m_step) { m_step = 1; lines->setClosed(true); lines->resize(3); Point2d pnt(snapPoint(sender, true)); for (int i = 0; i < 3; i++) { dynshape()->shape()->setPoint(i, pnt); } } else { dynshape()->shape()->setPoint(m_step, snapPoint(sender)); } dynshape()->shape()->update(); return MgCommandDraw::touchBegan(sender); }
bool MgCmdDrawSplines::touchMoved(const MgMotion* sender) { MgBaseLines* lines = (MgBaseLines*)dynshape()->shape(); Point2d pnt(!m_freehand ? snapPoint(sender) : (sender->pointM + sender->lastPtM) / 2.f); if (m_freehand) { if (canAddPoint(sender, false)) { lines->addPoint(pnt); m_step++; } } else { dynshape()->shape()->setPoint(m_step, pnt); if (m_step > 0 && canAddPoint(sender, false)) { m_step++; if (m_step >= dynshape()->shape()->getPointCount()) { lines->addPoint(pnt); } } } dynshape()->shape()->update(); return MgCommandDraw::touchMoved(sender); }
bool MgCmdDrawSplines::touchBegan(const MgMotion* sender) { MgBaseLines* lines = (MgBaseLines*)dynshape()->shape(); if (m_step > 0 && !m_freehand) { m_step++; if (m_step >= dynshape()->shape()->getPointCount()) { lines->addPoint(sender->pointM); dynshape()->shape()->update(); } return _touchMoved(sender); } else { lines->resize(2); m_freehand = !sender->pressDrag; m_step = 1; dynshape()->shape()->setPoint(0, sender->startPointM); dynshape()->shape()->setPoint(1, sender->pointM); dynshape()->shape()->update(); return _touchBegan(sender); } }
bool MgCmdDrawLines::doubleClick(const MgMotion* sender) { MgBaseLines* lines = (MgBaseLines*)dynshape()->shape(); Point2d pnt(_lastClicked ? lines->getPoint(m_index) : sender->pointM); if (m_step > (lines->isClosed() ? 2 : 1)) { if (lines->getPointCount() > (lines->isClosed() ? 2 : 1) && sender->displayMmToModel(5.f) > pnt.distanceTo(lines->getPoint(m_index))) { lines->removePoint(m_index--); } addShape(sender); m_step = 0; } return true; }