Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package utilities.input;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- public class MouseInput extends MouseAdapter {
- private static final int NUM_BUTTONS = 10;
- private static final boolean[] BUTTONS = new boolean[NUM_BUTTONS];
- private static final boolean[] LAST_BUTTONS = new boolean[NUM_BUTTONS];
- private static int x = -1, y = -1;
- private static int lastX = x, lastY = y;
- private static boolean moving = false;
- @Override
- public void mousePressed(MouseEvent me) {
- BUTTONS[me.getButton()] = true;
- }
- @Override
- public void mouseReleased(MouseEvent me) {
- BUTTONS[me.getButton()] = false;
- }
- @Override
- public void mouseMoved(MouseEvent me) {
- x = me.getX();
- y = me.getY();
- moving = true;
- }
- public static void update() {
- for (int i = 0; i < NUM_BUTTONS; i++) {
- LAST_BUTTONS[i] = BUTTONS[i];
- }
- if (x == lastX && y == lastY)
- moving = false;
- lastX = x;
- lastY = y;
- }
- public static boolean isButtonPressed(int button) {
- return BUTTONS[button];
- }
- public static boolean wasButtonPressed(int button) {
- return isButtonPressed(button) && !LAST_BUTTONS[button];
- }
- public static boolean wasButtonReleased(int button) {
- return !isButtonPressed(button) && LAST_BUTTONS[button];
- }
- public static int getX() {
- return x;
- }
- public static int getY() {
- return y;
- }
- public static boolean isMoving() {
- return moving;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement