Skip to content

Commit

Permalink
InputSystem|Client: InputDevice (de)activation is now observable
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 1, 2014
1 parent 5780aab commit 49e868b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions doomsday/client/include/ui/dd_input.h
Expand Up @@ -25,6 +25,7 @@
#include <de/smoother.h>
#include <de/Error>
#include <de/Event>
#include <de/Observers>
#include <de/String>

#include "api_event.h"
Expand All @@ -46,6 +47,9 @@ class InputDevice
/// Referenced control is missing. @ingroup errors
DENG2_ERROR(MissingControlError);

/// Notified when the active state of the device changes.
DENG2_DEFINE_AUDIENCE2(ActiveChange, void inputDeviceActiveChanged(InputDevice &device))

/**
* Base class for all controls.
*/
Expand Down
30 changes: 24 additions & 6 deletions doomsday/client/src/ui/dd_input.cpp
Expand Up @@ -561,8 +561,12 @@ DENG2_PIMPL(InputDevice)
qDeleteAll(buttons);
qDeleteAll(axes);
}

DENG2_PIMPL_AUDIENCE(ActiveChange)
};

DENG2_AUDIENCE_METHOD(InputDevice, ActiveChange)

InputDevice::InputDevice(String const &name) : d(new Instance(this))
{
DENG2_ASSERT(!name.isEmpty());
Expand All @@ -579,7 +583,13 @@ bool InputDevice::isActive() const

void InputDevice::activate(bool yes)
{
d->active = yes;
if(d->active != yes)
{
d->active = yes;

// Notify interested parties.
DENG2_FOR_AUDIENCE2(ActiveChange, i) i->inputDeviceActiveChanged(*this);
}
}

String InputDevice::name() const
Expand Down Expand Up @@ -644,15 +654,15 @@ void InputDevice::reset()
LOG_AS("InputDevice");
LOG_INPUT_VERBOSE("Reseting %s") << title();

for(InputDeviceAxisControl *axis : d->axes)
for(Control *axis : d->axes)
{
axis->reset();
}
for(InputDeviceButtonControl *button : d->buttons)
for(Control *button : d->buttons)
{
button->reset();
}
for(InputDeviceHatControl *hat : d->hats)
for(Control *hat : d->hats)
{
hat->reset();
}
Expand Down Expand Up @@ -684,10 +694,18 @@ LoopResult InputDevice::forAllControls(std::function<de::LoopResult (Control &)>

void InputDevice::consoleRegister()
{
for(InputDeviceAxisControl *axis : d->axes)
for(Control *axis : d->axes)
{
axis->consoleRegister();
}
for(Control *button : d->buttons)
{
button->consoleRegister();
}
for(Control *hat : d->hats)
{
hat->consoleRegister();
}
}

dint InputDevice::toAxisId(String const &name) const
Expand Down Expand Up @@ -977,7 +995,7 @@ static InputDevice *addDevice(InputDevice *device)
{
if(!otherDevice->name().compareWithoutCase(device->name()))
{
throw Error("InputSystem::addInputDevice", "Multiple devices with name:" + device->name() + " cannot coexist");
throw Error("InputSystem::addDevice", "Multiple devices with name:" + device->name() + " cannot coexist");
}
}

Expand Down

0 comments on commit 49e868b

Please sign in to comment.