|
@ -38,6 +38,11 @@ void Control::setDeadzone(float value) |
|
|
|
|
|
|
|
|
void Control::update() |
|
|
void Control::update() |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (!boundMouseWheelAxes.empty()) |
|
|
|
|
|
{ |
|
|
|
|
|
currentValue = 0.0f; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
previousValue = currentValue; |
|
|
previousValue = currentValue; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -53,7 +58,7 @@ bool Control::wasTriggered() const |
|
|
|
|
|
|
|
|
bool Control::isUnbound() const |
|
|
bool Control::isUnbound() const |
|
|
{ |
|
|
{ |
|
|
return (boundKeys.empty() && boundMouseButtons.empty() && boundGamepadButtons.empty() && boundGamepadAxes.empty()); |
|
|
|
|
|
|
|
|
return (boundKeys.empty() && boundMouseButtons.empty() && boundMouseWheelAxes.empty() && boundGamepadButtons.empty() && boundGamepadAxes.empty()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Control::bindKey(Keyboard* keyboard, int scancode) |
|
|
void Control::bindKey(Keyboard* keyboard, int scancode) |
|
@ -92,6 +97,24 @@ void Control::bindMouseButton(Mouse* mouse, int button) |
|
|
boundMouseButtons.push_back(std::pair<Mouse*, int>(mouse, button)); |
|
|
boundMouseButtons.push_back(std::pair<Mouse*, int>(mouse, button)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Control::bindMouseWheelAxis(Mouse* mouse, MouseWheelAxis axis) |
|
|
|
|
|
{ |
|
|
|
|
|
// Checking if already observing this mouse
|
|
|
|
|
|
bool observing = false; |
|
|
|
|
|
for (auto it: boundMouseWheelAxes) |
|
|
|
|
|
{ |
|
|
|
|
|
if (it.first == mouse) |
|
|
|
|
|
{ |
|
|
|
|
|
observing = true; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!observing) |
|
|
|
|
|
mouse->addMouseWheelObserver(static_cast<MouseWheelObserver*>(this)); |
|
|
|
|
|
boundMouseWheelAxes.push_back(std::pair<Mouse*, MouseWheelAxis>(mouse, axis)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void Control::bindGamepadButton(Gamepad* gamepad, int button) |
|
|
void Control::bindGamepadButton(Gamepad* gamepad, int button) |
|
|
{ |
|
|
{ |
|
|
bool observing = false; |
|
|
bool observing = false; |
|
@ -138,6 +161,27 @@ void Control::bind(const InputEvent& event) |
|
|
bindMouseButton(event.mouseButton.first, event.mouseButton.second); |
|
|
bindMouseButton(event.mouseButton.first, event.mouseButton.second); |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case InputEvent::Type::MOUSE_WHEEL: |
|
|
|
|
|
{ |
|
|
|
|
|
int x = std::get<1>(event.mouseWheel); |
|
|
|
|
|
int y = std::get<2>(event.mouseWheel); |
|
|
|
|
|
|
|
|
|
|
|
MouseWheelAxis axis; |
|
|
|
|
|
if (x > 0) |
|
|
|
|
|
axis = MouseWheelAxis::POSITIVE_X; |
|
|
|
|
|
else if (x < 0) |
|
|
|
|
|
axis = MouseWheelAxis::NEGATIVE_X; |
|
|
|
|
|
else if (y > 0) |
|
|
|
|
|
axis = MouseWheelAxis::POSITIVE_Y; |
|
|
|
|
|
else if (y < 0) |
|
|
|
|
|
axis = MouseWheelAxis::NEGATIVE_Y; |
|
|
|
|
|
else |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
bindMouseWheelAxis(std::get<0>(event.mouseWheel), axis); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
case InputEvent::Type::GAMEPAD_BUTTON: |
|
|
case InputEvent::Type::GAMEPAD_BUTTON: |
|
|
bindGamepadButton(event.gamepadButton.first, event.gamepadButton.second); |
|
|
bindGamepadButton(event.gamepadButton.first, event.gamepadButton.second); |
|
|
break; |
|
|
break; |
|
@ -189,6 +233,24 @@ void Control::unbind() |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
while (!boundMouseWheelAxes.empty()) |
|
|
|
|
|
{ |
|
|
|
|
|
// Remove the first bound mouse button and stop observing its mouse
|
|
|
|
|
|
Mouse* mouse = boundMouseWheelAxes.front().first; |
|
|
|
|
|
mouse->removeMouseWheelObserver(static_cast<MouseWheelObserver*>(this)); |
|
|
|
|
|
boundMouseWheelAxes.pop_front(); |
|
|
|
|
|
|
|
|
|
|
|
// Remove other bound mouse buttons which are associated with the mouse
|
|
|
|
|
|
auto it = boundMouseWheelAxes.begin(); |
|
|
|
|
|
while (it != boundMouseWheelAxes.end()) |
|
|
|
|
|
{ |
|
|
|
|
|
if (it->first == mouse) |
|
|
|
|
|
boundMouseWheelAxes.erase(it++); |
|
|
|
|
|
else |
|
|
|
|
|
++it; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
while (!boundGamepadButtons.empty()) |
|
|
while (!boundGamepadButtons.empty()) |
|
|
{ |
|
|
{ |
|
|
// Remove the first bound gamepad button and stop observing its gamepad
|
|
|
// Remove the first bound gamepad button and stop observing its gamepad
|
|
@ -274,6 +336,33 @@ void Control::mouseButtonReleased(int button, int x, int y) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Control::mouseWheelScrolled(int x, int y) |
|
|
|
|
|
{ |
|
|
|
|
|
for (auto it: boundMouseWheelAxes) |
|
|
|
|
|
{ |
|
|
|
|
|
if (it.second == MouseWheelAxis::POSITIVE_X && x > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
currentValue += x; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
else if (it.second == MouseWheelAxis::NEGATIVE_X && x < 0) |
|
|
|
|
|
{ |
|
|
|
|
|
currentValue -= x; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
else if (it.second == MouseWheelAxis::POSITIVE_Y && y > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
currentValue += y; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
else if (it.second == MouseWheelAxis::NEGATIVE_Y && y < 0) |
|
|
|
|
|
{ |
|
|
|
|
|
currentValue -= y; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void Control::gamepadButtonPressed(int button) |
|
|
void Control::gamepadButtonPressed(int button) |
|
|
{ |
|
|
{ |
|
|
for (auto it: boundGamepadButtons) |
|
|
for (auto it: boundGamepadButtons) |
|
@ -320,6 +409,11 @@ const std::list>* Control::getBoundMouseButtons() const |
|
|
return &boundMouseButtons; |
|
|
return &boundMouseButtons; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const std::list<std::pair<Mouse*, MouseWheelAxis>>* Control::getBoundMouseWheelAxes() const |
|
|
|
|
|
{ |
|
|
|
|
|
return &boundMouseWheelAxes; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const std::list<std::pair<Gamepad*, int>>* Control::getBoundGamepadButtons() const |
|
|
const std::list<std::pair<Gamepad*, int>>* Control::getBoundGamepadButtons() const |
|
|
{ |
|
|
{ |
|
|
return &boundGamepadButtons; |
|
|
return &boundGamepadButtons; |
|
@ -354,6 +448,7 @@ bool ControlProfile::save(const std::string& filename) |
|
|
Control* control = it->second; |
|
|
Control* control = it->second; |
|
|
const std::list<std::pair<Keyboard*, int>>* boundKeys = control->getBoundKeys(); |
|
|
const std::list<std::pair<Keyboard*, int>>* boundKeys = control->getBoundKeys(); |
|
|
const std::list<std::pair<Mouse*, int>>* boundMouseButtons = control->getBoundMouseButtons(); |
|
|
const std::list<std::pair<Mouse*, int>>* boundMouseButtons = control->getBoundMouseButtons(); |
|
|
|
|
|
const std::list<std::pair<Mouse*, MouseWheelAxis>>* boundMouseWheelAxes = control->getBoundMouseWheelAxes(); |
|
|
const std::list<std::pair<Gamepad*, int>>* boundGamepadButtons = control->getBoundGamepadButtons(); |
|
|
const std::list<std::pair<Gamepad*, int>>* boundGamepadButtons = control->getBoundGamepadButtons(); |
|
|
const std::list<std::tuple<Gamepad*, int, bool>>* boundGamepadAxes = control->getBoundGamepadAxes(); |
|
|
const std::list<std::tuple<Gamepad*, int, bool>>* boundGamepadAxes = control->getBoundGamepadAxes(); |
|
|
|
|
|
|
|
@ -369,6 +464,24 @@ bool ControlProfile::save(const std::string& filename) |
|
|
file << "control\t" << it->first << "\tmouse\tbutton\t" << button << '\n'; |
|
|
file << "control\t" << it->first << "\tmouse\tbutton\t" << button << '\n'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (auto boundMouseWheelAxis: *boundMouseWheelAxes) |
|
|
|
|
|
{ |
|
|
|
|
|
MouseWheelAxis axis = boundMouseWheelAxis.second; |
|
|
|
|
|
|
|
|
|
|
|
file << "control\t" << it->first << "\tmouse\twheel\t"; |
|
|
|
|
|
if (axis == MouseWheelAxis::POSITIVE_X) |
|
|
|
|
|
file << "+x"; |
|
|
|
|
|
else if (axis == MouseWheelAxis::NEGATIVE_X) |
|
|
|
|
|
file << "-x"; |
|
|
|
|
|
else if (axis == MouseWheelAxis::POSITIVE_Y) |
|
|
|
|
|
file << "+y"; |
|
|
|
|
|
else if (axis == MouseWheelAxis::NEGATIVE_Y) |
|
|
|
|
|
file << "-y"; |
|
|
|
|
|
else |
|
|
|
|
|
file << "unknown"; |
|
|
|
|
|
file << '\n'; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
for (auto boundGamepadButton: *boundGamepadButtons) |
|
|
for (auto boundGamepadButton: *boundGamepadButtons) |
|
|
{ |
|
|
{ |
|
|
const std::string& gamepadName = boundGamepadButton.first->getName(); |
|
|
const std::string& gamepadName = boundGamepadButton.first->getName(); |
|
@ -463,6 +576,25 @@ bool ControlProfile::load(const std::string& filename) |
|
|
|
|
|
|
|
|
control->bindMouseButton(mouse, button); |
|
|
control->bindMouseButton(mouse, button); |
|
|
} |
|
|
} |
|
|
|
|
|
else if (tokens[3] == "wheel") |
|
|
|
|
|
{ |
|
|
|
|
|
MouseWheelAxis axis; |
|
|
|
|
|
if (tokens[4] == "+x") |
|
|
|
|
|
axis = MouseWheelAxis::POSITIVE_X; |
|
|
|
|
|
else if (tokens[4] == "-x") |
|
|
|
|
|
axis = MouseWheelAxis::NEGATIVE_X; |
|
|
|
|
|
else if (tokens[4] == "+y") |
|
|
|
|
|
axis = MouseWheelAxis::POSITIVE_Y; |
|
|
|
|
|
else if (tokens[4] == "-y") |
|
|
|
|
|
axis = MouseWheelAxis::NEGATIVE_Y; |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
std::cerr << "Invalid line \"" << line << "\" in control profile \"" << filename << "\"" << std::endl; |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
control->bindMouseWheelAxis(mouse, axis); |
|
|
|
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
std::cerr << "Invalid line \"" << line << "\" in control profile \"" << filename << "\"" << std::endl; |
|
|
std::cerr << "Invalid line \"" << line << "\" in control profile \"" << filename << "\"" << std::endl; |
|
|