|
|
| version 1.5, 2003/10/24 12:35:19 | version 1.6, 2003/11/12 19:56:50 |
|---|---|
| Line 1 | Line 1 |
| #if defined(NP2GCC) | |
| #include "compiler.h" | #include "compiler.h" |
| #include "np2.h" | #include "np2.h" |
| #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; | |
| static void getmaincenter(Point *cp) { | |
| Rect rct; | BYTE mousemng_getstat(SINT16 *x, SINT16 *y, int clear) { |
| GetWindowBounds(hWndMain, kWindowContentRgn, &rct); | *x = mousemng.x; |
| cp->h = (rct.right + rct.left) / 2; | *y = mousemng.y; |
| cp->v = (rct.bottom + rct.top) / 2; | if (clear) { |
| mousemng.x = 0; | |
| mousemng.y = 0; | |
| } | |
| return(mousemng.btn); | |
| } | } |
| // ---- | |
| void mouseonoff(BYTE flg) { | static void SetMouse(const Point *cp) { |
| Point cp; | CGPoint pt; |
| if ((lastmouse ^ flg) & 1) { | pt.x = (float)cp->h; |
| lastmouse = (flg & 1); | pt.y = (float)cp->v; |
| if (lastmouse & 1) { | CGWarpMouseCursorPosition(pt); |
| HideCursor(); | |
| getmaincenter(&cp); | |
| CGWarpMouseCursorPosition(CGPointMake(cp.h, cp.v)); | |
| } | |
| else { | |
| ShowCursor(); | |
| } | |
| } | |
| } | } |
| // --------------------------------------------------------------------------- | static void getmaincenter(Point *cp) { |
| BYTE mouse_flag(void) { | Rect rct; |
| return(mouserunning); | GetWindowBounds(hWndMain, kWindowContentRgn, &rct); |
| cp->h = (rct.right + rct.left) / 2; | |
| cp->v = (rct.bottom + rct.top) / 2; | |
| } | } |
| static void mousecapture(BOOL capture) { | |
| void mouse_running(BYTE flg) { | Point cp; |
| BYTE mf = mouserunning; | |
| switch(flg & 0xc0) { | if (capture) { |
| case 0x00: | HideCursor(); |
| mf &= ~(1 << (flg & 7)); | getmaincenter(&cp); |
| break; | SetMouse(&cp); |
| case 0x40: | |
| mf ^= (1 << (flg & 7)); | |
| break; | |
| default: | |
| mf |= (1 << (flg & 7)); | |
| break; | |
| } | } |
| if ((mf ^ mouserunning) & MOUSE_MASK) { | else { |
| mouserunning = (mf & MOUSE_MASK); | ShowCursor(); |
| if (mouserunning == 1) { | |
| mouseonoff(1); | |
| } | |
| else { | |
| mouseonoff(0); | |
| } | |
| } | } |
| } | } |
| void mousemng_initialize(void) { | |
| ZeroMemory(&mousemng, sizeof(mousemng)); | |
| mousemng.btn = uPD8255A_LEFTBIT | uPD8255A_RIGHTBIT; | |
| mousemng.flag = (1 << MOUSEPROC_SYSTEM); | |
| } | |
| void mouse_callback(HIPoint delta) { | void mousemng_callback(HIPoint delta) { |
| Point cp; | Point cp; |
| if (lastmouse & 1) { | if (!mousemng.flag) { |
| mousex += (short)delta.x; | |
| mousey += (short)delta.y; | |
| getmaincenter(&cp); | getmaincenter(&cp); |
| CGWarpMouseCursorPosition(CGPointMake(cp.h, cp.v)); | mousemng.x += (SINT16)delta.x; |
| mousemng.y += (SINT16)delta.y; | |
| SetMouse(&cp); | |
| } | } |
| } | } |
| BOOL mousemng_buttonevent(UINT event) { | |
| BYTE mousemng_getstat(short *x, short *y, int clear) { | if (!mousemng.flag) { |
| switch(event) { | |
| *x = mousex; | case MOUSEMNG_LEFTDOWN: |
| *y = mousey; | mousemng.btn &= ~(uPD8255A_LEFTBIT); |
| if (clear) { | break; |
| mousex = 0; | |
| mousey = 0; | |
| } | |
| return(mouseb); | |
| } | |
| case MOUSEMNG_LEFTUP: | |
| mousemng.btn |= uPD8255A_LEFTBIT; | |
| break; | |
| BYTE mouse_btn(BYTE btn) { | case MOUSEMNG_RIGHTDOWN: |
| mousemng.btn &= ~(uPD8255A_RIGHTBIT); | |
| break; | |
| if (!(lastmouse & 1)) { | case MOUSEMNG_RIGHTUP: |
| return(0); | mousemng.btn |= uPD8255A_RIGHTBIT; |
| break; | |
| } | |
| return(TRUE); | |
| } | } |
| switch(btn) { | else { |
| case MOUSE_LEFTDOWN: | return(FALSE); |
| mouseb &= 0x7f; | |
| break; | |
| case MOUSE_LEFTUP: | |
| mouseb |= 0x80; | |
| break; | |
| case MOUSE_RIGHTDOWN: | |
| mouseb &= 0xdf; | |
| break; | |
| case MOUSE_RIGHTUP: | |
| mouseb |= 0x20; | |
| break; | |
| } | } |
| return(1); | |
| } | } |
| #else | void mousemng_enable(UINT proc) { |
| #include "compiler.h" | UINT bit; |
| #include "mousemng.h" | |
| BYTE mousemng_getstat(SINT16 *x, SINT16 *y, int clear) { | bit = 1 << proc; |
| if (mousemng.flag & bit) { | |
| mousemng.flag &= ~bit; | |
| if (!mousemng.flag) { | |
| mousecapture(TRUE); | |
| } | |
| } | |
| } | |
| *x = 0; | void mousemng_disable(UINT proc) { |
| *y = 0; | |
| (void)clear; | if (!mousemng.flag) { |
| return(0xa0); | mousecapture(FALSE); |
| } | |
| mousemng.flag |= (1 << proc); | |
| } | } |
| #endif | void mousemng_toggle(UINT proc) { |
| if (!mousemng.flag) { | |
| mousecapture(FALSE); | |
| } | |
| mousemng.flag ^= (1 << proc); | |
| if (!mousemng.flag) { | |
| mousecapture(TRUE); | |
| } | |
| } |