Added mouse support for linux. It is still rather crude, but it works.

Unfortunately the mouse pointer doesn't match up very well with the IR pointer yet.
Also, I had to add the PointerMotionMask to XSelectInput which adds overhead to the already stressed X event loops.  Five event loops by my count, really?


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4961 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Glenn Rice
2010-01-26 00:11:45 +00:00
parent dacc0a19a7
commit 727283c4de
5 changed files with 63 additions and 6 deletions

View File

@ -199,6 +199,10 @@ void LoadRecordedMovements()
}
}
#if defined(HAVE_X11) && HAVE_X11
MousePosition MousePos;
#endif
/* Calibrate the mouse position to the emulation window. g_WiimoteInitialize.hWnd is the rendering window handle. */
void GetMousePos(float& x, float& y)
{
@ -217,6 +221,14 @@ void GetMousePos(float& x, float& y)
float WinHeight = (float)(Rect.bottom - Rect.top);
float XOffset = 0, YOffset = 0;
float PictureWidth = WinWidth, PictureHeight = WinHeight;
#else
#if defined(HAVE_X11) && HAVE_X11
float WinWidth = (float)MousePos.WinWidth;
float WinHeight = (float)MousePos.WinHeight;
float XOffset = 0, YOffset = 0;
float PictureWidth = WinWidth, PictureHeight = WinHeight;
#endif
#endif
/* Calculate the actual picture size and location */
// Output: PictureWidth, PictureHeight, XOffset, YOffset
@ -283,6 +295,7 @@ void GetMousePos(float& x, float& y)
}
// Return the mouse position as a fraction of one, inside the picture, with (0.0, 0.0) being the upper left corner of the picture
#ifdef _WIN32
x = ((float)point.x - XOffset) / PictureWidth;
y = ((float)point.y - YOffset) / PictureHeight;
@ -291,11 +304,11 @@ void GetMousePos(float& x, float& y)
INFO_LOG(WIIMOTE, "GetClientRect: %i %i %i %i", Rect.left, Rect.right, Rect.top, Rect.bottom);
INFO_LOG(WIIMOTE, "Position X:%1.2f Y:%1.2f", x, y);
*/
#else
// TODO fix on linux
x = 0.5f;
y = 0.5f;
#if defined(HAVE_X11) && HAVE_X11
x = ((float)MousePos.x - XOffset) / PictureWidth;
y = ((float)MousePos.y - YOffset) / PictureHeight;
#endif
#endif
}
@ -696,6 +709,37 @@ void ReadLinuxKeyboard()
}
break;
}
case ButtonPress:
{
int button = ((XButtonEvent*)&E)->button;
if (button == 1)
KeyStatus[EWM_A] = true;
else if (button == 3)
KeyStatus[EWM_B] = true;
else
XPutBackEvent(WMdisplay, &E);
break;
}
case ButtonRelease:
{
int button = ((XButtonEvent*)&E)->button;
if (button == 1)
KeyStatus[EWM_A] = false;
else if (button == 3)
KeyStatus[EWM_B] = false;
else
XPutBackEvent(WMdisplay, &E);
break;
}
case MotionNotify:
{
MousePos.x = E.xmotion.x;
MousePos.y = E.xmotion.y;
XWindowAttributes WinAttribs;
XGetWindowAttributes (E.xmotion.display, E.xmotion.window, &WinAttribs);
MousePos.WinWidth = WinAttribs.width;
MousePos.WinHeight = WinAttribs.height;
}
default:
break;
}