Skip to content

Commit

Permalink
UI|Bindings: Added widget for making an input binding
Browse files Browse the repository at this point in the history
The bindings subsystem was enhanced with functions for finding
existing bindings for a command and deleting bindings based on
the bound command.

InputBindingWidget currently supports only command bindings for
the keyboard device.
  • Loading branch information
skyjake committed Mar 9, 2014
1 parent a5bae2b commit 514dcfa
Show file tree
Hide file tree
Showing 9 changed files with 381 additions and 9 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/client.pro
Expand Up @@ -398,6 +398,7 @@ DENG_HEADERS += \
include/ui/widgets/gameuiwidget.h \
include/ui/widgets/gamewidget.h \
include/ui/widgets/icvarwidget.h \
include/ui/widgets/inputbindingwidget.h \
include/ui/widgets/keygrabberwidget.h \
include/ui/widgets/mpselectionwidget.h \
include/ui/widgets/multiplayermenuwidget.h \
Expand Down Expand Up @@ -733,6 +734,7 @@ SOURCES += \
src/ui/widgets/gamesessionwidget.cpp \
src/ui/widgets/gamewidget.cpp \
src/ui/widgets/gameuiwidget.cpp \
src/ui/widgets/inputbindingwidget.cpp \
src/ui/widgets/keygrabberwidget.cpp \
src/ui/widgets/mpselectionwidget.cpp \
src/ui/widgets/multiplayermenuwidget.cpp \
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/include/ui/b_command.h
Expand Up @@ -52,6 +52,8 @@ evbinding_t* B_NewCommandBinding(evbinding_t* listRoot, const char* desc, const
void B_DestroyCommandBinding(evbinding_t* eb);
void B_EventBindingToString(const evbinding_t* eb, ddstring_t* str);

evbinding_t *B_FindCommandBinding(evbinding_t const *listRoot, char const *command, uint device);

/**
* Checks if the event matches the binding's conditions, and if so, returns an
* action with the bound command.
Expand Down
9 changes: 7 additions & 2 deletions doomsday/client/include/ui/b_context.h
Expand Up @@ -98,8 +98,13 @@ de::Action *B_ActionForEvent(ddevent_t const *event);
*/
de::Action *BindContext_ActionForEvent(bcontext_t *bc, ddevent_t const *event, bool respectHigherAssociatedContexts);

dd_bool B_FindMatchingBinding(bcontext_t* bc, evbinding_t* match1, dbinding_t* match2,
evbinding_t** evResult, dbinding_t** dResult);
/**
* Looks through context @a bc and looks for a binding that matches either
* @a match1 or @a match2.
*/
dd_bool B_FindMatchingBinding(bcontext_t* bc, evbinding_t* match1, dbinding_t* match2,
evbinding_t** evResult, dbinding_t** dResult);

void B_PrintContexts(void);
void B_PrintAllBindings(void);
void B_WriteContextToFile(const bcontext_t* bc, FILE* file);
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/include/ui/b_main.h
Expand Up @@ -57,6 +57,8 @@ struct evbinding_s* B_BindCommand(const char* eventDesc, const char* command);
struct dbinding_s* B_BindControl(const char* controlDesc, const char* device);
struct dbinding_s* B_GetControlDeviceBindings(int localNum, int control, struct bcontext_s** bContext);

bool B_UnbindCommand(char const *command);

// Utils
/// @todo: move to b_util.h
int B_NewIdentifier(void);
Expand Down
62 changes: 62 additions & 0 deletions doomsday/client/include/ui/widgets/inputbindingwidget.h
@@ -0,0 +1,62 @@
/** @file inputbindingwidget.h Widget for creating input bindings.
*
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef DENG_CLIENT_INPUTBINDINGWIDGET_H
#define DENG_CLIENT_INPUTBINDINGWIDGET_H

#include <de/AuxButtonWidget>

/**
* Widget for viewing and changing an input binding.
*/
class InputBindingWidget : public de::AuxButtonWidget
{
public:
InputBindingWidget();

void setDefaultBinding(de::String const &eventDesc);

void setCommand(de::String const &command);

/**
* Enables or disables explicitly specified modifier conditions. Bindings can be
* specified with or without modifiers -- if modifiers are not specified, the binding
* can be triggered regardless of modifier state.
*
* @param mods @c true to includes modifiers in the binding. If @c false, modifiers
* can be bound like any other input.
*/
void enableModifiers(bool mods);

void setContext(QString const &bindingContext) {
setContexts(QStringList() << bindingContext);
}

void setContexts(QStringList const &contexts);

// Events.
bool handleEvent(de::Event const &event);

public:
static InputBindingWidget *newTaskBarShortcut();

private:
DENG2_PRIVATE(d)
};

#endif // DENG_CLIENT_INPUTBINDINGWIDGET_H
13 changes: 13 additions & 0 deletions doomsday/client/src/ui/b_command.cpp
Expand Up @@ -514,3 +514,16 @@ void B_EventBindingToString(const evbinding_t* eb, ddstring_t* str)
B_AppendConditionToString(&eb->conds[i], str);
}
}

evbinding_t *B_FindCommandBinding(evbinding_t const *listRoot, char const *command, uint device)
{
for(evbinding_t *i = listRoot->next; i != listRoot; i = i->next)
{
if(!qstricmp(i->command, command) &&
(device >= NUM_INPUT_DEVICES || i->device == device))
{
return i;
}
}
return 0;
}
8 changes: 1 addition & 7 deletions doomsday/client/src/ui/b_context.cpp
Expand Up @@ -404,11 +404,9 @@ void B_ReorderContext(bcontext_t* bc, int pos)

controlbinding_t* B_NewControlBinding(bcontext_t* bc)
{
int i;

controlbinding_t* conBin = (controlbinding_t *) M_Calloc(sizeof(controlbinding_t));
conBin->bid = B_NewIdentifier();
for(i = 0; i < DDMAXPLAYERS; ++i)
for(int i = 0; i < DDMAXPLAYERS; ++i)
{
B_InitDeviceBindingList(&conBin->deviceBinds[i]);
}
Expand Down Expand Up @@ -724,10 +722,6 @@ dd_bool B_AreConditionsEqual(int count1, const statecondition_t* conds1,
return true;
}

/**
* Looks through context @a bc and looks for a binding that matches either
* @a match1 or @a match2.
*/
dd_bool B_FindMatchingBinding(bcontext_t* bc, evbinding_t* match1,
dbinding_t* match2, evbinding_t** evResult,
dbinding_t** dResult)
Expand Down
14 changes: 14 additions & 0 deletions doomsday/client/src/ui/b_main.cpp
Expand Up @@ -725,3 +725,17 @@ DENG_EXTERN_C int DD_GetKeyCode(const char* key)
int code = B_KeyForShortName(key);
return (code ? code : key[0]);
}

bool B_UnbindCommand(const char *command)
{
bool deleted = false;
for(int i = 0; i < B_ContextCount(); ++i)
{
bcontext_t *bc = B_ContextByPos(i);
while(evbinding_t *ev = B_FindCommandBinding(&bc->commandBinds, command, NUM_INPUT_DEVICES))
{
deleted |= B_DeleteBinding(bc, ev->bid);
}
}
return deleted;
}

0 comments on commit 514dcfa

Please sign in to comment.