Skip to content

Commit

Permalink
Bindings: Allow specifying fallback responder for ddevents
Browse files Browse the repository at this point in the history
Previously a binding context's fallback responder accepted
only game-side events. This commit adds another responder
that handles ddevent_t.
  • Loading branch information
skyjake committed Feb 13, 2012
1 parent 4bd9f36 commit d69c8f9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doomsday/engine/portable/include/b_context.h
Expand Up @@ -53,6 +53,7 @@ typedef struct bcontext_s {
byte flags;
evbinding_t commandBinds; // List of command bindings.
controlbinding_t controlBinds;
int (*ddFallbackResponder)(const ddevent_t* ddev);
int (*fallbackResponder)(event_t* event); // event_t
} bcontext_t;

Expand All @@ -62,6 +63,7 @@ void B_DestroyAllContexts(void);
void B_ActivateContext(bcontext_t* bc, boolean doActivate);
void B_AcquireKeyboard(bcontext_t* bc, boolean doAcquire);
void B_AcquireAll(bcontext_t* bc, boolean doAcquire);
void B_SetContextFallbackForDDEvents(const char* name, int (*ddResponderFunc)(const ddevent_t*));
void B_SetContextFallback(const char* name, int (*responderFunc)(event_t*));
bcontext_t* B_ContextByPos(int pos);
bcontext_t* B_ContextByName(const char* name);
Expand Down
18 changes: 15 additions & 3 deletions doomsday/engine/portable/src/b_context.c
Expand Up @@ -301,7 +301,7 @@ static void B_RemoveContext(bcontext_t* bc)
*/
bcontext_t* B_NewContext(const char* name)
{
bcontext_t* bc = M_Calloc(sizeof(bcontext_t));
bcontext_t* bc = M_Calloc(sizeof(bcontext_t));

bc->name = strdup(name);
B_InitCommandBindingList(&bc->commandBinds);
Expand Down Expand Up @@ -370,6 +370,16 @@ void B_AcquireAll(bcontext_t* bc, boolean doAcquire)
B_UpdateDeviceStateAssociations();
}

void B_SetContextFallbackForDDEvents(const char* name, int (*ddResponderFunc)(const ddevent_t*))
{
bcontext_t *ctx = B_ContextByName(name);

if(!ctx)
return;

ctx->ddFallbackResponder = ddResponderFunc;
}

void B_SetContextFallback(const char* name, int (*responderFunc)(event_t*))
{
bcontext_t *ctx = B_ContextByName(name);
Expand Down Expand Up @@ -562,7 +572,7 @@ boolean B_TryEvent(ddevent_t* event)

for(i = 0; i < bindContextCount; ++i)
{
bcontext_t* bc = bindContexts[i];
bcontext_t* bc = bindContexts[i];

if(!(bc->flags & BCF_ACTIVE))
continue;
Expand All @@ -574,7 +584,9 @@ boolean B_TryEvent(ddevent_t* event)
return true;
}

// Try the fallback.
// Try the fallbacks.
if(bc->ddFallbackResponder && bc->ddFallbackResponder(event))
return true;
if(bc->fallbackResponder && bc->fallbackResponder(&ev))
return true;
}
Expand Down

0 comments on commit d69c8f9

Please sign in to comment.