1 // $Header: x:/prj/tech/libsrc/inputbnd/RCS/inpbnd_i.h 1.27 1999/10/21 15:23:18 MAT Exp $
19 #define IBFLAG_USER 0x00000001
20 #define IBFLAG_ALIAS 0x00000002
21 #define IBFLAG_FALLS_THRU_MOD 0x00000004
30 // Standard UI handler
31 typedef bool (*tBindHandler
) (uiEvent
*pEvent
, Region
*pReg
, void *pState
);
33 // Passes to you the control string, command string, and user data.
34 // Return TRUE if you accept the bind request.
35 typedef BOOL (*tTrapBindFilter
) (char *pControl
, char *pCmd
, void *pUserData
);
37 // For doing any work after a bind trap has occured. bBound will contain
38 // whether or not the control was bound to the command.
39 typedef void (*tTrapBindPostFunc
) (BOOL bBound
);
41 // Accepts an array of pointers to all channels of a var,
42 // the number of channels in the array, and a char buffer
43 // of IB_VARSTRMAX length, for which to stuff the prevailing
44 // value of the conflicting channels. Should also return
45 // TRUE if conflict was resolved.
46 typedef BOOL (*tBindAggCallback
) (struct _intrnl_var_channel
**ppChannels
, long iNum
, char *pBuf
);
48 // Accepts variable name, value in string form, and
49 // whether or not the control was already down.
50 // Most callbacks should return NULL, as this
52 typedef char *(*tBindProcCallback
) (char *pCmd
, char *pValStr
, BOOL bAlreadyDown
);
56 //provided aggregation callbacks
57 EXTERN BOOL
IBMaxActiveAgg (struct _intrnl_var_channel
**, long, char *);
58 EXTERN BOOL
IBAddActiveAgg (struct _intrnl_var_channel
**, long, char *);
59 EXTERN BOOL
IBAveActiveAgg (struct _intrnl_var_channel
**, long, char *);
60 EXTERN BOOL
IBMRUActiveAgg (struct _intrnl_var_channel
**, long, char *);
66 --------------------------------------------------------------------------------------
67 Input Binding command variable. Used for registering cmd vars to the Variable Manager
68 --------------------------------------------------------------------------------------
70 #define IB_VARSTRMAX 32
71 #define IB_VALSTRMAX 64
72 typedef struct _IB_var
{
73 char name
[IB_VARSTRMAX
];
74 char val
[IB_VALSTRMAX
];
79 //for internal use. user can set this to anything safely, VarSet will just override it
80 char last_val
[IB_VARSTRMAX
];
85 ----------------------------------------------------------------------
86 Input control channel.
87 An array of these gets passed into a variable's aggregation callback.
88 ----------------------------------------------------------------------
90 typedef struct _intrnl_var_channel
{
91 char val
[IB_VARSTRMAX
];
95 unsigned long context
;
101 ///////////////////////////////////////////////////////////////////////////////
102 // Structure used to associate binding contexts. In a bind file, a bind command
103 // may be prefixed by a string. This structure is used to map the string (case-
104 // insensitive) to its context. "" for aszStr indicates no prefix.
105 typedef struct _sBindContext
{
106 char aszStr
[IB_VARSTRMAX
];
110 #define kBindContextNull {"", 0}
117 --------------------------------------------------------------
118 Base class for processing joystick axis input.
119 App's derived class must be registered with the input binder.
120 Expect joystick axis' to be given in -1.0 to 1.0 range,
122 --------------------------------------------------------------
124 class cIBJoyAxisProcess
{
126 cIBJoyAxisProcess ();
128 void SetDeadZoneX (double x
) {m_deadzone_x
= x
;}
129 void SetDeadZoneY (double y
) {m_deadzone_y
= y
;}
130 void SetDeadZoneZ (double z
) {m_deadzone_z
= z
;}
131 void SetDeadZoneR (double r
) {m_deadzone_r
= r
;}
133 void GetDeadZoneX (double *x
) {*x
= m_deadzone_x
;}
134 void GetDeadZoneY (double *y
) {*y
= m_deadzone_y
;}
135 void GetDeadZoneZ (double *z
) {*z
= m_deadzone_z
;}
136 void GetDeadZoneR (double *r
) {*r
= m_deadzone_r
;}
138 //be sure to call this base method in your inherited Process,
139 //probably before you do your own processing
140 virtual void ProcessXY (double *x
, double *y
);
141 virtual void ProcessZR (double *z
, double *r
);
144 void ApplyDeadzone (double *axis
, double deadzone
);
146 double m_deadzone_x
, m_deadzone_y
, m_deadzone_z
, m_deadzone_r
;
154 ************************************************
156 ************************************************
160 #define INTERFACE IInputBinder
164 #define MAX_CONTEXTS 32
165 DECLARE_INTERFACE_(IInputBinder
, IUnknown
)
167 DECLARE_UNKNOWN_PURE();
170 // Can initialize binding vars and a .bnd file to load upon Init.
171 // pVars and pBndFname can both be NULL.
173 STDMETHOD_(char *, Init
) (THIS_ IB_var
*pVars
, char *pBndFname
) PURE
;
174 STDMETHOD_(char *, Term
) (THIS
) PURE
;
177 // Stuffs ppHandler with the input binder's ui handler.
179 STDMETHOD_(void, GetHandler
) (THIS_ tBindHandler
*ppHandler
) PURE
;
182 // Used to mask which events the binder will trap.
183 // These are defined in event.h
185 STDMETHOD_(void, SetValidEvents
) (THIS_ ulong iEventMask
) PURE
;
186 STDMETHOD_(ulong
, GetValidEvents
) (THIS
) PURE
;
189 // Binds pCmd to pControl. Multiple worded commands should
190 // be wrapped in quotes. Returns TRUE if all went well.
192 STDMETHOD_(BOOL
, Bind
) (THIS_
char *pControl
, char *pCmd
) PURE
;
195 // Uninds pControl. Returns FALSE if pControl is invalid.
197 STDMETHOD_(BOOL
, Unbind
) (THIS_
char *pControl
) PURE
;
200 // Stuffs pCmdBuf with whatever command pControl is bound to.
202 STDMETHOD_(void, QueryBind
) (THIS_
char *pControl
, char *pCmdBuf
, long iBufLen
) PURE
;
205 // Stuffs pValBuf with the value of pVarStr. Currently does not take
206 // channels into account.
208 STDMETHOD_(void, GetVarValue
) (THIS_
char *pVarStr
, char *pValBuf
, long iBufLen
) PURE
;
211 // Accepts a string which contains commands
212 // to interact with the binder. Most users
213 // should not have to call this.
215 STDMETHOD_(char *, ProcessCmd
) (THIS_
char *pCmdStr
) PURE
;
218 // Trap a control, and bind it to pCmdStr, if the filter callback allows it.
219 // Both callbacks and pUserData may be NULL, however.
221 STDMETHOD_(void, TrapBind
) (THIS_
char *pCmdStr
, tTrapBindFilter
, tTrapBindPostFunc
, void *pUserData
) PURE
;
224 // Merely sets the internal mapper to the correct context.
225 // Usually not needed.
227 STDMETHOD_(char *, Update
) (THIS
) PURE
;
230 // Polls keys and sends out appropriate commands upon change of state.
232 STDMETHOD_(void, PollAllKeys
) (THIS
) PURE
;
235 // Registers the application's joystick processor, inherited from above.
237 STDMETHOD_(void, RegisterJoyProcObj
) (void *pJoyProc
) PURE
;
241 // This is the preferred method of bind loading. You associate context bitmasks
242 // and context strings with the ContextAssociate method, then LoadBndContexted
243 // will parse the file only once, and map the contexted commands accordingly.
245 STDMETHOD_(void, LoadBndContexted
) (THIS_
char *pBndFname
) PURE
;
248 // Accepts a pointer to a kBindContextNull-terminated array of sBindContext's.
249 // A call to this method wipes out any previoius context associations. These
250 // associations are then used when mapping contexted binds during a call to
253 STDMETHOD_(void, ContextAssociate
) (THIS_ sBindContext
*pBindContext
) PURE
;
257 // Loads a .bnd file into the specified iContext. If pPrefix is not NULL,
258 // we bind only the matching prefixed binds.
260 STDMETHOD_(char *, LoadBndFile
) (THIS_
char *pBndFname
, unsigned long iContext
, char *pPrefix
) PURE
;
263 // Saves a bind file under the current context only. Should undoubtedly
264 // change this in the future. If pHeader is non-NULL, the string will
265 // be placed at the top of the file.
267 STDMETHOD_(char *, SaveBndFile
) (THIS_
char *pBndFname
, char *pHeader
) PURE
;
270 // Methods for setting and unsetting bind command variables.
272 STDMETHOD_(BOOL
, VarSet
) (THIS_ IB_var
*pVars
) PURE
;//must be NULL-terminated
273 STDMETHOD_(BOOL
, VarSetn
) (THIS_ IB_var
*pVars
, long iNum
) PURE
;
274 // if bUser is set, then the variable(s) can be unset by the player.
275 STDMETHOD_(char *, VarUnset
) (THIS_
char **ppVarNames
, BOOL bUser
) PURE
;//must be NULL-terminated
276 STDMETHOD_(char *, VarUnsetn
) (THIS_
char **ppVarNames
, long iNum
, BOOL bUser
) PURE
;
277 STDMETHOD_(char *, VarUnsetAll
) (THIS
) PURE
;
281 // For setting and getting out current context. This should be a bitmask.
282 // Also, do we want to poll when changing to a different context?
284 STDMETHOD_(BOOL
, SetContext
) (THIS_
unsigned long iContext
, BOOL bPoll
) PURE
;
286 STDMETHOD_(void, GetContext
) (THIS_
unsigned long *pContext
) PURE
;
289 // Set globally master agg callback.
290 // This is also set interally to IBMaxActiveAgg, so most don't need
293 STDMETHOD_(void, SetMasterAggregation
) (THIS_ tBindAggCallback
) PURE
;
296 // Set the default variable processing callback. When a command variable
297 // doesn't have its own callback, or a bound command isn't an input command
298 // this callback will be used. Useful for sending most commands along to
299 // a game's command system.
301 STDMETHOD_(void, SetMasterProcessCallback
) (THIS_ tBindProcCallback
) PURE
;
304 // Iterators for getting which controls are bound to a certain command.
305 // pControlBuf really should be at least 32 chars long.
307 STDMETHOD_(char *, GetControlFromCmdStart
) (THIS_
char *pCmd
, char *pControlBuf
) PURE
;
308 STDMETHOD_(char *, GetControlFromCmdNext
) (THIS_
char *pControlBuf
) PURE
;
311 // Not currently used.
313 STDMETHOD_(void, SetResPath
) (THIS_
char *pPath
) PURE
;
316 // Useful for taking a composed control (ie. "p+shift+alt") and separating
317 // then into ppControls. Maximum controls is 4 (some control+alt+crtl+shift).
318 // pNumControls will be stuffed with the number of controls separated.
320 STDMETHOD_(char *, DecomposeControl
) (THIS_
char *pControlStr
, char ppControls
[4][32], long *pNumControls
) PURE
;
323 // Clears all binds in the current context.
325 STDMETHOD_(void, Reset
)(THIS
) PURE
;
330 #define InputBinderCreate(ppInputBinder) \
332 IUnknown * pAppUnknown = AppGetObj(IUnknown); \
333 _CreateInputBinder(IID_TO_REFIID(IID_IInputBinder), ppInputBinder, pAppUnknown); \
334 COMRelease(pAppUnknown); \
337 // this is internal--use the above macro
338 EXTERN tResult LGAPI
_CreateInputBinder(REFIID
, IInputBinder
**ppInputBinder
, IUnknown
*pOuter
);
342 #define IInputBinder_QueryInterface(p, a, b) COMQueryInterface(p, a, b)
343 #define IInputBinder_AddRef(p) COMAddRef(p)
344 #define IInputBinder_Release(p) COMRelease(p)
345 #define IInputBinder_Init(p, a, b) COMCall2(p, a, b)
346 #define IInputBinder_Term(p) COMCall0(p)
347 #define IInputBinder_GetHandler(p, a) COMCall1(p, a)
348 #define IInputBinder_ProcessCmd(p, a) COMCall1(p, a)
349 #define IInputBinder_Update(p) COMCall0(p)
350 #define IInputBinder_LoadBndFile(p, a, b, c) COMCall3(p, a, b, c)
351 #define IInputBinder_LoadBndFile(p, a, b, c) COMCall3(p, a, b, c)
352 #define IInputBinder_SaveBndFile(p, a) COMCall1(p, a)
353 #define IInputBinder_VarSet(p, a) COMCall1(p, a)
354 #define IInputBinder_VarSetn(p, a, b) COMCall2(p, a, b)
355 #define IInputBinder_VarUnset(p, a, b) COMCall2(p, a, b)
356 #define IInputBinder_VarUnsetn(p, a, b, c) COMCall3(p, a, b, c)
357 #define IInputBinder_SetContext(p, a) COMCall2(p, a, b)
358 #define IInputBinder_GetContext(p, a) COMCall1(p, a)