// SPDX-FileCopyrightText: 2021 Jorrit Rouwe // SPDX-License-Identifier: MIT #pragma once // We're using DX8's DirectInput API #define DIRECTINPUT_VERSION 0x0800 #include class Renderer; /// Mouse interface class, keeps track of the mouse button state and of the absolute and relative movements of the mouse. class Mouse { public: /// Constructor Mouse(); ~Mouse(); /// Initialization / shutdown bool Initialize(Renderer *inWindow); void Shutdown(); /// Update the mouse state void Poll(); int GetX() const { return mMousePos.x; } int GetY() const { return mMousePos.y; } int GetDX() const { return mMouseState.lX; } int GetDY() const { return mMouseState.lY; } bool IsLeftPressed() const { return (mMouseState.rgbButtons[0] & 0x80) != 0; } bool IsRightPressed() const { return (mMouseState.rgbButtons[1] & 0x80) != 0; } bool IsMiddlePressed() const { return (mMouseState.rgbButtons[2] & 0x80) != 0; } bool IsLeftDoubleClicked() const { return mLeftButtonDoubleClicked; } void HideCursor(); void ShowCursor(); void SetExclusive(bool inExclusive = true); private: void Reset(); void ResetMouse(); enum { BUFFERSIZE = 64, ///< Number of keys cached DCLICKTIME = 300 ///< Minimum time between key release and key down to make it a double click }; Renderer * mRenderer; ComPtr mDI; ComPtr mMouse; DIMOUSESTATE mMouseState; bool mMousePosInitialized = false; POINT mMousePos; DIDEVICEOBJECTDATA mDOD[BUFFERSIZE]; DWORD mDODLength; int mTimeLeftButtonLastReleased; bool mLeftButtonDoubleClicked; };