private void Poll() { if (_numMice == 0) { // Refresh check for mice occassionally? } else { // TODO: should sometimes check if we lost a mouse and then send out a "lost mouse" signal in that mouse object // Signal to clear out old deltas for (int i = 0; i < _numMice; i++) { _manyMice[i].PollingReset(); } // Poll until empty ManyMouseEvent mouseEvent = new ManyMouseEvent(); int eventsLeft = ManyMouse_PollEvent(ref mouseEvent); while (eventsLeft > 0) { ProcessEvent(mouseEvent); eventsLeft = ManyMouse_PollEvent(ref mouseEvent); } } }
internal void ProcessEvent(ManyMouseEvent mouseEvent) { // I do not trigger events in here so that all changes since last polling are fully cached. switch (mouseEvent.type) { case ManyMouseEventType.MANYMOUSE_EVENT_ABSMOTION: // Absolute motion, set at the beginning maybe? Pos.x += mouseEvent.item == 0 ? mouseEvent.value : 0; Pos.y += mouseEvent.item == 1 ? mouseEvent.value : 0; if (mouseEvent.item == 0) { collateVector.x = mouseEvent.value; } if (mouseEvent.item == 1) { collateVector.y = mouseEvent.value; } break; case ManyMouseEventType.MANYMOUSE_EVENT_RELMOTION: // Relative motion: Movement since last polling Delta.x += mouseEvent.item == 0 ? mouseEvent.value : 0; Delta.y += mouseEvent.item == 1 ? -mouseEvent.value : 0; if (mouseEvent.item == 0) { collateVector.x = mouseEvent.value; } if (mouseEvent.item == 1) { collateVector.y = mouseEvent.value; } break; case ManyMouseEventType.MANYMOUSE_EVENT_BUTTON: MouseButtons[mouseEvent.item] = mouseEvent.value == 1; EventButtonChange(this, (int)mouseEvent.item, mouseEvent.value == 1); if (mouseEvent.value == 1) { EventButtonDown(this, (int)mouseEvent.item); } else { EventButtonUp(this, (int)mouseEvent.item); } break; case ManyMouseEventType.MANYMOUSE_EVENT_SCROLL: MouseWheel = mouseEvent.value; EventWheelScroll(this, mouseEvent.value); break; case ManyMouseEventType.MANYMOUSE_EVENT_DISCONNECT: EventMouseDisconnected(this); break; default: throw new ArgumentOutOfRangeException(); } if (mouseEvent.type == ManyMouseEventType.MANYMOUSE_EVENT_ABSMOTION && mouseEvent.item == 1) { EventMouseReposition(this, new Vector2()); } if (mouseEvent.type == ManyMouseEventType.MANYMOUSE_EVENT_RELMOTION && mouseEvent.item == 1) { EventMouseDelta(this, new Vector2()); } }
private static extern int ManyMouse_PollEvent(ref ManyMouseEvent mouseEvent);
// Note you'll be recieving this very rapidly! private void ProcessEvent(ManyMouseEvent mouseEvent) { _manyMice[(int)mouseEvent.device].ProcessEvent(mouseEvent); }