예제 #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 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);
}
예제 #3
0
MgShape* MgCmdErase::hitTest(const MgMotion* sender)
{
    Box2d limits(sender->startPointM, mgDisplayMmToModel(6, sender), 0);
    Point2d nearpt;
    
    return sender->view->shapes()->hitTest(limits, nearpt);
}
예제 #4
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);
}
예제 #5
0
bool MgCmdDrawSplines::canAddPoint(const MgMotion* sender, bool ended)
{
    if (!m_freehand && !ended)
        return false;
    
    if (m_step > 0 && mgDisplayMmToModel(ended ? 0.2f : 0.5f, sender)
        > sender->pointM.distanceTo(dynshape()->shape()->getPoint(m_step - 1))) {
        return false;
    }
    
    return true;
}
예제 #6
0
bool MgCmdDrawLines::doubleClick(const MgMotion* sender)
{
    if (m_step > 1) {
        while (m_step > 1 && mgDisplayMmToModel(3.f, sender) >
            sender->pointM.distanceTo(dynshape()->shape()->getPoint(m_step))) {
            ((MgBaseLines*)dynshape()->shape())->removePoint(m_step--);
        }
        _addshape(sender);
        _delayClear();
        m_step = 0;
    }
    return true;
}
예제 #7
0
bool MgCommandDraw::_click(const MgMotion* sender)
{
    Box2d limits(sender->pointM, mgDisplayMmToModel(10, sender), 0);
    Point2d nearpt;
    MgShape* shape = sender->view->shapes()->hitTest(limits, nearpt);
    
    if (shape) {
        g_newShapeID = shape->getID();
        mgGetCommandManager()->setCommand(sender, "select");
    }
    
    return shape || longPress(sender);
}
예제 #8
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);
}
예제 #9
0
bool MgCmdDrawRect::touchEnded(const MgMotion* sender)
{
    Point2d pt1(m_startPt);
    Point2d pt2(snapPoint(sender));
    MgBaseRect* shape = (MgBaseRect*)dynshape()->shape();
    
    shape->setRect2P(pt1, pt2);
    dynshape()->shape()->update();

    float minDist = mgDisplayMmToModel(5, sender);

    if (shape->getWidth() > minDist && shape->getHeight() > minDist) {
        addRectShape(sender);
    }

    return _touchEnded(sender);
}
예제 #10
0
bool MgCmdDrawTriangle::touchEnded(const MgMotion* sender)
{
    Point2d pnt(snapPoint(sender));
    float distmin = mgDisplayMmToModel(2.f, sender);
    
    dynshape()->shape()->setPoint(m_step, pnt);
    dynshape()->shape()->update();
    
    if (pnt.distanceTo(dynshape()->shape()->getPoint(m_step - 1)) > distmin) {
        m_step++;
        if (3 == m_step) {
            _addshape(sender);
            _delayClear();
            m_step = 0;
        }
    }

    return _touchEnded(sender);
}
예제 #11
0
bool MgCommandDraw::_touchEnded2(const MgMotion* sender)
{
    Point2d pnt(snapPoint(sender));
    float distmin = mgDisplayMmToModel(2.f, sender);
    
    setStepPoint(m_step, pnt);
    dynshape()->shape()->update();
    
    if (pnt.distanceTo(dynshape()->shape()->getPoint(m_step - 1)) > distmin) {
        m_step++;
        if (m_step >= getMaxStep()) {
            _addshape(sender);
            _delayClear();
            m_step = 0;
        }
    }

    return _touchEnded(sender);
}
예제 #12
0
bool MgCmdDrawLines::canAddPoint(const MgMotion* sender, bool ended)
{
    float minDist = mgDisplayMmToModel(3, sender);
    Point2d endPt  = m_shape->shape()->getPoint(m_step - 1);
    float distToEnd = endPt.distanceTo(sender->pointM);
    float turnAngle = 90;
    
    if (m_step > 1)
    {
        Point2d lastPt = m_shape->shape()->getPoint(m_step - 2);
        turnAngle = (endPt - lastPt).angleTo(sender->pointM - endPt);
        turnAngle = mgRad2Deg(fabs(turnAngle));
    }
    
    if (distToEnd < minDist * (ended ? 0.25 : 1))
        return false;
    if (!ended && sin(turnAngle) * distToEnd < 5)
        return false;
    
    return true;
}
예제 #13
0
bool MgCmdDrawRect::touchEnded(const MgMotion* sender)
{
    Point2d pt1(m_startPt);
    Point2d pt2(snapPoint(sender));
    MgBaseRect* shape = (MgBaseRect*)dynshape()->shape();
    
    if (shape->getFlag(kMgSquare)) {
        float len = (float)mgMax(fabs(pt2.x - pt1.x), fabs(pt2.y - pt1.y));
        Box2d rect(m_startPt, 2.f * len, 0);
        pt1 = rect.leftTop();
        pt2 = rect.rightBottom();
    }
    shape->setRect(pt1, pt2);
    dynshape()->shape()->update();

    float minDist = mgDisplayMmToModel(5, sender);

    if (shape->getWidth() > minDist && shape->getHeight() > minDist) {
        addRectShape(sender);
    }

    return _touchEnded(sender);
}