From 3561eafa9adac57469fc36d0abb1e2d87ce6f930 Mon Sep 17 00:00:00 2001 From: Diego Waxemberg Date: Sat, 7 Dec 2013 22:13:30 -0500 Subject: [PATCH] added support for mouse --- .../src/com/limelight/gui/StreamFrame.java | 22 +++++- .../src/com/limelight/input/MouseHandler.java | 78 +++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 limelight-pc/src/com/limelight/input/MouseHandler.java diff --git a/limelight-pc/src/com/limelight/gui/StreamFrame.java b/limelight-pc/src/com/limelight/gui/StreamFrame.java index f503428..991059f 100644 --- a/limelight-pc/src/com/limelight/gui/StreamFrame.java +++ b/limelight-pc/src/com/limelight/gui/StreamFrame.java @@ -1,25 +1,45 @@ package com.limelight.gui; +import java.awt.Cursor; import java.awt.Dimension; +import java.awt.Point; import java.awt.Toolkit; +import java.awt.image.BufferedImage; import javax.swing.JFrame; import com.limelight.input.KeyboardHandler; +import com.limelight.input.MouseHandler; import com.limelight.nvstream.NvConnection; public class StreamFrame extends JFrame { private static final long serialVersionUID = 1L; private KeyboardHandler keyboard; - + private MouseHandler mouse; + public void build(NvConnection conn) { keyboard = new KeyboardHandler(conn); + mouse = new MouseHandler(conn, this); + this.addKeyListener(keyboard); + this.addMouseListener(mouse); + this.addMouseMotionListener(mouse); + Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); this.setSize(1280,720); //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); + + // 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); } } diff --git a/limelight-pc/src/com/limelight/input/MouseHandler.java b/limelight-pc/src/com/limelight/input/MouseHandler.java new file mode 100644 index 0000000..a652937 --- /dev/null +++ b/limelight-pc/src/com/limelight/input/MouseHandler.java @@ -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(); + } + +}