VR-Engage  2.2
Loading...
Searching...
No Matches
mouseControl.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies, Inc.
3** All rights reserved.
4*******************************************************************************/
5
6//! \file
7//! \brief Mouse control handling with focus detection and state management
8
9#pragma once
10
11#include "vreInput/export.h"
12
15
16// Disable Boost signals to allow Qt signals
17
18#include <QtCore/QObject>
19
20namespace makVre
21{
22//! \brief Helper class to detect and monitor window focus changes
23//!
24//! This Qt-based class monitors focus changes in application windows and
25//! notifies the mouse control system when focus state changes occur.
26//! This enables proper handling of mouse input when the application loses focus.
28{
29 Q_OBJECT
30public:
31 //! \brief Constructor that initializes focus watching
32 //!
33 //! Sets up the focus watcher with the given display environment and
34 //! connects to the Qt signal for application focus changes.
35 //!
36 //! \param de Reference to the display environment
38
39 //! \brief Destructor
40 //!
41 //! Cleans up focus watcher resources
42 virtual ~DtMouseControlFocusWatcher() override;
43
44 //! \brief Check and update the application focus state
45 //!
46 //! Determines if the application window has focus and sends a message
47 //! if the focus state has changed since the last check.
49
50private:
51 //! \brief Reference to the display environment
52 makVrv::DtDe& myDe;
53
54 //! \brief Connection to Qt's focus changed signal
55 QMetaObject::Connection myFocusChangedConnection;
56
57 //! \brief Flag indicating if a widget within the application has focus
59
60 //! \brief Current focus state of the application
62};
63
64
65//! \brief Manages mouse control state and behavior
66//!
67//! This class implements configurable mouse control with focus awareness.
68//! It provides functionality to toggle mouse control on/off, handle focus changes,
69//! and manage mouse centering. It integrates with the message system to respond
70//! to system-wide state changes that affect mouse behavior.
72{
73public:
74 //! \brief Constructor that initializes mouse control
75 //!
76 //! Sets up the mouse control system with the given display environment.
77 //!
78 //! \param de Reference to the display environment
79 DtMouseControl(makVrv::DtDe& de);
80
81 //! \brief Virtual destructor
82 //!
83 //! Cleans up resources owned by the mouse control system
84 virtual ~DtMouseControl();
85
86 //! \brief Initialize the mouse control system
87 //!
88 //! Sets up message handlers and initializes the mouse control state.
89 //!
90 //! \return True if initialization succeeded, false otherwise
91 virtual bool init();
92
93 //! \brief Shut down the mouse control system
94 //!
95 //! Unregisters message handlers and cleans up resources allocated during initialization
96 virtual void shutdown();
97
98 //! \brief Check if mouse control is currently enabled
99 //!
100 //! \return True if mouse control is enabled, false otherwise
101 virtual bool isEnabled() const;
102
103 //! \brief Check if the application window has focus
104 //!
105 //! \return True if the application has focus, false otherwise
106 virtual bool isFocused() const;
107
108 //! \brief Center the mouse cursor in the application window
109 //!
110 //! Positions the mouse cursor at the center of the current viewport
111 virtual void centerMouse();
112
113 //! \brief Get the current input channel
114 //!
115 //! Returns the channel used for mouse input events
116 //!
117 //! \return Pointer to the current input channel
118 makVrv::DtChannel* getChannel() const;
119
120protected:
121 //! \brief Update the mouse control state based on current system state
122 //!
123 //! Evaluates focus state, toggle state, and player controls state to determine
124 //! whether mouse control should be enabled or disabled
126 //! \brief Handle message to toggle mouse control on or off
127 //!
128 //! Message handler that toggles the mouse control state when requested
129 //!
130 //! \param msg Pointer to the toggle mouse control message
131 //! \return Result indicating whether the message was handled
133 //! \brief Handle message indicating player controls state change
134 //!
135 //! Message handler that updates mouse control in response to player controls state changes
136 //!
137 //! \param msg Pointer to the player controls state message
138 //! \return Result indicating whether the message was handled
140 //! \brief Handle message indicating focus state change
141 //!
142 //! Message handler that updates mouse control in response to window focus changes
143 //!
144 //! \param msg Pointer to the focus state message
145 //! \return Result indicating whether the message was handled
147
148 //! \brief Update the input channel for mouse events
149 //!
150 //! Sets or updates the channel used for mouse input events based on
151 //! window and channel names
152 //!
153 //! \param windowName Name of the window to associate with the channel
154 //! \param channelName Name of the channel to use
155 virtual void updateChannel(const std::string& windowName = "", const std::string& channelName = "");
156
157 //! \brief Focus watcher for detecting window focus changes
159
160 //! \brief Reference to the display environment
161 makVrv::DtDe& myDe;
162
163 //! \brief Pointer to the current input channel
164 makVrv::DtChannel* myChannel;
165
166 //! \brief Flag indicating if mouse control is currently enabled
168
169 //! \brief Flag indicating if mouse control is toggled on by the user
170 //!
171 //! When true, mouse control should be enabled if system state allows it
173
174 //! \brief Flag indicating if player controls are enabled
176
177 //! \brief Flag indicating if application has focus
179};
180
181} // namespace makVre
Helper class to detect and monitor window focus changes.
Definition mouseControl.h:28
makVrv::DtDe & myDe
Reference to the display environment.
Definition mouseControl.h:52
void updateFocusState()
Check and update the application focus state.
bool myWidgetInFocus
Flag indicating if a widget within the application has focus.
Definition mouseControl.h:58
DtMouseControlFocusWatcher(makVrv::DtDe &de)
Constructor that initializes focus watching.
QMetaObject::Connection myFocusChangedConnection
Connection to Qt's focus changed signal.
Definition mouseControl.h:55
virtual ~DtMouseControlFocusWatcher() override
Destructor.
bool myFocusState
Current focus state of the application.
Definition mouseControl.h:61
bool myIsToggledOn
Flag indicating if mouse control is toggled on by the user.
Definition mouseControl.h:172
virtual ~DtMouseControl()
Virtual destructor.
virtual void centerMouse()
Center the mouse cursor in the application window.
bool myPlayerControlsEnabled
Flag indicating if player controls are enabled.
Definition mouseControl.h:175
virtual void shutdown()
Shut down the mouse control system.
virtual bool isEnabled() const
Check if mouse control is currently enabled.
virtual DtVreMessageResult handleFocusState(DtVreMessage *msg)
Handle message indicating focus state change.
makVrv::DtDe & myDe
Reference to the display environment.
Definition mouseControl.h:161
virtual DtVreMessageResult handleToggleMouseControl(DtVreMessage *msg)
Handle message to toggle mouse control on or off.
DtMouseControlFocusWatcher myMouseControlFocusWatcher
Focus watcher for detecting window focus changes.
Definition mouseControl.h:158
virtual bool init()
Initialize the mouse control system.
virtual void updateMouseControlState()
Update the mouse control state based on current system state.
virtual bool isFocused() const
Check if the application window has focus.
bool myEnabled
Flag indicating if mouse control is currently enabled.
Definition mouseControl.h:167
virtual void updateChannel(const std::string &windowName="", const std::string &channelName="")
Update the input channel for mouse events.
bool myHasFocus
Flag indicating if application has focus.
Definition mouseControl.h:178
virtual DtVreMessageResult handlePlayerControlsState(DtVreMessage *msg)
Handle message indicating player controls state change.
DtMouseControl(makVrv::DtDe &de)
Constructor that initializes mouse control.
makVrv::DtChannel * myChannel
Pointer to the current input channel.
Definition mouseControl.h:164
makVrv::DtChannel * getChannel() const
Get the current input channel.
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Defines DLL export/import macros for the vreInput library.
#define VREINPUT_DLL
DLL export/import macro for the vreInput library.
Definition export.h:25
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
makVrv::DtDe * de()
Gets the display element pointer used by the plugin.
Defines the event processor for handling display channel events.
Defines the base class for all VREngage messages.