Пример #1
0
bool MgCmdDrawLines::touchEnded(const MgMotion* sender)
{
    Point2d pnt(snapPoint(sender));
    float distmin = mgDisplayMmToModel(2.f, sender);
    bool closed = false;
    
    dynshape()->shape()->setPoint(m_step, pnt);
    
    if (needCheckClosed()) {
        closed = m_step > 2 && pnt.distanceTo(dynshape()->shape()->getPoint(0)) < distmin;
        ((MgBaseLines*)dynshape()->shape())->setClosed(closed);
    }
    
    dynshape()->shape()->update();
    
    if (pnt.distanceTo(dynshape()->shape()->getPoint(m_step - 1)) > distmin) {
        if (closed || needEnded()) {
            if (closed) {
                ((MgBaseLines*)dynshape()->shape())->removePoint(m_step);
            }
            _addshape(sender);
            _delayClear();
            m_step = 0;
        }
        else if (++m_step >= dynshape()->shape()->getPointCount()) {
            ((MgBaseLines*)dynshape()->shape())->addPoint(pnt);
        }
    }
    
    return _touchEnded(sender);
}
Пример #2
0
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;
}
Пример #3
0
bool MgCmdDrawLines::touchMoved(const MgMotion* sender)
{
    Point2d pnt(snapPoint(sender));
    dynshape()->shape()->setPoint(m_step, pnt);
    
    if (needCheckClosed()) {
        float distmin = mgDisplayMmToModel(2.f, sender);
        bool closed = m_step > 2 && pnt.distanceTo(dynshape()->shape()->getPoint(0)) < distmin;
        ((MgBaseLines*)dynshape()->shape())->setClosed(closed);
    }
    
    dynshape()->shape()->update();
    
    return _touchMoved(sender);
}