parent
e0af6118bd
commit
cb4174f7e5
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
@ -0,0 +1,112 @@ |
||||
package sig; |
||||
|
||||
import java.awt.Color; |
||||
import java.awt.Rectangle; |
||||
import java.awt.image.BufferedImage; |
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
|
||||
import javax.imageio.ImageIO; |
||||
import javax.swing.JPanel; |
||||
|
||||
public class Calibrator{ |
||||
Calibrator(JPanel p) throws IOException, InterruptedException { |
||||
boolean failed=false; |
||||
int x = Math.min(MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.x); |
||||
int y = Math.min(MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.y); |
||||
int width = (Math.max(MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.x)-Math.min(MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.x)); |
||||
int height = (Math.max(MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.y)-Math.min(MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.y)); |
||||
|
||||
if (MyRobot.STARTDRAG.x>MyRobot.ENDDRAG.x) { |
||||
int xTemp=MyRobot.STARTDRAG.x; |
||||
MyRobot.STARTDRAG.x=MyRobot.ENDDRAG.x; |
||||
MyRobot.ENDDRAG.x=xTemp; |
||||
} |
||||
if (MyRobot.STARTDRAG.y>MyRobot.ENDDRAG.y) { |
||||
int yTemp=MyRobot.STARTDRAG.y; |
||||
MyRobot.STARTDRAG.y=MyRobot.ENDDRAG.y; |
||||
MyRobot.ENDDRAG.y=yTemp; |
||||
} |
||||
|
||||
/*Rectangle currentPointer = new Rectangle( |
||||
x,y, |
||||
(int)Math.floor(x+width*0.03984375d), |
||||
(int)Math.floor(y+height*0.30833333333333333333333333333333d)); |
||||
calibrationline=currentPointer;*/ |
||||
failed=CalibrationStage1(p); |
||||
if (failed) {return;} |
||||
failed=CalibrationStage2(p); |
||||
if (failed) {return;} |
||||
p.setVisible(true); |
||||
MyRobot.CALIBRATIONSTATUS="First calibration set done: X"+(x-MyRobot.STARTDRAG.x)+" Y"+(y-MyRobot.STARTDRAG.y); |
||||
// failed=CalibrationStage3(p);
|
||||
// if (failed) {return;}
|
||||
// failed=CalibrationStage4(p);
|
||||
// if (failed) {return;}
|
||||
//MyRobot.CALIBRATIONSTATUS="First calibration set done: X"+(x-MyRobot.STARTDRAG.x)+" Y"+(y-MyRobot.STARTDRAG.y);
|
||||
} |
||||
|
||||
private boolean CalibrationStage1(JPanel p) throws IOException, InterruptedException { |
||||
boolean calibrated=false; |
||||
int MAXTRIES=10000; |
||||
MyRobot.CALIBRATIONSTATUS="Calibration Stage 1..."; |
||||
p.repaint(); |
||||
//ImageIO.write(MYROBOT.getSizedCapture(new Rectangle(x,y,width,height)),"png",new File("capture.png"));
|
||||
BufferedImage currentScreen = MyRobot.MYROBOT.getSizedCapture(new Rectangle(0,0,MyRobot.screenSize.width,MyRobot.screenSize.height)); |
||||
ImageIO.write(currentScreen.getSubimage(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y),"png",new File("capture.png")); |
||||
while (!calibrated&&MAXTRIES>0) { |
||||
//Try moving left until the difference is too high or the colors are not right anymore.
|
||||
MyRobot.STARTDRAG.x-=1; |
||||
//BufferedImage pixel = MYROBOT.getSizedCapture(new Rectangle(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,1,1));
|
||||
currentScreen = currentScreen.getSubimage(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,1,1); |
||||
ImageIO.write(currentScreen,"png",new File("capture_"+System.nanoTime()+".png")); |
||||
Color col = new Color(currentScreen.getRGB(0, 0)); |
||||
System.out.println("Checking "+col); |
||||
if (!(col.getRed()>=5&&col.getRed()<=40&& |
||||
col.getGreen()>=170&&col.getGreen()<=210&& |
||||
col.getBlue()>=205&&col.getBlue()<=250)) { |
||||
//This is the max X. Calibration on this side good.
|
||||
MyRobot.STARTDRAG.x++; |
||||
System.out.println("End at "+MyRobot.STARTDRAG.x); |
||||
return false; |
||||
} |
||||
MAXTRIES--; |
||||
} |
||||
MyRobot.CALIBRATIONSTATUS="Calibration failed! Try making the capture region larger and defining it more accurately."; |
||||
p.repaint(); |
||||
return true; |
||||
} |
||||
|
||||
private boolean CalibrationStage2(JPanel p) throws IOException { |
||||
boolean calibrated=false; |
||||
int MAXTRIES=10000; |
||||
MyRobot.CALIBRATIONSTATUS="Calibration Stage 2..."; |
||||
p.repaint(); |
||||
//ImageIO.write(MYROBOT.getSizedCapture(new Rectangle(x,y,width,height)),"png",new File("capture.png"));
|
||||
//BufferedImage currentScreen = MYROBOT.getSizedCapture(new Rectangle(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,MyRobot.ENDDRAG,height));
|
||||
BufferedImage currentScreen = MyRobot.MYROBOT.getSizedCapture(new Rectangle(0,0,MyRobot.screenSize.width,MyRobot.screenSize.height)); |
||||
ImageIO.write(currentScreen.getSubimage(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y),"png",new File("capture_2.png")); |
||||
while (!calibrated&&MAXTRIES>0) { |
||||
//Try moving left until the difference is too high or the colors are not right anymore.
|
||||
MyRobot.STARTDRAG.y-=1; |
||||
p.repaint(); |
||||
//currentScreen.setRGB(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y, new Color(0,0,0).getRGB());
|
||||
currentScreen = currentScreen.getSubimage(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,1,1); |
||||
ImageIO.write(currentScreen,"png",new File("capture_2_"+System.nanoTime()+".png")); |
||||
Color col = new Color(currentScreen.getRGB(0, 0)); |
||||
System.out.println("Checking "+col); |
||||
if (!(col.getRed()>=5&&col.getRed()<=40&& |
||||
col.getGreen()>=170&&col.getGreen()<=210&& |
||||
col.getBlue()>=205&&col.getBlue()<=250)) { |
||||
//This is the max Y. Calibration on this side good.
|
||||
MyRobot.STARTDRAG.y++; |
||||
System.out.println("End at "+MyRobot.STARTDRAG.y); |
||||
return false; |
||||
} |
||||
MAXTRIES--; |
||||
} |
||||
MyRobot.CALIBRATIONSTATUS="Calibration failed! Try making the capture region larger and defining it more accurately."; |
||||
p.repaint(); |
||||
return true; |
||||
} |
||||
} |
@ -0,0 +1,83 @@ |
||||
package sig; |
||||
|
||||
import java.awt.Color; |
||||
import java.awt.Graphics; |
||||
import java.awt.event.MouseEvent; |
||||
import java.awt.event.MouseListener; |
||||
import java.awt.event.MouseMotionListener; |
||||
|
||||
import javax.swing.JPanel; |
||||
|
||||
public class Overlay extends JPanel implements MouseMotionListener,MouseListener{ |
||||
|
||||
Overlay() { |
||||
Thread t = new Thread() { |
||||
public void run() { |
||||
while (true) { |
||||
repaint(); |
||||
try { |
||||
Thread.sleep(1000/60); |
||||
} catch (InterruptedException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
t.start(); |
||||
} |
||||
|
||||
@Override |
||||
public void paintComponent(Graphics g) { |
||||
super.paintComponent(g); |
||||
g.setColor(new Color(0,0,0,1)); |
||||
g.fillRect(0, 0, MyRobot.screenSize.width, MyRobot.screenSize.height); |
||||
g.setColor(new Color(0,255,255,96)); |
||||
if (MyRobot.STARTDRAG!=null&&MyRobot.ENDDRAG!=null) { |
||||
g.fillRect(0,0,Math.min(MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.x),MyRobot.screenSize.height); |
||||
g.fillRect(Math.min(MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.x),0,MyRobot.screenSize.width,Math.min(MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.y)); |
||||
g.fillRect(Math.min(MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.x), Math.max(MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.y), Math.max(MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.x)-Math.min(MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.x), MyRobot.screenSize.height-Math.max(MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.y)); |
||||
g.fillRect(Math.max(MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.x), Math.min(MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.y), MyRobot.screenSize.width-Math.max(MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.x), MyRobot.screenSize.height-Math.min(MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.y)); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
} |
||||
|
||||
@Override |
||||
public void mousePressed(MouseEvent e) { |
||||
MyRobot.STARTDRAG=e.getLocationOnScreen(); |
||||
} |
||||
|
||||
@Override |
||||
public void mouseReleased(MouseEvent e) { |
||||
MyRobot.ENDDRAG=e.getLocationOnScreen(); |
||||
if (MyRobot.STARTDRAG.x>MyRobot.ENDDRAG.x) { |
||||
var xTemp = MyRobot.STARTDRAG.x; |
||||
MyRobot.STARTDRAG.x=MyRobot.ENDDRAG.x; |
||||
MyRobot.ENDDRAG.x=xTemp; |
||||
} |
||||
if (MyRobot.STARTDRAG.y>MyRobot.ENDDRAG.y) { |
||||
var xTemp = MyRobot.STARTDRAG.y; |
||||
MyRobot.STARTDRAG.y=MyRobot.ENDDRAG.y; |
||||
MyRobot.ENDDRAG.y=xTemp; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void mouseEntered(MouseEvent e) { |
||||
} |
||||
|
||||
@Override |
||||
public void mouseExited(MouseEvent e) { |
||||
} |
||||
|
||||
@Override |
||||
public void mouseDragged(MouseEvent e) { |
||||
MyRobot.ENDDRAG=e.getLocationOnScreen(); |
||||
} |
||||
|
||||
@Override |
||||
public void mouseMoved(MouseEvent e) { |
||||
} |
||||
} |
Loading…
Reference in new issue