#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_WINDOWMESSAGEMOUSE_H #define NUCLEX_INPUT_DEVICES_WINDOWMESSAGEMOUSE_H #include "../Buffered/BufferedMouse.h" #define WIN32_LEAN_AND_MEAN #define VC_EXTRALEAN #include namespace Nuclex { namespace Input { namespace Devices { // ------------------------------------------------------------------------------------------- // /// Mouse that listens in on window messages class WindowMessageMouse : public BufferedMouse { /// Initializes a new window message based mouse /// Handle of the game's main window public: WindowMessageMouse(HWND windowHandle); /// Frees all resources used by the window message based mouse public: virtual ~WindowMessageMouse(); /// Updates the mouse's state in accordance to a window message /// Type of message being sent to the window /// First message-dependent parameter /// Second message-dependent parameter /// True if the message was consumed, false if not public: bool ProcessWindowMessage(UINT message, WPARAM parameter1, LPARAM parameter2); /// Locks the mouse cursor to the window for FPS control /// Whether to lock the mouse cursor to the window public: void SetLocked(bool locked = true); /// Whether the mouse cursor is currently locked to the window /// True if the mouse cursor is locked to the window, otherwise false public: bool IsLocked() const { return this->isLocked; } /// Whether the input device is currently attached /// True if the input device is attached, otherwise false public: bool IsAttached() const { return true; } /// Retrieves the human-readable name of the input device /// The human-readable name of the input device public: const std::string &GetName() const; /// Called when the window gains or loses the focus /// Describes what has happened to the window private: void windowActivationStateChanged(WORD activationAction); /// Processes raw input delivered to the process /// Handle for the raw input being delivered private: void processRawInput(HRAWINPUT rawInputHandle); /// Registers the window to receive raw input messages private: void registerForRawInput(); /// Called the mouseMoved() method if the cursor position has changed /// Contains the X and Y coordinate of the mouse private: void callMouseMovedIfPositionChanged(LPARAM parameter); /// Determines whether the mouse cursor is restricted currently /// True if the mouse cursor is restricted, false otherwise private: bool isMouseRestricted() const; /// Restricts the movement of the mouse cursor to the client area private: void restrictMouse(); /// Lets the mouse move across the whole screen again private: void freeMouse(); /// Begins tracking the mouse cursor for when it leaves the window private: void startTrackingMouseLeave(); /// Stops tracking the mouse cursor for when it leaves the window /// Whether to throw an exception when the method fails private: void stopTrackingMouseLeave(bool throwOnError = true); /// Determines a window's client area in screen coordinates /// A rectangle containing the bounds of the window's client area private: void updateClientRectangleInScreenCoordinates(); private: WindowMessageMouse(const WindowMessageMouse &); private: WindowMessageMouse &operator =(const WindowMessageMouse &); /// Handle of the game's main window private: HWND windowHandle; /// The current client rectangle of the window in screen coordinates private: RECT clientRectangleInScreenCoordinates; /// Used to be notified when the mouse leaves the client area private: TRACKMOUSEEVENT trackMouseEvent; /// Whether the user wants the mouse to be locked direct motion control private: bool isLocked; /// Whether the game's main window has the focus private: bool hasFocus; /// Whether the window is currently dealing with the menu loop private: bool isInsideMenuLoop; /// Whether the mouse is currently being tracked by the window private: bool isTrackingMouse; /// Whether the mouse cursor is inside the window's client area private: bool isMouseInsideClientArea; /// Last known X coordinate of the mouse cursor private: int lastKnownMouseX; /// Last known Y coordinate of the mouse cursor private: int lastKnownMouseY; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Input::Devices #endif // NUCLEX_INPUT_DEVICES_WINDOWMESSAGEMOUSE_H