/// <summary> /// Converts an LParam representing a Point to a C# point. Equivalent /// to the standard LPARAM macros in winuser.h /// </summary> public static System.Drawing.Point LParamToPoint(System.IntPtr lParam) { long lParam64 = lParam.ToInt64(); return new System.Drawing.Point((int) (lParam64 & 0x0000FFFF), (int) (lParam64 >> 16)); }
private static Engine.Joystick GetJoystick(System.IntPtr device) { foreach (Engine.Joystick joystick in engine.joysticks) { if (joystick != null) { if (joystick.id == device.ToInt64 ()) { return joystick; } } } return null; }
private static void DeviceAdded(System.IntPtr context, System.IntPtr res, System.IntPtr sender, System.IntPtr device) { if (MacNative.IOHIDDeviceOpen (device, IntPtr.Zero) == IntPtr.Zero) { if (MacNative.IOHIDDeviceConformsTo (device, HIDDesktop, HIDJoystick) || MacNative.IOHIDDeviceConformsTo (device, HIDDesktop, HIDGamePad) || MacNative.IOHIDDeviceConformsTo (device, HIDDesktop, HIDMultiAxis) || MacNative.IOHIDDeviceConformsTo (device, HIDDesktop, HIDWheel)) { System.IntPtr product = MacNative.IOHIDDeviceGetProperty (device, MacNative.CFString ("Product")); string productName = MacNative.CString (product); int index = 0; foreach (Engine.Joystick joystick in engine.joysticks) { if (joystick == null) { engine.joysticks [index] = new Engine.Joystick (); engine.joysticks [index].index = index; engine.joysticks [index].id = device.ToInt64 (); engine.joysticks [index].name = productName; MacNative.IOHIDDeviceRegisterInputValueCallback (device, DeviceInputCallback, device); MacNative.IOHIDDeviceScheduleWithRunLoop (device, runLoop, defaultLoopMode); return; } index++; } } MacNative.IOHIDDeviceClose (device, IntPtr.Zero); } }
private static void DeviceRemoved(System.IntPtr context, System.IntPtr res, System.IntPtr sender, System.IntPtr device) { foreach (Engine.Joystick joystick in engine.joysticks) { if (joystick != null) { if (joystick.id == device.ToInt64 ()) { engine.joysticks [joystick.index] = null; MacNative.IOHIDDeviceRegisterInputValueCallback (device, IntPtr.Zero, IntPtr.Zero); MacNative.IOHIDDeviceUnscheduleFromRunLoop (device, runLoop, defaultLoopMode); MacNative.IOHIDDeviceClose (device, IntPtr.Zero); return; } } } }