-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc8ad70
commit 2d4ab1d
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2020-present, Fred Emmott <[email protected]> | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the ISC license found in the LICENSE file | ||
* in the root directory of this source tree. | ||
*/ | ||
#pragma once | ||
|
||
#include "Sink.h" | ||
#include "SinkPtr.h" | ||
|
||
namespace fredemmott::inputmapping { | ||
|
||
template <control T> | ||
class Shift : public Sink<T> { | ||
private: | ||
bool* mShifted = nullptr; | ||
SinkPtr<T> mA, mB; | ||
|
||
public: | ||
template <convertible_to_sink_ptr<T> A, convertible_to_sink_ptr<T> B> | ||
Shift(bool* shifted, A&& a, B&& b) | ||
: mShifted(shifted), | ||
mA(convert_to_any_sink_ptr(std::forward<A>(a))), | ||
mB(convert_to_any_sink_ptr(std::forward<B>(b))) { | ||
} | ||
|
||
virtual void map(typename T::Value value) override { | ||
auto next = *mShifted ? mB : mA; | ||
next->map(value); | ||
} | ||
}; | ||
|
||
// Help template inference along a bit... | ||
|
||
template <convertible_to_sink_ptr<Axis> A, convertible_to_sink_ptr<Axis> B> | ||
Shift(bool*, A, B) -> Shift<Axis>; | ||
|
||
template <convertible_to_sink_ptr<Button> A, convertible_to_sink_ptr<Button> B> | ||
Shift(bool*, A, B) -> Shift<Button>; | ||
|
||
template <convertible_to_sink_ptr<Hat> A, convertible_to_sink_ptr<Hat> B> | ||
Shift(bool*, A, B) -> Shift<Hat>; | ||
|
||
}// namespace fredemmott::inputmapping |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2020-present, Fred Emmott <[email protected]> | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the ISC license found in the LICENSE file | ||
* in the root directory of this source tree. | ||
*/ | ||
|
||
#include "Shift.h" | ||
|
||
#include "MappableVJoyOutput.h" | ||
#include "tests.h" | ||
|
||
using namespace fredemmott::inputmapping; | ||
|
||
TEST_CASE("Shift") { | ||
bool shifted = false; | ||
TestButton button; | ||
bool a = false, b = false; | ||
|
||
button >> Shift(&shifted, &a, &b); | ||
|
||
button.emit(true); | ||
REQUIRE(a); | ||
REQUIRE(!b); | ||
|
||
button.emit(false); | ||
REQUIRE(!a); | ||
REQUIRE(!b); | ||
|
||
shifted = true; | ||
button.emit(true); | ||
REQUIRE(!a); | ||
REQUIRE(b); | ||
} |