#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 #ifndef NUCLEX_INPUT_DEVICES_BUFFEREDKEYBOARD_H #define NUCLEX_INPUT_DEVICES_BUFFEREDKEYBOARD_H #include "Nuclex/Input/Devices/Keyboard.h" #include "../../ConcurrentQueue.h" namespace Nuclex { namespace Input { namespace Devices { // ------------------------------------------------------------------------------------------- // /// Keyboard that buffers changes until an Update call happens class BufferedKeyboard : public Keyboard { /// A snapshot has been recorded private: static const int SnapshotNotification = 0; /// Key has been pressed private: static const int KeyPressNotification = 1; /// Key has been pressed private: static const int KeyReleaseNotification = 2; /// Character has been entered private: static const int CharacterEntryNotification = 3; #pragma region struct Event /// Stores a buffered change notification private: struct Event { /// Type of event that has been recorded public: int Type; union { /// Key that has been pressed or released public: Key::Enum PressedOrReleasedKey; /// Character that has been entered public: wchar_t EnteredCharacter; }; }; #pragma endregion // struct Event /// Initializes a new buffered keyboard protected: BufferedKeyboard() {} /// Frees all resources owned by the buffered keyboard public: virtual ~BufferedKeyboard() {} /// Retrieves the current state of the input device /// The input device's current state public: virtual const KeyboardState &GetState() const { return this->currentState; } /// Buffers a key press notification /// Key that has been pressed protected: void BufferKeyPress(Key::Enum pressedKey); /// Buffers a key release notification /// Key that has been released protected: void BufferKeyRelease(Key::Enum releasedKey); /// Buffers a character entry notification /// Character that has been entered protected: void BufferCharacterEntry(wchar_t enteredCharacter); /// Updates the state of the input device protected: void Update(); /// Takes a snapshot of the input device's current state protected: void TakeSnapshot(); /// Removes all snapshots the device has taken protected: void ClearSnapshots(); /// Plays back an event, updating the keyboard's state /// Event that will be played back private: void playbackEvent(const Event &recordedEvent); private: BufferedKeyboard(const BufferedKeyboard &); private: BufferedKeyboard &operator =(const BufferedKeyboard &); /// Events that have been buffered private: ConcurrentQueue bufferedEvents; /// Current state of the keyboard private: KeyboardState currentState; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Input::Devices #endif // NUCLEX_INPUT_DEVICES_BUFFEREDKEYBOARD_H