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