From 7e638dbf05ecbfdd88e4be466d8f0a7ea72047bb Mon Sep 17 00:00:00 2001 From: Brendan Robert Date: Tue, 9 Jul 2024 19:53:47 -0500 Subject: [PATCH] #41: Treat mouse clicks as joystick buttons --- src/main/java/jace/hardware/Joystick.java | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main/java/jace/hardware/Joystick.java b/src/main/java/jace/hardware/Joystick.java index 0cc96f6..4db93f1 100644 --- a/src/main/java/jace/hardware/Joystick.java +++ b/src/main/java/jace/hardware/Joystick.java @@ -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; @@ -280,6 +281,38 @@ public class Joystick extends Device { 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) { xSwitch = (MemorySoftSwitch) SoftSwitches.PDL0.getSwitch();