示例#1
0
bool MgCmdDrawSplines::click(const MgMotion* sender)
{
    if (m_freehand) {
        MgShapeT<MgLine> line;
        
        if (sender->view->context()) {
            *line.context() = *sender->view->context();
        }
        
        Point2d pt (sender->pointM);
        
        if (sender->point.distanceTo(sender->startPoint) < 1.f) {
        	pt = (sender->point + Vector2d(1.f, 1.f)) * sender->view->xform()->displayToModel();
        }
        line.shape()->setPoint(0, sender->startPointM);
        line.shape()->setPoint(1, pt);
        
        if (sender->view->shapeWillAdded(&line)) {
            _addshape(sender, &line);
        }
        
        return true;
    }
    return MgCommandDraw::click(sender);
}
示例#2
0
MgShape* MgCmdManagerImpl::addImageShape(const MgMotion* sender,
        const char* name, float width, float height)
{
    if (!name || *name == 0 || width < 1 || height < 1)
        return NULL;

    Vector2d size(Vector2d(width, height) * sender->view->xform()->displayToWorld());
    while (fabsf(size.x) > 200.f || fabsf(size.y) > 200.f) {
        size *= 0.95f;
    }
    Box2d rect(sender->view->xform()->getWndRectW() + Vector2d(10.f, -10.f));
    rect = Box2d(rect.leftTop(), rect.leftTop() + size);
    rect *= sender->view->xform()->worldToModel();

    MgShapeT<MgImageShape> shape;
    MgImageShape* imagesp = (MgImageShape*)shape.shape();

    shape.context()->setLineStyle(kGiLineNull);         // 默认没有边框
    shape.context()->setFillColor(GiColor::White());    // 设为实填充,避免在中心无法点中
    imagesp->setName(name);
    imagesp->setRect2P(rect.leftTop(), rect.rightBottom());

    MgShapesLock locker(MgShapesLock::Add, sender->view);
    if (sender->view->shapeWillAdded(&shape)) {
        MgShape* newsp = sender->view->shapes()->addShape(shape);
        sender->view->shapeAdded(newsp);

        sender->view->setNewShapeID(newsp->getID());
        sender->view->cancel(sender);

        return newsp;
    }

    return NULL;
}
示例#3
0
void MgCmdErase::gatherShapes(const MgMotion* sender, MgShapes* shapes)
{
    if (m_boxsel) {
        MgShapeT<MgRect> shape;
        
        GiContext ctxshap(0, GiColor(0, 0, 255, 128), 
                          isIntersectMode(sender) ? kGiLineDash : kGiLineSolid, GiColor(0, 0, 255, 32));
        *shape.context() = ctxshap;
        ((MgRect*)shape.shape())->setRect2P(sender->startPointM, sender->pointM);
        shapes->addShape(shape);
    }
}
示例#4
0
MgShape* MgCmdManagerImpl::addImageShape(const MgMotion* sender, const char* name,
                                         float xc, float yc, float w, float h)
{
    if (!name || *name == 0 || w < 1 || h < 1)
        return NULL;
    
    Vector2d size(Vector2d(w, h) * sender->view->xform()->displayToWorld());
    while (fabsf(size.x) > 200.f || fabsf(size.y) > 200.f) {
        size *= 0.95f;
    }
    size *= sender->view->xform()->worldToDisplay();
    
    Box2d rect(xc - size.x / 2, yc - size.y / 2, xc + size.x / 2, yc + size.y / 2);
    LOGD("addImageShape %s x:%.0f y:%.0f w:%.0f h:%.0f", 
         name, rect.xmin, rect.ymin, rect.width(), rect.height());
    rect *= sender->view->xform()->displayToModel();
    
    MgShapeT<MgImageShape> shape;
    MgImageShape* imagesp = (MgImageShape*)shape.shape();
    
    shape.context()->setLineStyle(kGiLineNull);         // 默认没有边框
    shape.context()->setFillColor(GiColor::White());    // 设为实填充,避免在中心无法点中
    imagesp->setName(name);
    imagesp->setRect2P(rect.leftTop(), rect.rightBottom());
    
    MgShapesLock locker(MgShapesLock::Add, sender->view);
    if (sender->view->shapeWillAdded(&shape)) {
        MgShape* newsp = sender->view->shapes()->addShape(shape);
        sender->view->shapeAdded(newsp);
        
        sender->view->setNewShapeID(newsp->getID());
        sender->toSelectCommand();
        
        return newsp;
    }
    
    return NULL;
}