GL Studio C++ Runtime API
input_handler.h
Go to the documentation of this file.
1/*! \file
2 \brief The input handler interface
3
4 \par Copyright Information
5
6 Copyright (c) 2016 by The DiSTI Corporation.<br>
7 11301 Corporate Blvd; Suite 100<br>
8 Orlando, Florida 32817<br>
9 USA<br>
10 <br>
11 All rights reserved.<br>
12
13 This Software contains proprietary trade secrets of DiSTI and may not be
14reproduced, in whole or part, in any form, or by any means of electronic,
15mechanical, or otherwise, without the written permission of DiSTI. Said
16permission may be derived through the purchase of applicable DiSTI product
17licenses which detail the distribution rights of this content and any
18Derivative Works based on this or other copyrighted DiSTI Software.
19
20 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26
27 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34EXCEED FIVE DOLLARS (US$5.00).
35
36 The aforementioned terms and restrictions are governed by the laws of the
37State of Florida and the United States of America.
38
39*/
40#ifndef INCLUDED_INPUT_HANDLER_H
41#define INCLUDED_INPUT_HANDLER_H
42
43#include "disti_assert.h"
45#include "weak_reference.h"
46
47namespace disti
48{
49class DisplayObject;
50class DisplayEvent;
51class KeyboardEvent;
52class MouseEvent;
53
54/** Class used to call a callback method that takes a KeyboardEvent */
56{
57public:
58 /// Call the callback with the provided display event.
59 /// \param ev The event to process.
60 virtual void Call( KeyboardEvent* ev ) = 0;
61
62 /// \return True if the callback is valid to call.
63 virtual bool IsValid() const = 0;
64
65 virtual ~KeyboardCallbackBase() {}
66};
67
68/** Interface for creating a callback from a class method. The class must implement WeakReferenceable.
69 * Don't use this directly. Use CreateInputHandlerCallback instead
70 */
71template<class T>
73{
74public:
75 typedef void ( T::*Callback )( KeyboardEvent* ev ); ///< Typedef for a function pointer accepting a keyboard event.
76
77 /// Constructor
78 /// \param method Function pointer to call back.
79 /// \param object The object containing the function pointer.
80 KeyboardMethodCallback( Callback method, T* object )
81 : _method( method )
82 , _object( object )
83 {
85 GLS_VERIFY( NULL != method );
86 GLS_VERIFY( NULL != object );
87 }
88
90 {
91 if( IsValid() )
92 {
93 ( _object.Get()->*( _method ) )( ev );
94 }
95 }
96
97 virtual bool IsValid() const DISTI_METHOD_OVERRIDE
98 {
99 return !_object.IsNull();
100 }
101
102protected:
103 Callback _method; ///< The function pointer to call back.
104 WeakRef<T> _object; ///< The object containing the function pointer.
105};
106
107/// Helper method to create a KeyboardCallbackBase from a class method.
108/// \param method A class method pointer.
109/// \param obj The object to call the method on.
110/// \return A pointer to a new KeyboardMethodCallback object.
111template<class Class>
113 const typename KeyboardMethodCallback<Class>::Callback method,
114 Class* const obj )
115{
116 return new KeyboardMethodCallback<Class>( method, obj );
117}
118
119/** Class used to call a callback method that takes a MouseEvent */
121{
122public:
123 /// Call the callback with the provided display event.
124 /// \param ev The event to process.
125 virtual void Call( MouseEvent* ev ) = 0;
126
127 /// \return True if the callback is valid to call.
128 virtual bool IsValid() const = 0;
129
130 virtual ~MouseCallbackBase() {}
131};
132
133/** Interface for creating a callback from a class method. The class must implement WeakReferenceable.
134 * Don't use this directly. Use CreateInputHandlerCallback instead
135 */
136template<class T>
138{
139public:
140 typedef void ( T::*Callback )( MouseEvent* ev ); ///< Typedef for a function pointer accepting a mouse event.
141
142 /// Constructor
143 /// \param method Function pointer to call back.
144 /// \param object The object containing the function pointer.
145 MouseMethodCallback( Callback method, T* object )
146 : _method( method )
147 , _object( object )
148 {
150 GLS_VERIFY( NULL != method );
151 GLS_VERIFY( NULL != object );
152 }
153
155 {
156 if( IsValid() )
157 {
158 ( _object.Get()->*( _method ) )( ev );
159 }
160 }
161
162 virtual bool IsValid() const DISTI_METHOD_OVERRIDE
163 {
164 return !_object.IsNull();
165 }
166
167protected:
168 Callback _method; ///< The function pointer to call back.
169 WeakRef<T> _object; ///< The object containing the function pointer.
170};
171
172/// Helper method to create a MouseCallbackBase from a class method.
173/// \param method A class method pointer.
174/// \param obj The object to call the method on.
175/// \return A pointer to a new MouseMethodCallback object.
176template<class Class>
178 const typename MouseMethodCallback<Class>::Callback method,
179 Class* const obj )
180{
181 return new MouseMethodCallback<Class>( method, obj );
182}
183
184/** Base class implemented by all input handlers */
186{
187public:
188 /// Type for unique identifiers
189 typedef unsigned int ID;
190
191 /** Handle the event
192 * \param ev the event to handle
193 * \return the object that handled the event, or NULL if no object handled the event
194 */
196
197 /** Register a global keyboard handler.
198 * \param callback the callback to call when a keyboard event occurs. The input handler owns the callback and will delete it.
199 * \return unique ID. Used to unregister.
200 */
202
203 /** Register a global mouse handler.
204 * \param callback the callback to call when a mouse event occurs. The input handler owns the callback and will delete it.
205 * \return unique ID. Used to unregister.
206 */
208
209 /** Unregister a global keyboard handler.
210 * \param id the unique identifier returned from RegisterGlobalKeyboardHandler.
211 */
212 virtual void UnregisterGlobalKeyboardHandler( ID id ) = 0;
213
214 /** Unregister a global mouse handler.
215 * \param id the unique identifier returned from RegisterGlobalMouseHandler.
216 */
217 virtual void UnregisterGlobalMouseHandler( ID id ) = 0;
218
219 /** destructor */
220 virtual ~InputHandler() {}
221};
222
223} // namespace disti
224
225#endif
Definition: events.h:113
Definition: display.h:96
Definition: input_handler.h:186
virtual ID RegisterGlobalKeyboardHandler(KeyboardCallbackBase *callback)=0
virtual ID RegisterGlobalMouseHandler(MouseCallbackBase *callback)=0
unsigned int ID
Type for unique identifiers.
Definition: input_handler.h:189
virtual void UnregisterGlobalKeyboardHandler(ID id)=0
virtual void UnregisterGlobalMouseHandler(ID id)=0
virtual DisplayObject * HandleInput(DisplayEvent *ev)=0
virtual ~InputHandler()
Definition: input_handler.h:220
Definition: input_handler.h:56
virtual void Call(KeyboardEvent *ev)=0
virtual bool IsValid() const =0
Definition: events.h:282
Definition: input_handler.h:73
WeakRef< T > _object
The object containing the function pointer.
Definition: input_handler.h:104
KeyboardMethodCallback(Callback method, T *object)
Definition: input_handler.h:80
Callback _method
The function pointer to call back.
Definition: input_handler.h:103
void(T::* Callback)(KeyboardEvent *ev)
Typedef for a function pointer accepting a keyboard event.
Definition: input_handler.h:75
virtual bool IsValid() const override
Definition: input_handler.h:97
void Call(KeyboardEvent *ev) override
Definition: input_handler.h:89
Definition: input_handler.h:121
virtual void Call(MouseEvent *ev)=0
virtual bool IsValid() const =0
Definition: events.h:225
Definition: input_handler.h:138
void Call(MouseEvent *ev) override
Definition: input_handler.h:154
MouseMethodCallback(Callback method, T *object)
Definition: input_handler.h:145
WeakRef< T > _object
The object containing the function pointer.
Definition: input_handler.h:169
Callback _method
The function pointer to call back.
Definition: input_handler.h:168
void(T::* Callback)(MouseEvent *ev)
Typedef for a function pointer accepting a mouse event.
Definition: input_handler.h:140
virtual bool IsValid() const override
Definition: input_handler.h:162
Definition: weak_reference.h:92
Definition: weak_reference.h:65
Contains the DistiAssert macro.
#define GLS_VERIFY(exp)
Definition: disti_assert.h:170
Macros and helper code to determine what subset of C++11/14/17 is available.
#define DISTI_STATIC_ASSERT_IS_CONVERTIBLE_TO(T, ConvertsTo)
Definition: gls_cpp_lang_support.h:264
#define DISTI_METHOD_OVERRIDE
Macro to wrap the override keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:214
Force inclusion of the DirectShow library.
Definition: bmpimage.h:47
KeyboardCallbackBase * CreateInputHandlerCallback(const typename KeyboardMethodCallback< Class >::Callback method, Class *const obj)
Definition: input_handler.h:112
weak reference and related classes