|
|
| version 1.1, 2003/11/26 15:08:42 | version 1.2, 2003/12/19 16:08:02 |
|---|---|
| Line 32 | Line 32 |
| #include "mousemng.h" | #include "mousemng.h" |
| #include "qt/xnp2.h" | #include "qt/xnp2.h" |
| #include "qt/qtdraw.h" | |
| #include <qcursor.h> | #include <qcursor.h> |
| static QWidget *pEmulationScreen = 0; | typedef struct { |
| static QCursor blankCursor(Qt::BlankCursor); | int mouserunning; // showing |
| int lastmouse; // working | |
| static BYTE mouse_move_ratio = MOUSE_RATIO_100; | short mousex; |
| static BYTE mouse_move_mul; | short mousey; |
| static BYTE mouse_move_div; | BYTE mouseb; |
| static int mouserunning = 0; // showing | BYTE mouse_move_ratio; |
| static int lastmouse = 0; // working | BYTE mouse_move_mul; |
| static short mousex = 0; | BYTE mouse_move_div; |
| static short mousey = 0; | |
| static BYTE mouseb = 0xa0; | QWidget *pEmulationScreen; |
| } mouse_stat_t; | |
| static mouse_stat_t ms_default = { | |
| 0, 0, 0, 0, 0xa0, | |
| MOUSE_RATIO_100, 1, 1, | |
| NULL, | |
| }; | |
| static mouse_stat_t ms; | |
| // | // |
| // Event | // Event |
| // | // |
| void | void |
| emulationWindow::mousePressEvent(QMouseEvent *ev) | emulationScreen::mousePressEvent(QMouseEvent *ev) |
| { | { |
| switch (ev->button() & MouseButtonMask) { | switch (ev->button() & MouseButtonMask) { |
| case LeftButton: | case Qt::LeftButton: |
| mouse_btn(MOUSE_LEFTDOWN); | mouse_btn(MOUSE_LEFTDOWN); |
| break; | break; |
| case MidButton: | case Qt::MidButton: |
| mouse_running(M_XOR); | mouse_running(M_XOR); |
| break; | break; |
| case RightButton: | case Qt::RightButton: |
| mouse_btn(MOUSE_RIGHTDOWN); | mouse_btn(MOUSE_RIGHTDOWN); |
| break; | break; |
| case NoButton: | case Qt::NoButton: |
| case MouseButtonMask: | case Qt::MouseButtonMask: |
| case ShiftButton: | case Qt::ShiftButton: |
| case ControlButton: | case Qt::ControlButton: |
| case MetaButton: | #if QT_VERSION >= 300 |
| case KeyButtonMask: | case Qt::MetaButton: |
| case Keypad: | #endif |
| case Qt::KeyButtonMask: | |
| case Qt::Keypad: | |
| default: | default: |
| break; | break; |
| } | } |
| } | } |
| void | void |
| emulationWindow::mouseReleaseEvent(QMouseEvent *ev) | emulationScreen::mouseReleaseEvent(QMouseEvent *ev) |
| { | { |
| switch (ev->button() & MouseButtonMask) { | switch (ev->button() & MouseButtonMask) { |
| case LeftButton: | case Qt::LeftButton: |
| mouse_btn(MOUSE_LEFTUP); | mouse_btn(MOUSE_LEFTUP); |
| break; | break; |
| case MidButton: | case Qt::MidButton: |
| break; | break; |
| case RightButton: | case Qt::RightButton: |
| mouse_btn(MOUSE_RIGHTUP); | mouse_btn(MOUSE_RIGHTUP); |
| break; | break; |
| case NoButton: | case Qt::NoButton: |
| case MouseButtonMask: | case Qt::MouseButtonMask: |
| case ShiftButton: | case Qt::ShiftButton: |
| case ControlButton: | case Qt::ControlButton: |
| case MetaButton: | #if QT_VERSION >= 300 |
| case KeyButtonMask: | case Qt::MetaButton: |
| case Keypad: | #endif |
| case Qt::KeyButtonMask: | |
| case Qt::Keypad: | |
| default: | default: |
| break; | break; |
| } | } |
| Line 117 int | Line 130 int |
| mousemng_initialize(void) | mousemng_initialize(void) |
| { | { |
| pEmulationScreen = (QWidget *)np2EmulationWindow->getEmulationScreen(); | ms = ms_default; |
| ms.pEmulationScreen = (QWidget *)np2EmulationWindow->getEmulationScreen(); | |
| return SUCCESS; | return SUCCESS; |
| } | } |
| Line 131 static void | Line 145 static void |
| getmaincenter(int *cx, int *cy) | getmaincenter(int *cx, int *cy) |
| { | { |
| *cx = pEmulationScreen->width() / 2; | *cx = ms.pEmulationScreen->width() / 2; |
| *cy = pEmulationScreen->height() / 2; | *cy = ms.pEmulationScreen->height() / 2; |
| } | } |
| static void | static void |
| Line 140 mouseonoff(int flag) | Line 154 mouseonoff(int flag) |
| { | { |
| int curx, cury; | int curx, cury; |
| if ((lastmouse ^ flag) & 1) { | if ((ms.lastmouse ^ flag) & 1) { |
| lastmouse = flag & 1; | ms.lastmouse = flag & 1; |
| if (lastmouse) { | if (ms.lastmouse) { |
| pEmulationScreen->grabMouse(blankCursor); | ms.pEmulationScreen->grabMouse(Qt::blankCursor); |
| getmaincenter(&curx, &cury); | getmaincenter(&curx, &cury); |
| qt_setPointer(pEmulationScreen, curx, cury); | qt_setPointer(ms.pEmulationScreen, curx, cury); |
| } else { | } else { |
| pEmulationScreen->releaseMouse(); | ms.pEmulationScreen->releaseMouse(); |
| } | } |
| } | } |
| } | } |
| Line 156 BYTE | Line 170 BYTE |
| mouse_flag(void) | mouse_flag(void) |
| { | { |
| return mouserunning; | return ms.mouserunning; |
| } | } |
| void | void |
| mouse_running(BYTE flg) | mouse_running(BYTE flg) |
| { | { |
| BYTE mf = mouserunning; | BYTE mf = ms.mouserunning; |
| switch (flg & 0xc0) { | switch (flg & 0xc0) { |
| case M_RES: | case M_RES: |
| Line 178 mouse_running(BYTE flg) | Line 192 mouse_running(BYTE flg) |
| break; | break; |
| } | } |
| if ((mf ^ mouserunning) & MOUSE_MASK) { | if ((mf ^ ms.mouserunning) & MOUSE_MASK) { |
| mouserunning = (mf & MOUSE_MASK); | ms.mouserunning = (mf & MOUSE_MASK); |
| mouseonoff((mouserunning == 1) ? 1 : 0); | mouseonoff((ms.mouserunning == 1) ? 1 : 0); |
| } | } |
| } | } |
| Line 190 mousemng_callback(void) | Line 204 mousemng_callback(void) |
| int wx, wy; | int wx, wy; |
| int cx, cy; | int cx, cy; |
| if (lastmouse & 1) { | if (ms.lastmouse & 1) { |
| qt_getPointer(pEmulationScreen, &wx, &wy); | qt_getPointer(ms.pEmulationScreen, &wx, &wy); |
| getmaincenter(&cx, &cy); | getmaincenter(&cx, &cy); |
| mousex += (short)((wx - cx) / 2); | ms.mousex += (short)((wx - cx) / 2); |
| mousey += (short)((wy - cy) / 2); | ms.mousey += (short)((wy - cy) / 2); |
| qt_setPointer(pEmulationScreen, cx, cy); | qt_setPointer(ms.pEmulationScreen, cx, cy); |
| } | } |
| } | } |
| Line 203 BYTE | Line 217 BYTE |
| mouse_btn(BYTE button) | mouse_btn(BYTE button) |
| { | { |
| if ((lastmouse & 1) == 0) | if ((ms.lastmouse & 1) == 0) |
| return 0; | return 0; |
| switch (button) { | switch (button) { |
| case MOUSE_LEFTDOWN: | case MOUSE_LEFTDOWN: |
| mouseb &= 0x7f; | ms.mouseb &= 0x7f; |
| break; | break; |
| case MOUSE_LEFTUP: | case MOUSE_LEFTUP: |
| mouseb |= 0x80; | ms.mouseb |= 0x80; |
| break; | break; |
| case MOUSE_RIGHTDOWN: | case MOUSE_RIGHTDOWN: |
| mouseb &= 0xdf; | ms.mouseb &= 0xdf; |
| break; | break; |
| case MOUSE_RIGHTUP: | case MOUSE_RIGHTUP: |
| mouseb |= 0x20; | ms.mouseb |= 0x20; |
| break; | break; |
| } | } |
| return 1; | return 1; |
| Line 230 BYTE | Line 244 BYTE |
| mousemng_getstat(short *x, short *y, int clear) | mousemng_getstat(short *x, short *y, int clear) |
| { | { |
| if (mouse_move_ratio == MOUSE_RATIO_100) { | if (ms.mouse_move_ratio == MOUSE_RATIO_100) { |
| *x = mousex; | *x = ms.mousex; |
| *y = mousey; | *y = ms.mousey; |
| } else if (mouse_move_div == 1) { | } else if (ms.mouse_move_div == 1) { |
| *x = mousex * mouse_move_mul; | *x = ms.mousex * ms.mouse_move_mul; |
| *y = mousey * mouse_move_mul; | *y = ms.mousey * ms.mouse_move_mul; |
| } else { | } else { |
| *x = (mousex * mouse_move_mul) / mouse_move_div; | *x = (ms.mousex * ms.mouse_move_mul) / ms.mouse_move_div; |
| *y = (mousey * mouse_move_mul) / mouse_move_div; | *y = (ms.mousey * ms.mouse_move_mul) / ms.mouse_move_div; |
| } | } |
| if (clear) { | if (clear) { |
| mousex = 0; | ms.mousex = 0; |
| mousey = 0; | ms.mousey = 0; |
| } | } |
| return mouseb; | return ms.mouseb; |
| } | } |
| void | void |
| Line 252 mousemng_set_ratio(BYTE new_ratio) | Line 266 mousemng_set_ratio(BYTE new_ratio) |
| { | { |
| np2oscfg.mouse_move_ratio = new_ratio; | np2oscfg.mouse_move_ratio = new_ratio; |
| mouse_move_ratio = np2oscfg.mouse_move_ratio; | ms.mouse_move_ratio = np2oscfg.mouse_move_ratio; |
| mouse_move_mul = (mouse_move_ratio >> 4) & 0xf; | ms.mouse_move_mul = (ms.mouse_move_ratio >> 4) & 0xf; |
| mouse_move_div = mouse_move_ratio & 0xf; | ms.mouse_move_div = ms.mouse_move_ratio & 0xf; |
| } | } |