Ejemplo n.º 1
0
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);
}
Ejemplo n.º 2
0
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);
}
Ejemplo n.º 3
0
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);
}
Ejemplo n.º 4
0
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);
}
Ejemplo n.º 5
0
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;
}