Example #1
0
bool MgShape::draw(int mode, GiGraphics& gs, const GiContext *ctx, int segment) const
{
    if (shapec()->isKindOf(6)) { // MgComposite
        GiContext ctxnull(0, GiColor(), kGiLineNull);
        return shapec()->draw(mode, gs, ctx ? *ctx : ctxnull, segment);
    }

    GiContext tmpctx(*contextc());

    if (ctx) {
        float addw  = ctx->getLineWidth();
        float width = tmpctx.getLineWidth();

        width = -gs.calcPenWidth(width, tmpctx.isAutoScale());  // 像素宽度,负数
        if (addw <= 0)
            tmpctx.setLineWidth(width + addw, false);           // 像素宽度加宽
        else                                                    // 传入正数表示像素宽度
            tmpctx.setLineWidth(-addw, ctx->isAutoScale());     // 换成新的像素宽度
    }

    if (ctx && ctx->getLineColor().a > 0) {
        tmpctx.setLineColor(ctx->getLineColor());
    }
    if (ctx && !ctx->isNullLine()) {
        tmpctx.setLineStyle(ctx->getLineStyle());
    }
    if (ctx && ctx->hasFillColor()) {
        tmpctx.setFillColor(ctx->getFillColor());
    }

    return shapec()->draw(mode, gs, tmpctx, segment);
}
Example #2
0
bool MgDot::_draw(int mode, GiGraphics& gs, const GiContext& ctx, int segment) const
{
    GiContext ctx2(0, GiColor::Invalid(), GiContext::kNullLine,
                   ctx.hasFillColor() ? ctx.getFillColor() : ctx.getLineColor());
    float w = gs.calcPenWidth(ctx.getLineWidth(), false);
    
    bool ret = gs.drawCircle(&ctx2, _point, gs.xf().displayToModel(w));
    return __super::_draw(mode, gs, ctx, segment) || ret;
}
Example #3
0
bool MgShape::draw(int mode, GiGraphics& gs, const GiContext *ctx, int segment) const
{
    GiContext tmpctx(*contextc());

    if (shapec()->isKindOf(6)) { // MgComposite
        tmpctx = ctx ? *ctx : GiContext(0, GiColor(), kGiLineNull);
    }
    else {
        if (ctx) {
            float addw  = ctx->getLineWidth();
            float width = tmpctx.getLineWidth();

            width = -gs.calcPenWidth(width, tmpctx.isAutoScale());  // 像素宽度,负数
            if (addw <= 0)
                tmpctx.setLineWidth(width + addw, false);           // 像素宽度加宽
            else                                                    // 传入正数表示像素宽度
                tmpctx.setLineWidth(-addw, ctx->isAutoScale());     // 换成新的像素宽度
        }

        if (ctx && ctx->getLineColor().a > 0) {
            tmpctx.setLineColor(ctx->getLineColor());
        }
        if (ctx && !ctx->isNullLine()) {
            tmpctx.setLineStyle(ctx->getLineStyle());
        }
        if (ctx && ctx->hasFillColor()) {
            tmpctx.setFillColor(ctx->getFillColor());
        }
    }

    bool ret = false;
    Box2d rect(shapec()->getExtent() * gs.xf().modelToDisplay());

    rect.inflate(1 + gs.calcPenWidth(tmpctx.getLineWidth(), tmpctx.isAutoScale()) / 2);

    if (gs.beginShape(shapec()->getType(), getID(), rect.xmin,
        rect.ymin, rect.width(), rect.height())) {
        ret = shapec()->draw(mode, gs, tmpctx, segment);
        gs.endShape(shapec()->getType(), getID(), rect.xmin, rect.ymin);
    }
    return ret;
}
Example #4
0
bool MgGrid::_draw(int mode, GiGraphics& gs, const GiContext& ctx) const
{
    Vector2d cell(m_cell / 2);
    
    if (cell.x < _MGZERO || cell.y < _MGZERO) {
        GiContext ctxedge(ctx);
        ctxedge.setNoFillColor();
        gs.drawRect(&ctxedge, getRect());
        return __super::_draw(mode, gs, ctx);
    }
    
    int nx = (int)(getWidth() / cell.x + _MGZERO);
    int ny = (int)(getHeight() / cell.y + _MGZERO);
    Box2d rect(getPoint(3), getPoint(3)
               + Vector2d((float)(cell.x * nx), (float)(cell.y * ny)));
    
    float w = gs.calcPenWidth(ctx.getLineWidth(), ctx.isAutoScale()) / -2.f;
    GiContext ctxgrid(w, ctx.getLineColor());
    
    bool antiAlias = gs.setAntiAliasMode(false);
    int ret = gs.drawRect(&ctxgrid, rect) ? 1 : 0;
    
    bool switchx = (nx >= 10 && cell.x < gs.xf().displayToModel(20, true));
    bool switchy = (ny >= 10 && cell.y < gs.xf().displayToModel(20, true));
    Point2d pts[2] = { rect.leftTop(), rect.leftBottom() };
    
    for (int i = 1; i < nx; i++) {
        pts[0].x += cell.x;
        pts[1].x += cell.x;
        ctxgrid.setLineWidth(!switchx || i%5 > 0 ? w/2 : w, false);
        ctxgrid.setLineAlpha(-w < 0.9f && (!switchx || i%5 > 0) ?
            ctx.getLineAlpha() / 2 : ctx.getLineAlpha());
        ret += gs.drawLine(&ctxgrid, pts[0], pts[1]) ? 1 : 0;
    }
    
    pts[0] = rect.leftBottom();
    pts[1] = rect.rightBottom();
    for (int j = 1; j < ny; j++) {
        pts[0].y += cell.y;
        pts[1].y += cell.y;
        ctxgrid.setLineWidth(!switchy || j%5 > 0 ? w/2 : w, false);
        ctxgrid.setLineAlpha(-w < 0.9f && (!switchy || j%5 > 0) ?
            ctx.getLineAlpha() / 2 : ctx.getLineAlpha());
        ret += gs.drawLine(&ctxgrid, pts[0], pts[1]) ? 1 : 0;
    }

    gs.setAntiAliasMode(antiAlias);
    
    return __super::_draw(mode, gs, ctx) || ret > 0;
}
Example #5
0
bool MgShape::draw(int mode, GiGraphics& gs, const GiContext *ctx, int segment) const
{
    GiContext tmpctx(context());

    if (shapec()->isKindOf(6)) { // MgComposite
        tmpctx = ctx ? *ctx : GiContext(0, GiColor(), GiContext::kNullLine);
    }
    else if (ctx) {
        float addw = ctx->getLineWidth();
        
        if (addw < -0.1f) {
            tmpctx.setExtraWidth(-addw);
        } else if (addw > 0.1f) {                               // 传入正数表示像素宽度
            tmpctx.setLineWidth(-addw, ctx->isAutoScale());     // 换成新的像素宽度
        }
        
        if (ctx->getLineColor().a > 0) {
            tmpctx.setLineColor(ctx->getLineColor());
        }
        if (!ctx->isNullLine()) {
            tmpctx.setLineStyle(ctx->getLineStyle());
        }
        if (ctx->hasFillColor()) {
            tmpctx.setFillColor(ctx->getFillColor());
        }
    }

    bool ret = false;
    Box2d rect(shapec()->getExtent() * gs.xf().modelToDisplay());

    rect.inflate(1 + gs.calcPenWidth(tmpctx.getLineWidth(), tmpctx.isAutoScale()) / 2);

    if (gs.beginShape(shapec()->getType(), getID(),
                      (int)shapec()->getChangeCount(),
                      rect.xmin, rect.ymin, rect.width(), rect.height())) {
        ret = drawShape(getParent(), *shapec(), mode, gs, tmpctx, segment);
        gs.endShape(shapec()->getType(), getID(), rect.xmin, rect.ymin);
    }
    return ret;
}