Class for mouse input. More...
Classes | |
struct | DeviceStruct |
union | MouseEvent_t |
Public Types | |
enum | { MOUSEBUFFSIZE =128 } |
enum | eMouseButtons { BUTTON_LEFT =0x1 , BUTTON_RIGHT =0x2 , BUTTON_MIDDLE =0x4 , BUTTON_4 =0x8 , BUTTON_5 =0x10 , BUTTON_6 =0x20 , BUTTON_7 =0x40 , BUTTON_8 =0x80 , BUTTON_9 =0x100 , BUTTON_10 =0x200 , BUTTON_11 =0x400 , BUTTON_12 =0x800 , BUTTON_13 =0x1000 , BUTTON_14 =0x2000 , BUTTON_15 =0x4000 , BUTTON_16 =0x8000 } |
enum | { MAX_MOUSE_DEVICE_COUNT =8 } |
Public Member Functions | |
const Burger::StaticRTTI * | get_StaticRTTI (void) const noexcept override |
Get the description to the class. | |
Mouse (GameApp *pGameApp) | |
Initialize the mouse device for input. | |
virtual | ~Mouse () |
Release the mouse device. | |
uint_t | PeekMouseEvent (MouseEvent_t *pEvent) |
Peek at the next mouse event. | |
uint_t | GetMouseEvent (MouseEvent_t *pEvent) |
Get the next mouse event. | |
uint_t | IsPresent (void) const |
Detect if a mouse is plugged in. | |
uint32_t | ReadButtons (void) |
Return the buttons pressed. | |
uint32_t | ReadButtonDowns (void) |
Return the buttons clicked. | |
void | Read (uint32_t *pX, uint32_t *pY) |
Return the current mouse location. | |
void | Read (int32_t *pX, int32_t *pY) |
Return the mouse motion. | |
int32_t | ReadWheelX (void) |
Return the mouse horizontal scroll wheel. | |
int32_t | ReadWheelY (void) |
Return the mouse vertical scroll wheel. | |
void | SetRange (uint32_t x, uint32_t y) |
Set the range of the mouse cursor. | |
void | PostMousePosition (uint32_t x, uint32_t y, uint32_t uMSTimeStamp=0) |
Set the location of the mouse cursor. | |
void | PostMouseMotion (int32_t x, int32_t y, uint32_t uMSTimeStamp=0) |
Set the location of the mouse cursor. | |
void | PostMouseDown (uint32_t uMouseBits, uint32_t uMSTimeStamp=0) |
Post a mouse button down event. | |
void | PostMouseUp (uint32_t uMouseBits, uint32_t uMSTimeStamp=0) |
Post a mouse button up event. | |
void | PostMouseWheel (int32_t iWheelXMovement, int32_t iWheelYMovement, uint32_t uMSTimeStamp=0) |
Manually move the mouse wheel. | |
uint_t | PostMouseEvent (const EventHeader_t *pEvent) |
Post a mouse event. | |
void | AcquireDirectInput (void) noexcept |
Acquire DirectInput (Windows only) | |
void | UnacquireDirectInput (void) noexcept |
Release DirectInput (Windows only) | |
void | ReadSystemMouseValues (void) noexcept |
Read System mouse constants (Windows only) | |
Public Member Functions inherited from Burger::Base | |
const char * | get_class_name (void) const noexcept |
Get the name of the class. | |
virtual | ~Base () noexcept=default |
Destructor. | |
Static Public Member Functions | |
static void | EnumerationCallback (void *pData, int iReturn, void *pSender, __IOHIDDevice *pDevice) |
static void | DisconnectionCallback (void *pData, int iReturn, void *pSender) |
static void | InputCallback (void *pData, int iReturn, void *pSender, __IOHIDValue *pValue) |
static RunQueue::eReturnCode | Poll (void *pData) noexcept |
Static Public Attributes | |
static const Burger::StaticRTTI | g_StaticRTTI |
Static Public Attributes inherited from Burger::Base | |
static const Burger::StaticRTTI | g_StaticRTTI |
The global description of the class. | |
Static Protected Member Functions | |
static uintptr_t | WindowsMouseThread (void *pData) |
Windows thread for monitoring mouse events (Windows only) | |
Protected Attributes | |
GameApp * | m_pGameApp |
Application instance. | |
Mutex | m_MouseLock |
Lock for multi-threading. | |
IDirectInputDevice8W * | m_pMouseDevice |
Direct input device (Windows only) | |
void * | m_pMouseEvent |
Event signal for DirectInput (Windows only) | |
Thread | m_MouseThread |
Asynchronous thread monitoring DirectInput (Windows only) | |
uint_t | m_bAcquired |
TRUE if DirectInput8 is active (Windows only) | |
volatile uint32_t | m_bQuit |
TRUE when the thread is shutting down (Windows only) | |
__IOHIDManager * | m_pHIDManager |
HID Manager pointer. | |
DeviceStruct | m_Mice [MAX_MOUSE_DEVICE_COUNT] |
Array of mice devices. | |
uint_t | m_uMiceCount |
Number of mice devices found. | |
uint32_t | m_uX |
Current X coordinate of the mouse. | |
uint32_t | m_uY |
Current Y coordinate of the mouse. | |
uint32_t | m_uBoundsX |
Screen width bounds for the mouse. | |
uint32_t | m_uBoundsY |
Screen height bounds for the mouse. | |
int32_t | m_iDeltaX |
Accumulated X motion of the mouse. | |
int32_t | m_iDeltaY |
Accumulated Y motion of the mouse. | |
int32_t | m_iMouseWheelX |
Accumulated X motion of the mouse wheel. | |
int32_t | m_iMouseWheelY |
Accumulated Y motion of the mouse wheel. | |
uint32_t | m_uButtons |
Current state of the mouse buttons. | |
uint32_t | m_uPressedButtons |
Mouse buttons pressed since last read. | |
uint_t | m_bButtonSwap |
Switch the left and right buttons for lefties. | |
uint_t | m_uArrayStart |
Read index for m_KeyEvents. | |
uint_t | m_uArrayEnd |
Write index for m_KeyEvents. | |
MouseEvent_t | m_MouseEvents [MOUSEBUFFSIZE] |
Circular buffer holding mouse events. | |
Private Member Functions | |
Mouse (const Mouse &)=delete | |
Mouse & | operator= (const Mouse &)=delete |
Mouse (Mouse &&)=delete | |
Mouse & | operator= (Mouse &&)=delete |
Class for mouse input.
This class will handle the reading of mouse input on platforms that support mice.
On some platforms, the reading of the mouse is handled by a background thread for low latency.
|
privatedelete |
|
privatedelete |
Burger::Mouse::Mouse | ( | GameApp * | pGameApp | ) |
Initialize the mouse device for input.
Open the mouse device driver (if needed) and prepare for input
pGameApp | Pointer to the GameApp of the game that's requesting input. |
|
virtual |
Release the mouse device.
Close the mouse device driver (if needed)
|
noexcept |
Acquire DirectInput (Windows only)
Call Acquire() on the DirectInput mouse device.
|
static |
|
static |
|
overridevirtualnoexcept |
Get the description to the class.
This virtual function will pull the pointer to the StaticRTTI instance that has the name of the class. Due to it being virtual, it will be the name of the most derived class.
Reimplemented from Burger::Base.
uint_t BURGER_API Burger::Mouse::GetMouseEvent | ( | MouseEvent_t * | pEvent | ) |
Get the next mouse event.
See if an event is pending from the mouse, if so, return the event after removing it from the queue.
pEvent | Pointer to a buffer to receive the event |
|
static |
uint_t Burger::Mouse::IsPresent | ( | void | ) | const |
uint_t BURGER_API Burger::Mouse::PeekMouseEvent | ( | MouseEvent_t * | pEvent | ) |
Peek at the next mouse event.
See if an event is pending from the mouse, if so, return the event without removing it from the queue.
pEvent | Pointer to a buffer to receive the event |
|
staticnoexcept |
void BURGER_API Burger::Mouse::PostMouseDown | ( | uint32_t | uMouseBits, |
uint32_t | uMSTimeStamp = 0 ) |
Post a mouse button down event.
Manually post a mouse button down event.
uMouseBits | eMouseButtons enumeration of mouse buttons |
uMSTimeStamp | Timestamp in Milliseconds, 0 will fill in the value from Tick::read_ms() |
uint_t BURGER_API Burger::Mouse::PostMouseEvent | ( | const EventHeader_t * | pEvent | ) |
Post a mouse event.
Post the event in the ring buffer and update the current mouse state
pEvent | Pointer to a filled in Mouse event |
void BURGER_API Burger::Mouse::PostMouseMotion | ( | int32_t | x, |
int32_t | y, | ||
uint32_t | uMSTimeStamp = 0 ) |
Set the location of the mouse cursor.
Set's the location of the mouse cursor. It will be clamped by the cursor bounds.
x | X coordinate of the mouse cursor in pixels |
y | Y coordinate of the mouse cursor in pixels |
uMSTimeStamp | Timestamp in Milliseconds, 0 will fill in the value from Tick::read_ms() |
void BURGER_API Burger::Mouse::PostMousePosition | ( | uint32_t | x, |
uint32_t | y, | ||
uint32_t | uMSTimeStamp = 0 ) |
Set the location of the mouse cursor.
Set's the location of the mouse cursor. It will be clamped by the cursor bounds.
x | X coordinate of the mouse cursor in pixels |
y | Y coordinate of the mouse cursor in pixels |
uMSTimeStamp | Timestamp in Milliseconds, 0 will fill in the value from Tick::read_ms() |
void BURGER_API Burger::Mouse::PostMouseUp | ( | uint32_t | uMouseBits, |
uint32_t | uMSTimeStamp = 0 ) |
Post a mouse button up event.
Manually post a mouse button up event.
uMouseBits | eMouseButtons enumeration of mouse buttons |
uMSTimeStamp | Timestamp in Milliseconds, 0 will fill in the value from Tick::read_ms() |
void BURGER_API Burger::Mouse::PostMouseWheel | ( | int32_t | iWheelXMovement, |
int32_t | iWheelYMovement, | ||
uint32_t | uMSTimeStamp = 0 ) |
Manually move the mouse wheel.
Move the mouse wheels. The first value is for VERTICAL motion and the second is horizontal
iWheelYMovement | Motion for the vertical mouse wheel |
iWheelXMovement | Motion for the horizontal mouse wheel |
uMSTimeStamp | Timestamp in Milliseconds, 0 will fill in the value from Tick::read_ms() |
void BURGER_API Burger::Mouse::Read | ( | int32_t * | pX, |
int32_t * | pY ) |
Return the mouse motion.
Set the mouse to relative tracking mode and return the amount of motion the mouse has made since the last time it was read.
pX | Pointer to a value to receive the X coordinate of the mouse delta or NULL if this value is not requested |
pY | Pointer to a value to receive the Y coordinate of the mouse delta or NULL if this value is not requested |
void BURGER_API Burger::Mouse::Read | ( | uint32_t * | pX, |
uint32_t * | pY ) |
Return the current mouse location.
Set the mouse to cursor tracking mode and return the current location of the mouse cursor on the screen
pX | Pointer to a value to receive the X coordinate of the mouse cursor or NULL if this value is not requested |
pY | Pointer to a value to receive the Y coordinate of the mouse cursor or NULL if this value is not requested |
uint32_t BURGER_API Burger::Mouse::ReadButtonDowns | ( | void | ) |
Return the buttons clicked.
Since the last time this function was called, set bits for which mouse buttons were pressed and then clear the flags. This function is used to handle mouse press events without the overhead of having to monitor for a mouse up / down cycle.
uint32_t BURGER_API Burger::Mouse::ReadButtons | ( | void | ) |
Return the buttons pressed.
Return the state of the mouse buttons at this precise moment.
|
noexcept |
Read System mouse constants (Windows only)
On startup and when a WM_SETTINGCHANGE event is triggered, read the settings for the mouse button swap from Windows and record it so left/right is as the user requested it.
int32_t BURGER_API Burger::Mouse::ReadWheelX | ( | void | ) |
Return the mouse horizontal scroll wheel.
For some mice, the Apple Mighty Mouse for example, have a scroll ball which returns horizontal motion. This function returns that value.
int32_t BURGER_API Burger::Mouse::ReadWheelY | ( | void | ) |
Return the mouse vertical scroll wheel.
Most mice have a vertical scroll wheel. Return the motion delta.
void BURGER_API Burger::Mouse::SetRange | ( | uint32_t | uBoundsX, |
uint32_t | uBoundsY ) |
Set the range of the mouse cursor.
On full screen applications, or systems where the mouse driver is completely handled by Burgerlib, set the range of motion for the mouse so the driver can properly clamp the cursor to the screen bounds.
uBoundsX | Width of the screen in pixels |
uBoundsY | Height of the screen in pixels |
|
noexcept |
Release DirectInput (Windows only)
Call Unacquire() on the DirectInput mouse device.
|
staticprotected |
Windows thread for monitoring mouse events (Windows only)
Burgerlib reads mouse events using DirectInput and asynchronous thread events.
This function runs as a separate thread and processes all DirectInput events.
pData | Pointer to the Mouse class instance |
|
static |
|
protected |
TRUE when the thread is shutting down (Windows only)
|
protected |
Accumulated X motion of the mouse.
|
protected |
Accumulated Y motion of the mouse.
|
protected |
Accumulated X motion of the mouse wheel.
|
protected |
Accumulated Y motion of the mouse wheel.
|
protected |
Array of mice devices.
|
protected |
Circular buffer holding mouse events.
|
protected |
Lock for multi-threading.
|
protected |
Asynchronous thread monitoring DirectInput (Windows only)
|
protected |
Application instance.
|
protected |
HID Manager pointer.
|
protected |
Direct input device (Windows only)
|
protected |
Event signal for DirectInput (Windows only)
|
protected |
Write index for m_KeyEvents.
|
protected |
Read index for m_KeyEvents.
|
protected |
Screen width bounds for the mouse.
|
protected |
Screen height bounds for the mouse.
|
protected |
Current state of the mouse buttons.
|
protected |
Number of mice devices found.
|
protected |
Mouse buttons pressed since last read.
|
protected |
Current X coordinate of the mouse.
|
protected |
Current Y coordinate of the mouse.