commit 4148c1788af6b4ca41131b0116f872dceb9b5b46 Author: sigonasr2 Date: Fri Dec 28 19:46:34 2018 -0600 Created initial tracking of numbers for the Bandori Tracker. diff --git a/BandoriTracker/.classpath b/BandoriTracker/.classpath new file mode 100644 index 0000000..d171cd4 --- /dev/null +++ b/BandoriTracker/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/BandoriTracker/.externalToolBuilders/New_Builder (4).launch b/BandoriTracker/.externalToolBuilders/New_Builder (4).launch new file mode 100644 index 0000000..b8ff294 --- /dev/null +++ b/BandoriTracker/.externalToolBuilders/New_Builder (4).launch @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/BandoriTracker/.project b/BandoriTracker/.project new file mode 100644 index 0000000..0b306d3 --- /dev/null +++ b/BandoriTracker/.project @@ -0,0 +1,27 @@ + + + BandoriTracker + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/New_Builder (4).launch + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/BandoriTracker/.settings/org.eclipse.jdt.core.prefs b/BandoriTracker/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..bb35fa0 --- /dev/null +++ b/BandoriTracker/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/BandoriTracker/HelloWorld.jar b/BandoriTracker/HelloWorld.jar new file mode 100644 index 0000000..1b5a88e Binary files /dev/null and b/BandoriTracker/HelloWorld.jar differ diff --git a/BandoriTracker/bin/.gitignore b/BandoriTracker/bin/.gitignore new file mode 100644 index 0000000..b735555 --- /dev/null +++ b/BandoriTracker/bin/.gitignore @@ -0,0 +1 @@ +/sig/ diff --git a/BandoriTracker/projectBuilder.xml b/BandoriTracker/projectBuilder.xml new file mode 100644 index 0000000..a1293ea --- /dev/null +++ b/BandoriTracker/projectBuilder.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/BandoriTracker/src/sig/tracker/BandoriTracker.java b/BandoriTracker/src/sig/tracker/BandoriTracker.java new file mode 100644 index 0000000..c1cf4fa --- /dev/null +++ b/BandoriTracker/src/sig/tracker/BandoriTracker.java @@ -0,0 +1,326 @@ +package sig.tracker; + +import java.awt.AWTException; +import java.awt.Color; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.imageio.ImageIO; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; +import javax.swing.Timer; + +public class BandoriTracker { + public static BufferedImage capture; + public static BufferedImage footprint_img; + public static Robot robot = null; + static UpdateEvent runEvent = new UpdateEvent(); + static Timer programClock = new Timer(16,runEvent); + public static DrawPanel panel; + public static final ModeType MODE = ModeType.FOOTPRINT; + public static ModeType FOOTPRINT_MODE = ModeType.FOOTPRINT_ORIGIN1; + public static Point origin1,origin2; + public static Character character; + public static DChar displayedFootprint; + public static List footprint_database = new ArrayList(); + public static void main(String[] args) { + try { + robot = new Robot(); + } catch (AWTException e) { + e.printStackTrace(); + } + capture = robot.createScreenCapture(new Rectangle(0,0,(int)Toolkit.getDefaultToolkit().getScreenSize().getWidth(),(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight())); + + JFrame f = new JFrame(); + panel = new DrawPanel(); + f.add(panel); + f.pack(); + f.setSize(500, 500); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + f.setVisible(true); + } + + }); + programClock.start(); + + switch (MODE) { + case FOOTPRINT:{ + JFileChooser browse = new JFileChooser(); + browse.setDialogTitle("Select Footprint File"); + if (browse.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { + String fileloc = browse.getSelectedFile().getAbsolutePath(); + try { + footprint_img = ImageIO.read(new File(fileloc)); + JOptionPane.showMessageDialog(null, "Click on origin location."); + FOOTPRINT_MODE = ModeType.FOOTPRINT_ORIGIN1; + ChangeCursor(Cursor.CROSSHAIR_CURSOR); + } catch (IOException e) { + e.printStackTrace(); + } + } + }break; + default:{ + + } + } + } + public static void ChangeCursor(int cursor) { + BandoriTracker.panel.setCursor(Cursor.getPredefinedCursor(cursor)); + } +} + +class DrawPanel extends JPanel implements MouseListener{ + + DrawPanel() { + addMouseListener(this); + } + + public Dimension getPreferredSize() { + return new Dimension(1280,480); + } + + public void paintComponent(Graphics g) { + switch (BandoriTracker.MODE) { + case FOOTPRINT:{ + if (DisplaySampledFootprint()) { + g.clearRect(0, 0, getWidth(), getHeight()); + BandoriTracker.displayedFootprint.draw(14,new Point(0,0),g); + BandoriTracker.displayedFootprint.draw(BandoriTracker.displayedFootprint.initial_size,new Point(32,0),g); + BandoriTracker.displayedFootprint.draw(32,new Point(64,0),g); + } else + if (BandoriTracker.footprint_img!=null) { + g.drawImage(BandoriTracker.footprint_img, 0,0, null); + } + }break; + default:{ + if (BandoriTracker.capture!=null) { + g.drawImage(BandoriTracker.capture, 0, 0, BandoriTracker.capture.getWidth()/2, BandoriTracker.capture.getHeight()/2, null); + } + } + } + } + + @Override + public void mouseClicked(MouseEvent e) { + } + + @Override + public void mousePressed(MouseEvent e) { + if (GettingFirstClick()) { + BandoriTracker.origin1 = e.getPoint(); + BandoriTracker.FOOTPRINT_MODE = ModeType.FOOTPRINT_ORIGIN2; + JOptionPane.showMessageDialog(null, "Click on ending location."); + } else + if (GettingSecondClick()) { + BandoriTracker.origin2 = e.getPoint(); + BandoriTracker.FOOTPRINT_MODE = ModeType.FOOTPRINT_CHARACTER; + BandoriTracker.ChangeCursor(Cursor.DEFAULT_CURSOR); + String input = JOptionPane.showInputDialog("What character is this representing?"); + BandoriTracker.character = input.charAt(0); + + DChar footprint = new DChar(BandoriTracker.footprint_img,BandoriTracker.character,BandoriTracker.origin1,BandoriTracker.origin2); + BandoriTracker.footprint_database.add(BandoriTracker.displayedFootprint = footprint); + BandoriTracker.FOOTPRINT_MODE = ModeType.FOOTPRINT_PRINT; + } + + //System.out.println("Clicked: "+e.getX()+","+e.getY()); + } + + @Override + public void mouseReleased(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseEntered(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseExited(MouseEvent e) { + // TODO Auto-generated method stub + + } + + boolean GettingFirstClick() { + return BandoriTracker.MODE == ModeType.FOOTPRINT && BandoriTracker.FOOTPRINT_MODE == ModeType.FOOTPRINT_ORIGIN1; + } + boolean GettingSecondClick() { + return BandoriTracker.MODE == ModeType.FOOTPRINT && BandoriTracker.FOOTPRINT_MODE == ModeType.FOOTPRINT_ORIGIN2; + } + boolean DisplaySampledFootprint() { + return BandoriTracker.MODE == ModeType.FOOTPRINT && BandoriTracker.FOOTPRINT_MODE == ModeType.FOOTPRINT_PRINT; + } +} +class UpdateEvent implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + BandoriTracker.capture = BandoriTracker.robot.createScreenCapture(new Rectangle(9+66,30+10,(int)Toolkit.getDefaultToolkit().getScreenSize().getWidth()-18-66*2,(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight()-62-10*2)); + BandoriTracker.panel.repaint(); + } +} + +class DChar { + Character character; + Point[] points; + Integer initial_size; + + DChar(Image ref_img, Character c, Point origin1, Point origin2){ + Color back_col; + this.character=c; + BufferedImage img = toBufferedImage(ref_img); + int width = origin2.x-origin1.x; + int[] pixels = img.getRGB(origin1.x, origin1.y, width, origin2.y-origin1.y, null, 0, width); + System.out.println(Arrays.toString(pixels)); + //First trim the image. + int top_height = -1; + int bottom_height = -1; + for (int j=0;j=0;j--) { + for (int i=width-1;i>=0;i--) { + if (ColorMeetsThreshold(pixels[i+j*width],25)) { + //Found bottom-most pixel. + bottom_height=j+1; + break; + } + } + if (bottom_height!=-1) { + break; + } + } + int left_width = -1; + int right_width = -1; + for (int i=0;i=0;i--) { + for (int j=pixels.length/width-1;j>=0;j--) { + if (ColorMeetsThreshold(pixels[i+j*width],25)) { + right_width=i; + break; + } + } + if (right_width!=-1) { + break; + } + } + //System.out.println("TOP:"+top_height+",BOTTOM:"+bottom_height+",LEFT:"+left_width+",RIGHT:"+right_width+". Size: "+pixels.length); + pixels = Arrays.copyOfRange(pixels, top_height*width, bottom_height*width); + int goodpixels = 0; + for (int i=0;iright_width) { + pixels[i]=Integer.MAX_VALUE; + } else { + goodpixels++; + } + } + int[] trim_pixels = new int[goodpixels]; + int goodpixelslot = 0; + for (int i=0;i pointlist = new ArrayList(); + for (int j=0;j coloredRectangles = new ArrayList(); + private Rectangle shape; + + public DrawingArea() + { + setBackground(Color.WHITE); + + MyMouseListener ml = new MyMouseListener(); + addMouseListener(ml); + addMouseMotionListener(ml); + } + + @Override + public Dimension getPreferredSize() + { + return isPreferredSizeSet() ? + super.getPreferredSize() : new Dimension(AREA_SIZE, AREA_SIZE); + } + + @Override + protected void paintComponent(Graphics g) + { + super.paintComponent(g); + + // Custom code to paint all the Rectangles from the List + + Color foreground = g.getColor(); + + g.setColor( Color.BLACK ); + g.drawString("Add a rectangle by doing mouse press, drag and release!", 40, 15); + + for (DrawingArea.ColoredRectangle cr : coloredRectangles) + { + g.setColor( cr.getForeground() ); + Rectangle r = cr.getRectangle(); + g.drawRect(r.x, r.y, r.width, r.height); + } + + // Paint the Rectangle as the mouse is being dragged + + if (shape != null) + { + Graphics2D g2d = (Graphics2D)g; + g2d.setColor( foreground ); + g2d.draw( shape ); + } + } + + public void addRectangle(Rectangle rectangle, Color color) + { + // Add the Rectangle to the List so it can be repainted + + ColoredRectangle cr = new ColoredRectangle(color, rectangle); + coloredRectangles.add( cr ); + repaint(); + } + + public void clear() + { + coloredRectangles.clear(); + repaint(); + } + + class MyMouseListener extends MouseInputAdapter + { + private Point startPoint; + + public void mousePressed(MouseEvent e) + { + startPoint = e.getPoint(); + shape = new Rectangle(); + } + + public void mouseDragged(MouseEvent e) + { + int x = Math.min(startPoint.x, e.getX()); + int y = Math.min(startPoint.y, e.getY()); + int width = Math.abs(startPoint.x - e.getX()); + int height = Math.abs(startPoint.y - e.getY()); + + shape.setBounds(x, y, width, height); + repaint(); + } + + public void mouseReleased(MouseEvent e) + { + if (shape.width != 0 || shape.height != 0) + { + addRectangle(shape, e.getComponent().getForeground()); + } + + shape = null; + } + } + + class ColoredRectangle + { + private Color foreground; + private Rectangle rectangle; + + public ColoredRectangle(Color foreground, Rectangle rectangle) + { + this.foreground = foreground; + this.rectangle = rectangle; + } + + public Color getForeground() + { + return foreground; + } + + public void setForeground(Color foreground) + { + this.foreground = foreground; + } + + public Rectangle getRectangle() + { + return rectangle; + } + } + } +} \ No newline at end of file