| version 1.1.1.1, 2003/10/16 17:58:46 | version 1.7, 2007/11/11 07:11:26 | 
| Line 3 | Line 3 | 
 | #include        "mousemng.h" | #include        "mousemng.h" | 
 |  |  | 
 |  |  | 
| static  BYTE    mouserunning = 0; | #define MOUSEMNG_RANGE          128 | 
| static  BYTE    lastmouse = 0; |  | 
| static  short   mousex = 0; |  | 
| static  short   mousey = 0; |  | 
| static  BYTE    mouseb = 0xa0; |  | 
 |  |  | 
 |  |  | 
 |  | typedef struct { | 
 |  | SINT16  x; | 
 |  | SINT16  y; | 
 |  | UINT8   btn; | 
 |  | UINT    flag; | 
 |  | } MOUSEMNG; | 
 |  |  | 
 |  | static  MOUSEMNG        mousemng; | 
 |  |  | 
 |  |  | 
 |  | UINT8 mousemng_getstat(SINT16 *x, SINT16 *y, int clear) { | 
 |  |  | 
 |  | *x = mousemng.x; | 
 |  | *y = mousemng.y; | 
 |  | if (clear) { | 
 |  | mousemng.x = 0; | 
 |  | mousemng.y = 0; | 
 |  | } | 
 |  | return(mousemng.btn); | 
 |  | } | 
 |  |  | 
 |  |  | 
 |  | // ---- | 
 |  |  | 
 | static void getmaincenter(POINT *cp) { | static void getmaincenter(POINT *cp) { | 
 |  |  | 
 | RECT    rct; | RECT    rct; | 
 |  |  | 
| GetWindowRect(hWndMain, &rct); | GetWindowRect(g_hWndMain, &rct); | 
 | cp->x = (rct.right + rct.left) / 2; | cp->x = (rct.right + rct.left) / 2; | 
 | cp->y = (rct.bottom + rct.top) / 2; | cp->y = (rct.bottom + rct.top) / 2; | 
 | } | } | 
 |  |  | 
 |  | static void mousecapture(BOOL capture) { | 
 |  |  | 
| void mouseonoff(BYTE flg) { | LONG    style; | 
|  |  | 
 | POINT   cp; | POINT   cp; | 
 | RECT    rct; | RECT    rct; | 
 |  |  | 
| if ((lastmouse ^ flg) & 1) { | style = GetClassLong(g_hWndMain, GCL_STYLE); | 
| lastmouse = (flg & 1); | if (capture) { | 
| if (lastmouse & 1) { | ShowCursor(FALSE); | 
| ShowCursor(FALSE); | getmaincenter(&cp); | 
| getmaincenter(&cp); | rct.left = cp.x - MOUSEMNG_RANGE; | 
| rct.left = cp.x - 200; | rct.right = cp.x + MOUSEMNG_RANGE; | 
| rct.right = cp.x + 200; | rct.top = cp.y - MOUSEMNG_RANGE; | 
| rct.top = cp.y - 200; | rct.bottom = cp.y + MOUSEMNG_RANGE; | 
| rct.bottom = cp.y + 200; | SetCursorPos(cp.x, cp.y); | 
| SetCursorPos(cp.x, cp.y); | ClipCursor(&rct); | 
| ClipCursor(&rct); | style &= ~(CS_DBLCLKS); | 
| } |  | 
| else { |  | 
| ShowCursor(TRUE); |  | 
| ClipCursor(NULL); |  | 
| } |  | 
 | } | } | 
 |  | else { | 
 |  | ShowCursor(TRUE); | 
 |  | ClipCursor(NULL); | 
 |  | style |= CS_DBLCLKS; | 
 |  | } | 
 |  | SetClassLong(g_hWndMain, GCL_STYLE, style); | 
 | } | } | 
 |  |  | 
| // --------------------------------------------------------------------------- | void mousemng_initialize(void) { | 
|  |  | 
| BYTE mouse_flag(void) { |  | 
 |  |  | 
| return(mouserunning); | ZeroMemory(&mousemng, sizeof(mousemng)); | 
|  | mousemng.btn = uPD8255A_LEFTBIT | uPD8255A_RIGHTBIT; | 
|  | mousemng.flag = (1 << MOUSEPROC_SYSTEM); | 
 | } | } | 
 |  |  | 
 |  | void mousemng_sync(void) { | 
 |  |  | 
| void mouse_running(BYTE flg) { | POINT   p; | 
|  | POINT   cp; | 
| BYTE    mf = mouserunning; |  | 
 |  |  | 
| switch(flg & 0xc0) { | if ((!mousemng.flag) && (GetCursorPos(&p))) { | 
| case 0x00: | getmaincenter(&cp); | 
| mf &= ~(1 << (flg & 7)); | mousemng.x += (SINT16)((p.x - cp.x) / 2); | 
| break; | mousemng.y += (SINT16)((p.y - cp.y) / 2); | 
| case 0x40: | SetCursorPos(cp.x, cp.y); | 
| mf ^= (1 << (flg & 7)); |  | 
| break; |  | 
| default: |  | 
| mf |= (1 << (flg & 7)); |  | 
| break; |  | 
| } |  | 
| if ((mf ^ mouserunning) & MOUSE_MASK) { |  | 
| mouserunning = (mf & MOUSE_MASK); |  | 
| if (mouserunning == 1) { |  | 
| mouseonoff(1); |  | 
| } |  | 
| else { |  | 
| mouseonoff(0); |  | 
| } |  | 
 | } | } | 
 | } | } | 
 |  |  | 
 |  | BOOL mousemng_buttonevent(UINT event) { | 
 |  |  | 
| void mouse_callback(void) { | if (!mousemng.flag) { | 
|  | switch(event) { | 
| POINT   p, cp; | case MOUSEMNG_LEFTDOWN: | 
|  | mousemng.btn &= ~(uPD8255A_LEFTBIT); | 
| if ((lastmouse & 1) && (GetCursorPos(&p))) { | break; | 
| getmaincenter(&cp); |  | 
| mousex += (short)((p.x - cp.x) / 2); | case MOUSEMNG_LEFTUP: | 
| mousey += (short)((p.y - cp.y) / 2); | mousemng.btn |= uPD8255A_LEFTBIT; | 
| SetCursorPos(cp.x, cp.y); | break; | 
|  |  | 
|  | case MOUSEMNG_RIGHTDOWN: | 
|  | mousemng.btn &= ~(uPD8255A_RIGHTBIT); | 
|  | break; | 
|  |  | 
|  | case MOUSEMNG_RIGHTUP: | 
|  | mousemng.btn |= uPD8255A_RIGHTBIT; | 
|  | break; | 
|  | } | 
|  | return(TRUE); | 
|  | } | 
|  | else { | 
|  | return(FALSE); | 
 | } | } | 
 | } | } | 
 |  |  | 
 |  | void mousemng_enable(UINT proc) { | 
 |  |  | 
| BYTE mousemng_getstat(short *x, short *y, int clear) { | UINT    bit; | 
 |  |  | 
| *x = mousex; | bit = 1 << proc; | 
| *y = mousey; | if (mousemng.flag & bit) { | 
| if (clear) { | mousemng.flag &= ~bit; | 
| mousex = 0; | if (!mousemng.flag) { | 
| mousey = 0; | mousecapture(TRUE); | 
|  | } | 
 | } | } | 
 | return(mouseb); |  | 
 | } | } | 
 |  |  | 
 |  | void mousemng_disable(UINT proc) { | 
 |  |  | 
 |  | if (!mousemng.flag) { | 
 |  | mousecapture(FALSE); | 
 |  | } | 
 |  | mousemng.flag |= (1 << proc); | 
 |  | } | 
 |  |  | 
| BYTE mouse_btn(BYTE btn) { | void mousemng_toggle(UINT proc) { | 
 |  |  | 
| if (!(lastmouse & 1)) { | if (!mousemng.flag) { | 
| return(0); | mousecapture(FALSE); | 
 | } | } | 
| switch(btn) { | mousemng.flag ^= (1 << proc); | 
| case MOUSE_LEFTDOWN: | if (!mousemng.flag) { | 
| mouseb &= 0x7f; | mousecapture(TRUE); | 
| break; |  | 
| case MOUSE_LEFTUP: |  | 
| mouseb |= 0x80; |  | 
| break; |  | 
| case MOUSE_RIGHTDOWN: |  | 
| mouseb &= 0xdf; |  | 
| break; |  | 
| case MOUSE_RIGHTUP: |  | 
| mouseb |= 0x20; |  | 
| break; |  | 
 | } | } | 
 | return(1); |  | 
 | } | } | 
 |  |  |