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; }
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; }