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

📄 devrgn.c

📁 神龙卡开发原代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Portions Copyright (c) 1999, 2000 Greg Haerr <greg@censoft.com> *	Somewhat less shamelessly ripped from the Wine distribution * * Device-independent multi-rectangle clipping routines. * * GDI region objects. Shamelessly ripped out from the X11 distribution * Thanks for the nice licence. * * Copyright 1993, 1994, 1995 Alexandre Julliard * Modifications and additions: Copyright 1998 Huw Davies *//************************************************************************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 its documentation 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 in supporting 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... */#include <stdio.h>#include <stdlib.h>#include <string.h>#include "device.h"typedef void (*voidProcp)();/*  1 if two RECTs overlap. *  0 if two RECTs do not overlap. */#define EXTENTCHECK(r1, r2) \	((r1)->right > (r2)->left && \	 (r1)->left < (r2)->right && \	 (r1)->bottom > (r2)->top && \	 (r1)->top < (r2)->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) = realloc(\           (firstrect), (2 * (sizeof(MWRECT)) * ((reg)->size)));\          if ((firstrect) == 0)\            return;\          (reg)->size *= 2;\          (rect) = &(firstrect)[(reg)->numRects];\         }\       }#define REGION_NOT_EMPTY(pReg) pReg->numRects#define EMPTY_REGION(pReg) { \    (pReg)->numRects = 0; \    (pReg)->extents.left = (pReg)->extents.top = 0; \    (pReg)->extents.right = (pReg)->extents.bottom = 0; \    (pReg)->type = MWREGION_NULL; \ }#define INRECT(r, x, y) \      ( ( ((r).right >  x)) && \        ( ((r).left <= x)) && \        ( ((r).bottom >  y)) && \        ( ((r).top <= y)) )/* return TRUE if point is in region*/MWBOOLGdPtInRegion(MWCLIPREGION *rgn, MWCOORD x, MWCOORD y){    int i;    if (rgn->numRects > 0 && INRECT(rgn->extents, x, y))	for (i = 0; i < rgn->numRects; i++)	    if (INRECT (rgn->rects[i], x, y))		return TRUE;    return FALSE;}/* return whether rectangle is all in, partly in, or out of region*/int GdRectInRegion(MWCLIPREGION *rgn, const MWRECT *rect){    MWRECT *	pCurRect;    MWRECT *	pRectEnd;    MWCOORD	rx, ry;    MWBOOL	partIn, partOut;    /* this is (just) a useful optimization */    if (!rgn->numRects || !EXTENTCHECK(&rgn->extents, rect))        return MWRECT_OUT;    partOut = FALSE;    partIn = FALSE;    rx = rect->left;    ry = rect->top;    /*      * can stop when both partOut and partIn are TRUE,     * or we reach rect->bottom     */    for (pCurRect = rgn->rects, pRectEnd = pCurRect + rgn->numRects;		 pCurRect < pRectEnd; pCurRect++) {	if (pCurRect->bottom <= ry)	   continue;		/* not far enough down yet*/	if (pCurRect->top > ry) {	   partOut = TRUE;	/* missed part of rectangle above */	   if (partIn || (pCurRect->top >= rect->bottom))	      break;	   ry = pCurRect->top;	/* x guaranteed to be == rect->left */	}	if (pCurRect->right <= rx)	   continue;		/* not far enough over yet */	if (pCurRect->left > rx) {	   partOut = TRUE;	/* missed part of rectangle to left */	   if (partIn)	      break;	}	if (pCurRect->left < rect->right) {	    partIn = TRUE;	/* definitely overlap */	    if (partOut)	       break;	}	if (pCurRect->right >= rect->right) {	   ry = pCurRect->bottom;	/* finished with this band */	   if (ry >= rect->bottom)	      break;	   rx = rect->left;	/* reset x out to left again */	} else {	    /*	     * Because boxes in a band are maximal width, if the first box	     * to overlap the rectangle doesn't completely cover it in that	     * band, the rectangle must be partially out, since some of it	     * will be uncovered in that band. partIn will have been set true	     * by now...	     */	    break;	}    }    return(partIn ? ((ry < rect->bottom) ? MWRECT_PARTIN : MWRECT_ALLIN) : 		MWRECT_OUT);}#if 0000/* Returns TRUE if rect is at least partly inside rgn*/MWBOOLGdRectInRegion(MWCLIPREGION *rgn, const MWRECT *rect){    MWRECT *pCurRect, *pRectEnd;    MWBOOL ret = FALSE;    /* this is (just) a useful optimization */	if ((rgn->numRects > 0) && EXTENTCHECK(&rgn->extents, rect))	{	    for (pCurRect = rgn->rects, pRectEnd = pCurRect +	     rgn->numRects; pCurRect < pRectEnd; pCurRect++)	    {	        if (pCurRect->bottom <= rect->top)			continue;             /* not far enough down yet */		if (pCurRect->top >= rect->bottom) {		    ret = FALSE;          /* too far down */		    break;		}		if (pCurRect->right <= rect->left)		    continue;              /* not far enough over yet */		if (pCurRect->left >= rect->right) {		    continue;		}		ret = TRUE;		break;	    }	}	return ret;}#endifstatic MWBOOLEQUALRECT(MWRECT *r1, MWRECT *r2){	return ((r1->left == r2->left) && (r1->right == r2->right) &&		(r1->top == r2->top) && (r1->bottom == r2->bottom));}MWBOOLGdEqualRegion(MWCLIPREGION *r1, MWCLIPREGION *r2){	int	i;	if (r1->numRects != r2->numRects)		return FALSE;	if (r1->numRects == 0)		return TRUE;	if (!EQUALRECT(&r1->extents, &r2->extents))		return FALSE;	for (i = 0; i < r1->numRects; i++) {		if (!EQUALRECT(r1->rects + i, r2->rects + i))			return FALSE;	}	return TRUE;}MWBOOLGdEmptyRegion(MWCLIPREGION *rgn){	return rgn->numRects == 0;}/* *            Create a new empty MWCLIPREGION. */MWCLIPREGION *GdAllocRegion(void)    {    MWCLIPREGION *rgn;    if ((rgn = malloc(sizeof( MWCLIPREGION ))))    {	if ((rgn->rects = malloc(sizeof( MWRECT ))))	{	    rgn->size = 1;	    EMPTY_REGION(rgn);	    return rgn;	}	free(rgn);    }    return NULL;}MWCLIPREGION *GdAllocRectRegion(MWCOORD left, MWCOORD top, MWCOORD right, MWCOORD bottom){	MWCLIPREGION *rgn;	rgn = GdAllocRegion();	if (rgn)		GdSetRectRegion(rgn, left, top, right, bottom);	return rgn;}MWCLIPREGION *GdAllocRectRegionIndirect(MWRECT *prc){	return GdAllocRectRegion(prc->left, prc->top, prc->right, prc->bottom);}voidGdSetRectRegion(MWCLIPREGION *rgn, MWCOORD left, MWCOORD top, MWCOORD right,	MWCOORD bottom){	if (left != right && top != bottom) {		rgn->rects->left = rgn->extents.left = left;		rgn->rects->top = rgn->extents.top = top;		rgn->rects->right = rgn->extents.right = right;		rgn->rects->bottom = rgn->extents.bottom = bottom;		rgn->numRects = 1;		rgn->type = MWREGION_SIMPLE;	} else		EMPTY_REGION(rgn);}voidGdSetRectRegionIndirect(MWCLIPREGION *rgn, MWRECT *prc){	GdSetRectRegion(rgn, prc->left, prc->top, prc->right, prc->bottom);}voidGdDestroyRegion(MWCLIPREGION *rgn){	if(rgn) {		free(rgn->rects);		free(rgn);	}}voidGdOffsetRegion(MWCLIPREGION *rgn, MWCOORD x, MWCOORD y){	int	nbox = rgn->numRects;	MWRECT *pbox = rgn->rects;	if(nbox && (x || y)) {		while(nbox--) {			pbox->left += x;			pbox->right += x;			pbox->top += y;			pbox->bottom += y;			pbox++;		}		rgn->extents.left += x;		rgn->extents.right += x;		rgn->extents.top += y;		rgn->extents.bottom += y;	}}/* get bounding box for region, return region type*/intGdGetRegionBox(MWCLIPREGION *rgn, MWRECT *prc){	*prc = rgn->extents;	return rgn->type;}/*********************************************************************** *           GdUnionRectWithRegion *           Adds a rectangle to a MWCLIPREGION */voidGdUnionRectWithRegion(const MWRECT *rect, MWCLIPREGION *rgn){    MWCLIPREGION region;    region.rects = &region.extents;    region.numRects = 1;    region.size = 1;    region.type = MWREGION_SIMPLE;    region.extents = *rect;    GdUnionRegion(rgn, rgn, &region);}/*********************************************************************** *           GdSubtractRectWithRegion *           Subtracts a rectangle from a MWCLIPREGION */voidGdSubtractRectFromRegion(const MWRECT *rect, MWCLIPREGION *rgn){    MWCLIPREGION region;    region.rects = &region.extents;    region.numRects = 1;    region.size = 1;    region.type = MWREGION_SIMPLE;    region.extents = *rect;    GdSubtractRegion(rgn, rgn, &region);}/*********************************************************************** *           GdCopyRegion */voidGdCopyRegion(MWCLIPREGION *dst, MWCLIPREGION *src){    if (dst != src) /*  don't want to copy to itself */    {  	if (dst->size < src->numRects)	{	    if (! (dst->rects = realloc( dst->rects, src->numRects * sizeof(MWRECT))))		return;	    dst->size = src->numRects;	}	dst->numRects = src->numRects;	dst->extents.left = src->extents.left;	dst->extents.top = src->extents.top;	dst->extents.right = src->extents.right;	dst->extents.bottom = src->extents.bottom;	dst->type = src->type;	memcpy((char *) dst->rects, (char *) src->rects,	       (int) (src->numRects * sizeof(MWRECT)));    }}/*********************************************************************** *           REGION_SetExtents *           Re-calculate the extents of a region */static voidREGION_SetExtents (MWCLIPREGION *pReg){    MWRECT *pRect, *pRectEnd, *pExtents;    if (pReg->numRects == 0)    {	pReg->extents.left = 0;	pReg->extents.top = 0;	pReg->extents.right = 0;	pReg->extents.bottom = 0;	return;    }    pExtents = &pReg->extents;    pRect = pReg->rects;    pRectEnd = &pRect[pReg->numRects - 1];    /*     * Since pRect is the first rectangle in the region, it must have the     * smallest top and since pRectEnd is the last rectangle in the region,     * it must have the largest bottom, because of banding. Initialize left and     * right from pRect and pRectEnd, resp., as good things to initialize them     * to...     */    pExtents->left = pRect->left;    pExtents->top = pRect->top;    pExtents->right = pRectEnd->right;    pExtents->bottom = pRectEnd->bottom;    while (pRect <= pRectEnd)    {

⌨️ 快捷键说明

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