Add support for intercepting mouse and keyboard input
Also allow translating mouse input for stretched fixed mode. This is required for moving overlays, and interacting with the instance map.
This commit is contained in:
@@ -28,6 +28,9 @@ import com.google.common.eventbus.EventBus;
|
||||
import com.google.inject.Injector;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.Client;
|
||||
@@ -52,6 +55,8 @@ import static net.runelite.api.widgets.WidgetID.WORLD_MAP;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.chat.ChatMessageManager;
|
||||
import net.runelite.client.game.DeathChecker;
|
||||
import net.runelite.client.input.KeyManager;
|
||||
import net.runelite.client.input.MouseManager;
|
||||
import net.runelite.client.task.Scheduler;
|
||||
import net.runelite.client.ui.overlay.OverlayLayer;
|
||||
import net.runelite.client.ui.overlay.OverlayRenderer;
|
||||
@@ -73,6 +78,8 @@ public class Hooks
|
||||
private static final InfoBoxManager infoBoxManager = injector.getInstance(InfoBoxManager.class);
|
||||
private static final ChatMessageManager chatMessageManager = injector.getInstance(ChatMessageManager.class);
|
||||
private static final OverlayRenderer renderer = injector.getInstance(OverlayRenderer.class);
|
||||
private static final MouseManager mouseManager = injector.getInstance(MouseManager.class);
|
||||
private static final KeyManager keyManager = injector.getInstance(KeyManager.class);
|
||||
private static final DeathChecker death = new DeathChecker(client, eventBus);
|
||||
private static final GameTick tick = new GameTick();
|
||||
|
||||
@@ -140,6 +147,61 @@ public class Hooks
|
||||
}
|
||||
}
|
||||
|
||||
public static MouseEvent mousePressed(MouseEvent mouseEvent)
|
||||
{
|
||||
return mouseManager.processMousePressed(mouseEvent);
|
||||
}
|
||||
|
||||
public static MouseEvent mouseReleased(MouseEvent mouseEvent)
|
||||
{
|
||||
return mouseManager.processMouseReleased(mouseEvent);
|
||||
}
|
||||
|
||||
public static MouseEvent mouseClicked(MouseEvent mouseEvent)
|
||||
{
|
||||
return mouseManager.processMouseClicked(mouseEvent);
|
||||
}
|
||||
|
||||
public static MouseEvent mouseEntered(MouseEvent mouseEvent)
|
||||
{
|
||||
return mouseManager.processMouseEntered(mouseEvent);
|
||||
}
|
||||
|
||||
public static MouseEvent mouseExited(MouseEvent mouseEvent)
|
||||
{
|
||||
return mouseManager.processMouseExited(mouseEvent);
|
||||
}
|
||||
|
||||
public static MouseEvent mouseDragged(MouseEvent mouseEvent)
|
||||
{
|
||||
return mouseManager.processMouseDragged(mouseEvent);
|
||||
}
|
||||
|
||||
public static MouseEvent mouseMoved(MouseEvent mouseEvent)
|
||||
{
|
||||
return mouseManager.processMouseMoved(mouseEvent);
|
||||
}
|
||||
|
||||
public static void mouseWheelMoved(MouseWheelEvent event)
|
||||
{
|
||||
mouseManager.processMouseWheelMoved(event);
|
||||
}
|
||||
|
||||
public static void keyPressed(KeyEvent keyEvent)
|
||||
{
|
||||
keyManager.processKeyPressed(keyEvent);
|
||||
}
|
||||
|
||||
public static void keyReleased(KeyEvent keyEvent)
|
||||
{
|
||||
keyManager.processKeyReleased(keyEvent);
|
||||
}
|
||||
|
||||
public static void keyTyped(KeyEvent keyEvent)
|
||||
{
|
||||
keyManager.processKeyTyped(keyEvent);
|
||||
}
|
||||
|
||||
public static void draw(MainBufferProvider mainBufferProvider, Graphics graphics, int x, int y)
|
||||
{
|
||||
final BufferedImage image = (BufferedImage) mainBufferProvider.getImage();
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.client.input;
|
||||
|
||||
public interface KeyListener extends java.awt.event.KeyListener
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.client.input;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class KeyManager
|
||||
{
|
||||
private final List<KeyListener> keyListeners = new CopyOnWriteArrayList<>();
|
||||
|
||||
public void registerKeyListener(KeyListener keyListener)
|
||||
{
|
||||
keyListeners.add(keyListener);
|
||||
}
|
||||
|
||||
public void unregisterKeyListener(KeyListener keyListener)
|
||||
{
|
||||
keyListeners.remove(keyListener);
|
||||
}
|
||||
|
||||
public void processKeyPressed(KeyEvent keyEvent)
|
||||
{
|
||||
for (KeyListener keyListener : keyListeners)
|
||||
{
|
||||
keyListener.keyPressed(keyEvent);
|
||||
}
|
||||
}
|
||||
|
||||
public void processKeyReleased(KeyEvent keyEvent)
|
||||
{
|
||||
for (KeyListener keyListener : keyListeners)
|
||||
{
|
||||
keyListener.keyReleased(keyEvent);
|
||||
}
|
||||
}
|
||||
|
||||
public void processKeyTyped(KeyEvent keyEvent)
|
||||
{
|
||||
for (KeyListener keyListener : keyListeners)
|
||||
{
|
||||
keyListener.keyTyped(keyEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.client.input;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public abstract class MouseListener
|
||||
{
|
||||
public MouseEvent mouseClicked(MouseEvent mouseEvent)
|
||||
{
|
||||
return mouseEvent;
|
||||
}
|
||||
|
||||
public MouseEvent mousePressed(MouseEvent mouseEvent)
|
||||
{
|
||||
return mouseEvent;
|
||||
}
|
||||
|
||||
public MouseEvent mouseReleased(MouseEvent mouseEvent)
|
||||
{
|
||||
return mouseEvent;
|
||||
}
|
||||
|
||||
public MouseEvent mouseEntered(MouseEvent mouseEvent)
|
||||
{
|
||||
return mouseEvent;
|
||||
}
|
||||
|
||||
public MouseEvent mouseExited(MouseEvent mouseEvent)
|
||||
{
|
||||
return mouseEvent;
|
||||
}
|
||||
|
||||
public MouseEvent mouseDragged(MouseEvent mouseEvent)
|
||||
{
|
||||
return mouseEvent;
|
||||
}
|
||||
|
||||
public MouseEvent mouseMoved(MouseEvent mouseEvent)
|
||||
{
|
||||
return mouseEvent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.client.input;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class MouseManager
|
||||
{
|
||||
private final List<MouseListener> mouseListeners = new CopyOnWriteArrayList<>();
|
||||
private final List<MouseWheelListener> mouseWheelListeners = new CopyOnWriteArrayList<>();
|
||||
|
||||
public void registerMouseListener(MouseListener mouseListener)
|
||||
{
|
||||
mouseListeners.add(mouseListener);
|
||||
}
|
||||
|
||||
public void unregisterMouseListener(MouseListener mouseListener)
|
||||
{
|
||||
mouseListeners.remove(mouseListener);
|
||||
}
|
||||
|
||||
public void registerMouseWheelListener(MouseWheelListener mouseWheelListener)
|
||||
{
|
||||
mouseWheelListeners.add(mouseWheelListener);
|
||||
}
|
||||
|
||||
public void unregisterMouseWheelListener(MouseWheelListener mouseWheelListener)
|
||||
{
|
||||
mouseWheelListeners.remove(mouseWheelListener);
|
||||
}
|
||||
|
||||
public MouseEvent processMousePressed(MouseEvent mouseEvent)
|
||||
{
|
||||
for (MouseListener mouseListener : mouseListeners)
|
||||
{
|
||||
mouseEvent = mouseListener.mousePressed(mouseEvent);
|
||||
}
|
||||
return mouseEvent;
|
||||
}
|
||||
|
||||
public MouseEvent processMouseReleased(MouseEvent mouseEvent)
|
||||
{
|
||||
for (MouseListener mouseListener : mouseListeners)
|
||||
{
|
||||
mouseEvent = mouseListener.mouseReleased(mouseEvent);
|
||||
}
|
||||
return mouseEvent;
|
||||
}
|
||||
|
||||
public MouseEvent processMouseClicked(MouseEvent mouseEvent)
|
||||
{
|
||||
for (MouseListener mouseListener : mouseListeners)
|
||||
{
|
||||
mouseEvent = mouseListener.mouseClicked(mouseEvent);
|
||||
}
|
||||
return mouseEvent;
|
||||
}
|
||||
|
||||
public MouseEvent processMouseEntered(MouseEvent mouseEvent)
|
||||
{
|
||||
for (MouseListener mouseListener : mouseListeners)
|
||||
{
|
||||
mouseEvent = mouseListener.mouseEntered(mouseEvent);
|
||||
}
|
||||
return mouseEvent;
|
||||
}
|
||||
|
||||
public MouseEvent processMouseExited(MouseEvent mouseEvent)
|
||||
{
|
||||
for (MouseListener mouseListener : mouseListeners)
|
||||
{
|
||||
mouseEvent = mouseListener.mouseExited(mouseEvent);
|
||||
}
|
||||
return mouseEvent;
|
||||
}
|
||||
|
||||
public MouseEvent processMouseDragged(MouseEvent mouseEvent)
|
||||
{
|
||||
for (MouseListener mouseListener : mouseListeners)
|
||||
{
|
||||
mouseEvent = mouseListener.mouseDragged(mouseEvent);
|
||||
}
|
||||
return mouseEvent;
|
||||
}
|
||||
|
||||
public MouseEvent processMouseMoved(MouseEvent mouseEvent)
|
||||
{
|
||||
for (MouseListener mouseListener : mouseListeners)
|
||||
{
|
||||
mouseEvent = mouseListener.mouseMoved(mouseEvent);
|
||||
}
|
||||
return mouseEvent;
|
||||
}
|
||||
|
||||
public void processMouseWheelMoved(MouseWheelEvent mouseWheelEvent)
|
||||
{
|
||||
for (MouseWheelListener mouseWheelListener : mouseWheelListeners)
|
||||
{
|
||||
mouseWheelListener.mouseWheelMoved(mouseWheelEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.client.input;
|
||||
|
||||
public interface MouseWheelListener extends java.awt.event.MouseWheelListener
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user