|
@@ -1,9 +1,12 @@
|
|
#include "input/Buttons.h"
|
|
#include "input/Buttons.h"
|
|
|
|
|
|
-Buttons::Axis::Axis() : less(0.0f), greater(0.0f), lessIndex(-1), greaterIndex(-1) {
|
|
|
|
|
|
+Buttons::Axis::Axis()
|
|
|
|
+ : less(0.0f), greater(0.0f), lessIndex(-1), greaterIndex(-1) {
|
|
}
|
|
}
|
|
|
|
|
|
-Buttons::Buttons(const Window& window) : window(window), dummy(0, "Dummy"), activeController(-1), gamepadToButton(-1) {
|
|
|
|
|
|
+Buttons::Buttons(const Window& window)
|
|
|
|
+ : window(window), dummy(0, "Dummy"), activeController(-1),
|
|
|
|
+ gamepadToButton(-1) {
|
|
}
|
|
}
|
|
|
|
|
|
Button& Buttons::add(int key, const char* name) {
|
|
Button& Buttons::add(int key, const char* name) {
|
|
@@ -13,6 +16,13 @@ Button& Buttons::add(int key, const char* name) {
|
|
return buttons[buttons.getLength() - 1];
|
|
return buttons[buttons.getLength() - 1];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+Button& Buttons::addMouse(int mouse, const char* name) {
|
|
|
|
+ if(mouseButtons.add(mouse, name)) {
|
|
|
|
+ return dummy;
|
|
|
|
+ }
|
|
|
|
+ return mouseButtons[mouseButtons.getLength() - 1];
|
|
|
|
+}
|
|
|
|
+
|
|
void Buttons::mapGamepadButton(const Button& button, int mapping) {
|
|
void Buttons::mapGamepadButton(const Button& button, int mapping) {
|
|
gamepadToButton[mapping] = searchButton(button);
|
|
gamepadToButton[mapping] = searchButton(button);
|
|
}
|
|
}
|
|
@@ -35,12 +45,38 @@ void Buttons::tick() {
|
|
for(int i = 0; i < buttons.getLength(); i++) {
|
|
for(int i = 0; i < buttons.getLength(); i++) {
|
|
buttons[i].tick(window.isKeyDown(buttons[i].key) || down[i]);
|
|
buttons[i].tick(window.isKeyDown(buttons[i].key) || down[i]);
|
|
}
|
|
}
|
|
|
|
+ for(int i = 0; i < mouseButtons.getLength(); i++) {
|
|
|
|
+ mouseButtons[i].tick(window.isMouseDown(mouseButtons[i].key));
|
|
|
|
+ }
|
|
|
|
+ lastMouseX = mouseX;
|
|
|
|
+ lastMouseY = mouseY;
|
|
|
|
+ window.getMousePosition(mouseX, mouseY);
|
|
}
|
|
}
|
|
|
|
|
|
const ButtonList& Buttons::get() const {
|
|
const ButtonList& Buttons::get() const {
|
|
return buttons;
|
|
return buttons;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+const MouseList& Buttons::getMouse() const {
|
|
|
|
+ return mouseButtons;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+double Buttons::getLastMouseX() const {
|
|
|
|
+ return lastMouseX;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+double Buttons::getLastMouseY() const {
|
|
|
|
+ return lastMouseY;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+double Buttons::getMouseX() const {
|
|
|
|
+ return mouseX;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+double Buttons::getMouseY() const {
|
|
|
|
+ return mouseY;
|
|
|
|
+}
|
|
|
|
+
|
|
bool Buttons::searchForGamepad() {
|
|
bool Buttons::searchForGamepad() {
|
|
if(activeController != -1) {
|
|
if(activeController != -1) {
|
|
return true;
|
|
return true;
|
|
@@ -65,9 +101,11 @@ void Buttons::checkGamepad(DownArray& down) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for(int i = 0; i <= GLFW_GAMEPAD_AXIS_LAST; i++) {
|
|
for(int i = 0; i <= GLFW_GAMEPAD_AXIS_LAST; i++) {
|
|
- if(gamepadAxisToButton[i].greaterIndex != -1 && state.axes[i] > gamepadAxisToButton[i].greater) {
|
|
|
|
|
|
+ if(gamepadAxisToButton[i].greaterIndex != -1 &&
|
|
|
|
+ state.axes[i] > gamepadAxisToButton[i].greater) {
|
|
down[gamepadAxisToButton[i].greaterIndex] = true;
|
|
down[gamepadAxisToButton[i].greaterIndex] = true;
|
|
- } else if(gamepadAxisToButton[i].lessIndex != -1 && state.axes[i] < gamepadAxisToButton[i].less) {
|
|
|
|
|
|
+ } else if(gamepadAxisToButton[i].lessIndex != -1 &&
|
|
|
|
+ state.axes[i] < gamepadAxisToButton[i].less) {
|
|
down[gamepadAxisToButton[i].lessIndex] = true;
|
|
down[gamepadAxisToButton[i].lessIndex] = true;
|
|
}
|
|
}
|
|
}
|
|
}
|