|
|
| version 1.1.1.1, 2003/10/16 17:58:46 | version 1.4, 2003/11/09 21:57:04 |
|---|---|
| Line 3 | Line 3 |
| #include "mousemng.h" | #include "mousemng.h" |
| static BYTE mouserunning = 0; | typedef struct { |
| static BYTE lastmouse = 0; | SINT16 x; |
| static short mousex = 0; | SINT16 y; |
| static short mousey = 0; | BYTE btn; |
| static BYTE mouseb = 0xa0; | UINT flag; |
| } MOUSEMNG; | |
| static MOUSEMNG mousemng; | |
| BYTE 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) { |
| Line 19 static void getmaincenter(POINT *cp) { | Line 36 static void getmaincenter(POINT *cp) { |
| 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(hWndMain, GCL_STYLE); |
| lastmouse = (flg & 1); | if (capture) { |
| if (lastmouse & 1) { | ShowCursor(FALSE); |
| ShowCursor(FALSE); | getmaincenter(&cp); |
| getmaincenter(&cp); | rct.left = cp.x - 200; |
| rct.left = cp.x - 200; | rct.right = cp.x + 200; |
| rct.right = cp.x + 200; | rct.top = cp.y - 200; |
| rct.top = cp.y - 200; | rct.bottom = cp.y + 200; |
| rct.bottom = cp.y + 200; | SetCursorPos(cp.x, cp.y); |
| SetCursorPos(cp.x, cp.y); | ClipCursor(&rct); |
| ClipCursor(&rct); | style &= ~(CS_DBLCLKS); |
| } | } |
| else { | else { |
| ShowCursor(TRUE); | ShowCursor(TRUE); |
| ClipCursor(NULL); | ClipCursor(NULL); |
| } | style |= CS_DBLCLKS; |
| } | } |
| SetClassLong(hWndMain, GCL_STYLE, style); | |
| } | } |
| // --------------------------------------------------------------------------- | void mousemng_initialize(void) { |
| BYTE mouse_flag(void) { | ZeroMemory(&mousemng, sizeof(mousemng)); |
| mousemng.btn = uPD8255A_LEFTBIT | uPD8255A_RIGHTBIT; | |
| return(mouserunning); | #if 1 |
| mousemng.flag = (1 << MOUSEPROC_SYSTEM); | |
| #else | |
| mousemng.flag = (1 << MOUSEPROC_SYSTEM) + (1 << MOUSEPROC_WINUI) + | |
| (1 << MOUSEPROC_BG); | |
| #endif | |
| } | } |
| void mousemng_callback(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); | |
| } | } |