package panels;

import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

import frames.GameFrame;

@SuppressWarnings("serial")
public class MainMenu extends JPanel{
	BufferedImage background;
	Rectangle game1,game2;
	public MainMenu(){
		setFocusable(true);
		this.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if(game1.intersects(e.getX(), e.getY(), 1, 1)){
					new GameFrame(new spaceinvaders.panels.ContentPanel());
				}else if(game2.intersects(e.getX(), e.getY(), 1, 1)){
					new GameFrame(new bullithell.panels.ContentPanel());
				}
			}
		});
		this.addMouseMotionListener(new MouseMotionAdapter() {
			public void mouseMoved(MouseEvent e) {
				if(game1.intersects(e.getX(), e.getY(), 1, 1)){
					setCursor(new Cursor(Cursor.HAND_CURSOR));
				}else if(game2.intersects(e.getX(), e.getY(), 1, 1)){
					setCursor(new Cursor(Cursor.HAND_CURSOR));
				}else{
					setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
				}
			}
		});
		try {
			background = ImageIO.read(new File("res/mainmenu.png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		game1 = new Rectangle(91,411,469,378);
		game2 = new Rectangle(842,406,469,378);
	}
	
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		Graphics2D g2 = (Graphics2D)g;
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		g2.drawImage(background, 0, 0, null);
	}
}
