📄 qregion_qws.cpp
字号:
/****************************************************************************** $Id: qt/src/3rdparty/kernel/qregion_qws.cpp 2.3.10 edited 2005-01-24 $**** Implementation of QRegion class for FB**** Created : 991026**** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.**** This file is part of the kernel module of the Qt GUI Toolkit.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition** licenses for Qt/Embedded may use this file in accordance with the** Qt Embedded Commercial License Agreement provided with the Software.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for** information about Qt Commercial License Agreements.** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "qregion.h"#include "qrect.h"#include "qpointarray.h"#include "qbuffer.h"#include "qimage.h"#include "qbitmap.h"#include <stdlib.h>// inline QRect::setCoordsinline void QRect::setCoords( int xp1, int yp1, int xp2, int yp2 ){ x1 = (QCOORD)xp1; y1 = (QCOORD)yp1; x2 = (QCOORD)xp2; y2 = (QCOORD)yp2;}typedef struct { short x, y; // #### we can use ints if useful} XPoint;typedef struct _XRegion *Region;#define Xmalloc malloc#define Xrealloc realloc#define Xfree freestatic int XUnionRegion(Region reg1, Region reg2, Region newReg);static int XIntersectRegion(Region reg1, Region reg2, register Region newReg);static void miRegionOp(register Region newReg, Region reg1, Region reg2, void (*overlapFunc)(...), void (*nonOverlap1Func)(...), void (*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#define TRUE 1#define FALSE 0#define MAXSHORT 32767#define MINSHORT -MAXSHORT#ifndef MAX#define MAX(a,b) (((a) > (b)) ? (a) : (b))#endif#ifndef MIN#define MIN(a,b) (((a) < (b)) ? (a) : (b))#endif/* * clip region */typedef struct _XRegion { int numRects; QArray<QRect> rects; QRect extents; _XRegion() { numRects = 0; } _XRegion( const QRect &r ) : rects(1) { numRects = 1; rects[0] = r; extents = r; } _XRegion( const _XRegion &r ) { rects = r.rects; numRects = r.numRects; extents = r.extents; } _XRegion &operator=( const _XRegion &r ) { rects = r.rects; numRects = r.numRects; extents = r.extents; return *this; }} REGION;/* Xutil.h contains the declaration: * typedef struct _XRegion *Region; *//* 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(reg, rect, firstrect){\ if ((reg)->numRects >= ((reg)->size - 1)){\ (firstrect) = (BOX *) Xrealloc \ ((char *)(firstrect), (unsigned) (2 * (sizeof(BOX)) * ((reg)->size)));\ if ((firstrect) == 0)\ return(0);\ (reg)->size *= 2;\ (rect) = &(firstrect)[(reg)->numRects];\ }\ }*/#define MEMCHECK(reg, rect, firstrect){\ if ((reg)->numRects >= (int)((reg)->rects.size()-1)){\ firstrect.resize(firstrect.size() * 2); \ (rect) = (firstrect).data() + (reg)->numRects;\ }\ }#if 0 // MRJ/* this routine checks to see if the previous rectangle is the same * or subsumes the new rectangle to add. */#define CHECK_PREVIOUS(Reg, R, Rx1, Ry1, Rx2, Ry2)\ (!(((Reg)->rects.numRects > 0)&&\ ((R-1)->top() == (Ry1)) &&\ ((R-1)->bottom() == (Ry2)) &&\ ((R-1)->left() <= (Rx1)) &&\ ((R-1)->right() >= (Rx2))))/* add a rectangle to the given Region */#define ADDRECT(reg, r, rx1, ry1, rx2, ry2){\ if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&\ CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\ (r)->x1 = (rx1);\ (r)->y1 = (ry1);\ (r)->x2 = (rx2);\ (r)->y2 = (ry2);\ EXTENTS((r), (reg));\ (reg)->numRects++;\ (r)++;\ }\ }/* add a rectangle to the given Region */#define ADDRECTNOX(reg, r, rx1, ry1, rx2, ry2){\ if ((rx1 < rx2) && (ry1 < ry2) &&\ CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\ (r)->x1 = (rx1);\ (r)->y1 = (ry1);\ (r)->x2 = (rx2);\ (r)->y2 = (ry2);\ (reg)->numRects++;\ (r)++;\ }\ }#endif //MRJ#define EMPTY_REGION(pReg) pReg->numRects = 0#define REGION_NOT_EMPTY(pReg) pReg->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 { XPoint 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 $ *//* WWA#include "Xlibint.h"#include "Xutil.h"#include "region.h"#include "poly.h"*/#ifdef DEBUG#include <stdio.h>#define assert(expr) {if (!(expr)) fprintf(stderr,\"Assertion failed file %s, line %d: expr\n", __FILE__, __LINE__); }#else#define assert(expr)#endiftypedef void (*voidProcp)(...);/* Create a new empty region */static inline Region XCreateRegion(){ return (new REGION);}staticintXUnionRectWithRegion(register QRect *rect, Region source, Region dest){ REGION region; if (!rect->width() || !rect->height()) return 0; region.rects.resize(1); region.numRects = 1; region.rects[0] = *rect; region.extents = *rect; return XUnionRegion(®ion, source, dest);}/*- *----------------------------------------------------------------------- * 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 voidmiSetExtents (Region pReg){ register QRect *pBox, *pBoxEnd, *pExtents; if (pReg->numRects == 0) { pReg->extents.setCoords(0, 0, 0, 0); return; } pExtents = &pReg->extents; pBox = pReg->rects.data(); pBoxEnd = &pBox[pReg->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() );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -