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

📄 draw.c

📁 这是ARM嵌入式系统的实验教程中的MINIGUI的实验源代码!
💻 C
📖 第 1 页 / 共 2 页
字号:
    pdc->CurPenPos.y = y;

    if (dc_IsGeneralHDC(hdc)) {
        pthread_mutex_lock (&pdc->pGCRInfo->lock);
        if (!dc_GenerateECRgn (pdc, FALSE)) {
            pthread_mutex_unlock (&pdc->pGCRInfo->lock);
            return;
        }
    }

    // Transfer logical to device to screen here.
    coor_LP2SP(pdc, &x, &y);
    coor_LP2SP(pdc, &startx, &starty);
    rcOutput.left = startx;
    rcOutput.top  = starty;
    rcOutput.right = x;
    rcOutput.bottom = y;
    NormalizeRect (&rcOutput);
    InflateRect (&rcOutput, 1, 1);

    pthread_mutex_lock (&__mg_gdilock);
    IntersectRect (&rcOutput, &rcOutput, &pdc->ecrgn.rcBound);
    if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(FALSE, &rcOutput);

    // set graphics context.
    GAL_SetGC (pdc->gc);
    GAL_SetFgColor (pdc->gc, pdc->pencolor);

    pClipRect = pdc->ecrgn.head;
    while(pClipRect)
    {
        if (DoesIntersect (&rcOutput, &pClipRect->rc)) {
            GAL_SetClipping (pdc->gc, pClipRect->rc.left, pClipRect->rc.top,
                    pClipRect->rc.right - 1, pClipRect->rc.bottom - 1);

            if(starty == y) {
                if (startx > x)
                    GAL_DrawHLine (pdc->gc, x, y, startx - x, pdc->pencolor);
                else
                    GAL_DrawHLine (pdc->gc, startx, y, x - startx, pdc->pencolor);
            }
            else
                GAL_Line (pdc->gc, startx, starty, x, y, pdc->pencolor);
        }
            
        pClipRect = pClipRect->next;
    }

    if (!dc_IsMemHDC (hdc)) ShowCursorForGDI (TRUE, &rcOutput);
    pthread_mutex_unlock (&__mg_gdilock);
    if (dc_IsGeneralHDC(hdc)) pthread_mutex_unlock (&pdc->pGCRInfo->lock);
}

void GUIAPI PolyLineTo (HDC hdc, const POINT* point, int poinum)
{
    int   i;

    MoveTo (hdc, point[0].x, point[0].y);

    for (i=1; i<poinum; i++)
        LineTo (hdc, point[i].x, point[i].y);
}

/************************ Circle and Rectangle *******************************/
void GUIAPI Circle(HDC hdc, int x, int y, int r)
{
    PCLIPRECT pClipRect;
    PDC pdc;
    RECT rcOutput;

    pdc = dc_HDC2PDC(hdc);

    if (dc_IsGeneralHDC(hdc)) {
        pthread_mutex_lock (&pdc->pGCRInfo->lock);
        if (!dc_GenerateECRgn (pdc, FALSE)) {
            pthread_mutex_unlock (&pdc->pGCRInfo->lock);
            return;
        }
    }

    // Transfer logical to device to screen here.
    coor_LP2SP(pdc, &x, &y);

    rcOutput.left = x - r;
    rcOutput.top  = y - r;
    rcOutput.right = x + r + 1;
    rcOutput.bottom = y + r + 1;

    pthread_mutex_lock (&__mg_gdilock);
    IntersectRect (&rcOutput, &rcOutput, &pdc->ecrgn.rcBound);
    if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(FALSE, &rcOutput);

    // set graphics context.
    GAL_SetGC (pdc->gc);
    GAL_SetFgColor (pdc->gc, pdc->pencolor);

    pClipRect = pdc->ecrgn.head;
    while(pClipRect)
    {
        if (DoesIntersect (&rcOutput, &pClipRect->rc)) {
            GAL_SetClipping (pdc->gc, pClipRect->rc.left, pClipRect->rc.top,
                    pClipRect->rc.right -1 , pClipRect->rc.bottom - 1);
            GAL_Circle (pdc->gc, x, y, r, pdc->pencolor);
        }
            
        pClipRect = pClipRect->next;
    }

    if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(TRUE, &rcOutput);
    pthread_mutex_unlock(&__mg_gdilock);
    if (dc_IsGeneralHDC(hdc)) pthread_mutex_unlock (&pdc->pGCRInfo->lock);
}

void GUIAPI Rectangle(HDC hdc, int x0, int y0, int x1, int y1)
{
    PCLIPRECT pClipRect;
    PDC pdc;
    RECT rcOutput;

    pdc = dc_HDC2PDC(hdc);

    if (dc_IsGeneralHDC(hdc)) {
        pthread_mutex_lock (&pdc->pGCRInfo->lock);
        if (!dc_GenerateECRgn (pdc, FALSE)) {
            pthread_mutex_unlock (&pdc->pGCRInfo->lock);
            return;
        }
    }

    // Transfer logical to device to screen here.
    coor_LP2SP(pdc, &x0, &y0); 
    coor_LP2SP(pdc, &x1, &y1); 
    
    rcOutput.left = x0;
    rcOutput.top = y0;
    rcOutput.right = x1;
    rcOutput.bottom = y1;
    NormalizeRect (&rcOutput);
    rcOutput.right ++;
    rcOutput.bottom ++;

    pthread_mutex_lock (&__mg_gdilock);
    IntersectRect (&rcOutput, &rcOutput, &pdc->ecrgn.rcBound);
    if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(FALSE, &rcOutput);

    // set graphics context.
    GAL_SetGC (pdc->gc);
    GAL_SetFgColor (pdc->gc, pdc->pencolor);

    pClipRect = pdc->ecrgn.head;
    while(pClipRect)
    {
        if (DoesIntersect (&rcOutput, &pClipRect->rc)) {
            GAL_SetClipping (pdc->gc, pClipRect->rc.left, pClipRect->rc.top,
                    pClipRect->rc.right - 1, pClipRect->rc.bottom - 1);

            GAL_Rectangle (pdc->gc, x0, y0, x1, y1, pdc->pencolor);
        }
            
        pClipRect = pClipRect->next;
    }
    
    if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(TRUE, &rcOutput);
    pthread_mutex_unlock(&__mg_gdilock);
    if (dc_IsGeneralHDC(hdc)) pthread_mutex_unlock (&pdc->pGCRInfo->lock);
}

void GUIAPI FocusRect(HDC hdc, int x0, int y0, int x1, int y1)
{
    PCLIPRECT pClipRect;
    PDC pdc;
    int l, t, r, b, w, h;
    RECT rcOutput;
    size_t sizeh, sizev;
    BYTE* vbuff = NULL;
    BYTE* hline1 = NULL, * hline2 = NULL;
    BYTE* vline1 = NULL, * vline2 = NULL;
    int bpp;
    BYTE xor_byte;

    pdc = dc_HDC2PDC(hdc);
    bpp = GAL_BytesPerPixel (pdc->gc);

    if (GAL_BitsPerPixel (pdc->gc) < 8)
        xor_byte = 0x0F;
    else
        xor_byte = 0xFF;

    if (dc_IsGeneralHDC(hdc)) {
        pthread_mutex_lock (&pdc->pGCRInfo->lock);
        if (!dc_GenerateECRgn (pdc, FALSE)) {
            pthread_mutex_unlock (&pdc->pGCRInfo->lock);
            return;
        }
    }

    // Transfer logical to device to screen here.
    coor_LP2SP(pdc, &x0, &y0); 
    coor_LP2SP(pdc, &x1, &y1); 

    l = MIN (x0, x1); t = MIN (y0, y1); r = MAX (x0, x1); b = MAX (y0, y1);
    rcOutput.left = l; rcOutput.top = t;
    rcOutput.right = r + 1; rcOutput.bottom = b + 1;

    pthread_mutex_lock (&__mg_gdilock);
    IntersectRect (&rcOutput, &rcOutput, &pdc->ecrgn.rcBound);
    if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(FALSE, &rcOutput);

    GAL_SetGC (pdc->gc);

    w = r - l + 1;
    h = b - t - 1;

    if (w == 0 || h == 0)
        goto my_exit;

    sizeh = w * bpp;
    sizev = h * bpp;
#ifdef HAVE_ALLOCA
    if (!(vbuff = alloca ((sizeh << 1) + (sizev << 1))))
#else
    if (!(vbuff = malloc ((sizeh << 1) + (sizev << 1))))
#endif
        goto my_exit;

    if (w > 0) {
        int i, j;
        int offset;
       
        hline1 = vbuff;
        hline2 = vbuff + sizeh;

        GAL_GetBox (pdc->gc, l, t, w, 1, hline1);
        GAL_GetBox (pdc->gc, l, b, w, 1, hline2);

        offset = 0;
        for (i = 0; i < w; i += 2) {
            for (j = 0; j < bpp; j++) {
                hline1[offset + j] ^= xor_byte;
                hline2[offset + j] ^= xor_byte;
            }
            offset += bpp << 1; 
        }
    }
    
    if (h > 0) {
        int i, j, offset;
        
        vline1 = vbuff + (sizeh << 1);
        vline2 = vbuff + (sizeh << 1) + sizev;
            
        GAL_GetBox (pdc->gc, l, t + 1, 1, h, vline1);
        GAL_GetBox (pdc->gc, r, t + 1, 1, h, vline2);
        
        offset = 0;
        for (i = 0; i < h; i += 2) {
            for (j = 0; j < bpp; j++) {
                vline1[offset + j] ^= xor_byte;
                vline2[offset + j] ^= xor_byte;
            }
            offset += bpp << 1; 
        }
    }

    // set graphics context.
    GAL_SetGC (pdc->gc);

    pClipRect = pdc->ecrgn.head;
    while(pClipRect)
    {
        if (DoesIntersect (&rcOutput, &pClipRect->rc)) {
            GAL_SetClipping(pdc->gc, pClipRect->rc.left, pClipRect->rc.top,
                    pClipRect->rc.right - 1, pClipRect->rc.bottom - 1);
            
            if (hline1) {
                GAL_PutBox (pdc->gc, l, t, w, 1, hline1);
                GAL_PutBox (pdc->gc, l, b, w, 1, hline2);
            }
            
            if (vline1) {
                GAL_PutBox (pdc->gc, l, t + 1, 1, h, vline1);
                GAL_PutBox (pdc->gc, r, t + 1, 1, h, vline2);
            }
        }
            
        pClipRect = pClipRect->next;
    }
    
my_exit:
    if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(TRUE, &rcOutput);
    pthread_mutex_unlock (&__mg_gdilock);
    if (dc_IsGeneralHDC(hdc)) pthread_mutex_unlock (&pdc->pGCRInfo->lock);
#ifndef HAVE_ALLOCA
    free (vbuff);
#endif
}

⌨️ 快捷键说明

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