#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2013 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License // If the library is compiled as a DLL, this ensures symbols are exported #define NUCLEX_INPUT_SOURCE 1 #include "BufferedMouse.h" namespace Nuclex { namespace Input { namespace Devices { // ------------------------------------------------------------------------------------------- // void BufferedMouse::BufferButtonPress(MouseButtons::Enum pressedButton) { Event buttonPressEvent; buttonPressEvent.Type = ButtonPressNotification; buttonPressEvent.State.PressedOrReleasedButtons = pressedButton; this->bufferedEvents.Add(buttonPressEvent); } // ------------------------------------------------------------------------------------------- // void BufferedMouse::BufferButtonRelease(MouseButtons::Enum releasedButton) { Event buttonReleaseEvent; buttonReleaseEvent.Type = ButtonPressNotification; buttonReleaseEvent.State.PressedOrReleasedButtons = releasedButton; this->bufferedEvents.Add(buttonReleaseEvent); } // ------------------------------------------------------------------------------------------- // void BufferedMouse::BufferCursorMovement(int x, int y) { Event cursorMoveEvent; cursorMoveEvent.Type = CursorMoveNotification; cursorMoveEvent.State.Position.X = x; cursorMoveEvent.State.Position.Y = y; this->bufferedEvents.Add(cursorMoveEvent); } // ------------------------------------------------------------------------------------------- // void BufferedMouse::BufferMovement(float deltaX, float deltaY) { Event movementEvent; movementEvent.Type = MoveNotification; movementEvent.State.Movement.DeltaX = deltaX; movementEvent.State.Movement.DeltaY = deltaY; this->bufferedEvents.Add(movementEvent); } // ------------------------------------------------------------------------------------------- // void BufferedMouse::BufferWheelRotation(float delta) { Event wheelRotationEvent; wheelRotationEvent.Type = WheelRotationNotification; wheelRotationEvent.State.WheelDelta = delta; this->bufferedEvents.Add(wheelRotationEvent); } // ------------------------------------------------------------------------------------------- // void BufferedMouse::Update() { Event nextRecordedEvent; while(this->bufferedEvents.TryPop(nextRecordedEvent)) { if(nextRecordedEvent.Type == SnapshotNotification) { break; } playbackEvent(nextRecordedEvent); } } // ------------------------------------------------------------------------------------------- // void BufferedMouse::TakeSnapshot() { Event snapshotEvent; snapshotEvent.Type = SnapshotNotification; this->bufferedEvents.Add(snapshotEvent); } // ------------------------------------------------------------------------------------------- // void BufferedMouse::ClearSnapshots() { Event nextRecordedEvent; while(this->bufferedEvents.TryPop(nextRecordedEvent)) { playbackEvent(nextRecordedEvent); } } // ------------------------------------------------------------------------------------------- // void BufferedMouse::playbackEvent(const BufferedMouse::Event &recordedEvent) { switch(recordedEvent.Type) { case ButtonPressNotification: { playbackButtonPressEvent(recordedEvent); break; } case ButtonReleaseNotification: { playbackButtonReleaseEvent(recordedEvent); break; } case CursorMoveNotification: { this->currentState.X = recordedEvent.State.Position.X; this->currentState.Y = recordedEvent.State.Position.Y; CursorMoved(recordedEvent.State.Position.X, recordedEvent.State.Position.Y); break; } case MoveNotification: { Moved(recordedEvent.State.Movement.DeltaX, recordedEvent.State.Movement.DeltaY); break; } case WheelRotationNotification: { WheelRotated(recordedEvent.State.WheelDelta); break; } } } // ------------------------------------------------------------------------------------------- // void BufferedMouse::playbackButtonPressEvent(const BufferedMouse::Event &buttonPressEvent) { MouseButtons::Enum pressedButtons = buttonPressEvent.State.PressedOrReleasedButtons; if(pressedButtons & MouseButtons::Left) { this->currentState.LeftButton = true; } if(pressedButtons & MouseButtons::Right) { this->currentState.RightButton = true; } if(pressedButtons & MouseButtons::Middle) { this->currentState.MiddleButton = true; } if(pressedButtons & MouseButtons::X1) { this->currentState.XButton1 = true; } if(pressedButtons & MouseButtons::X2) { this->currentState.XButton2 = true; } ButtonPressed(pressedButtons); } // ------------------------------------------------------------------------------------------- // void BufferedMouse::playbackButtonReleaseEvent(const BufferedMouse::Event &buttonReleaseEvent) { MouseButtons::Enum releasedButtons = buttonReleaseEvent.State.PressedOrReleasedButtons; if(releasedButtons & MouseButtons::Left) { this->currentState.LeftButton = false; } if(releasedButtons & MouseButtons::Right) { this->currentState.RightButton = false; } if(releasedButtons & MouseButtons::Middle) { this->currentState.MiddleButton = false; } if(releasedButtons & MouseButtons::X1) { this->currentState.XButton1 = false; } if(releasedButtons & MouseButtons::X2) { this->currentState.XButton2 = false; } ButtonReleased(releasedButtons); } // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Input::Devices