mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-02-16 10:30:47 +00:00
now support all 3 mouse buttons. audio renderer no longer lags. app is now full screen
This commit is contained in:
@@ -34,7 +34,7 @@ public class JavaxAudioRenderer implements AudioRenderer {
|
||||
@Override
|
||||
public void streamInitialized(int channelCount, int sampleRate) {
|
||||
AudioFormat audioFormat = new AudioFormat(sampleRate, 16, channelCount, true, true);
|
||||
DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat, OpusDecoder.getMaxOutputShorts());
|
||||
DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat, OpusDecoder.getMaxOutputShorts()*8);
|
||||
try {
|
||||
soundLine = (SourceDataLine) AudioSystem.getLine(info);
|
||||
soundLine.open(audioFormat);
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package com.limelight.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Point;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.image.BufferedImage;
|
||||
@@ -14,34 +18,51 @@ 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);
|
||||
|
||||
|
||||
this.setFocusTraversalKeysEnabled(false);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
makeFullScreen();
|
||||
hideCursor();
|
||||
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
private void makeFullScreen() {
|
||||
this.setUndecorated(true);
|
||||
this.setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||
this.setBackground(Color.BLACK);
|
||||
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
||||
if (gd.isFullScreenSupported()) {
|
||||
gd.setFullScreenWindow(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void hideCursor() {
|
||||
// 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");
|
||||
cursorImg, new Point(0, 0), "blank cursor");
|
||||
|
||||
// Set the blank cursor to the JFrame.
|
||||
this.getContentPane().setCursor(blankCursor);
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,18 +8,20 @@ import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import com.limelight.nvstream.NvConnection;
|
||||
import com.limelight.nvstream.input.MouseButtonPacket;
|
||||
|
||||
public class MouseHandler implements MouseListener, MouseMotionListener {
|
||||
private NvConnection conn;
|
||||
private Robot robot;
|
||||
private JFrame parent;
|
||||
private Dimension size;
|
||||
private JFrame parent;
|
||||
private int lastX = 0;
|
||||
private int lastY = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
public MouseHandler(NvConnection conn, JFrame parent) {
|
||||
this.conn = conn;
|
||||
this.parent = parent;
|
||||
@@ -29,8 +31,9 @@ public class MouseHandler implements MouseListener, MouseMotionListener {
|
||||
e.printStackTrace();
|
||||
}
|
||||
size = new Dimension();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
}
|
||||
@@ -41,8 +44,6 @@ public class MouseHandler implements MouseListener, MouseMotionListener {
|
||||
|
||||
@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;
|
||||
@@ -50,12 +51,44 @@ public class MouseHandler implements MouseListener, MouseMotionListener {
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
conn.sendMouseButtonDown();
|
||||
byte mouseButton = 0x0;
|
||||
|
||||
if (SwingUtilities.isLeftMouseButton(e)) {
|
||||
mouseButton = MouseButtonPacket.BUTTON_1;
|
||||
}
|
||||
|
||||
if (SwingUtilities.isMiddleMouseButton(e)) {
|
||||
mouseButton = MouseButtonPacket.BUTTON_2;
|
||||
}
|
||||
|
||||
if (SwingUtilities.isRightMouseButton(e)) {
|
||||
mouseButton = MouseButtonPacket.BUTTON_3;
|
||||
}
|
||||
|
||||
if (mouseButton > 0) {
|
||||
conn.sendMouseButtonDown(mouseButton);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
conn.sendMouseButtonUp();
|
||||
byte mouseButton = 0x0;
|
||||
|
||||
if (SwingUtilities.isLeftMouseButton(e)) {
|
||||
mouseButton = MouseButtonPacket.BUTTON_1;
|
||||
}
|
||||
|
||||
if (SwingUtilities.isMiddleMouseButton(e)) {
|
||||
mouseButton = MouseButtonPacket.BUTTON_2;
|
||||
}
|
||||
|
||||
if (SwingUtilities.isRightMouseButton(e)) {
|
||||
mouseButton = MouseButtonPacket.BUTTON_3;
|
||||
}
|
||||
|
||||
if (mouseButton > 0) {
|
||||
conn.sendMouseButtonUp(mouseButton);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,6 +103,18 @@ public class MouseHandler implements MouseListener, MouseMotionListener {
|
||||
conn.sendMouseMove((short)(x - lastX), (short)(y - lastY));
|
||||
lastX = x;
|
||||
lastY = y;
|
||||
}
|
||||
|
||||
parent.getSize(size);
|
||||
|
||||
if (x < size.width / 2 - 500 || x > size.width / 2 + 500) {
|
||||
robot.mouseMove(size.width / 2, y);
|
||||
lastX = size.width / 2;
|
||||
}
|
||||
if (y < size.height / 2 - 300 || y > size.height / 2 + 300) {
|
||||
robot.mouseMove(x, size.height / 2);
|
||||
lastY = size.height / 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user