#41: Treat mouse clicks as joystick buttons

This commit is contained in:
Brendan Robert 2024-07-09 19:53:47 -05:00
parent 41310b43e7
commit 7e638dbf05

View File

@ -41,6 +41,7 @@ import jace.core.Utility;
import jace.core.Utility.OS;
import jace.state.Stateful;
import javafx.application.Platform;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
@ -279,6 +280,38 @@ public class Joystick extends Device {
joyX = (int) (event.getX() / stage.getWidth() * 255);
joyY = (int) (event.getY() / stage.getHeight() * 255);
}
});
stage.addEventHandler(MouseEvent.MOUSE_PRESSED, event -> {
if (!useKeyboard && !selectedPhysicalController()) {
if (event.getButton() == MouseButton.PRIMARY) {
if (port == 0) {
SoftSwitches.PB0.getSwitch().setState(true);
Keyboard.isOpenApplePressed = true;
} else {
SoftSwitches.PB2.getSwitch().setState(true);
}
}
if (event.getButton() == MouseButton.SECONDARY) {
Keyboard.isClosedApplePressed = true;
SoftSwitches.PB1.getSwitch().setState(true);
}
}
});
stage.addEventHandler(MouseEvent.MOUSE_RELEASED, event -> {
if (event.getButton() == MouseButton.PRIMARY) {
if (port == 0) {
SoftSwitches.PB0.getSwitch().setState(false);
Keyboard.isOpenApplePressed = false;
} else {
SoftSwitches.PB2.getSwitch().setState(false);
}
}
if (event.getButton() == MouseButton.SECONDARY) {
Keyboard.isClosedApplePressed = false;
SoftSwitches.PB1.getSwitch().setState(false);
}
});
this.port = port;
if (port == 0) {