Skip to content

Commit

Permalink
Bindings: Removed special-case responders
Browse files Browse the repository at this point in the history
All event processing should occur within the binding context stack.
Fixes the issue of F11 not working in the Control Panel or when
no game is loaded.

Todo: Test thoroughly.
  • Loading branch information
skyjake committed May 15, 2012
1 parent c2a3268 commit 4d02b5b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 25 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/con_main.h
Expand Up @@ -180,7 +180,7 @@ void Con_ShutdownDatabases(void);
void Con_Ticker(timespan_t time);

/// @return @c true iff the event is 'eaten'.
boolean Con_Responder(ddevent_t* ev);
boolean Con_Responder(const ddevent_t* ev);

/**
* Attempt to change the 'open' state of the console.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/ui_main.h
Expand Up @@ -237,7 +237,7 @@ void UI_SetPage(ui_page_t* page);
void UI_UpdatePageLayout(void);

/// Directs events through the ui and current page if active.
int UI_Responder(ddevent_t* ev);
int UI_Responder(const ddevent_t* ev);

void UI_Ticker(timespan_t time);

Expand Down
35 changes: 32 additions & 3 deletions doomsday/engine/portable/src/b_main.c
Expand Up @@ -38,6 +38,7 @@

#include "b_command.h"
#include "p_control.h"
#include "ui_main.h"

#include <ctype.h>

Expand Down Expand Up @@ -179,6 +180,35 @@ void B_Register(void)
#undef PROTECTED_FLAGS
}

/**
* Binding context fallback for the "global" context.
*
* @param ddev Event being processed.
*
* @return @c true, if the event was eaten and can be processed by the rest of
* the binding context stack.
*/
static int globalContextFallback(const ddevent_t* ddev)
{
if(UI_Responder(ddev)) return true; // Eaten.
if(Con_Responder(ddev)) return true; // Eaten.

if(DD_GameLoaded())
{
event_t ev;
DD_ConvertEvent(ddev, &ev);

// The game's normal responder only returns true if the bindings can't
// be used (like when chatting). Note that if the event is eaten here,
// the rest of the bindings contexts won't get a chance to process the
// event.
if(gx.Responder && gx.Responder(&ev))
return true;
}

return false;
}

/**
* Called once on init.
*/
Expand Down Expand Up @@ -214,12 +244,13 @@ void B_Init(void)
B_AcquireKeyboard(bc, true); // Console takes over all keyboard events.

// UI doesn't let anything past it.
B_AcquireAll(B_NewContext(UI_BINDING_CONTEXT_NAME), true);
B_AcquireAll(bc = B_NewContext(UI_BINDING_CONTEXT_NAME), true);

// Top-level context that is always active and overrides every other context.
// To be used only for system-level functionality.
bc = B_NewContext(GLOBAL_BINDING_CONTEXT_NAME);
bc->flags |= BCF_PROTECTED;
bc->ddFallbackResponder = globalContextFallback;
B_ActivateContext(bc, true);

/*
Expand Down Expand Up @@ -805,8 +836,6 @@ static bindcontrol_t* B_GetBindControlForEvent(ddevent_t* ev)
*/
boolean B_Responder(ddevent_t* ev)
{
if(ev->type == E_FOCUS) return false; // Cannot be bound.

if(symbolicEchoMode && ev->type != E_SYMBOLIC)
{
// Make an echo.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/con_main.c
Expand Up @@ -1512,7 +1512,7 @@ static void insertOnCommandLine(byte ch)
complPos = cmdCursor;
}

boolean Con_Responder(ddevent_t* ev)
boolean Con_Responder(const ddevent_t* ev)
{
// The console is only interested in keyboard toggle events.
if(!IS_KEY_TOGGLE(ev))
Expand Down
17 changes: 0 additions & 17 deletions doomsday/engine/portable/src/dd_input.c
Expand Up @@ -1096,12 +1096,6 @@ static void dispatchEvents(eventqueue_t* q, timespan_t ticLength, boolean update

DD_ConvertEvent(ddev, &ev);

/**
* @todo Refactor: all event processing should occur within the binding
* context stack. Convert all of these special case handlers to context
* fallbacks (may require adding new contexts).
*/

if(callGameResponders)
{
// Does the game's special responder use this event? This is
Expand All @@ -1111,17 +1105,6 @@ static void dispatchEvents(eventqueue_t* q, timespan_t ticLength, boolean update
continue;
}

if(UI_Responder(ddev)) continue; /// @todo: use the bindings system (deui context fallback)
if(Con_Responder(ddev)) continue; /// @todo refactor: use the bindings system

if(callGameResponders) /// @todo refactor: use the bindings system (chat context fallback)
{
// The game's normal responder only returns true if the bindings can't
// be used (like when chatting).
if(gx.Responder && gx.Responder(&ev))
continue;
}

// The bindings responder.
if(B_Responder(ddev)) continue;

Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/ui_main.c
Expand Up @@ -479,7 +479,7 @@ void UI_SetPage(ui_page_t* page)
uiMoved = false;
}

int UI_Responder(ddevent_t* ev)
int UI_Responder(const ddevent_t* ev)
{
if(!uiActive)
return false;
Expand Down Expand Up @@ -509,7 +509,7 @@ int UI_Responder(ddevent_t* ev)
}

// Call the page's responder.
uiCurrentPage->responder(uiCurrentPage, ev);
uiCurrentPage->responder(uiCurrentPage, (ddevent_t*) ev);
// If the UI is active, all events are eaten by it.

return true;
Expand Down

0 comments on commit 4d02b5b

Please sign in to comment.