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

📄 cursor-lite.c

📁 miniucgui1.30版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
        CSR_OLDBOXLEFT  = -100;        CSR_OLDBOXTOP = -100;    }#ifdef _USE_NEWGAL    csr_bmp.bmBitsPerPixel = __gal_screen->format->BitsPerPixel;    csr_bmp.bmBytesPerPixel = __gal_screen->format->BytesPerPixel;    csr_bmp.bmPitch = __gal_screen->format->BytesPerPixel * CURSORWIDTH;#endif        return TRUE;}// The following function must be called at last. void TerminateCursor (void){    int i;    if (mgIsServer) {        free (cursorbits);        CSR_CURRENT = NULL;        CSR_SHOW_COUNT = 0;         for (i = 0; i < ((PG_RES)mgSharedRes)->csrnum; i++) {            if (sys_cursors [i]) {                free (sys_cursors [i]);                sys_cursors [i] = NULL;            }        }    }}// Cursor pointer shape and hiding and showing.inline static int boxleft (void){    if (!CSR_CURRENT) return -100;    return CSR_CURSORX - CSR_XHOTSPOT;}inline static int boxtop (void){    if (!CSR_CURRENT) return -100;    return CSR_CURSORY - CSR_YHOTSPOT;}#ifdef _USE_NEWGALstatic GAL_Rect csr_rect = {0, 0, CURSORWIDTH, CURSORHEIGHT};static void hidecursor (void){    csr_rect.x = CSR_OLDBOXLEFT;    csr_rect.y = CSR_OLDBOXTOP;    csr_bmp.bmBits = CSR_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 = CSR_SAVEDBITS;    GAL_SetClipRect (__gal_screen, NULL);    GAL_GetBox (__gal_screen, &csr_rect, &csr_bmp);    CSR_OLDBOXLEFT = x;    CSR_OLDBOXTOP = y;    GAL_memcpy4 (cursorbits, CSR_SAVEDBITS, __mg_csrimgsize >> 2);#ifdef ASM_memandcpy4    ASM_memandcpy4 (cursorbits, CSR_CURRENT->AndBits, __mg_csrimgsize >> 2);    ASM_memxorcpy4 (cursorbits, CSR_CURRENT->XorBits, __mg_csrimgsize >> 2);#else    {        int i;        Uint32* andbits = (Uint32*) CSR_CURRENT->AndBits;        Uint32* xorbits = (Uint32*) CSR_CURRENT->XorBits;        Uint32* dst = (Uint32*) cursorbits;        for (i = 0; i < __mg_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 void hidecursor (void){    GAL_SetGC (PHYSICALGC);    GAL_DisableClipping (PHYSICALGC);        GAL_PutBox (PHYSICALGC, CSR_OLDBOXLEFT, CSR_OLDBOXTOP,                     CURSORWIDTH, CURSORHEIGHT, CSR_SAVEDBITS);}static void showcursor (void){    int x, y;    GAL_SetGC (PHYSICALGC);    x = boxleft ();    y = boxtop ();    GAL_DisableClipping (PHYSICALGC);    GAL_GetBox (PHYSICALGC, x, y, CURSORWIDTH, CURSORHEIGHT, CSR_SAVEDBITS);    CSR_OLDBOXLEFT = x;    CSR_OLDBOXTOP = y;    memcpy (cursorbits, CSR_SAVEDBITS, __mg_csrimgsize);    {        int i;        Uint32* dst = (Uint32*) cursorbits;        Uint32* andbits = (Uint32*) CSR_CURRENT->AndBits;        Uint32* xorbits = (Uint32*) CSR_CURRENT->XorBits;        for (i = 0; i < __mg_csrimgsize >> 2; i++) {            dst [i] &= andbits [i];            dst [i] ^= xorbits[i];        }    }    GAL_EnableClipping (PHYSICALGC);    GAL_PutBox (PHYSICALGC, x, y, CURSORWIDTH, CURSORHEIGHT, cursorbits);}#endif /* _USE_NEWGAL */#endif /* _CURSOR_SUPPORT */// The return value indicates whether mouse has moved. // TRUE for moved.// NOTE that only server can call this function.BOOL RefreshCursor (int* x, int* y, int* button){    int curx, cury;    BOOL moved = FALSE;    if (!mgIsServer) return FALSE;    IAL_GetMouseXY (x, y);    SHAREDRES_MOUSEX = curx = *x;    SHAREDRES_MOUSEY = cury = *y;    if (button)        SHAREDRES_BUTTON = *button = IAL_GetMouseButton ();    if (oldx != curx || oldy != cury) {#ifdef _CURSOR_SUPPORT        lock_cursor_sem ();        if (CSR_SHOW_COUNT >= 0 && CSR_CURRENT) {            CSR_CURSORX = curx;            CSR_CURSORY = cury;            if (get_hidecursor_sem_val ()) {                reset_hidecursor_sem ();            }            else                hidecursor ();            showcursor ();        }        unlock_cursor_sem ();#endif /* _CURSOR_SUPPORT */        oldx = curx;        oldy = cury;        moved = TRUE;    }    return moved;}#ifdef _CURSOR_SUPPORT/* show cursor hidden by client GDI function */void ReShowCursor (void){    lock_cursor_sem ();    if (CSR_SHOW_COUNT >= 0 && CSR_CURRENT) {        if (get_hidecursor_sem_val ()) {            reset_hidecursor_sem ();            showcursor ();        }    }    unlock_cursor_sem ();}/* Always call with "setdef = FALSE" for clients at server side. */HCURSOR GUIAPI SetCursorEx (HCURSOR hcsr, BOOL setdef){    PCURSOR old, pcsr;    if (!mgIsServer) {        REQUEST req;        req.id = REQID_SETCURSOR;        req.data = &hcsr;        req.len_data = sizeof (HCURSOR);        if (cli_request (&req, &old, sizeof (PCURSOR)) < 0)            return 0;        return (HCURSOR) old;    }    if (setdef) {        old = (PCURSOR) def_cursor;        def_cursor = hcsr;    }    else        old = CSR_CURRENT;    if ((PCURSOR)hcsr == CSR_CURRENT) {        return (HCURSOR) old;    }    pcsr = (PCURSOR)hcsr;    lock_cursor_sem ();    if (CSR_CURRENT && CSR_SHOW_COUNT >= 0                    && get_hidecursor_sem_val () == 0)        hidecursor();    CSR_CURRENT = pcsr;    CSR_XHOTSPOT = pcsr ? pcsr->xhotspot : -100;    CSR_YHOTSPOT = pcsr ? pcsr->yhotspot : -100;    if (CSR_CURRENT && CSR_SHOW_COUNT >= 0                    && get_hidecursor_sem_val () == 0)        showcursor();    unlock_cursor_sem ();    return (HCURSOR) old;}HCURSOR GUIAPI GetCurrentCursor (void){#if 1    return (HCURSOR)CSR_CURRENT;#else    HCURSOR hcsr;    if (!mgIsServer) {        REQUEST req;        req.id = REQID_GETCURRENTCURSOR;        req.data = 0;        req.len_data = 0;        if (cli_request (&req, &hcsr, sizeof (HCURSOR)) < 0)            return 0;        return hcsr;    }    return (HCURSOR)CSR_CURRENT;#endif}inline static BOOL does_need_hide (const RECT* prc){    int csrleft, csrright, csrtop, csrbottom;    int intleft, intright, inttop, intbottom;    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)        return FALSE;    return TRUE;}void ShowCursorForGDI (BOOL fShow, const RECT* prc){    if (!mgIsServer && (SHAREDRES_TOPMOST_LAYER != __mg_layer)) {#ifndef _USE_NEWGAL        /* avoiding dead lock. */        if (fShow && (get_cursor_sem_pid () == getpid ())) {            unlock_cursor_sem ();        }#endif        return;    }    if (!fShow) {        lock_cursor_sem ();        if (CSR_SHOW_COUNT >= 0 && CSR_CURRENT && does_need_hide (prc)) {            if (get_hidecursor_sem_val () == 0) {                inc_hidecursor_sem ();                hidecursor ();            }        }    }    else {#ifdef _USE_NEWGAL        GAL_UpdateRect (__gal_screen, prc->left, prc->top, RECTWP(prc), RECTHP(prc));#endif        unlock_cursor_sem ();    }}int GUIAPI ShowCursor (BOOL fShow){    if (!mgIsServer) {        REQUEST req;        int ret_value;        req.id = REQID_SHOWCURSOR;        req.data = &fShow;        req.len_data = sizeof (BOOL);        cli_request (&req, &ret_value, sizeof (int));        return ret_value;    }    lock_cursor_sem ();    if (fShow) {        CSR_SHOW_COUNT++;        if (CSR_SHOW_COUNT == 0 && CSR_CURRENT                    && get_hidecursor_sem_val () == 0)           showcursor();    }    else {        CSR_SHOW_COUNT--;        if (CSR_SHOW_COUNT == -1 && CSR_CURRENT)           hidecursor();    }    unlock_cursor_sem ();    return CSR_SHOW_COUNT;}#elsevoid ShowCursorForGDI (BOOL fShow, const RECT* prc){    if (!mgIsServer && (SHAREDRES_TOPMOST_LAYER != __mg_layer))        return;#ifdef _USE_NEWGAL    if (fShow)        GAL_UpdateRect (__gal_screen, prc->left, prc->top, RECTWP(prc), RECTHP(prc));#endif}#endif /* _CURSOR_SUPPORT */void GUIAPI GetCursorPos (POINT* ppt){    ppt->x = SHAREDRES_MOUSEX;    ppt->y = SHAREDRES_MOUSEY;}void GUIAPI SetCursorPos (int x, int y){    if (mgIsServer) {        IAL_SetMouseXY (x, y);        RefreshCursor (&x, &y, NULL);    }    else {        REQUEST req;        POINT pt = {x, y};        req.id = REQID_SETCURSORPOS;        req.data = &pt;        req.len_data = sizeof (POINT);        cli_request (&req, NULL, 0);    }}// Cursor clipping support.void GUIAPI ClipCursor (const RECT* prc){    RECT rc;    if (!mgIsServer) {        REQUEST req;        req.id = REQID_CLIPCURSOR;        req.data = prc;        req.len_data = sizeof (RECT);        cli_request (&req, NULL, 0);        return;    }    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);        return;    }    memcpy (&rc, prc, sizeof(RECT));    NormalizeRect (&rc);    IntersectRect (&cliprc, &rc, &cliprc);    NormalizeRect (&cliprc);    IAL_SetMouseRange (cliprc.left, cliprc.top, cliprc.right, cliprc.bottom);}void GUIAPI GetClipCursor (RECT* prc){    if (!mgIsServer) {        REQUEST req;        req.id = REQID_GETCLIPCURSOR;        req.data = NULL;        req.len_data = 0;        cli_request (&req, prc, sizeof (RECT));        return;    }    memcpy (prc, &cliprc, sizeof(RECT));}

⌨️ 快捷键说明

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