Exemplo n.º 1
0
bool MgShape::save(MgStorage* s) const
{
    GiColor c;

    s->writeUInt32("tag", getTag());
    s->writeUInt8("lineStyle", (unsigned char)contextc()->getLineStyle());
    s->writeFloat("lineWidth", contextc()->getLineWidth());

    c = contextc()->getLineColor();
    s->writeUInt32("lineColor", c.b | (c.g << 8) | (c.r << 16) | (c.a << 24));
    c = contextc()->getFillColor();
    s->writeUInt32("fillColor", c.b | (c.g << 8) | (c.r << 16) | (c.a << 24));
    s->writeBool("autoFillColor", contextc()->isAutoFillColor());

    return shapec()->save(s);
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
0
bool MgShape::equals(const MgObject& src) const
{
    bool ret = false;

    if (src.isKindOf(Type())) {
        const MgShape& _src = (const MgShape&)src;
        ret = shapec()->equals(*_src.shapec())
            && contextc()->equals(*_src.contextc())
            && getTag() == _src.getTag();
    }

    return ret;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
bool MgShape::hasFillColor() const
{
    return contextc()->hasFillColor() && shapec()->isClosed();
}