当前位置: 首页>>代码示例>>C++>>正文


C++ Box2d函数代码示例

本文整理汇总了C++中Box2d函数的典型用法代码示例。如果您正苦于以下问题:C++ Box2d函数的具体用法?C++ Box2d怎么用?C++ Box2d使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Box2d函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: fabsf

bool GiGraphics::beginPaint(GiCanvas* canvas, const RECT_2D& clipBox)
{
    if (!canvas || m_impl->canvas || isStopping()) {
        return false;
    }
    
    m_impl->canvas = canvas;
    m_impl->ctxused = 0;
    m_impl->stopping = 0;
    
    float phase = fabsf(m_impl->phase);
    m_impl->phase = (phase < 1e4f ? phase + 0.5f : 0.5f) * (m_impl->phase > 0 ? 1.f : -1.f);
    
    if (m_impl->lastZoomTimes != xf().getZoomTimes()) {
        m_impl->zoomChanged();
        m_impl->lastZoomTimes = xf().getZoomTimes();
    }
    
    m_impl->clipBox0 = clipBox;
    if (Box2d(clipBox).isEmpty()) {
        xf().getWndRect().get(m_impl->clipBox0);
    }
    m_impl->clipBox  = m_impl->clipBox0;
    m_impl->rectDraw = m_impl->clipBox0;
    m_impl->rectDraw.inflate(GiGraphicsImpl::CLIP_INFLATE);
    m_impl->rectDrawM = Box2d(m_impl->rectDraw) * xf().displayToModel();
    m_impl->rectDrawMaxM = xf().getWndRectM();
    m_impl->rectDrawW = m_impl->rectDrawM * xf().modelToWorld();
    m_impl->rectDrawMaxW = m_impl->rectDrawMaxM * xf().modelToWorld();
    
    return true;
}
开发者ID:Vito2015,项目名称:vgcore,代码行数:32,代码来源:gigraph.cpp

示例2: box

bool GiGraphics::setClipWorld(const Box2d& rectWorld)
{
    bool ret = false;

    if (isDrawing() && !rectWorld.isEmpty())
    {
        Box2d box (rectWorld * xf().worldToDisplay());

        box.intersectWith(Box2d(m_impl->clipBox0));
        if (!box.isEmpty(Tol(1, 0)))
        {
            if (box != Box2d(m_impl->clipBox))
            {
                box.get(m_impl->clipBox);
                m_impl->rectDraw = box;
                m_impl->rectDraw.inflate(GiGraphicsImpl::CLIP_INFLATE);
                m_impl->rectDrawM = m_impl->rectDraw * xf().displayToModel();
                m_impl->rectDrawW = m_impl->rectDrawM * xf().modelToWorld();
                SafeCall(m_impl->canvas, _clipBoxChanged(m_impl->clipBox));
            }

            ret = true;
        }
    }

    return ret;
}
开发者ID:acekiller,项目名称:touchvg,代码行数:27,代码来源:gigraph.cpp

示例3: setClipBox

bool GiGraphics::setClipBox(const RECT_2D& rc)
{
    if (m_impl->drawRefcnt < 1)
        return false;

    bool ret = false;
    Box2d rect;

    if (!rect.intersectWith(Box2d(rc), Box2d(m_impl->clipBox0)).isEmpty())
    {
        if (rect != Box2d(m_impl->clipBox))
        {
            rect.get(m_impl->clipBox);
            m_impl->rectDraw.set(Box2d(rc));
            m_impl->rectDraw.inflate(GiGraphicsImpl::CLIP_INFLATE);
            m_impl->rectDrawM = m_impl->rectDraw * xf().displayToModel();
            m_impl->rectDrawW = m_impl->rectDrawM * xf().modelToWorld();
            SafeCall(m_impl->canvas, clipRect(m_impl->clipBox.left, m_impl->clipBox.top,
                                              m_impl->clipBox.width(),
                                              m_impl->clipBox.height()));
        }
        ret = true;
    }

    return ret;
}
开发者ID:gkrists,项目名称:TouchVG,代码行数:26,代码来源:gigraph.cpp

示例4: giInterlockedIncrement

bool GiGraphics::beginPaint(GiCanvas* canvas, const RECT_2D& clipBox)
{
    if (!canvas || m_impl->canvas || m_impl->drawRefcnt > 0) {
        return false;
    }
    
    m_impl->canvas = canvas;
    m_impl->ctxused = 0;
    m_impl->stopping = 0;
    giInterlockedIncrement(&m_impl->drawRefcnt);
    
    if (m_impl->lastZoomTimes != xf().getZoomTimes()) {
        m_impl->zoomChanged();
        m_impl->lastZoomTimes = xf().getZoomTimes();
    }
    
    m_impl->clipBox0 = clipBox;
    if (Box2d(clipBox).isEmpty()) {
        (xf().getWndRectW() * xf().worldToDisplay()).get(m_impl->clipBox0);
    }
    m_impl->clipBox  = m_impl->clipBox0;
    m_impl->rectDraw = m_impl->clipBox0;
    m_impl->rectDraw.inflate(GiGraphicsImpl::CLIP_INFLATE);
    m_impl->rectDrawM = Box2d(m_impl->rectDraw) * xf().displayToModel();
    m_impl->rectDrawMaxM = xf().getWndRectM();
    m_impl->rectDrawW = m_impl->rectDrawM * xf().modelToWorld();
    m_impl->rectDrawMaxW = m_impl->rectDrawMaxM * xf().modelToWorld();
    
    return true;
}
开发者ID:gkrists,项目名称:TouchVG,代码行数:30,代码来源:gigraph.cpp

示例5: xf

bool GiCanvasGdi::drawImage(long hmWidth, long hmHeight, HBITMAP hbitmap, 
                            const Box2d& rectW, bool fast)
{
    BOOL ret = FALSE;
    HDC hdc = m_draw->getDrawDC();

    if (hdc != NULL && hmWidth > 0 && hmHeight > 0 && hbitmap != NULL
        && m_owner->getClipWorld().isIntersect(Box2d(rectW, true)))
    {
        RECT_2D clipBox;
        RECT rc, rcDraw, rcFrom;

        // rc: 整个图像对应的显示坐标区域
        (rectW * xf().worldToDisplay()).get(rc);

        // rcDraw: 图像经剪裁后的可显示部分
        Box2d(gs()->getClipBox(clipBox)).get(rcFrom);
        if (!IntersectRect(&rcDraw, &rc, &rcFrom))
            return false;

        long width, height;       // pixel units
        width = MulDiv(hmWidth, GetDeviceCaps(hdc, LOGPIXELSX), 2540);
        height = MulDiv(hmHeight, GetDeviceCaps(hdc, LOGPIXELSY), 2540);

        // rcFrom: rcDraw在原始图像上对应的图像范围
        rcFrom.left = MulDiv(rcDraw.left - rc.left, width, rc.right - rc.left);
        rcFrom.top = MulDiv(rcDraw.top - rc.top, height, rc.bottom - rc.top);
        rcFrom.right = MulDiv(rcDraw.right - rc.left, width, rc.right - rc.left);
        rcFrom.bottom = MulDiv(rcDraw.bottom - rc.top, height, rc.bottom - rc.top);

        // 根据rectW正负决定是否颠倒显示图像
        if (rectW.xmin > rectW.xmax)
            mgSwap(rcDraw.left, rcDraw.right);
        if (rectW.ymin > rectW.ymax)
            mgSwap(rcDraw.top, rcDraw.bottom);

        GiCompatibleDC memDC (hdc);
        if (memDC == NULL)
            return false;
        KGDIObject bmp (memDC, hbitmap, false);
        KGDIObject brush (hdc, ::GetStockObject(NULL_BRUSH), false);

        int nBltMode = (!fast || m_owner->isPrint()) ? HALFTONE : COLORONCOLOR;
        int nOldMode = ::SetStretchBltMode(hdc, nBltMode);
        ::SetBrushOrgEx(hdc, rcDraw.left % 8, rcDraw.top % 8, NULL);
        ret = ::StretchBlt(hdc, 
            rcDraw.left, rcDraw.top, 
            rcDraw.right - rcDraw.left, 
            rcDraw.bottom - rcDraw.top, 
            memDC, 
            rcFrom.left, rcFrom.top, 
            rcFrom.right - rcFrom.left, 
            rcFrom.bottom - rcFrom.top, 
            SRCCOPY);
        ::SetStretchBltMode(hdc, nOldMode);
    }

    return ret ? true : false;
}
开发者ID:huangzongwu,项目名称:touchvg,代码行数:59,代码来源:canvasgdi.cpp

示例6: matD

bool GiGraphics::drawBeziers(const GiContext* ctx, int count, 
                             const Point2d* points, bool closed, bool modelUnit)
{
    if (count < 4 || !points || isStopping())
        return false;
    if (count > 0x2000)
        count = 0x2000;
    count = 1 + (count - 1) / 3 * 3;

    bool ret = false;
    vector<Point2d> pxpoints;
    vector<Point2d> pointBuf;
    int i, j, n, si, ei;
    Point2d * pxs;
    Matrix2d matD(S2D(xf(), modelUnit));

    const Box2d extent (count, points);                 // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;
    
    if (closed) {
        pxpoints.resize(count);
        pxs = &pxpoints.front();
        for (i = 0; i < count; i++)
            pxs[i] = points[i] * matD;
        ret = rawBeziers(ctx, pxs, count, closed);
    }
    else if (DRAW_MAXR(m_impl, modelUnit).contains(extent)) {   // 全部在显示区域内
        pxpoints.resize(count);
        pxs = &pxpoints.front();
        for (i = 0; i < count; i++)
            pxs[i] = points[i] * matD;
        ret = rawBeziers(ctx, pxs, count);
    } else {
        pointBuf.resize(count);
        for (i = 0; i < count; i++)                 // 转换到像素坐标
            pointBuf[i] = points[i] * matD;
        Point2d* pts = &pointBuf.front();

        for (i = 0; i + 3 < count;) {
            for (; i + 3 < count && !m_impl->rectDraw.isIntersect(Box2d(4, &pts[i])); i += 3) ;
            si = ei = i;
            for (; i + 3 < count && m_impl->rectDraw.isIntersect(Box2d(4, &pts[i])); i += 3)
                ei = i + 3;
            if (ei > si) {
                n = ei - si + 1;
                pxpoints.resize(n);
                pxs = &pxpoints.front();
                for (j=0; j<n; j++)
                    pxs[j] = pts[si + j];
                ret = rawBeziers(ctx, pxs, n);
            }
        }
    }
    return ret;
}
开发者ID:Vito2015,项目名称:vgcore,代码行数:56,代码来源:gigraph.cpp

示例7: pt1

float MgEllipse::_hitTest(const Point2d& pt, float tol, MgHitResult& res) const
{
    if (isCircle()) {
        Point2d pt1(getCenter()), pt2(pt);
        crossCircle(pt1, pt2, this);
        float d1 = pt.distanceTo(pt1);
        float d2 = pt.distanceTo(pt2);
        res.nearpt = d1 < d2 ? pt1 : pt2;
        return mgMin(d1, d2);
    }
    
    float distMin = _FLT_MAX;
    const Box2d rect (pt, 2 * tol, 2 * tol);
    Point2d ptTemp;

    for (int i = 0; i < 4; i++) {
        if (rect.isIntersect(Box2d(4, _bzpts + 3 * i))) {
            mgnear::nearestOnBezier(pt, _bzpts + 3 * i, ptTemp);
            float dist = pt.distanceTo(ptTemp);
            if (dist <= tol && dist < distMin) {
                distMin = dist;
                res.nearpt = ptTemp;
                res.segment = i;
            }
        }
    }

    return distMin;
}
开发者ID:Vito2015,项目名称:vgcore,代码行数:29,代码来源:mgellipse.cpp

示例8: size

MgShape* MgCmdManagerImpl::addImageShape(const MgMotion* sender,
        const char* name, float width, float height)
{
    if (!name || *name == 0 || width < 1 || height < 1)
        return NULL;

    Vector2d size(Vector2d(width, height) * sender->view->xform()->displayToWorld());
    while (fabsf(size.x) > 200.f || fabsf(size.y) > 200.f) {
        size *= 0.95f;
    }
    Box2d rect(sender->view->xform()->getWndRectW() + Vector2d(10.f, -10.f));
    rect = Box2d(rect.leftTop(), rect.leftTop() + size);
    rect *= sender->view->xform()->worldToModel();

    MgShapeT<MgImageShape> shape;
    MgImageShape* imagesp = (MgImageShape*)shape.shape();

    shape.context()->setLineStyle(kGiLineNull);         // 默认没有边框
    shape.context()->setFillColor(GiColor::White());    // 设为实填充,避免在中心无法点中
    imagesp->setName(name);
    imagesp->setRect2P(rect.leftTop(), rect.rightBottom());

    MgShapesLock locker(MgShapesLock::Add, sender->view);
    if (sender->view->shapeWillAdded(&shape)) {
        MgShape* newsp = sender->view->shapes()->addShape(shape);
        sender->view->shapeAdded(newsp);

        sender->view->setNewShapeID(newsp->getID());
        sender->view->cancel(sender);

        return newsp;
    }

    return NULL;
}
开发者ID:rhcad,项目名称:touchvg-v0.6,代码行数:35,代码来源:mgcmdmgr2.cpp

示例9: rect

float MgEllipse::_hitTest(const Point2d& pt, float tol, 
                          Point2d& nearpt, int& segment) const
{
    float distMin = _FLT_MAX;
    const Box2d rect (pt, 2 * tol, 2 * tol);
    Point2d ptTemp;

    segment = -1;
    for (int i = 0; i < 4; i++)
    {
        if (rect.isIntersect(Box2d(4, _bzpts + 3 * i)))
        {
            mgNearestOnBezier(pt, _bzpts + 3 * i, ptTemp);
            float dist = pt.distanceTo(ptTemp);
            if (dist <= tol && dist < distMin)
            {
                distMin = dist;
                nearpt = ptTemp;
                segment = i;
            }
        }
    }

    return distMin;
}
开发者ID:firehot,项目名称:touchvg,代码行数:25,代码来源:mgellipse.cpp

示例10: Box2d

Box2d GiTransform::setWorldLimits(const Box2d& rect)
{
    Box2d ret = m_impl->rectLimitsW;
    m_impl->rectLimitsW = rect.isEmpty() ? Box2d(Point2d::kOrigin(), 2e5f, 2e5f) : rect;
    m_impl->rectLimitsW.normalize();
    return ret;
}
开发者ID:wangzhengnan,项目名称:vgcore,代码行数:7,代码来源:gixform.cpp

示例11: Box2d

 inline
 Box2d
 Circle2d::bounds() const {
     return Box2d(
         Interval(centerPoint().x() - radius(), centerPoint().x() + radius()),
         Interval(centerPoint().y() - radius(), centerPoint().y() + radius())
     );
 }
开发者ID:ianmackenzie,项目名称:cpp-opensolid-core,代码行数:8,代码来源:Circle.hpp

示例12: rect

bool GiCoreView::zoomToModel(float x, float y, float w, float h)
{
    Box2d rect(Box2d(x, y, x + w, y + h) * impl->xform()->modelToWorld());
    bool ret = impl->xform()->zoomTo(rect);
    if (ret) {
        impl->regenAll();
    }
    return ret;
}
开发者ID:arthur-zhang,项目名称:touchvg,代码行数:9,代码来源:gicoreview.cpp

示例13: fabs

void MgEllipse::setRadius(float rx, float ry)
{
    rx = fabs(rx);
    rx = fabs(ry);
    if (rx < _MGZERO)
        rx = rx;

    setRect(Box2d(getCenter(), rx * 2, ry * 2), getAngle());
}
开发者ID:acekiller,项目名称:touchvg,代码行数:9,代码来源:mgellipse.cpp

示例14: drawHandle

 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;
 }
开发者ID:thinkfeed,项目名称:touchvg,代码行数:9,代码来源:Step3View.cpp

示例15: gs

bool GiCanvasGdipImpl::drawImage(G::Bitmap* pBmp, const Box2d& rectW, bool fast)
{
    RECT_2D rc, rcDraw, rcFrom;
    Box2d rect;
    float width = (float)pBmp->GetWidth();
    float height = (float)pBmp->GetHeight();

    // rc: 整个图像对应的显示坐标区域
    (rectW * gs()->xf().worldToDisplay()).get(rc);

    // rcDraw: 图像经剪裁后的可显示部分
    gs()->getClipBox(rcDraw);
    if (rect.intersectWith(Box2d(rc), Box2d(rcDraw)).isEmpty())
        return false;
    rect.get(rcDraw);

    // rcFrom: rcDraw在原始图像上对应的图像范围
    rcFrom.left = (rcDraw.left - rc.left) * width / (rc.right - rc.left);
    rcFrom.top  = (rcDraw.top - rc.top) * height / (rc.bottom - rc.top);
    rcFrom.right = (rcDraw.right - rc.left) * width / (rc.right - rc.left);
    rcFrom.bottom = (rcDraw.bottom - rc.top) * height / (rc.bottom - rc.top);

    // 根据rectW正负决定是否颠倒显示图像
    if (rectW.xmin > rectW.xmax)
        mgSwap(rcDraw.left, rcDraw.right);
    if (rectW.ymin > rectW.ymax)
        mgSwap(rcDraw.top, rcDraw.bottom);

    G::InterpolationMode nOldMode = getDrawGs()->GetInterpolationMode();
    getDrawGs()->SetInterpolationMode( (!fast || gs()->isPrint())
        ? G::InterpolationModeBilinear : G::InterpolationModeLowQuality);

    G::Status ret = getDrawGs()->DrawImage(pBmp, 
        G::RectF(rcDraw.left, rcDraw.top, 
        rcDraw.right - rcDraw.left, 
        rcDraw.bottom - rcDraw.top), 
        rcFrom.left, rcFrom.top, 
        rcFrom.right - rcFrom.left, 
        rcFrom.bottom - rcFrom.top, 
        G::UnitPixel);
    getDrawGs()->SetInterpolationMode(nOldMode);

    return G::Ok == ret;
}
开发者ID:fanliugen,项目名称:touchvg,代码行数:44,代码来源:canvasgdip.cpp


注:本文中的Box2d函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。