--- np2/macosx/mousemng.cpp 2003/10/16 17:59:38 1.1 +++ np2/macosx/mousemng.cpp 2003/10/19 14:48:07 1.2 @@ -1,3 +1,134 @@ +#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; + + +static void getmaincenter(Point *cp) { + + Rect rct; + + GetWindowBounds(hWndMain, kWindowContentRgn, &rct); + cp->h = (rct.right + rct.left) / 2; + cp->v = (rct.bottom + rct.top) / 2; +} + + +void mouseonoff(BYTE flg) { + + Point cp; + + if ((lastmouse ^ flg) & 1) { + lastmouse = (flg & 1); + if (lastmouse & 1) { + CGDisplayHideCursor(kCGDirectMainDisplay); + getmaincenter(&cp); + CGWarpMouseCursorPosition(CGPointMake(cp.h, cp.v)); + } + else { + CGDisplayShowCursor(kCGDirectMainDisplay); + } + } +} + +// --------------------------------------------------------------------------- + +BYTE mouse_flag(void) { + + return(mouserunning); +} + + +void mouse_running(BYTE flg) { + + BYTE mf = mouserunning; + + switch(flg & 0xc0) { + case 0x00: + mf &= ~(1 << (flg & 7)); + break; + case 0x40: + 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); + } + } +} + + +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)); + } + } +} + + +BYTE mousemng_getstat(short *x, short *y, int clear) { + + *x = mousex; + *y = mousey; + if (clear) { + mousex = 0; + mousey = 0; + } + return(mouseb); +} + + + +BYTE mouse_btn(BYTE btn) { + + if (!(lastmouse & 1)) { + return(0); + } + 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; + } + return(1); +} + +#else #include "compiler.h" #include "mousemng.h" @@ -10,3 +141,4 @@ BYTE mousemng_getstat(SINT16 *x, SINT16 return(0xa0); } +#endif \ No newline at end of file