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

📄 cursor.c

📁 运行于嵌入式linux的数控系统图形界面
💻 C
📖 第 1 页 / 共 2 页
字号:
        sprintf(szKey, "cursor%d", i);        if (GetValueFromEtcFile(ETCFILEPATH, CURSORSECTION,                                 szKey, szValue, MAX_NAME) < 0)            goto error;        strcpy(szFileName, szPathName);        strcat(szFileName, szValue);        if (!(SysCursor[i] = (PCURSOR)LoadCursorFromFile(szFileName)))             goto error;#endif /* _INCORE_RES */    }	    pthread_mutex_init(&__mg_mouselock, NULL);    return TRUE;error:    TerminateCursor();    return FALSE;}// The following function must be called at last. void TerminateCursor( void ){    int i;    if (!savedbits ) return;    pthread_mutex_destroy (&__mg_mouselock);    free(savedbits);    free(cursorbits);    savedbits = NULL;    pCurCsr = NULL;    nShowCount = 0;     for(i = 0; i<= MAX_SYSCURSORINDEX; i++)    {        if( SysCursor[i] ) {            free(SysCursor[i]->AndBits);            free(SysCursor[i]->XorBits);            free(SysCursor[i]);            SysCursor[i] = NULL;       }    }}HCURSOR GUIAPI GetCurrentCursor(void){    HCURSOR hcsr;    pthread_mutex_lock (&__mg_mouselock);        hcsr = (HCURSOR)pCurCsr;    pthread_mutex_unlock(&__mg_mouselock);    return hcsr;}// Cursor pointer shape and hiding and showing.static inline int boxleft(void){    if(!pCurCsr) return -100;    return curx - pCurCsr->xhotspot;}static inline int boxtop(void){    if(!pCurCsr) return -100;    return cury - pCurCsr->yhotspot;}#ifdef _USE_NEWGALstatic GAL_Rect csr_rect = {0, 0, CURSORWIDTH, CURSORHEIGHT};static void hidecursor (void){    csr_rect.x = oldboxleft;    csr_rect.y = oldboxtop;    csr_bmp.bmBits = savedbits;    GAL_SetClipRect (__gal_screen, NULL);    GAL_PutBox (__gal_screen, &csr_rect, &csr_bmp);     GAL_UpdateRects (__gal_screen, 1, &csr_rect);}static void showcursor (void){    int x, y;    x = boxleft ();    y = boxtop ();    csr_rect.x = x;    csr_rect.y = y;    csr_bmp.bmBits = savedbits;    GAL_SetClipRect (__gal_screen, NULL);    GAL_GetBox (__gal_screen, &csr_rect, &csr_bmp);    oldboxleft = x;    oldboxtop = y;    GAL_memcpy4 (cursorbits, savedbits, csrimgsize >> 2);#ifdef ASM_memandcpy4    ASM_memandcpy4 (cursorbits, pCurCsr->AndBits, csrimgsize >> 2);    ASM_memxorcpy4 (cursorbits, pCurCsr->XorBits, csrimgsize >> 2);#else    {        int i;        Uint32* andbits = (Uint32*) pCurCsr->AndBits;        Uint32* xorbits = (Uint32*) pCurCsr->XorBits;        Uint32* dst = (Uint32*) cursorbits;        for (i = 0; i < csrimgsize >> 2; i++) {            dst [i] &= andbits [i];            dst [i] ^= xorbits[i];        }    }#endif    csr_bmp.bmBits = cursorbits;    GAL_PutBox (__gal_screen, &csr_rect, &csr_bmp);    GAL_UpdateRects (__gal_screen, 1, &csr_rect);}#elsestatic inline void hidecursor(void){    GAL_SetGC(PHYSICALGC);    GAL_EnableClipping(PHYSICALGC);    GAL_PutBox(PHYSICALGC, oldboxleft, oldboxtop, CURSORWIDTH, CURSORHEIGHT, savedbits);}static inline void showcursor(void){    int x, y;    GAL_SetGC(PHYSICALGC);    x = boxleft();    y = boxtop();    GAL_DisableClipping(PHYSICALGC);    GAL_GetBox(PHYSICALGC, x, y, CURSORWIDTH, CURSORHEIGHT, savedbits);    oldboxleft = x;    oldboxtop = y;    memcpy(cursorbits, savedbits, csrimgsize);    {        int i;        Uint32* andbits = (Uint32*) pCurCsr->AndBits;        Uint32* xorbits = (Uint32*) pCurCsr->XorBits;        Uint32* dst = (Uint32*) cursorbits;        for (i = 0; i < csrimgsize >> 2; i++) {            dst [i] &= andbits [i];            dst [i] ^= xorbits[i];        }    }    GAL_EnableClipping(PHYSICALGC);    GAL_PutBox(PHYSICALGC, x, y, CURSORWIDTH, CURSORHEIGHT, cursorbits);}#endifHCURSOR GUIAPI SetCursorEx (HCURSOR hcsr, BOOL setdef){    PCURSOR old, pcsr;    pthread_mutex_lock (&__mg_mouselock);    if (setdef) {        old = (PCURSOR) def_cursor;        def_cursor = hcsr;    }    else        old = pCurCsr;    if ((PCURSOR)hcsr == pCurCsr) {        pthread_mutex_unlock(&__mg_mouselock);        return (HCURSOR) old;    }    pthread_mutex_unlock(&__mg_mouselock);    pthread_mutex_lock (&__mg_gdilock);    pthread_mutex_lock (&__mg_mouselock);    pcsr = (PCURSOR)hcsr;    if (pCurCsr)        hidecursor();    pCurCsr = pcsr;    if (nShowCount >= 0 && pCurCsr)        showcursor();    pthread_mutex_unlock(&__mg_mouselock);    pthread_mutex_unlock(&__mg_gdilock);    return (HCURSOR) old;}void ShowCursorForGDI(BOOL fShow, const RECT* prc){    int csrleft, csrright, csrtop, csrbottom;    int intleft, intright, inttop, intbottom;    if (!fShow)        pthread_mutex_lock (&__mg_mouselock);    csrleft = boxleft();    csrright = csrleft + CURSORWIDTH;    csrtop = boxtop();    csrbottom = csrtop + CURSORHEIGHT;    intleft = (csrleft > prc->left) ? csrleft : prc->left;    inttop  = (csrtop > prc->top) ? csrtop : prc->top;    intright = (csrright < prc->right) ? csrright : prc->right;    intbottom = (csrbottom < prc->bottom) ? csrbottom : prc->bottom;    if (intleft >= intright || inttop >= intbottom) {        if (fShow) {#ifdef _USE_NEWGAL            GAL_UpdateRect (__gal_screen, prc->left, prc->top, RECTWP(prc), RECTHP(prc));#endif            pthread_mutex_unlock(&__mg_mouselock);        }        return;    }    if (fShow && nShowCount >= 0 && pCurCsr) {        showcursor();    }    if (!fShow && nShowCount >= 0 && pCurCsr) {        hidecursor();    }    if (fShow) {#ifdef _USE_NEWGAL        GAL_UpdateRect (__gal_screen, prc->left, prc->top, RECTWP(prc), RECTHP(prc));#endif        pthread_mutex_unlock(&__mg_mouselock);    }}int GUIAPI ShowCursor(BOOL fShow){    int count;    pthread_mutex_lock (&__mg_gdilock);    pthread_mutex_lock (&__mg_mouselock);    if(fShow) {        nShowCount++;        if(nShowCount == 0 && pCurCsr)           showcursor();    }    else {        nShowCount--;        if(nShowCount == -1 && pCurCsr);           hidecursor();    }    count = nShowCount;    pthread_mutex_unlock(&__mg_mouselock);    pthread_mutex_unlock(&__mg_gdilock);    return count;}#elsevoid ShowCursorForGDI(BOOL fShow, const RECT* prc){#ifdef _USE_NEWGAL    if (fShow)        GAL_UpdateRect (__gal_screen, prc->left, prc->top, RECTWP(prc), RECTHP(prc));#endif}#endif /* _CURSOR_SUPPORT */BOOL RefreshCursor(int* x, int* y, int* button){    pthread_mutex_lock (&__mg_gdilock);    pthread_mutex_lock (&__mg_mouselock);    IAL_GetMouseXY (x, y);    curx = *x;    cury = *y;    *button = IAL_GetMouseButton ();    if(oldx != curx || oldy != cury)    {#ifdef _CURSOR_SUPPORT        if(nShowCount >= 0 && pCurCsr) {            hidecursor();            showcursor();        }#endif        oldx = curx;        oldy = cury;        pthread_mutex_unlock(&__mg_mouselock);        pthread_mutex_unlock(&__mg_gdilock);        return TRUE;    }    pthread_mutex_unlock(&__mg_mouselock);    pthread_mutex_unlock(&__mg_gdilock);    return FALSE;}// Cursor position.void GUIAPI GetCursorPos(POINT* ppt){    pthread_mutex_lock (&__mg_mouselock);    ppt->x = curx;    ppt->y = cury;    pthread_mutex_unlock(&__mg_mouselock);}void GUIAPI SetCursorPos(int x, int y){    pthread_mutex_lock (&__mg_gdilock);    pthread_mutex_lock (&__mg_mouselock);    IAL_SetMouseXY (x, y);    IAL_GetMouseXY (&curx, &cury);    if (oldx != curx || oldy != cury) {#ifdef _CURSOR_SUPPORT        if(nShowCount >= 0 && pCurCsr) {            hidecursor();            showcursor();        }#endif        oldx = curx;        oldy = cury;    }    pthread_mutex_unlock(&__mg_mouselock);    pthread_mutex_unlock(&__mg_gdilock);}// Cursor clipping support.void GUIAPI ClipCursor(const RECT* prc){    RECT rc;    pthread_mutex_lock (&__mg_mouselock);    if( IsRectEmpty(&cliprc) )        SetRect(&cliprc, 0, 0, WIDTHOFPHYGC - 1, HEIGHTOFPHYGC - 1);    if(prc == NULL)    {        IAL_SetMouseRange (0,0,WIDTHOFPHYGC - 1,HEIGHTOFPHYGC - 1);        SetRect(&cliprc, 0, 0, WIDTHOFPHYGC - 1, HEIGHTOFPHYGC - 1);        pthread_mutex_unlock(&__mg_mouselock);        return;    }            memcpy(&rc, prc, sizeof(RECT));    NormalizeRect(&rc);    IntersectRect(&cliprc, &rc, &cliprc);    NormalizeRect(&cliprc);    IAL_SetMouseRange (cliprc.left,cliprc.top, cliprc.right,cliprc.bottom);    pthread_mutex_unlock(&__mg_mouselock);}void GUIAPI GetClipCursor(RECT* prc){    pthread_mutex_lock (&__mg_mouselock);    memcpy(prc, &cliprc, sizeof(RECT));    pthread_mutex_unlock(&__mg_mouselock);}

⌨️ 快捷键说明

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