void GcGraphView::draw(GiGraphics& gs) { int gridType = cmdView()->getOptionInt("showGrid", 0); if (gridType < 1 || gridType > 2 || gs.xf().getViewScale() < 0.05f) return; Box2d rect(gs.xf().getWndRectW()); GiContext ctx(0, GiColor(127, 127, 127, gridType == 2 ? 48 : 20)); if (gridType == 1) { GiContext ctx5(0, GiColor(127, 127, 127, 48)); float x = mgbase::roundReal(rect.xmin, -1) - 10; float y = mgbase::roundReal(rect.ymin, -1) - 10; int i = mgRound(x) / 10; for (; x < rect.xmax + 10; x += 10) { gs.drawLine(i++ % 5 ? &ctx : &ctx5, Point2d(x, rect.ymin), Point2d(x, rect.ymax), false); } i = mgRound(y) / 10; for (; y < rect.ymax + 10; y += 10) { gs.drawLine(i++ % 5 ? &ctx : &ctx5, Point2d(rect.xmin, y), Point2d(rect.xmax, y), false); } } else if (gridType == 2) { for (float x = rect.xmin - 10; x < rect.xmax + 10; x += 10) { for (float y = rect.ymin - 10; y < rect.ymax + 10; y += 10) { gs.drawLine(&ctx, Point2d(x, y - 0.5f), Point2d(x, y + 0.5f), false); gs.drawLine(&ctx, Point2d(x - 0.5f, y), Point2d(x + 0.5f, y), false); } } } GcBaseView::draw(gs); }
bool MgImageShape::_draw(int, GiGraphics& gs, const GiContext& ctx, int) const { Box2d rect(getRect() * gs.xf().modelToDisplay()); Vector2d vec((_points[1] - _points[0]) * gs.xf().modelToWorld()); bool ret = false; if (isVisible()) { ret = (gs.rawImage(_name, rect.center().x, rect.center().y, rect.width(), rect.height(), vec.angle2()) || drawBox(gs, ctx)); } return ret; }
bool MgRecordShape::draw(int mode, GiGraphics& gs, const GiContext& ctx, int segment) const { const Matrix2d& w2d = gs.xf().worldToDisplay(); for (ITEMS::const_iterator it = _items.begin(); it != _items.end(); ++it) { (*it)->draw(gs, w2d); } return _draw(mode, gs, ctx, segment) || !_items.empty(); }
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; }
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 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 MgRoundRect::_draw(GiGraphics& gs, const GiContext& ctx) const { bool ret = false; if (isOrtho()) { ret = gs.drawRoundRect(&ctx, Box2d(_points[0], _points[2]), _rx, _ry); } else { GiSaveModelTransform xf(&gs.xf(), Matrix2d::rotation(getAngle(), getCenter())); ret = gs.drawRoundRect(&ctx, getRect(), _rx, _ry); } return __super::_draw(gs, ctx) || ret; }
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; }
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; }