clip.c

来自「在ecos 下mingui 的移植开发」· C语言 代码 · 共 261 行

C
261 行
字号
// $Id: clip.c,v 1.2 2000/06/19 01:54:15 weiym Exp $//// Clipping operations of GDI.//// Copyright (C) 2000, Wei Yongming.//// Current maintainer: Wei Yongming./***  This library is free software; you can redistribute it and/or**  modify it under the terms of the GNU Library General Public**  License as published by the Free Software Foundation; either**  version 2 of the License, or (at your option) any later version.****  This library is distributed in the hope that it will be useful,**  but WITHOUT ANY WARRANTY; without even the implied warranty of**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU**  Library General Public License for more details.****  You should have received a copy of the GNU Library General Public**  License along with this library; if not, write to the Free**  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,**  MA 02111-1307, USA*/// Create date: 2000/06/12, derived from original gdi.c//// Modify records:////  Who             When        Where       For What                Status//-----------------------------------------------------------------------------//// TODO:// #include <pthread.h>#include <semaphore.h>#include "common.h"#include "gdi.h"#include "window.h"#include "cliprect.h"#include "gal.h"#include "internals.h"#include "dc.h"#ifndef lintstatic char fileid[] = "$Id: clip.c,v 1.2 2000/06/19 01:54:15 weiym Exp $";#endifextern pthread_mutex_t gdilock;extern BOOL dc_GenerateECRgn (PDC pdc, BOOL fForce);/************************* Clipping support **********************************/void GUIAPI ExcludeClipRect(HDC hdc, int left, int top,                            int right, int bottom){    PDC pdc;    RECT rc;    pdc = dc_HDC2PDC(hdc);    SetRect(&rc, left, top, right, bottom);    NormalizeRect(&rc);    if (IsRectEmpty (&rc)) return;    SubtractClipRect (&pdc->lcrgn, &rc);    // Transfer logical to device to screen here.    coor_LP2SP(pdc, &left, &top);    coor_LP2SP(pdc, &right, &bottom);    SetRect(&rc, left, top, right, bottom);    NormalizeRect(&rc);    SubtractClipRect (&pdc->ecrgn, &rc);}void GUIAPI IncludeClipRect(HDC hdc, int left, int top,                               int right, int bottom){    PDC pdc;    RECT rc;    pdc = dc_HDC2PDC(hdc);    SetRect(&rc, left, top, right, bottom);    NormalizeRect(&rc);    if (IsRectEmpty (&rc)) return;    SubtractClipRect (&pdc->lcrgn, &rc);    AddClipRect (&pdc->lcrgn, &rc);        // Transfer logical to device to screen here.    coor_LP2SP(pdc, &rc.left, &rc.top);    coor_LP2SP(pdc, &rc.right, &rc.bottom);    NormalizeRect(&rc);    if (dc_IsGeneralHDC(hdc)) {        pthread_mutex_lock (&pdc->pGCRInfo->lock);        dc_GenerateECRgn (pdc, TRUE);        pthread_mutex_unlock (&pdc->pGCRInfo->lock);    }    else {        SubtractClipRect (&pdc->ecrgn, &rc);        IntersectClipRect (&pdc->ecrgn, &rc);    }}void GUIAPI ClipRectIntersect(HDC hdc, const RECT* prc){    PDC pdc;    RECT rc;    pdc = dc_HDC2PDC(hdc);    rc = *prc;    NormalizeRect(&rc);    if (IsRectEmpty (&rc)) return;    IntersectClipRect (&pdc->lcrgn, &rc);    // Transfer logical to device to screen here.    coor_LP2SP(pdc, &rc.left, &rc.top);    coor_LP2SP(pdc, &rc.right, &rc.bottom);    NormalizeRect(&rc);    IntersectClipRect (&pdc->ecrgn, &rc);}void GUIAPI SelectClipRect(HDC hdc, const RECT* prc){    PDC pdc;    RECT rc;    pdc = dc_HDC2PDC(hdc);    if (prc) {        rc = *prc;        NormalizeRect(&rc);        if (IsRectEmpty (&rc)) return;        SetClipRgn (&pdc->lcrgn, &rc);        coor_LP2SP(pdc, &rc.left, &rc.top);        coor_LP2SP(pdc, &rc.right, &rc.bottom);        NormalizeRect(&rc);                if (!IntersectRect (&rc, &rc, &pdc->DevRC))            return;    }    else {        EmptyClipRgn (&pdc->lcrgn);        rc = pdc->DevRC;    }        if (dc_IsGeneralHDC(hdc)) {        pthread_mutex_lock (&pdc->pGCRInfo->lock);        dc_GenerateECRgn (pdc, TRUE);        pthread_mutex_unlock (&pdc->pGCRInfo->lock);    }    else        SetClipRgn (&pdc->ecrgn, &rc);}void GUIAPI SelectClipRegion (HDC hdc, const CLIPRGN* pRgn){    PDC pdc;    PCLIPRECT pCRect;    PCLIPRGN pLcrgn;    pdc = dc_HDC2PDC(hdc);    pLcrgn = &pdc->lcrgn;    pCRect = pRgn->head;    if (pCRect) {        SetClipRgn (pLcrgn, &pCRect->rc);        pCRect = pCRect->next;        while (pCRect) {            SubtractClipRect (pLcrgn, &pCRect->rc);            AddClipRect (pLcrgn, &pCRect->rc);            pCRect = pCRect->next;        }    }    else        return;    if (dc_IsGeneralHDC(hdc)) {        pthread_mutex_lock (&pdc->pGCRInfo->lock);        dc_GenerateECRgn (pdc, TRUE);        pthread_mutex_unlock (&pdc->pGCRInfo->lock);    }    else {        // not implemented.    }}void GUIAPI GetBoundsRect(HDC hdc, RECT* pRect){    PDC pdc;    pdc = dc_HDC2PDC(hdc);    *pRect = pdc->lcrgn.rcBound;}BOOL GUIAPI PtVisible(HDC hdc, const POINT* pPt){    PCLIPRECT pClipRect;    PDC pdc;    int x, y;    pdc = dc_HDC2PDC(hdc);    x = pPt->x;    y = pPt->y;//    coor_LP2SP(pdc, &x, &y);    pClipRect = pdc->lcrgn.head;    if (pClipRect == NULL)        return PtInRect (&pdc->DevRC, x, y);            while(pClipRect)    {        if(PtInRect(&(pClipRect->rc), x, y)) return TRUE;        pClipRect = pClipRect->next;    }    return FALSE;}BOOL GUIAPI RectVisible(HDC hdc, const RECT* pRect){    PCLIPRECT pClipRect;    PDC pdc;    RECT rc;    rc = *pRect;     pdc = dc_HDC2PDC(hdc);//    coor_LP2SP(pdc, &(rc.left), &(rc.top));//    coor_LP2SP(pdc, &(rc.right), &(rc.bottom));    pClipRect = pdc->lcrgn.head;    if (pClipRect == NULL)        return DoesIntersect (&pdc->DevRC, &rc);    while(pClipRect)    {        if (DoesIntersect (&rc, &(pClipRect->rc)))            return TRUE;        pClipRect = pClipRect->next;    }    return FALSE;}

⌨️ 快捷键说明

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