Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Static Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
Burger::Mouse Class Reference

Class for mouse input. More...

Inheritance diagram for Burger::Mouse:
Inheritance graph
[legend]
Collaboration diagram for Burger::Mouse:
Collaboration graph
[legend]

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::StaticRTTIget_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 charget_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

GameAppm_pGameApp
 Application instance.
 
Mutex m_MouseLock
 Lock for multi-threading.
 
IDirectInputDevice8Wm_pMouseDevice
 Direct input device (Windows only)
 
voidm_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)
 
__IOHIDManagerm_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
 
Mouseoperator= (const Mouse &)=delete
 
 Mouse (Mouse &&)=delete
 
Mouseoperator= (Mouse &&)=delete
 

Detailed Description

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.

Member Enumeration Documentation

◆ anonymous enum

Enumerator
MOUSEBUFFSIZE 

Number of mouse events in the event cache.

◆ anonymous enum

Enumerator
MAX_MOUSE_DEVICE_COUNT 

Maximum number of mice/trackpads OSX will track.

◆ eMouseButtons

Enumerator
BUTTON_LEFT 

Mask for the left mouse button.

BUTTON_RIGHT 

Mask for the right mouse button.

BUTTON_MIDDLE 

Mask for the center mouse button.

BUTTON_4 

Mask for the 4th mouse button.

BUTTON_5 

Mask for the 5th mouse button.

BUTTON_6 

Mask for the 6th mouse button.

BUTTON_7 

Mask for the 7th mouse button.

BUTTON_8 

Mask for the 8th mouse button.

BUTTON_9 

Mask for the 9th mouse button.

BUTTON_10 

Mask for the 10th mouse button.

BUTTON_11 

Mask for the 11th mouse button.

BUTTON_12 

Mask for the 12th mouse button.

BUTTON_13 

Mask for the 13th mouse button.

BUTTON_14 

Mask for the 14th mouse button.

BUTTON_15 

Mask for the 15th mouse button.

BUTTON_16 

Mask for the 16th mouse button.

Constructor & Destructor Documentation

◆ Mouse() [1/3]

Burger::Mouse::Mouse ( const Mouse & )
privatedelete

◆ Mouse() [2/3]

Burger::Mouse::Mouse ( Mouse && )
privatedelete

◆ Mouse() [3/3]

Burger::Mouse::Mouse ( GameApp * pGameApp)

Initialize the mouse device for input.


Open the mouse device driver (if needed) and prepare for input

Parameters
pGameAppPointer to the GameApp of the game that's requesting input.

◆ ~Mouse()

Burger::Mouse::~Mouse ( )
virtual

Release the mouse device.


Close the mouse device driver (if needed)

Member Function Documentation

◆ AcquireDirectInput()

void Burger::Mouse::AcquireDirectInput ( void )
noexcept

Acquire DirectInput (Windows only)


Call Acquire() on the DirectInput mouse device.

See also
UnacquireDirectInput(void)

◆ DisconnectionCallback()

void Burger::Mouse::DisconnectionCallback ( void * pData,
int iReturn,
void * pSender )
static

◆ EnumerationCallback()

void Burger::Mouse::EnumerationCallback ( void * pData,
int iReturn,
void * pSender,
__IOHIDDevice * pDevice )
static

◆ get_StaticRTTI()

const Burger::StaticRTTI * Burger::Mouse::get_StaticRTTI ( void ) const
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.

Returns
Pointer to a global, read only instance of StaticRTTI for the true class

Reimplemented from Burger::Base.

◆ GetMouseEvent()

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.

Parameters
pEventPointer to a buffer to receive the event
Returns
FALSE if no event is pending, TRUE if an event is pending
See also
PeekMouseEvent(MouseEvent_t *pEvent)

◆ InputCallback()

void Burger::Mouse::InputCallback ( void * pData,
int iReturn,
void * pSender,
__IOHIDValue * pValue )
static

◆ IsPresent()

uint_t Burger::Mouse::IsPresent ( void ) const

Detect if a mouse is plugged in.


Scan if there are any mice present in the system and return TRUE if one was found.

On platforms that don't have mice, such as mobile devices, this always returns FALSE

Returns
TRUE if a mouse is present, FALSE if not.

◆ operator=() [1/2]

Mouse & Burger::Mouse::operator= ( const Mouse & )
privatedelete

◆ operator=() [2/2]

Mouse & Burger::Mouse::operator= ( Mouse && )
privatedelete

◆ PeekMouseEvent()

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.

Parameters
pEventPointer to a buffer to receive the event
Returns
FALSE if no event is pending, TRUE if an event is pending
See also
GetMouseEvent(MouseEvent_t *pEvent)

◆ Poll()

Burger::RunQueue::eReturnCode BURGER_API Burger::Mouse::Poll ( void * pData)
staticnoexcept

◆ PostMouseDown()

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.

Parameters
uMouseBitseMouseButtons enumeration of mouse buttons
uMSTimeStampTimestamp in Milliseconds, 0 will fill in the value from Tick::read_ms()
See also
PostMouseUp(uint32_t,uint32_t)

◆ PostMouseEvent()

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

Parameters
pEventPointer to a filled in Mouse event
Returns
Zero if the event was posted, non-zero if the buffer is full

◆ PostMouseMotion()

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.

Parameters
xX coordinate of the mouse cursor in pixels
yY coordinate of the mouse cursor in pixels
uMSTimeStampTimestamp in Milliseconds, 0 will fill in the value from Tick::read_ms()
See also
SetRange(uint32_t,uint32_t)

◆ PostMousePosition()

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.

Parameters
xX coordinate of the mouse cursor in pixels
yY coordinate of the mouse cursor in pixels
uMSTimeStampTimestamp in Milliseconds, 0 will fill in the value from Tick::read_ms()
See also
SetRange(uint32_t,uint32_t)

◆ PostMouseUp()

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.

Parameters
uMouseBitseMouseButtons enumeration of mouse buttons
uMSTimeStampTimestamp in Milliseconds, 0 will fill in the value from Tick::read_ms()
See also
PostMouseDown(uint32_t,uint32_t)

◆ PostMouseWheel()

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

Parameters
iWheelYMovementMotion for the vertical mouse wheel
iWheelXMovementMotion for the horizontal mouse wheel
uMSTimeStampTimestamp in Milliseconds, 0 will fill in the value from Tick::read_ms()
See also
PostMouseUp(uint32_t,uint32_t) or PostMouseDown(uint32_t,uint32_t)

◆ Read() [1/2]

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.

Parameters
pXPointer to a value to receive the X coordinate of the mouse delta or NULL if this value is not requested
pYPointer to a value to receive the Y coordinate of the mouse delta or NULL if this value is not requested
See also
Read(uint32_t *,uint32_t *)

◆ Read() [2/2]

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

Parameters
pXPointer to a value to receive the X coordinate of the mouse cursor or NULL if this value is not requested
pYPointer to a value to receive the Y coordinate of the mouse cursor or NULL if this value is not requested
See also
Read(int32_t *,int32_t *)

◆ ReadButtonDowns()

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.

Note
This function can return multiple different mouse clicks at the same time. Test each bit individually if the user interface performs different actions for different buttons.
Returns
Zero if no buttons have been pressed since the last call, or a bit mask of eMouseButtons for all buttons that were pressed.
See also
ReadButtons()

◆ ReadButtons()

uint32_t BURGER_API Burger::Mouse::ReadButtons ( void )

Return the buttons pressed.


Return the state of the mouse buttons at this precise moment.

Returns
Zero if no buttons are pressed or a bit mask of Mouse::eMouseButtons for all buttons that are pressed.
See also
ReadButtonDowns()

◆ ReadSystemMouseValues()

void BURGER_API Burger::Mouse::ReadSystemMouseValues ( void )
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.

◆ ReadWheelX()

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.

Returns
A signed value of the amount of motion in the X axis from the mouse trackball.
See also
ReadWheelY(void)

◆ ReadWheelY()

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.

Returns
A signed value of the amount of motion in the Y axis from the mouse scroll wheel.
See also
ReadWheelX(void)

◆ SetRange()

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.

Parameters
uBoundsXWidth of the screen in pixels
uBoundsYHeight of the screen in pixels
See also
PostMousePosition(uint32_t,uint32_t,uint32_t)

◆ UnacquireDirectInput()

void Burger::Mouse::UnacquireDirectInput ( void )
noexcept

Release DirectInput (Windows only)


Call Unacquire() on the DirectInput mouse device.

See also
AcquireDirectInput(void)

◆ WindowsMouseThread()

uintptr_t BURGER_API Burger::Mouse::WindowsMouseThread ( void * pData)
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.

Note
This is used by the mouse manager, it's not intended to be used by applications.
Parameters
pDataPointer to the Mouse class instance
Returns
Zero when asked to shut down

Member Data Documentation

◆ g_StaticRTTI

const Burger::StaticRTTI Burger::Mouse::g_StaticRTTI
static

◆ m_bAcquired

uint_t Burger::Mouse::m_bAcquired
protected

TRUE if DirectInput8 is active (Windows only)

◆ m_bButtonSwap

uint_t Burger::Mouse::m_bButtonSwap
protected

Switch the left and right buttons for lefties.

◆ m_bQuit

volatile uint32_t Burger::Mouse::m_bQuit
protected

TRUE when the thread is shutting down (Windows only)

◆ m_iDeltaX

int32_t Burger::Mouse::m_iDeltaX
protected

Accumulated X motion of the mouse.

◆ m_iDeltaY

int32_t Burger::Mouse::m_iDeltaY
protected

Accumulated Y motion of the mouse.

◆ m_iMouseWheelX

int32_t Burger::Mouse::m_iMouseWheelX
protected

Accumulated X motion of the mouse wheel.

◆ m_iMouseWheelY

int32_t Burger::Mouse::m_iMouseWheelY
protected

Accumulated Y motion of the mouse wheel.

◆ m_Mice

DeviceStruct Burger::Mouse::m_Mice[MAX_MOUSE_DEVICE_COUNT]
protected

Array of mice devices.

◆ m_MouseEvents

MouseEvent_t Burger::Mouse::m_MouseEvents[MOUSEBUFFSIZE]
protected

Circular buffer holding mouse events.

◆ m_MouseLock

Mutex Burger::Mouse::m_MouseLock
protected

Lock for multi-threading.

◆ m_MouseThread

Thread Burger::Mouse::m_MouseThread
protected

Asynchronous thread monitoring DirectInput (Windows only)

◆ m_pGameApp

GameApp* Burger::Mouse::m_pGameApp
protected

Application instance.

◆ m_pHIDManager

__IOHIDManager* Burger::Mouse::m_pHIDManager
protected

HID Manager pointer.

◆ m_pMouseDevice

IDirectInputDevice8W* Burger::Mouse::m_pMouseDevice
protected

Direct input device (Windows only)

◆ m_pMouseEvent

void* Burger::Mouse::m_pMouseEvent
protected

Event signal for DirectInput (Windows only)

◆ m_uArrayEnd

uint_t Burger::Mouse::m_uArrayEnd
protected

Write index for m_KeyEvents.

◆ m_uArrayStart

uint_t Burger::Mouse::m_uArrayStart
protected

Read index for m_KeyEvents.

◆ m_uBoundsX

uint32_t Burger::Mouse::m_uBoundsX
protected

Screen width bounds for the mouse.

◆ m_uBoundsY

uint32_t Burger::Mouse::m_uBoundsY
protected

Screen height bounds for the mouse.

◆ m_uButtons

uint32_t Burger::Mouse::m_uButtons
protected

Current state of the mouse buttons.

◆ m_uMiceCount

uint_t Burger::Mouse::m_uMiceCount
protected

Number of mice devices found.

◆ m_uPressedButtons

uint32_t Burger::Mouse::m_uPressedButtons
protected

Mouse buttons pressed since last read.

◆ m_uX

uint32_t Burger::Mouse::m_uX
protected

Current X coordinate of the mouse.

◆ m_uY

uint32_t Burger::Mouse::m_uY
protected

Current Y coordinate of the mouse.