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

📄 qregion_unix.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://www.trolltech.com/products/qt/opensource.html**** If you are unsure which license is appropriate for your use, please** review the following information:** http://www.trolltech.com/products/qt/licensing.html or contact the** sales department at sales@trolltech.com.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qregion.h"#include "qpainterpath.h"#include "qpolygon.h"#include "qbuffer.h"#include "qimage.h"#include "qbitmap.h"#include <stdlib.h>/* *   clip region */struct QRegionPrivate {    int numRects;    QVector<QRect> rects;    QRect extents;    inline QRegionPrivate() : numRects(0) {}    inline QRegionPrivate(const QRect &r) : rects(1) {        numRects = 1;        rects[0] = r;        extents = r;    }    inline QRegionPrivate(const QRegionPrivate &r) {        rects = r.rects;        numRects = r.numRects;        extents = r.extents;    }    inline QRegionPrivate &operator=(const QRegionPrivate &r) {        rects = r.rects;        numRects = r.numRects;        extents = r.extents;        return *this;    }};#if defined(Q_WS_X11)# include "qregion_x11.cpp"#elif defined(Q_WS_MAC)# include "qregion_mac.cpp"#elif defined(Q_WS_QWS)static QRegionPrivate qrp;QRegion::QRegionData QRegion::shared_empty = {Q_ATOMIC_INIT(1), &qrp};#endifstatic inline bool isEmpty(const QRegionPrivate *preg){    return !preg || preg->numRects == 0;}typedef void (*OverlapFunc)(register QRegionPrivate &dest, register const QRect *r1, const QRect *r1End,                            register const QRect *r2, const QRect *r2End, register int y1, register int y2);typedef void (*NonOverlapFunc)(register QRegionPrivate &dest, register const QRect *r, const QRect *rEnd,                               register int y1, register int y2);static void UnionRegion(const QRegionPrivate *reg1, const QRegionPrivate *reg2, QRegionPrivate &dest);static void miRegionOp(register QRegionPrivate &dest, const QRegionPrivate *reg1, const QRegionPrivate *reg2,                       OverlapFunc overlapFunc, NonOverlapFunc nonOverlap1Func,                       NonOverlapFunc nonOverlap2Func);#define RectangleOut 0#define RectangleIn 1#define RectanglePart 2#define EvenOddRule 0#define WindingRule 1// START OF region.h extract/* $XConsortium: region.h,v 11.14 94/04/17 20:22:20 rws Exp $ *//************************************************************************Copyright (c) 1987  X ConsortiumPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THEX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER INAN 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 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.************************************************************************/#ifndef _XREGION_H#define _XREGION_H#include <limits.h>/*  1 if two BOXs overlap. *  0 if two BOXs do not overlap. *  Remember, x2 and y2 are not in the region */#define EXTENTCHECK(r1, r2) \        ((r1)->right() >= (r2)->left() && \         (r1)->left() <= (r2)->right() && \         (r1)->bottom() >= (r2)->top() && \         (r1)->top() <= (r2)->bottom())/* *  update region extents */#define EXTENTS(r,idRect){\            if((r)->left() < (idRect)->extents.left())\              (idRect)->extents.setLeft((r)->left());\            if((r)->top() < (idRect)->extents.top())\              (idRect)->extents.setTop((r)->top());\            if((r)->right() > (idRect)->extents.right())\              (idRect)->extents.setRight((r)->right());\            if((r)->bottom() > (idRect)->extents.bottom())\              (idRect)->extents.setBottom((r)->bottom());\        }/* *   Check to see if there is enough memory in the present region. */#define MEMCHECK(dest, rect, firstrect){\        if ((dest).numRects >= ((dest).rects.size()-1)){\          firstrect.resize(firstrect.size() * 2); \          (rect) = (firstrect).data() + (dest).numRects;\        }\      }/* * number of points to buffer before sending them off * to scanlines(): Must be an even number */#define NUMPTSTOBUFFER 200/* * used to allocate buffers for points and link * the buffers together */typedef struct _POINTBLOCK {    QPoint pts[NUMPTSTOBUFFER];    struct _POINTBLOCK *next;} POINTBLOCK;#endif// END OF region.h extract// START OF Region.c extract/* $XConsortium: Region.c /main/30 1996/10/22 14:21:24 kaleb $ *//************************************************************************Copyright (c) 1987, 1988  X ConsortiumPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THEX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER INAN 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;    region.rects.resize(1);    region.numRects = 1;    region.rects[0] = *rect;    region.extents = *rect;    UnionRegion(&region, source, dest);    return;}/*- *----------------------------------------------------------------------- * miSetExtents -- *      Reset the extents 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' structure is overwritten. * *----------------------------------------------------------------------- */static void miSetExtents(QRegionPrivate &dest){    register const QRect *pBox,                         *pBoxEnd;    register QRect *pExtents;    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());        ++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 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)

⌨️ 快捷键说明

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