--- np2/macosx/mousemng.cpp 2003/10/23 06:26:16 1.4 +++ np2/macosx/mousemng.cpp 2003/11/12 19:56:50 1.6 @@ -1,147 +1,137 @@ - -#if defined(NP2GCC) - #include "compiler.h" #include "np2.h" #include "mousemng.h" -static BYTE mouserunning = 0; -static BYTE lastmouse = 0; -static short mousex = 0; -static short mousey = 0; -static BYTE mouseb = 0xa0; +typedef struct { + SINT16 x; + SINT16 y; + BYTE btn; + 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); - cp->h = (rct.right + rct.left) / 2; - cp->v = (rct.bottom + rct.top) / 2; + *x = mousemng.x; + *y = mousemng.y; + 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) { - lastmouse = (flg & 1); - if (lastmouse & 1) { - HideCursor(); - getmaincenter(&cp); - CGWarpMouseCursorPosition(CGPointMake(cp.h, cp.v)); - } - else { - ShowCursor(); - } - } + pt.x = (float)cp->h; + pt.y = (float)cp->v; + CGWarpMouseCursorPosition(pt); } -// --------------------------------------------------------------------------- +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) { - - BYTE mf = mouserunning; + Point cp; - switch(flg & 0xc0) { - case 0x00: - mf &= ~(1 << (flg & 7)); - break; - case 0x40: - mf ^= (1 << (flg & 7)); - break; - default: - mf |= (1 << (flg & 7)); - break; + if (capture) { + HideCursor(); + getmaincenter(&cp); + SetMouse(&cp); } - if ((mf ^ mouserunning) & MOUSE_MASK) { - mouserunning = (mf & MOUSE_MASK); - if (mouserunning == 1) { - mouseonoff(1); - } - else { - mouseonoff(0); - } + else { + ShowCursor(); } } +void mousemng_initialize(void) { -void mouse_callback(void) { - - Point cp; - CGMouseDelta x,y; - static CGMouseDelta pastx=0,pasty=0; - - if (lastmouse & 1) { - CGGetLastMouseDelta(&x, &y); - if ((pastx!=x) && (pasty!=y)) { - mousex += (short)x; - mousey += (short)y; - pastx = x; - pasty = y; - getmaincenter(&cp); - CGWarpMouseCursorPosition(CGPointMake(cp.h, cp.v)); - } - } + ZeroMemory(&mousemng, sizeof(mousemng)); + mousemng.btn = uPD8255A_LEFTBIT | uPD8255A_RIGHTBIT; + mousemng.flag = (1 << MOUSEPROC_SYSTEM); } +void mousemng_callback(HIPoint delta) { -BYTE mousemng_getstat(short *x, short *y, int clear) { + Point cp; - *x = mousex; - *y = mousey; - if (clear) { - mousex = 0; - mousey = 0; + if (!mousemng.flag) { + getmaincenter(&cp); + mousemng.x += (SINT16)delta.x; + mousemng.y += (SINT16)delta.y; + SetMouse(&cp); } - return(mouseb); } +BOOL mousemng_buttonevent(UINT event) { + + if (!mousemng.flag) { + switch(event) { + case MOUSEMNG_LEFTDOWN: + mousemng.btn &= ~(uPD8255A_LEFTBIT); + break; + case MOUSEMNG_LEFTUP: + mousemng.btn |= uPD8255A_LEFTBIT; + break; -BYTE mouse_btn(BYTE btn) { + case MOUSEMNG_RIGHTDOWN: + mousemng.btn &= ~(uPD8255A_RIGHTBIT); + break; - if (!(lastmouse & 1)) { - return(0); + case MOUSEMNG_RIGHTUP: + mousemng.btn |= uPD8255A_RIGHTBIT; + break; + } + return(TRUE); } - switch(btn) { - case MOUSE_LEFTDOWN: - mouseb &= 0x7f; - break; - case MOUSE_LEFTUP: - mouseb |= 0x80; - break; - case MOUSE_RIGHTDOWN: - mouseb &= 0xdf; - break; - case MOUSE_RIGHTUP: - mouseb |= 0x20; - break; + else { + return(FALSE); } - return(1); } -#else +void mousemng_enable(UINT proc) { -#include "compiler.h" -#include "mousemng.h" + UINT bit; -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; - *y = 0; - (void)clear; - return(0xa0); +void mousemng_disable(UINT proc) { + + if (!mousemng.flag) { + 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); + } +}