mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-06-15 21:31:12 +00:00
added support for mouse
This commit is contained in:
@@ -1,25 +1,45 @@
|
|||||||
package com.limelight.gui;
|
package com.limelight.gui;
|
||||||
|
|
||||||
|
import java.awt.Cursor;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Point;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
import com.limelight.input.KeyboardHandler;
|
import com.limelight.input.KeyboardHandler;
|
||||||
|
import com.limelight.input.MouseHandler;
|
||||||
import com.limelight.nvstream.NvConnection;
|
import com.limelight.nvstream.NvConnection;
|
||||||
|
|
||||||
public class StreamFrame extends JFrame {
|
public class StreamFrame extends JFrame {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private KeyboardHandler keyboard;
|
private KeyboardHandler keyboard;
|
||||||
|
private MouseHandler mouse;
|
||||||
|
|
||||||
public void build(NvConnection conn) {
|
public void build(NvConnection conn) {
|
||||||
keyboard = new KeyboardHandler(conn);
|
keyboard = new KeyboardHandler(conn);
|
||||||
|
mouse = new MouseHandler(conn, this);
|
||||||
|
|
||||||
this.addKeyListener(keyboard);
|
this.addKeyListener(keyboard);
|
||||||
|
this.addMouseListener(mouse);
|
||||||
|
this.addMouseMotionListener(mouse);
|
||||||
|
|
||||||
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
|
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
|
||||||
this.setSize(1280,720);
|
this.setSize(1280,720);
|
||||||
//This might break if the screen res is too small...not sure though
|
//This might break if the screen res is too small...not sure though
|
||||||
this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2);
|
this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2);
|
||||||
|
|
||||||
|
// Transparent 16 x 16 pixel cursor image.
|
||||||
|
BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
|
||||||
|
// Create a new blank cursor.
|
||||||
|
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(
|
||||||
|
cursorImg, new Point(0, 0), "blank cursor");
|
||||||
|
|
||||||
|
// Set the blank cursor to the JFrame.
|
||||||
|
this.getContentPane().setCursor(blankCursor);
|
||||||
this.setVisible(true);
|
this.setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package com.limelight.input;
|
||||||
|
|
||||||
|
import java.awt.AWTException;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Robot;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
import java.awt.event.MouseMotionListener;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
|
import com.limelight.nvstream.NvConnection;
|
||||||
|
|
||||||
|
public class MouseHandler implements MouseListener, MouseMotionListener {
|
||||||
|
private NvConnection conn;
|
||||||
|
private Robot robot;
|
||||||
|
private JFrame parent;
|
||||||
|
private Dimension size;
|
||||||
|
private int lastX = 0;
|
||||||
|
private int lastY = 0;
|
||||||
|
|
||||||
|
|
||||||
|
public MouseHandler(NvConnection conn, JFrame parent) {
|
||||||
|
this.conn = conn;
|
||||||
|
this.parent = parent;
|
||||||
|
try {
|
||||||
|
this.robot = new Robot();
|
||||||
|
} catch (AWTException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
size = new Dimension();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent e) {
|
||||||
|
System.out.println("Mouse Exiting!");
|
||||||
|
parent.getSize(size);
|
||||||
|
robot.mouseMove(size.width / 2, size.height / 2);
|
||||||
|
lastX = size.width / 2;
|
||||||
|
lastY = size.height / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
conn.sendMouseButtonDown();
|
||||||
|
e.consume();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
conn.sendMouseButtonUp();
|
||||||
|
e.consume();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseDragged(MouseEvent e) {
|
||||||
|
mouseMoved(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseMoved(MouseEvent e) {
|
||||||
|
int x = e.getX();
|
||||||
|
int y = e.getY();
|
||||||
|
conn.sendMouseMove((short)(x - lastX), (short)(y - lastY));
|
||||||
|
lastX = x;
|
||||||
|
lastY = y;
|
||||||
|
e.consume();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user