⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qregion_unix.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shall not beused in advertising or otherwise to promote the sale, use or other dealingsin this Software without prior written authorization from the X Consortium.Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.                        All Rights ReservedPermission to use, copy, modify, and distribute this software and itsdocumentation for any purpose and without fee is hereby granted,provided that the above copyright notice appear in all copies and thatboth that copyright notice and this permission notice appear insupporting documentation, and that the name of Digital not beused in advertising or publicity pertaining to distribution of thesoftware without specific, written prior permission.DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDINGALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALLDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ORANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THISSOFTWARE.************************************************************************//* * The functions in this file implement the Region abstraction, similar to one * used in the X11 sample server. A Region is simply an area, as the name * implies, and is implemented as a "y-x-banded" array of rectangles. To * explain: Each Region is made up of a certain number of rectangles sorted * by y coordinate first, and then by x coordinate. * * Furthermore, the rectangles are banded such that every rectangle with a * given upper-left y coordinate (y1) will have the same lower-right y * coordinate (y2) and vice versa. If a rectangle has scanlines in a band, it * will span the entire vertical distance of the band. This means that some * areas that could be merged into a taller rectangle will be represented as * several shorter rectangles to account for shorter rectangles to its left * or right but within its "vertical scope". * * An added constraint on the rectangles is that they must cover as much * horizontal area as possible. E.g. no two rectangles in a band are allowed * to touch. * * Whenever possible, bands will be merged together to cover a greater vertical * distance (and thus reduce the number of rectangles). Two bands can be merged * only if the bottom of one touches the top of the other and they have * rectangles in the same places (of the same width, of course). This maintains * the y-x-banding that's so nice to have... *//* $XFree86: xc/lib/X11/Region.c,v 1.1.1.2.2.2 1998/10/04 15:22:50 hohndel Exp $ */static void UnionRectWithRegion(register const QRect *rect, const QRegionPrivate *source,                                QRegionPrivate &dest){    if (!rect->width() || !rect->height())        return;    QRegionPrivate region(*rect);    Q_ASSERT(EqualRegion(source, &dest));    Q_ASSERT(!isEmpty(&region));    if (dest.numRects == 0)        dest = region;    else if (dest.canAppend(&region))        dest.append(&region);    else        UnionRegion(&region, source, dest);}/*- *----------------------------------------------------------------------- * miSetExtents -- *      Reset the extents and innerRect of a region to what they should be. *      Called by miSubtract and miIntersect b/c they can't figure it out *      along the way or do so easily, as miUnion can. * * Results: *      None. * * Side Effects: *      The region's 'extents' and 'innerRect' structure is overwritten. * *----------------------------------------------------------------------- */static void miSetExtents(QRegionPrivate &dest){    register const QRect *pBox,                         *pBoxEnd;    register QRect *pExtents;    dest.innerRect.setCoords(0, 0, -1, -1);    dest.innerArea = -1;    if (dest.numRects == 0) {        dest.extents.setCoords(0, 0, 0, 0);        return;    }    pExtents = &dest.extents;    pBox = dest.rects.constData();    pBoxEnd = &pBox[dest.numRects - 1];    /*     * Since pBox is the first rectangle in the region, it must have the     * smallest y1 and since pBoxEnd is the last rectangle in the region,     * it must have the largest y2, because of banding. Initialize x1 and     * x2 from  pBox and pBoxEnd, resp., as good things to initialize them     * to...     */    pExtents->setLeft(pBox->left());    pExtents->setTop(pBox->top());    pExtents->setRight(pBoxEnd->right());    pExtents->setBottom(pBoxEnd->bottom());    Q_ASSERT(pExtents->top() <= pExtents->bottom());    while (pBox <= pBoxEnd) {        if (pBox->left() < pExtents->left())            pExtents->setLeft(pBox->left());        if (pBox->right() > pExtents->right())            pExtents->setRight(pBox->right());        dest.updateInnerRect(*pBox);        ++pBox;    }    Q_ASSERT(pExtents->left() <= pExtents->right());}/* TranslateRegion(pRegion, x, y)   translates in place   added by raymond*/static void OffsetRegion(register QRegionPrivate &region, register int x, register int y){    register int nbox;    register QRect *pbox;    pbox = region.rects.data();    nbox = region.numRects;    while (nbox--) {        pbox->translate(x, y);        ++pbox;    }    region.extents.translate(x, y);    region.innerRect.translate(x, y);}/*====================================================================== *          Region Intersection *====================================================================*//*- *----------------------------------------------------------------------- * miIntersectO -- *      Handle an overlapping band for miIntersect. * * Results: *      None. * * Side Effects: *      Rectangles may be added to the region. * *----------------------------------------------------------------------- */static void miIntersectO(register QRegionPrivate &dest, register const QRect *r1, const QRect *r1End,                         register const QRect *r2, const QRect *r2End, int y1, int y2){    register int x1;    register int x2;    register QRect *pNextRect;    pNextRect = dest.rects.data() + dest.numRects;    while (r1 != r1End && r2 != r2End) {        x1 = qMax(r1->left(), r2->left());        x2 = qMin(r1->right(), r2->right());        /*         * If there's any overlap between the two rectangles, add that         * overlap to the new region.         * There's no need to check for subsumption because the only way         * such a need could arise is if some region has two rectangles         * right next to each other. Since that should never happen...         */        if (x1 <= x2) {            Q_ASSERT(y1 <= y2);            MEMCHECK(dest, pNextRect, dest.rects)            pNextRect->setCoords(x1, y1, x2, y2);            ++dest.numRects;            ++pNextRect;        }        /*         * Need to advance the pointers. Shift the one that extends         * to the right the least, since the other still has a chance to         * overlap with that region's next rectangle, if you see what I mean.         */        if (r1->right() < r2->right()) {            ++r1;        } else if (r2->right() < r1->right()) {            ++r2;        } else {            ++r1;            ++r2;        }    }}/*====================================================================== *          Generic Region Operator *====================================================================*//*- *----------------------------------------------------------------------- * miCoalesce -- *      Attempt to merge the boxes in the current band with those in the *      previous one. Used only by miRegionOp. * * Results: *      The new index for the previous band. * * Side Effects: *      If coalescing takes place: *          - rectangles in the previous band will have their y2 fields *            altered. *          - dest.numRects will be decreased. * *----------------------------------------------------------------------- */static int miCoalesce(register QRegionPrivate &dest, int prevStart, int curStart){    register QRect *pPrevBox;   /* Current box in previous band */    register QRect *pCurBox;    /* Current box in current band */    register QRect *pRegEnd;    /* End of region */    int curNumRects;    /* Number of rectangles in current band */    int prevNumRects;   /* Number of rectangles in previous band */    int bandY1;         /* Y1 coordinate for current band */    QRect *rData = dest.rects.data();    pRegEnd = rData + dest.numRects;    pPrevBox = rData + prevStart;    prevNumRects = curStart - prevStart;    /*     * Figure out how many rectangles are in the current band. Have to do     * this because multiple bands could have been added in miRegionOp     * at the end when one region has been exhausted.     */    pCurBox = rData + curStart;    bandY1 = pCurBox->top();    for (curNumRects = 0; pCurBox != pRegEnd && pCurBox->top() == bandY1; ++curNumRects) {        ++pCurBox;    }    if (pCurBox != pRegEnd) {        /*         * If more than one band was added, we have to find the start         * of the last band added so the next coalescing job can start         * at the right place... (given when multiple bands are added,         * this may be pointless -- see above).         */        --pRegEnd;        while ((pRegEnd - 1)->top() == pRegEnd->top())            --pRegEnd;        curStart = pRegEnd - rData;        pRegEnd = rData + dest.numRects;    }    if (curNumRects == prevNumRects && curNumRects != 0) {        pCurBox -= curNumRects;        /*         * The bands may only be coalesced if the bottom of the previous         * matches the top scanline of the current.         */        if (pPrevBox->bottom() == pCurBox->top() - 1) {            /*             * Make sure the bands have boxes in the same places. This             * assumes that boxes have been added in such a way that they             * cover the most area possible. I.e. two boxes in a band must             * have some horizontal space between them.             */            do {                if (pPrevBox->left() != pCurBox->left() || pPrevBox->right() != pCurBox->right()) {                     // The bands don't line up so they can't be coalesced.                    return curStart;                }                ++pPrevBox;                ++pCurBox;                --prevNumRects;            } while (prevNumRects != 0);            dest.numRects -= curNumRects;            pCurBox -= curNumRects;            pPrevBox -= curNumRects;            /*             * The bands may be merged, so set the bottom y of each box             * in the previous band to that of the corresponding box in             * the current band.             */            do {                pPrevBox->setBottom(pCurBox->bottom());                dest.updateInnerRect(*pPrevBox);                ++pPrevBox;                ++pCurBox;                curNumRects -= 1;            } while (curNumRects != 0);            /*             * If only one band was added to the region, we have to backup             * curStart to the start of the previous band.             *             * If more than one band was added to the region, copy the             * other bands down. The assumption here is that the other bands             * came from the same region as the current one and no further             * coalescing can be done on them since it's all been done             * already... curStart is already in the right place.             */            if (pCurBox == pRegEnd) {                curStart = prevStart;            } else {                do {                    *pPrevBox++ = *pCurBox++;                    dest.updateInnerRect(*pPrevBox);                } while (pCurBox != pRegEnd);            }        }    }    return curStart;}/*- *----------------------------------------------------------------------- * miRegionOp -- *      Apply an operation to two regions. Called by miUnion, miInverse, *      miSubtract, miIntersect... * * Results: *      None. * * Side Effects: *      The new region is overwritten. * * Notes: *      The idea behind this function is to view the two regions as sets. *      Together they cover a rectangle of area that this function divides *      into horizontal bands where points are covered only by one region *      or by both. For the first case, the nonOverlapFunc is called with *      each the band and the band's upper and lower extents. For the *      second, the overlapFunc is called to process the entire band. It *      is responsible for clipping the rectangles in the band, though *      this function provides the boundaries. *      At the end of each band, the new region is coalesced, if possible, *      to reduce the number of rectangles in the region. * *----------------------------------------------------------------------- */static void miRegionOp(register QRegionPrivate &dest, const QRegionPrivate *reg1, const QRegionPrivate *reg2,                       OverlapFunc overlapFunc, NonOverlapFunc nonOverlap1Func,                       NonOverlapFunc nonOverlap2Func){    register const QRect *r1;         // Pointer into first region    register const QRect *r2;         // Pointer into 2d region    const QRect *r1End;               // End of 1st region    const QRect *r2End;               // End of 2d region    register int ybot;          // Bottom of intersection    register int ytop;          // Top of intersection    int prevBand;               // Index of start of previous band in dest    int curBand;                // Index of start of current band in dest    register const QRect *r1BandEnd;  // End of current band in r1    register const QRect *r2BandEnd;  // End of current band in r2

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -