Пример #1
0
bool TransformCmd::draw(const MgMotion* sender, GiGraphics* gs)
{
    if (_lastCmd)
        _lastCmd->draw(sender, gs);
    
    char text[20];
    GiContext ctx(-10, GiColor(255, 0, 0, 128));
    gs->drawLine(&ctx, getPointM(0, sender), getPointM(1, sender));

    Point2d pt(getPointM(1, sender) * gs->xf().modelToDisplay());
#if defined(_MSC_VER) && _MSC_VER >= 1400 // VC8
    sprintf_s(text, sizeof(text), "X %d %dd", 
#else
    sprintf(text, "X %d %dd", 
#endif
        mgRound(_axis[0].length()), mgRound(_axis[0].angle2() * _M_R2D));
    gs->rawTextCenter(text, pt.x, pt.y, 40);
    
    ctx.setLineColor(GiColor(0, 0, 255, 128));
    gs->drawLine(&ctx, getPointM(0, sender), getPointM(2, sender));
    pt = getPointM(2, sender) * gs->xf().modelToDisplay();
#if defined(_MSC_VER) && _MSC_VER >= 1400 // VC8
    sprintf_s(text, sizeof(text), "Y %d %dd", 
#else
    sprintf(text, "Y %d %dd", 
#endif
        mgRound(_axis[1].length()), mgRound(_axis[1].angle2() * _M_R2D));
    gs->rawTextCenter(text, pt.x, pt.y, 40);
    
    return true;
}
Пример #2
0
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);
}
Пример #3
0
void MgCmdErase::gatherShapes(const MgMotion* sender, MgShapes* shapes)
{
    if (m_boxsel) {
        MgShapeT<MgRect> shape;
        
        GiContext ctxshap(0, GiColor(0, 0, 255, 128), 
                          isIntersectMode(sender) ? kGiLineDash : kGiLineSolid, GiColor(0, 0, 255, 32));
        *shape.context() = ctxshap;
        ((MgRect*)shape.shape())->setRect2P(sender->startPointM, sender->pointM);
        shapes->addShape(shape);
    }
}
Пример #4
0
bool MgCmdDrawSplines::draw(const MgMotion* sender, GiGraphics* gs)
{
    if (getStep() > 0 && !m_freehand) {
        GiContext ctx(0, GiColor(64, 128, 64, 172), GiContext::kSolidLine, GiColor(0, 64, 64, 128));
        float radius = sender->displayMmToModel(0.8f, gs);
        
        for (int i = 1, n = dynshape()->shape()->getPointCount(); i < 6 && n >= i; i++) {
            gs->drawCircle(&ctx, dynshape()->shape()->getPoint(n - i), radius);
        }
        gs->drawCircle(&ctx, dynshape()->shape()->getPoint(0), radius * 1.5f);
    }
    return MgCommandDraw::draw(sender, gs);
}
Пример #5
0
bool MgCmdDrawSplines::draw(const MgMotion* sender, GiGraphics* gs)
{
    if (m_step > 0 && !m_freehand) {
        GiContext ctx(0, GiColor(64, 128, 64, 172), kLineSolid, GiColor(0, 64, 64, 128));
        float radius = gs->xf().displayToModel(4);
        
        for (UInt32 i = 1, n = dynshape()->shape()->getPointCount(); i < 6 && n >= i; i++) {
            gs->drawEllipse(&ctx, dynshape()->shape()->getPoint(n - i), radius);
        }
        gs->drawEllipse(&ctx, dynshape()->shape()->getPoint(0), radius * 1.5f);
    }
    return MgCommandDraw::draw(sender, gs);
}
Пример #6
0
bool MgCmdDrawLines::draw(const MgMotion* sender, GiGraphics* gs)
{
    if (m_step > 1) {
        GiContext ctxaux(0, GiColor(64, 64, 64, 128), kLineSolid, GiColor(0, 64, 64, 168));
        float radius = gs->xf().displayToModel(3);
        
        for (UInt32 i = 0; i < m_shape->shape()->getPointCount(); i++) {
            gs->drawEllipse(&ctxaux, m_shape->shape()->getPoint(i), radius);
        }
    }
    
    return MgCommandDraw::draw(sender, gs);
}
Пример #7
0
GiColor GiCanvasGdi::getNearestColor(const GiColor& color) const
{
    COLORREF cr = RGB(color.r, color.g, color.b);
    if (m_attribDC != NULL)
    {
        cr = ::GetNearestColor(m_attribDC, cr);
        return GiColor(GetRValue(cr), GetGValue(cr), GetBValue(cr), color.a);
    }
    if (m_draw->m_hdc != NULL)
    {
        cr = ::GetNearestColor(m_draw->m_hdc, cr);
        return GiColor(GetRValue(cr), GetGValue(cr), GetBValue(cr), color.a);
    }
    return color;
}
Пример #8
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);
}
Пример #9
0
bool MgCmdDrawEllipse::draw(const MgMotion* sender, GiGraphics* gs)
{
    if (getStep() > 0 && sender->dragging()) {
        GiContext ctxshap(0, GiColor(0, 0, 255, 128), kGiLineDash);
        gs->drawRect(&ctxshap, dynshape()->shape()->getExtent());
    }
    return MgCmdDrawRect::draw(sender, gs);
}
Пример #10
0
void CBaseView::DrawAll(GiGraphics* gs)
{
    CWaitCursor cursor;
    m_doc->draw(*gs);

    GiContext ctx(0, GiColor(128, 0, 0, 64), kGiLineDash);
    gs->drawRect(&ctx, m_doc->getExtent());
}
Пример #11
0
bool MgCmdManagerImpl::drawSnap(const MgMotion* sender, GiGraphics* gs)
{
    bool ret = false;
    
    if (sender->dragging() || !sender->view->useFinger()) {
        if (_snapType[0] >= kMgSnapPoint) {
            bool isnear = (_snapType[0] >= kMgSnapNearPt);
            GiContext ctx(-2, GiColor(0, 255, 0, 200), kGiLineDash, GiColor(0, 255, 0, 64));
            ret = gs->drawEllipse(&ctx, _ptSnap, displayMmToModel(isnear ? 3.f : 6.f, gs));
            gs->drawHandle(_ptSnap, kGiHandleVertex);
        }
        else {
            GiContext ctx(0, GiColor(0, 255, 0, 200), kGiLineDash, GiColor(0, 255, 0, 64));
            GiContext ctxcross(-2, GiColor(0, 255, 0, 200));
            
            if (_snapType[0] > 0) {
                if (_snapBase[0] == _ptSnap) {
                    if (_snapType[0] == kMgSnapGridX) {
                        Vector2d vec(0, displayMmToModel(15.f, gs));
                        ret = gs->drawLine(&ctxcross, _ptSnap - vec, _ptSnap + vec);
                        gs->drawEllipse(&ctx, _snapBase[0], displayMmToModel(4.f, gs));
                    }
                }
                else {  // kMgSnapSameX
                    ret = gs->drawLine(&ctx, _snapBase[0], _ptSnap);
                    gs->drawEllipse(&ctx, _snapBase[0], displayMmToModel(2.5f, gs));
                }
            }
            if (_snapType[1] > 0) {
                if (_snapBase[1] == _ptSnap) {
                    if (_snapType[1] == kMgSnapGridY) {
                        Vector2d vec(displayMmToModel(15.f, gs), 0);
                        ret = gs->drawLine(&ctxcross, _ptSnap - vec, _ptSnap + vec);
                        gs->drawEllipse(&ctx, _snapBase[1], displayMmToModel(4.f, gs));
                    }
                }
                else {  // kMgSnapSameY
                    ret = gs->drawLine(&ctx, _snapBase[1], _ptSnap);
                    gs->drawEllipse(&ctx, _snapBase[1], displayMmToModel(2.5f, gs));
                }
            }
        }
    }
    
    return ret;
}
Пример #12
0
 bool drawHandle(GiGraphics* gs, const Point2d& pnt, bool hotdot)
 {
     GiContext ctx(0, GiColor::Black(), kGiLineSolid,
         GiColor(240, 240, 240, hotdot ? 200 : 128));
     bool old = gs->setAntiAliasMode(false);
     gs->drawRect(&ctx, Box2d(pnt, gs->xf().displayToModel(hotdot ? 3.f : 1.5f, true), 0));
     gs->setAntiAliasMode(old);
     return true;
 }
Пример #13
0
bool MgShape::load(MgShapeFactory* factory, MgStorage* s)
{
    setParent(getParent(), s->readUInt32("tag", getTag()));

    context()->setLineStyle((GiLineStyle)s->readUInt8("lineStyle", 0));
    context()->setLineWidth(s->readFloat("lineWidth", 0), true);

    context()->setLineColor(GiColor(s->readUInt32("lineColor", 0xFF000000), true));
    context()->setFillColor(GiColor(s->readUInt32("fillColor", 0), true));
    context()->setAutoFillColor(s->readBool("autoFillColor", context()->isAutoFillColor()));

    bool ret = shape()->load(factory, s);
    if (ret) {
        shape()->update();
    }

    return ret;
}
Пример #14
0
bool MgCmdDrawEllipse::draw(const MgMotion* sender, GiGraphics* gs)
{
    if (m_step > 0 && sender->dragging) {
        GiContext ctxshap(0, GiColor(0, 0, 255, 128), kGiLineDash);
        bool antiAlias = gs->setAntiAliasMode(false);
        gs->drawRect(&ctxshap, dynshape()->shape()->getExtent());
        gs->setAntiAliasMode(antiAlias);
    }
    return MgCmdDrawRect::draw(sender, gs);
}
Пример #15
0
GiColor giFromCGColor(CGColorRef color)
{
    int num = CGColorGetNumberOfComponents(color);
    CGColorSpaceModel space = CGColorSpaceGetModel(CGColorGetColorSpace(color));
    const CGFloat *rgba = CGColorGetComponents(color);
    
    if (space == kCGColorSpaceModelMonochrome && num >= 2) {
        UInt8 c = (UInt8)mgRound(rgba[0] * 255);
        return GiColor(c, c, c, (UInt8)mgRound(rgba[1] * 255));
    }
    if (num < 3) {
        return GiColor::Invalid();
    }

    return GiColor((UInt8)mgRound(rgba[0] * 255),
                   (UInt8)mgRound(rgba[1] * 255),
                   (UInt8)mgRound(rgba[2] * 255),
                   (UInt8)mgRound(CGColorGetAlpha(color) * 255));
}
Пример #16
0
GiColor GiCanvasGdi::setBkColor(const GiColor& color)
{
    if (m_draw->getDrawDC() != NULL)
    {
        COLORREF cr = RGB(color.r, color.g, color.b);
        cr = ::SetBkColor(m_draw->getDrawDC(), cr);
        return GiColor(GetRValue(cr), GetGValue(cr), GetBValue(cr));
    }
    return color;
}
Пример #17
0
bool MgCmdErase::draw(const MgMotion* sender, GiGraphics* gs)
{
    if (m_boxsel) {
        GiContext ctxshap(0, GiColor(0, 0, 255, 80), 
                          isIntersectMode(sender) ? GiContext::kDashLine : GiContext::kSolidLine,
                          GiColor(0, 0, 255, 24));
        gs->drawRect(&ctxshap, Box2d(sender->startPtM, sender->pointM));
    }
    
    GiContext ctx(-4, GiColor(64, 64, 64, 128));
    
    for (std::vector<int>::const_iterator it = m_delIds.begin(); it != m_delIds.end(); ++it) {
        const MgShape* shape = sender->view->shapes()->findShape(*it);
        if (shape) {
            shape->draw(1, *gs, &ctx, -1);
        }
    }
    
    return true;
}
Пример #18
0
bool MgShape::load(MgShapeFactory* factory, MgStorage* s)
{
    setTag(s->readInt("tag", getTag()));

    GiContext ctx;
    ctx.setLineStyle(s->readInt("lineStyle", 0));
    ctx.setLineWidth(s->readFloat("lineWidth", 0), true);
    ctx.setLineColor(GiColor(s->readInt("lineColor", 0xFF000000), true));
    ctx.setFillColor(GiColor(s->readInt("fillColor", 0), true));
    ctx.setStartArrayHead(s->readInt("startArrayHead", 0));
    ctx.setEndArrayHead(s->readInt("endArrayHead", 0));
    setContext(ctx);

    bool ret = shape()->load(factory, s);
    if (ret) {
        shape()->update();
    }

    return ret;
}
Пример #19
0
bool MgCmdErase::draw(const MgMotion* sender, GiGraphics* gs)
{
    if (m_boxsel) {
        GiContext ctxshap(0, GiColor(0, 0, 255, 80), 
                          isIntersectMode(sender) ? kGiLineDash : kGiLineSolid, GiColor(0, 0, 255, 24));
        
        bool antiAlias = gs->setAntiAliasMode(false);
        gs->drawRect(&ctxshap, Box2d(sender->startPointM, sender->pointM));
        gs->setAntiAliasMode(antiAlias);
    }
    
    GiContext ctx(-4, GiColor(64, 64, 64, 128));
    
    for (std::vector<int>::const_iterator it = m_delIds.begin(); it != m_delIds.end(); ++it) {
        MgShape* shape = sender->view->shapes()->findShape(*it);
        if (shape)
            shape->draw(1, *gs, &ctx);
    }
    
    return true;
}
Пример #20
0
bool MgArc::_draw(int mode, GiGraphics& gs, const GiContext& ctx, int segment) const
{
    bool ret = gs.drawArc(&ctx, getCenter(), getRadius(), 0, getStartAngle(), getSweepAngle());
    if (mode > 0) {
        GiContext ctxln(0, GiColor(0, 126, 0, 64), kGiLineDashDot);
        gs.drawLine(&ctxln, getCenter(), getStartPoint());
        gs.drawLine(&ctxln, getCenter(), getEndPoint());
        gs.drawLine(&ctxln, getStartPoint(), getStartPoint() + getStartTangent());
        gs.drawLine(&ctxln, getEndPoint(), getEndPoint() + getEndTangent());
    }
    return __super::_draw(mode, gs, ctx, segment) || ret;
}
Пример #21
0
void CRandomShapeView::OnDynDraw(GiGraphics* gs)
{
    if (m_selection)
    {
        GiContext context(-4, GiColor(0, 0, 255, 55));
        m_selection->draw(*gs, &context);

        context.setLineWidth(0);
        gs->drawEllipse(&context, Box2d(m_ptNear, 1, 1));
        gs->drawLine(&context, m_ptNear, m_ptSnap);
    }
    CBaseView::OnDynDraw(gs);
}
Пример #22
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;
}
Пример #23
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;
}
Пример #24
0
int GiCoreView::setBkColor(GiView* view, int argb)
{
    GcBaseView* aview = impl->_doc->findView(view);
    return aview ? aview->graph()->setBkColor(GiColor(argb)).getARGB() : 0;
}