Include multi-monitor screen support

secondmonitor
sigonasr2 4 years ago
parent 632573750f
commit a5b56026c8
  1. BIN
      DivaBot/DivaBot.jar
  2. 2
      DivaBot/calibration_data.txt
  3. BIN
      DivaBot/capture_1.png
  4. BIN
      DivaBot/capture_2.png
  5. BIN
      DivaBot/capture_3.png
  6. 1
      DivaBot/screenConfig.txt
  7. 17
      DivaBot/src/sig/Calibrator2.java
  8. 19
      DivaBot/src/sig/CustomRobot.java
  9. 21
      DivaBot/src/sig/MyRobot.java
  10. 24
      DivaBot/src/sig/Overlay.java

Binary file not shown.

@ -1,4 +1,4 @@
438 437
288 288
1330 1330
793 793

Binary file not shown.

Before

Width:  |  Height:  |  Size: 864 KiB

After

Width:  |  Height:  |  Size: 883 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 834 KiB

After

Width:  |  Height:  |  Size: 233 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 862 KiB

After

Width:  |  Height:  |  Size: 880 KiB

@ -2,6 +2,8 @@ package sig;
import java.awt.Color; import java.awt.Color;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
@ -34,8 +36,9 @@ public class Calibrator2 {
int yoffset1=0; int yoffset1=0;
int xoffset2=0; int xoffset2=0;
int yoffset2=0; int yoffset2=0;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
img = MyRobot.MYROBOT.getSizedCapture(new Rectangle(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y)); GraphicsDevice[] gs = ge.getScreenDevices();
img = MyRobot.MYROBOT.getSizedCapture(new Rectangle(MyRobot.STARTDRAG.x+gs[MyRobot.screen].getDefaultConfiguration().getBounds().x,MyRobot.STARTDRAG.y+gs[MyRobot.screen].getDefaultConfiguration().getBounds().y,MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y));
ImageIO.write(img,"png",new File("capture_1.png")); ImageIO.write(img,"png",new File("capture_1.png"));
boolean found=false; boolean found=false;
for (int x=0;x<img.getWidth();x++) { for (int x=0;x<img.getWidth();x++) {
@ -55,7 +58,7 @@ public class Calibrator2 {
if (found) {break;} if (found) {break;}
} }
img = MyRobot.MYROBOT.getSizedCapture(new Rectangle(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y)); img = MyRobot.MYROBOT.getSizedCapture(new Rectangle(MyRobot.STARTDRAG.x+gs[MyRobot.screen].getDefaultConfiguration().getBounds().x,MyRobot.STARTDRAG.y+gs[MyRobot.screen].getDefaultConfiguration().getBounds().y,MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y));
ImageIO.write(img,"png",new File("capture_2.png")); ImageIO.write(img,"png",new File("capture_2.png"));
found=false; found=false;
@ -76,7 +79,7 @@ public class Calibrator2 {
if (found) {break;} if (found) {break;}
} }
for (int y=yoffset1;y>=0;y--) { for (int y=yoffset1;y>=0;y--) {
BufferedImage newimg = MyRobot.MYROBOT.getSizedCapture(new Rectangle(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y)); BufferedImage newimg = MyRobot.MYROBOT.getSizedCapture(new Rectangle(MyRobot.STARTDRAG.x+gs[MyRobot.screen].getDefaultConfiguration().getBounds().x,MyRobot.STARTDRAG.y+gs[MyRobot.screen].getDefaultConfiguration().getBounds().y,MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y));
Color col = new Color(newimg.getRGB(0, 0)); Color col = new Color(newimg.getRGB(0, 0));
if (col.getRed()+col.getGreen()+col.getBlue()<5) { if (col.getRed()+col.getGreen()+col.getBlue()<5) {
break; break;
@ -84,7 +87,7 @@ public class Calibrator2 {
MyRobot.STARTDRAG.y-=1; MyRobot.STARTDRAG.y-=1;
} }
for (int y=yoffset2;y<img.getHeight();y++) { for (int y=yoffset2;y<img.getHeight();y++) {
BufferedImage newimg = MyRobot.MYROBOT.getSizedCapture(new Rectangle(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y)); BufferedImage newimg = MyRobot.MYROBOT.getSizedCapture(new Rectangle(MyRobot.STARTDRAG.x+gs[MyRobot.screen].getDefaultConfiguration().getBounds().x,MyRobot.STARTDRAG.y+gs[MyRobot.screen].getDefaultConfiguration().getBounds().y,MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y));
Color col = new Color(newimg.getRGB(newimg.getWidth()-1, newimg.getHeight()-1)); Color col = new Color(newimg.getRGB(newimg.getWidth()-1, newimg.getHeight()-1));
if (col.getRed()+col.getGreen()+col.getBlue()<5) { if (col.getRed()+col.getGreen()+col.getBlue()<5) {
break; break;
@ -92,7 +95,7 @@ public class Calibrator2 {
MyRobot.ENDDRAG.y+=1; MyRobot.ENDDRAG.y+=1;
} }
img = MyRobot.MYROBOT.getSizedCapture(new Rectangle(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y)); img = MyRobot.MYROBOT.getSizedCapture(new Rectangle(MyRobot.STARTDRAG.x+gs[MyRobot.screen].getDefaultConfiguration().getBounds().x,MyRobot.STARTDRAG.y+gs[MyRobot.screen].getDefaultConfiguration().getBounds().y,MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y));
ImageIO.write(img,"png",new File("capture_3.png")); ImageIO.write(img,"png",new File("capture_3.png"));
System.out.println(MyRobot.STARTDRAG+","+MyRobot.ENDDRAG); System.out.println(MyRobot.STARTDRAG+","+MyRobot.ENDDRAG);
@ -120,7 +123,7 @@ public class Calibrator2 {
} }
MyRobot.FRAME.setAlwaysOnTop(true); MyRobot.FRAME.setAlwaysOnTop(true);
img = MyRobot.MYROBOT.getSizedCapture(new Rectangle(0,0,MyRobot.screenSize.width,MyRobot.screenSize.height)); //img = MyRobot.MYROBOT.getSizedCapture(new Rectangle(gs[MyRobot.screen].getDefaultConfiguration().getBounds().x,gs[MyRobot.screen].getDefaultConfiguration().getBounds().y,MyRobot.screenSize.width,MyRobot.screenSize.height));
FileUtils.deleteFile("calibration_data.txt"); FileUtils.deleteFile("calibration_data.txt");
FileUtils.logToFile(Integer.toString(MyRobot.STARTDRAG.x), "calibration_data.txt"); FileUtils.logToFile(Integer.toString(MyRobot.STARTDRAG.x), "calibration_data.txt");
FileUtils.logToFile(Integer.toString(MyRobot.STARTDRAG.y), "calibration_data.txt"); FileUtils.logToFile(Integer.toString(MyRobot.STARTDRAG.y), "calibration_data.txt");

@ -2,6 +2,7 @@ package sig;
import java.awt.AWTException; import java.awt.AWTException;
import java.awt.GraphicsDevice; import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.Robot; import java.awt.Robot;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@ -20,13 +21,23 @@ public class CustomRobot extends Robot{
BufferedImage scoreCurrentScreen; BufferedImage scoreCurrentScreen;
int[] calibration_data = new int[]{0,0,1,1}; int[] calibration_data = new int[]{0,0,1,1};
long lastCalibrationTime = 0; long lastCalibrationTime = 0;
GraphicsEnvironment ge;
GraphicsDevice[] gs;
public CustomRobot() throws AWTException { public CustomRobot() throws AWTException {
super(); super();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
this.ge=ge;
this.gs=gs;
} }
public CustomRobot(GraphicsDevice screen) throws AWTException { public CustomRobot(GraphicsDevice screen) throws AWTException {
super(screen); super(screen);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
this.ge=ge;
this.gs=gs;
} }
public synchronized BufferedImage getSizedCapture(Rectangle r) { public synchronized BufferedImage getSizedCapture(Rectangle r) {
@ -40,14 +51,14 @@ public class CustomRobot extends Robot{
} }
if (calibration_data.length>0) { if (calibration_data.length>0) {
try { try {
currentScreen = super.createScreenCapture(new Rectangle(calibration_data[0],calibration_data[1],calibration_data[2]-calibration_data[0],calibration_data[3]-calibration_data[1])); currentScreen = super.createScreenCapture(new Rectangle(calibration_data[0]+gs[MyRobot.screen].getDefaultConfiguration().getBounds().x,calibration_data[1]+gs[MyRobot.screen].getDefaultConfiguration().getBounds().y,calibration_data[2]-calibration_data[0],calibration_data[3]-calibration_data[1]));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
calibration_data=new int[4]; calibration_data=new int[4];
File f = new File("calibration_data.txt"); File f = new File("calibration_data.txt");
f.delete(); f.delete();
} }
} else { } else {
currentScreen = super.createScreenCapture(new Rectangle(418+18,204+83,912-18,586-83)); currentScreen = super.createScreenCapture(new Rectangle(418+18+gs[MyRobot.screen].getDefaultConfiguration().getBounds().x,204+83+gs[MyRobot.screen].getDefaultConfiguration().getBounds().y,912-18,586-83));
} }
} }
private void ReloadCalibrationData() throws IOException { private void ReloadCalibrationData() throws IOException {
@ -69,9 +80,9 @@ public class CustomRobot extends Robot{
ReloadCalibrationData(); ReloadCalibrationData();
} }
if (calibration_data.length>0) { if (calibration_data.length>0) {
scoreCurrentScreen = super.createScreenCapture(new Rectangle(calibration_data[0],calibration_data[1],calibration_data[2]-calibration_data[0],calibration_data[3]-calibration_data[1])); scoreCurrentScreen = super.createScreenCapture(new Rectangle(calibration_data[0]+gs[MyRobot.screen].getDefaultConfiguration().getBounds().x,calibration_data[1]+gs[MyRobot.screen].getDefaultConfiguration().getBounds().y,calibration_data[2]-calibration_data[0],calibration_data[3]-calibration_data[1]));
} else { } else {
scoreCurrentScreen = super.createScreenCapture(new Rectangle(418+23,204+85,912-18,586-83)); scoreCurrentScreen = super.createScreenCapture(new Rectangle(418+23+gs[MyRobot.screen].getDefaultConfiguration().getBounds().x,204+85+gs[MyRobot.screen].getDefaultConfiguration().getBounds().y,912-18,586-83));
} }
} }

@ -172,17 +172,22 @@ public class MyRobot{
public static void main(String[] args) throws JSONException, IOException, FontFormatException { public static void main(String[] args) throws JSONException, IOException, FontFormatException {
if (args.length>0) {
if (args[0].equalsIgnoreCase("calibrate")) {
File f = new File("screenConfig.txt"); File f = new File("screenConfig.txt");
if (f.exists()) { if (f.exists()) {
String[] data= FileUtils.readFromFile("screenConfig.txt"); String[] data= FileUtils.readFromFile("screenConfig.txt");
try { try {
screen=Integer.parseInt(data[0]); screen=Integer.parseInt(data[0]);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
if (gs.length<=screen) {
screen=0;
}
} catch (Exception e) { } catch (Exception e) {
System.err.println("Could not read from screenConfig.txt. It's invalid data, consider deleting the file and run the program again."); System.err.println("Could not read from screenConfig.txt. It's invalid data, consider deleting the file and run the program again.");
} }
} }
if (args.length>0) {
if (args[0].equalsIgnoreCase("calibrate")) {
CALIBRATION_MODE=true; CALIBRATION_MODE=true;
} }
if (args[0].equalsIgnoreCase("debug")) { if (args[0].equalsIgnoreCase("debug")) {
@ -625,7 +630,9 @@ public class MyRobot{
SongData.loadSongsFromFile(); SongData.loadSongsFromFile();
System.setProperty("awt.useSystemAAFontSettings","on"); System.setProperty("awt.useSystemAAFontSettings","on");
FRAME = new JFrame(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
FRAME = new JFrame(gs[screen].getDefaultConfiguration());
FRAME.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); FRAME.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p.difficulty="EXEX"; p.difficulty="EXEX";
p.songname = "Dear"; p.songname = "Dear";
@ -979,11 +986,12 @@ public class MyRobot{
void initialize() { void initialize() {
System.setProperty("sun.java2d.opengl", "True"); System.setProperty("sun.java2d.opengl", "True");
grEnv = GraphicsEnvironment.getLocalGraphicsEnvironment(); grEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
grDevice = grEnv.getDefaultScreenDevice(); GraphicsDevice[] gs = grEnv.getScreenDevices();
grDevice = gs[screen];
updateScreenInfo(); updateScreenInfo();
setKeyMap(); setKeyMap();
try { try {
MYROBOT = new CustomRobot(); MYROBOT = new CustomRobot(gs[screen]);
MYROBOT.refreshScreen(); MYROBOT.refreshScreen();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -992,7 +1000,7 @@ public class MyRobot{
} }
X = SCREEN_X / 2; X = SCREEN_X / 2;
Y = SCREEN_Y / 2; Y = SCREEN_Y / 2;
//MYROBOT.mouseMove(X, Y); //MYROBOT.mouseMove(X+grDevice.getDefaultConfiguration().getBounds().x, Y+grDevice.getDefaultConfiguration().getBounds().y);
PIX_CLOSE_ACTIVE_OFF_MOUSE = new Color(184, 67, 44); PIX_CLOSE_ACTIVE_OFF_MOUSE = new Color(184, 67, 44);
PIX_CLOSE_ACTIVE_ON_MOUSE = new Color(210, 35, 2); PIX_CLOSE_ACTIVE_ON_MOUSE = new Color(210, 35, 2);
} }
@ -1002,6 +1010,7 @@ public class MyRobot{
SCREEN_Y = grDevice.getDisplayMode().getHeight(); SCREEN_Y = grDevice.getDisplayMode().getHeight();
WINDOW_X = grEnv.getMaximumWindowBounds().width; WINDOW_X = grEnv.getMaximumWindowBounds().width;
WINDOW_Y = grEnv.getMaximumWindowBounds().height; WINDOW_Y = grEnv.getMaximumWindowBounds().height;
//System.out.println(SCREEN_X+"/"+SCREEN_Y+","+WINDOW_X+"/"+WINDOW_Y);
} }
void setKeyMap() { void setKeyMap() {

@ -4,6 +4,8 @@ import java.awt.Color;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Font; import java.awt.Font;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Point; import java.awt.Point;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
@ -16,6 +18,7 @@ import java.io.IOException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.JPanel; import javax.swing.JPanel;
import sig.utils.FileUtils;
import sig.utils.MouseUtils; import sig.utils.MouseUtils;
public class Overlay extends JPanel implements MouseMotionListener,MouseListener{ public class Overlay extends JPanel implements MouseMotionListener,MouseListener{
@ -98,7 +101,7 @@ public class Overlay extends JPanel implements MouseMotionListener,MouseListener
} else } else
{ {
g.drawImage(setupWindowButton,MyRobot.screenSize.width-setupWindowButton.getWidth()+1,0,this); g.drawImage(setupWindowButton,MyRobot.screenSize.width-setupWindowButton.getWidth()+1,0,this);
//g.drawImage(changeMonitorButton,MyRobot.screenSize.width-changeMonitorButton.getWidth()+1,setupWindowButton.getHeight(),this); g.drawImage(changeMonitorButton,MyRobot.screenSize.width-changeMonitorButton.getWidth()+1,setupWindowButton.getHeight(),this);
} }
} }
@ -110,7 +113,7 @@ public class Overlay extends JPanel implements MouseMotionListener,MouseListener
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
Point cursor = MouseUtils.GetCursorPosition(MyRobot.FRAME, e); Point cursor = MouseUtils.GetCursorPosition(MyRobot.FRAME, e);
if (started) { if (started) {
MyRobot.STARTDRAG=e.getLocationOnScreen(); MyRobot.STARTDRAG=e.getPoint();
} else } else
if (MyRobot.CALIBRATIONSTATUS.length()>0) { if (MyRobot.CALIBRATIONSTATUS.length()>0) {
if (cursor.x>=MyRobot.screenSize.width-finishButton.getWidth()+1&& if (cursor.x>=MyRobot.screenSize.width-finishButton.getWidth()+1&&
@ -126,6 +129,21 @@ public class Overlay extends JPanel implements MouseMotionListener,MouseListener
cursor.y>=0&& cursor.y>=0&&
cursor.y<=setupWindowButton.getHeight()) { cursor.y<=setupWindowButton.getHeight()) {
started=true; started=true;
} else
if (cursor.x>=MyRobot.screenSize.width-setupWindowButton.getWidth()+1&&
cursor.x<=MyRobot.screenSize.width&&
cursor.y>setupWindowButton.getHeight()&&
cursor.y<=setupWindowButton.getHeight()*2) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
MyRobot.screen=(MyRobot.screen+1)%gs.length;
FileUtils.writetoFile(new String[] {Integer.toString(MyRobot.screen)}, "screenConfig.txt", false);
try {
Runtime.getRuntime().exec("java -ea -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -jar DivaBot.jar calibrate");
} catch (IOException e1) {
e1.printStackTrace();
}
System.exit(0);
} }
} }
} }
@ -134,7 +152,7 @@ public class Overlay extends JPanel implements MouseMotionListener,MouseListener
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
if (started) { if (started) {
if (MyRobot.STARTDRAG!=null) { if (MyRobot.STARTDRAG!=null) {
MyRobot.ENDDRAG=e.getLocationOnScreen(); MyRobot.ENDDRAG=e.getPoint();
if (MyRobot.STARTDRAG.x>MyRobot.ENDDRAG.x) { if (MyRobot.STARTDRAG.x>MyRobot.ENDDRAG.x) {
int xTemp = MyRobot.STARTDRAG.x; int xTemp = MyRobot.STARTDRAG.x;
MyRobot.STARTDRAG.x=MyRobot.ENDDRAG.x; MyRobot.STARTDRAG.x=MyRobot.ENDDRAG.x;

Loading…
Cancel
Save