void GiGraphics::copy(const GiGraphics& src) { if (this != &src) { m_impl->bkcolor = src.m_impl->bkcolor; m_impl->maxPenWidth = src.m_impl->maxPenWidth; m_impl->drawColors = src.m_impl->drawColors; m_impl->xform->copy(src.xf()); } }
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; }
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; }
bool GiPath::draw(GiGraphics& gs, const GiContext* ctx, bool fill) { Matrix2d matD(gs.xf().modelToDisplay()); Point2d a, b, c; if (m_data->points.empty() || m_data->points.size() != m_data->types.size()) return false; gs.rawBeginPath(); for (size_t i = 0; i < m_data->points.size(); i++) { switch (m_data->types[i] & ~kGiCloseFigure) { case kGiMoveTo: a = m_data->points[i] * matD; gs.rawMoveTo(a.x, a.y); break; case kGiLineTo: a = m_data->points[i] * matD; gs.rawLineTo(a.x, a.y); break; case kGiBeziersTo: if (i + 2 >= m_data->points.size()) return false; a = m_data->points[i] * matD; b = m_data->points[i+1] * matD; c = m_data->points[i+2] * matD; gs.rawBezierTo(a.x, a.y, b.x, b.y, c.x, c.y); i += 2; break; default: return false; } if (m_data->types[i] & kGiCloseFigure) gs.rawClosePath(); } gs.rawEndPath(ctx, fill); return true; }
virtual void draw(GiGraphics& gs, const Matrix2d&) const { gs.getCanvas()->drawPath(stroke, fill); }
bool MgParallel::_draw(int mode, GiGraphics& gs, const GiContext& ctx, int segment) const { bool ret = gs.drawPolygon(&ctx, 4, _points); return __super::_draw(mode, gs, ctx, segment) || ret; }
bool MgLine::_draw(int mode, GiGraphics& gs, const GiContext& ctx, int segment) const { bool ret = gs.drawLine(&ctx, _points[0], _points[1]); return __super::_draw(mode, gs, ctx, segment) || ret; }
virtual void draw(GiGraphics& gs, const Matrix2d&) const { gs.getCanvas()->setBrush(argb, style); }
virtual void draw(GiGraphics& gs, const Matrix2d& w2d) const { Point2d pt2(pt * w2d); Vector2d vec2(vec * w2d); gs.getCanvas()->drawTextAt(text.c_str(), pt2.x, pt2.y, vec2.x, align); }
virtual void draw(GiGraphics& gs, const Matrix2d& w2d) const { Point2d pt2(pt * w2d); Vector2d vec2(vec * w2d); gs.getCanvas()->drawBitmap(name.c_str(), pt2.x, pt2.y, vec2.x, vec2.y, angle); }
virtual void draw(GiGraphics& gs, const Matrix2d& w2d) const { Point2d pt2(pt * w2d); Vector2d vec2(vec * w2d); gs.getCanvas()->clearRect(pt2.x, pt2.y, vec2.x, vec2.y); }
bool draw(const Point2d* pxs, int n) const { return pxs && n > 1 && m_gs->rawLines(m_pContext, pxs, n); }
virtual void draw(GiGraphics& gs, const Matrix2d&) const { gs.getCanvas()->closePath(); }
virtual void draw(GiGraphics& gs, const Matrix2d& w2d) const { Point2d cp2(cp * w2d), pt2(pt * w2d); gs.getCanvas()->quadTo(cp2.x, cp2.y, pt2.x, pt2.y); }
virtual void draw(GiGraphics& gs, const Matrix2d& w2d) const { Point2d c1t(c1 * w2d), c2t(c2 * w2d), pt2(pt * w2d); gs.getCanvas()->bezierTo(c1t.x, c1t.y, c2t.x, c2t.y, pt2.x, pt2.y); }
virtual void draw(GiGraphics& gs, const Matrix2d& w2d) const { Point2d pt2(pt * w2d); gs.getCanvas()->lineTo(pt2.x, pt2.y); }
virtual void draw(GiGraphics& gs, const Matrix2d& w2d) const { Point2d pt2(pt * w2d); Vector2d vec2(vec * w2d); gs.getCanvas()->drawEllipse(pt2.x, pt2.y, vec2.x, vec2.y, stroke, fill); }
virtual void draw(GiGraphics& gs, const Matrix2d& w2d) const { Point2d pt3(pt1 * w2d); Point2d pt4(pt2 * w2d); gs.getCanvas()->drawLine(pt3.x, pt3.y, pt4.x, pt4.y); }
bool MgLine::_draw(GiGraphics& gs, const GiContext& ctx) const { bool ret = gs.drawLine(&ctx, _points[0], _points[1]); return __super::_draw(gs, ctx) || ret; }
virtual void draw(GiGraphics& gs, const Matrix2d&) const { gs.getCanvas()->setPen(argb, width, style, phase, orgw); }
bool MgRect::_draw(GiGraphics& gs, const GiContext& ctx) const { bool ret = gs.drawPolygon(&ctx, 4, _points); return __super::_draw(gs, ctx) || ret; }
virtual void draw(GiGraphics& gs, const Matrix2d& w2d) const { Point2d pt2(pt * w2d); gs.getCanvas()->drawHandle(pt2.x, pt2.y, t); }