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
1330
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.Cursor;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
@ -34,8 +36,9 @@ public class Calibrator2 {
int yoffset1=0;
int xoffset2=0;
int yoffset2=0;
img = MyRobot.MYROBOT.getSizedCapture(new Rectangle(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y));
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
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"));
boolean found=false;
for (int x=0;x<img.getWidth();x++) {
@ -55,7 +58,7 @@ public class Calibrator2 {
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"));
found=false;
@ -76,7 +79,7 @@ public class Calibrator2 {
if (found) {break;}
}
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));
if (col.getRed()+col.getGreen()+col.getBlue()<5) {
break;
@ -84,7 +87,7 @@ public class Calibrator2 {
MyRobot.STARTDRAG.y-=1;
}
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));
if (col.getRed()+col.getGreen()+col.getBlue()<5) {
break;
@ -92,7 +95,7 @@ public class Calibrator2 {
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"));
System.out.println(MyRobot.STARTDRAG+","+MyRobot.ENDDRAG);
@ -120,7 +123,7 @@ public class Calibrator2 {
}
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.logToFile(Integer.toString(MyRobot.STARTDRAG.x), "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.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
@ -20,13 +21,23 @@ public class CustomRobot extends Robot{
BufferedImage scoreCurrentScreen;
int[] calibration_data = new int[]{0,0,1,1};
long lastCalibrationTime = 0;
GraphicsEnvironment ge;
GraphicsDevice[] gs;
public CustomRobot() throws AWTException {
super();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
this.ge=ge;
this.gs=gs;
}
public CustomRobot(GraphicsDevice screen) throws AWTException {
super(screen);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
this.ge=ge;
this.gs=gs;
}
public synchronized BufferedImage getSizedCapture(Rectangle r) {
@ -40,14 +51,14 @@ public class CustomRobot extends Robot{
}
if (calibration_data.length>0) {
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) {
calibration_data=new int[4];
File f = new File("calibration_data.txt");
f.delete();
}
} 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 {
@ -69,9 +80,9 @@ public class CustomRobot extends Robot{
ReloadCalibrationData();
}
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 {
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 {
if (args.length>0) {
if (args[0].equalsIgnoreCase("calibrate")) {
File f = new File("screenConfig.txt");
if (f.exists()) {
String[] data= FileUtils.readFromFile("screenConfig.txt");
try {
screen=Integer.parseInt(data[0]);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
if (gs.length<=screen) {
screen=0;
}
} 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.");
}
}
if (args.length>0) {
if (args[0].equalsIgnoreCase("calibrate")) {
CALIBRATION_MODE=true;
}
if (args[0].equalsIgnoreCase("debug")) {
@ -625,7 +630,9 @@ public class MyRobot{
SongData.loadSongsFromFile();
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);
p.difficulty="EXEX";
p.songname = "Dear";
@ -979,11 +986,12 @@ public class MyRobot{
void initialize() {
System.setProperty("sun.java2d.opengl", "True");
grEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
grDevice = grEnv.getDefaultScreenDevice();
GraphicsDevice[] gs = grEnv.getScreenDevices();
grDevice = gs[screen];
updateScreenInfo();
setKeyMap();
try {
MYROBOT = new CustomRobot();
MYROBOT = new CustomRobot(gs[screen]);
MYROBOT.refreshScreen();
} catch (Exception e) {
e.printStackTrace();
@ -992,7 +1000,7 @@ public class MyRobot{
}
X = SCREEN_X / 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_ON_MOUSE = new Color(210, 35, 2);
}
@ -1002,6 +1010,7 @@ public class MyRobot{
SCREEN_Y = grDevice.getDisplayMode().getHeight();
WINDOW_X = grEnv.getMaximumWindowBounds().width;
WINDOW_Y = grEnv.getMaximumWindowBounds().height;
//System.out.println(SCREEN_X+"/"+SCREEN_Y+","+WINDOW_X+"/"+WINDOW_Y);
}
void setKeyMap() {

@ -4,6 +4,8 @@ import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
@ -16,6 +18,7 @@ import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import sig.utils.FileUtils;
import sig.utils.MouseUtils;
public class Overlay extends JPanel implements MouseMotionListener,MouseListener{
@ -98,7 +101,7 @@ public class Overlay extends JPanel implements MouseMotionListener,MouseListener
} else
{
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) {
Point cursor = MouseUtils.GetCursorPosition(MyRobot.FRAME, e);
if (started) {
MyRobot.STARTDRAG=e.getLocationOnScreen();
MyRobot.STARTDRAG=e.getPoint();
} else
if (MyRobot.CALIBRATIONSTATUS.length()>0) {
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<=setupWindowButton.getHeight()) {
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) {
if (started) {
if (MyRobot.STARTDRAG!=null) {
MyRobot.ENDDRAG=e.getLocationOnScreen();
MyRobot.ENDDRAG=e.getPoint();
if (MyRobot.STARTDRAG.x>MyRobot.ENDDRAG.x) {
int xTemp = MyRobot.STARTDRAG.x;
MyRobot.STARTDRAG.x=MyRobot.ENDDRAG.x;

Loading…
Cancel
Save